aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/intertyper.js6
-rw-r--r--src/jsifier.js40
-rw-r--r--src/parseTools.js10
3 files changed, 29 insertions, 27 deletions
diff --git a/src/intertyper.js b/src/intertyper.js
index 8fb15654..22a953f1 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -340,7 +340,7 @@ function intertyper(data) {
item.type = { text: removePointing(item.pointerType.text) };
if (item.tokens[2].text == 'getelementptr') {
var last = getTokenIndexByText(item.tokens, ';');
- var data = parseFunctionCall(item.tokens.slice(1, last));
+ var data = parseLLVMFunctionCall(item.tokens.slice(1, last));
item.intertype = 'fastgetelementptrload';
item.type = data.type;
item.params = data.params;
@@ -378,7 +378,7 @@ function intertyper(data) {
var segment = [ item.tokens[first], { text: 'getelementptr' }, null, { item: [ {
tokens: item.tokens.slice(first, last)
} ] } ];
- var data = parseFunctionCall(segment);
+ var data = parseLLVMFunctionCall(segment);
item.intertype = 'getelementptr';
item.type = data.type;
item.params = data.params;
@@ -496,7 +496,7 @@ function intertyper(data) {
__result__: true,
intertype: 'store',
valueType: item.tokens[1],
- value: commaIndex == 3 ? addIdent(item.tokens[2]) : parseFunctionCall(item.tokens.slice(1, commaIndex)),
+ value: commaIndex == 3 ? addIdent(item.tokens[2]) : parseLLVMFunctionCall(item.tokens.slice(1, commaIndex)),
pointerType: item.tokens[commaIndex+1],
pointer: item.tokens[commaIndex+2],
ident: item.tokens[commaIndex+2].text,
diff --git a/src/jsifier.js b/src/jsifier.js
index f3e1d54e..39bb87e6 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -113,11 +113,11 @@ function JSify(data) {
return '0';
} else if (segment[1].text == 'zeroinitializer') {
return JSON.stringify(makeEmptyStruct(segment[0].text));
- } else if (segment[1].text == 'getelementptr') {
- return finalizeGetElementPtr(parseFunctionCall(segment));
- } else if (segment[1].text in searchable('bitcast', 'inttoptr', 'ptrtoint')) {
+ } else if (segment[1].text in searchable('bitcast', 'inttoptr', 'ptrtoint')) { // TODO: Use parse/finalizeLLVMFunctionCall
var type = segment[2].item[0].tokens.slice(-1)[0].text; // TODO: Use this?
return handleSegment(segment[2].item[0].tokens.slice(0, -2));
+ } else if (segment[1].text in PARSABLE_LLVM_FUNCTIONS) {
+ return finalizeLLVMFunctionCall(parseLLVMFunctionCall(segment));
} else if (segment[1].text == 'add') {
var subSegments = splitTokenList(segment[2].item[0].tokens);
return '(' + handleSegment(subSegments[0]) + ' + ' + handleSegment(subSegments[1]) + ')';
@@ -388,8 +388,8 @@ function JSify(data) {
//print('// zzqqzz ' + dump(item.value) + ' :::: ' + dump(item.pointer) + ' :::: ');
var ident = toNiceIdent(item.ident);
var value;
- if (item.value.intertype == 'getelementptr') {
- value = finalizeGetElementPtr(item.value);
+ if (item.value.intertype in PARSABLE_LLVM_FUNCTIONS) {
+ value = finalizeLLVMFunctionCall(item.value);
} else {
value = toNiceIdent(item.value.ident);
}
@@ -627,14 +627,17 @@ function JSify(data) {
return indexes.join('+');
}
- function finalizeGetElementPtr(item) {
- // TODO: statically combine indexes here if consts
- return makePointer(makeGetSlab(item.ident), getGetElementPtrIndexes(item));
- }
-
- function finalizeBitcast(item) {
- //print('//zz finalizeBC: ' + dump(item));
- return item.ident;
+ function finalizeLLVMFunctionCall(item) {
+ switch(item.intertype) {
+ case 'getelementptr':
+ return makePointer(makeGetSlab(item.ident), getGetElementPtrIndexes(item));
+ case 'bitcast':
+ case 'inttoptr':
+ case 'ptrtoint':
+ return item.ident;
+ default:
+ throw 'Invalid function to finalize: ' + dump(item);
+ }
}
makeFuncLineZyme('bitcast', function(item) {
@@ -643,6 +646,7 @@ function JSify(data) {
var ident = toNiceIdent(item.ident);
return ident;
});
+
function makeFunctionCall(ident, params) {
// Special cases
if (ident == '_llvm_va_start') {
@@ -658,17 +662,15 @@ function JSify(data) {
}
var params = params.map(function(param) {
- if (param.intertype === 'getelementptr') {
- return finalizeGetElementPtr(param);
- } else if (param.intertype === 'bitcast') {
- return finalizeBitcast(param);
+ if (param.intertype in PARSABLE_LLVM_FUNCTIONS) {
+ return finalizeLLVMFunctionCall(param);
} else {
- return toNiceIdent(param.ident); //.value;//'??arg ' + param.intertype + '??';
+ return toNiceIdent(param.ident);
}
});
return ident + '(' + params.join(', ') + ')';
}
- makeFuncLineZyme('getelementptr', function(item) { return finalizeGetElementPtr(item) });
+ makeFuncLineZyme('getelementptr', function(item) { return finalizeLLVMFunctionCall(item) });
makeFuncLineZyme('call', function(item) {
return makeFunctionCall(item.ident, item.params) + (item.standalone ? ';' : '');
});
diff --git a/src/parseTools.js b/src/parseTools.js
index 3d5a6f06..d27ef071 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -241,8 +241,8 @@ function parseParamTokens(params) {
ident: '_' + absIndex,
});
}
- } else if (segment[1].text in PARSABLE_FUNCTIONS) {
- ret.push(parseFunctionCall(segment));
+ } else if (segment[1].text in PARSABLE_LLVM_FUNCTIONS) {
+ ret.push(parseLLVMFunctionCall(segment));
} else {
if (segment[2] && segment[2].text == 'to') { // part of bitcast params
segment = segment.slice(0, 2);
@@ -273,13 +273,13 @@ function cleanSegment(segment) {
return segment;
}
-PARSABLE_FUNCTIONS = searchable('getelementptr', 'bitcast');
+PARSABLE_LLVM_FUNCTIONS = searchable('getelementptr', 'bitcast', 'inttoptr', 'ptrtoint');
// Parses a function call of form
// TYPE functionname MODIFIERS (...)
// e.g.
// i32* getelementptr inbounds (...)
-function parseFunctionCall(segment) {
+function parseLLVMFunctionCall(segment) {
segment = segment.slice(0);
segment = cleanSegment(segment);
// Remove additional modifiers
@@ -287,7 +287,7 @@ function parseFunctionCall(segment) {
segment.splice(2, 1);
}
assertTrue(['inreg', 'byval'].indexOf(segment[1].text) == -1);
- assert(segment[1].text in PARSABLE_FUNCTIONS);
+ assert(segment[1].text in PARSABLE_LLVM_FUNCTIONS);
var ret = {
intertype: segment[1].text,
type: segment[0],