aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-07-01 07:51:10 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-07-01 07:51:10 -0700
commit1c1d291964d025845228e5e8b985aec066bf79d2 (patch)
treec187be177043d0cec12d8f730d8b98ea6da56d1b /src
parent7d8e65edda5d330787c35a3d9f9aef3ba660d2c2 (diff)
handle complex expressions in br. fixes issue 39
Diffstat (limited to 'src')
-rw-r--r--src/intertyper.js7
-rw-r--r--src/jsifier.js7
-rw-r--r--src/parseTools.js12
3 files changed, 15 insertions, 11 deletions
diff --git a/src/intertyper.js b/src/intertyper.js
index 715b6fa4..972b5de6 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -715,11 +715,12 @@ function intertyper(data, parseFunctions, baseLineNum) {
lineNum: item.lineNum
}];
} else {
+ var commaIndex = findTokenText(item, ',');
return [{
intertype: 'branch',
- ident: toNiceIdent(item.tokens[2].text),
- labelTrue: toNiceIdent(item.tokens[5].text),
- labelFalse: toNiceIdent(item.tokens[8].text),
+ condition: parseLLVMSegment(item.tokens.slice(1, commaIndex)),
+ labelTrue: toNiceIdent(item.tokens[commaIndex+2].text),
+ labelFalse: toNiceIdent(item.tokens[commaIndex+5].text),
lineNum: item.lineNum
}];
}
diff --git a/src/jsifier.js b/src/jsifier.js
index 7784c1ab..1b83b991 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -606,14 +606,15 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
makeFuncLineActor('branch', function(item) {
if (item.stolen) return ';'; // We will appear where we were stolen to
- if (!item.ident) {
+ if (!item.condition) {
return makeBranch(item.label, item.currLabelId);
} else {
+ var condition = finalizeLLVMParameter(item.condition);
var labelTrue = makeBranch(item.labelTrue, item.currLabelId);
var labelFalse = makeBranch(item.labelFalse, item.currLabelId);
if (labelTrue == ';' && labelFalse == ';') return ';';
- var head = 'if (' + item.ident + ') { ';
- var head2 = 'if (!(' + item.ident + ')) { ';
+ var head = 'if (' + condition + ') { ';
+ var head2 = 'if (!(' + condition + ')) { ';
var else_ = ' } else { ';
var tail = ' }';
if (labelTrue == ';') {
diff --git a/src/parseTools.js b/src/parseTools.js
index debfb6da..8c8389fb 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -953,7 +953,7 @@ function finalizeLLVMFunctionCall(item) {
};
for (var i = 1; i <= 4; i++) {
if (item.params[i-1]) {
- temp['param' + i] = finalizeLLVMParameter(item.params[i-1]);
+ temp['param' + i] = item.params[i-1];
}
}
return processMathop(temp);
@@ -1106,8 +1106,10 @@ function isSignedOp(op, variant) {
}
function processMathop(item) { with(item) {
+ var paramTypes = ['', '', '', ''];
for (var i = 1; i <= 4; i++) {
if (item['param'+i]) {
+ paramTypes[i-1] = item['param'+i].type || type;
item['ident'+i] = finalizeLLVMParameter(item['param'+i]);
if (!isNumber(item['ident'+i])) {
item['ident'+i] = '(' + item['ident'+i] + ')'; // we may have nested expressions. So enforce the order of operations we want
@@ -1117,11 +1119,11 @@ function processMathop(item) { with(item) {
}
}
if (isUnsignedOp(op, variant)) {
- ident1 = makeSignOp(ident1, type, 'un');
- ident2 = makeSignOp(ident2, type, 'un');
+ ident1 = makeSignOp(ident1, paramTypes[0], 'un');
+ ident2 = makeSignOp(ident2, paramTypes[1], 'un');
} else if (isSignedOp(op, variant)) {
- ident1 = makeSignOp(ident1, type, 're');
- ident2 = makeSignOp(ident2, type, 're');
+ ident1 = makeSignOp(ident1, paramTypes[0], 're');
+ ident2 = makeSignOp(ident2, paramTypes[1], 're');
}
var bits = null;
if (item.type[0] === 'i') {