aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/intertyper.js2
-rw-r--r--src/jsifier.js22
-rw-r--r--src/parseTools.js11
-rw-r--r--tests/runner.py2
4 files changed, 28 insertions, 9 deletions
diff --git a/src/intertyper.js b/src/intertyper.js
index 9b7ebe06..7e071935 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -609,7 +609,7 @@ function intertyper(data, parseFunctions, baseLineNum) {
item.intertype = 'mathop';
item.op = item.tokens[0].text;
item.variant = null;
- if (item.tokens[1].text == 'nsw') item.tokens.splice(1, 1);
+ while (item.tokens[1].text in set('nsw', 'nuw')) item.tokens.splice(1, 1);
if (['icmp', 'fcmp'].indexOf(item.op) != -1) {
item.variant = item.tokens[1].text;
item.tokens.splice(1, 1);
diff --git a/src/jsifier.js b/src/jsifier.js
index 4a65d927..f4565bcc 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -515,7 +515,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) {
// Function lines
function makeFuncLineActor(intertype, func) {
- substrate.addActor('Intertype:' + intertype, {
+ return substrate.addActor('Intertype:' + intertype, {
processItem: function(item) {
item.JS = func(item);
if (!item.JS) throw "XXX - no JS generated for " + dump(item);
@@ -697,7 +697,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) {
}
}
- makeFuncLineActor('mathop', function(item) { with(item) {
+ var mathop = makeFuncLineActor('mathop', function(item) { with(item) {
for (var i = 1; i <= 4; i++) {
if (item['param'+i]) {
item['ident'+i] = indexizeFunctions(finalizeLLVMParameter(item['param'+i]));
@@ -878,14 +878,28 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) {
case 'inttoptr':
case 'ptrtoint':
return finalizeLLVMParameter(item.params[0]);
+ case 'icmp': case 'mul': case 'zext': // TODO: Other mathops
+ var temp = {
+ op: item.intertype,
+ variant: item.variant
+ };
+ for (var i = 1; i <= 4; i++) {
+ if (item.params[i-1]) {
+ temp['param' + i] = finalizeLLVMParameter(item.params[i-1]);
+ }
+ }
+ mathop.processItem(temp);
+ return temp.JS;
default:
- throw 'Invalid function to finalize: ' + dump(item);
+ throw 'Invalid function to finalize: ' + dump(item.intertype);
}
}
// From parseLLVMSegment
function finalizeLLVMParameter(param) {
- if (param.intertype in PARSABLE_LLVM_FUNCTIONS) {
+ if (isNumber(param) || typeof param === 'string') {
+ return param;
+ } else if (param.intertype in PARSABLE_LLVM_FUNCTIONS) {
return finalizeLLVMFunctionCall(param);
} else if (param.intertype == 'value') {
return parseNumerical(param.ident);
diff --git a/src/parseTools.js b/src/parseTools.js
index fa8b6ac6..58b1ed71 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -317,7 +317,7 @@ function cleanSegment(segment) {
return segment;
}
-PARSABLE_LLVM_FUNCTIONS = searchable('getelementptr', 'bitcast', 'inttoptr', 'ptrtoint');
+PARSABLE_LLVM_FUNCTIONS = searchable('getelementptr', 'bitcast', 'inttoptr', 'ptrtoint', 'mul', 'icmp', 'zext');
// Parses a function call of form
// TYPE functionname MODIFIERS (...)
@@ -327,13 +327,20 @@ function parseLLVMFunctionCall(segment) {
segment = segment.slice(0);
segment = cleanSegment(segment);
// Remove additional modifiers
+ var variant = null;
if (!segment[2] || !segment[2].item) {
- segment.splice(2, 1);
+ variant = segment.splice(2, 1)[0];
+ if (variant && variant.text) variant = variant.text; // needed for mathops
}
assertTrue(['inreg', 'byval'].indexOf(segment[1].text) == -1);
assert(segment[1].text in PARSABLE_LLVM_FUNCTIONS);
+ while (!segment[2].item) {
+ segment.splice(2, 1); // XXX Remove modifiers - should look into them some day
+ if (!segment[2]) throw 'Invalid segment!';
+ }
var ret = {
intertype: segment[1].text,
+ variant: variant,
type: segment[0].text,
params: parseParamTokens(segment[2].item.tokens)
};
diff --git a/tests/runner.py b/tests/runner.py
index a9786117..8b9be185 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -836,7 +836,6 @@ if 'benchmark' not in sys.argv:
def test_pystruct(self):
if COMPILER != LLVM_GCC: return # TODO: Clang here
- if LLVM_OPTS: return # TODO: fix
src = '''
#include <stdio.h>
@@ -1173,7 +1172,6 @@ if 'benchmark' not in sys.argv:
self.do_test(src, '*0.00,0.00,0.00*')
def test_nestedstructs(self):
- if LLVM_OPTS: return # FIXME
src = '''
#include <stdio.h>
#include "emscripten.h"