aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jsifier.js11
-rw-r--r--src/parseTools.js15
2 files changed, 19 insertions, 7 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 80d8b41f..5fcb6aa2 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -178,9 +178,6 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria
return handleSegment(segment[2].item.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.tokens);
- return '(' + handleSegment(subSegments[0]) + ' + ' + handleSegment(subSegments[1]) + ')';
} else if (segment[1].type == '{') {
// struct
var type = segment[0].text;
@@ -244,7 +241,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria
if (typeof constant === 'object') {
// This is a flattened object. We need to find its idents, so they can be assigned to later
constant.forEach(function(value, i) {
- if (value[0] in set('_', '(')) { // ident, or expression containing an ident
+ if (value[0] in set('_', '(') || value.substr(0, 14) === 'CHECK_OVERFLOW') { // ident, or expression containing an ident
ret.push({
intertype: 'GlobalVariablePostSet',
JS: 'IHEAP[' + item.ident + '+' + i + '] = ' + value + ';',
@@ -858,7 +855,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria
case 'inttoptr':
case 'ptrtoint':
return finalizeLLVMParameter(item.params[0]);
- case 'icmp': case 'mul': case 'zext': // TODO: Other mathops
+ case 'icmp': case 'mul': case 'zext': case 'add': case 'sub': case 'div':
var temp = {
op: item.intertype,
variant: item.variant,
@@ -878,8 +875,10 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria
// From parseLLVMSegment
function finalizeLLVMParameter(param) {
- if (isNumber(param) || typeof param === 'string') {
+ if (isNumber(param)) {
return param;
+ } else if (typeof param === 'string') {
+ return toNiceIdentCarefully(param);
} else if (param.intertype in PARSABLE_LLVM_FUNCTIONS) {
return finalizeLLVMFunctionCall(param);
} else if (param.intertype == 'value') {
diff --git a/src/parseTools.js b/src/parseTools.js
index 05c8fc10..5f94b5cc 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -60,6 +60,18 @@ function toNiceIdent(ident) {
return ident.replace('%', '$').replace(/["\\ \.@:<>,\*\[\]-]/g, '_');
}
+// Kind of a hack. In some cases we have strings that we do not want
+// to |toNiceIdent|, as they are the output of previous processing. We
+// should refactor everything into an object, with an explicit flag
+// saying what has been |toNiceIdent|ed. Until then, this will detect
+// simple idents that are in need of |toNiceIdent|ation. Or, we should
+// ensure that processed strings never start with %,@, e.g. by always
+// enclosing them in ().
+function toNiceIdentCarefully(ident) {
+ if (ident[0] == '%' || ident[0] == '@') ident = toNiceIdent(ident);
+ return ident;
+}
+
function isStructPointerType(type) {
// This test is necessary for clang - in llvm-gcc, we
// could check for %struct. The downside is that %1 can
@@ -161,6 +173,7 @@ function findTokenText(item, text) {
// Splits a list of tokens separated by commas. For example, a list of arguments in a function call
function splitTokenList(tokens) {
if (tokens.length == 0) return [];
+ if (!tokens.slice) tokens = tokens.tokens;
if (tokens.slice(-1)[0].text != ',') tokens.push({text:','});
var ret = [];
var seg = [];
@@ -318,7 +331,7 @@ function cleanSegment(segment) {
return segment;
}
-PARSABLE_LLVM_FUNCTIONS = set('getelementptr', 'bitcast', 'inttoptr', 'ptrtoint', 'mul', 'icmp', 'zext');
+PARSABLE_LLVM_FUNCTIONS = set('getelementptr', 'bitcast', 'inttoptr', 'ptrtoint', 'mul', 'icmp', 'zext', 'sub', 'add', 'div');
// Parses a function call of form
// TYPE functionname MODIFIERS (...)