diff options
author | Alon Zakai <azakai@mozilla.com> | 2010-12-07 21:54:29 -0800 |
---|---|---|
committer | Alon Zakai <azakai@mozilla.com> | 2010-12-07 21:54:29 -0800 |
commit | 023a34753e1e47f03eadfd91a7e639afbbead888 (patch) | |
tree | 966cd52abcd970bf1c58a6e5ec1b59e09480654b /src | |
parent | 78b2976bcbbb7e0e36a60bd643adefc1226a09a6 (diff) |
fix a few bugs related to highly-nested structs
Diffstat (limited to 'src')
-rw-r--r-- | src/jsifier.js | 18 | ||||
-rw-r--r-- | src/utility.js | 9 |
2 files changed, 16 insertions, 11 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index aadc021c..e5ab6b4c 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -137,11 +137,15 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) { soFar++; } // Add current value(s) - var currValue = values[i]; + var currValue = flatten(values[i]); ret.push(currValue); i += 1; soFar += typeof currValue === 'object' ? currValue.length : 1; } + while (soFar < typeData.flatSize) { + ret.push(0); + soFar++; + } return ret; } @@ -215,14 +219,6 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) { function parseConst(value, type, ident) { var constant = makeConst(value, type); if (typeof constant === 'object') { - function flatten(x) { - if (typeof x !== 'object') return x; - var ret = []; - for (var i = 0; i < x.length; i++) { - ret = ret.concat(flatten(x[i])); - } - return ret; - } constant = flatten(constant).map(function(x) { return parseNumerical(x) }) } return constant; @@ -863,12 +859,12 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) { function finalizeLLVMFunctionCall(item) { switch(item.intertype) { - case 'getelementptr': + case 'getelementptr': // XXX finalizeLLVMParameter on the ident and the indexes? return makePointer(makeGetSlab(item.ident, item.type), getGetElementPtrIndexes(item), null, item.type); case 'bitcast': case 'inttoptr': case 'ptrtoint': - return item.ident; + return finalizeLLVMParameter(item.params[0]); default: throw 'Invalid function to finalize: ' + dump(item); } diff --git a/src/utility.js b/src/utility.js index 5020c911..68fab711 100644 --- a/src/utility.js +++ b/src/utility.js @@ -227,3 +227,12 @@ function isNumber(x) { return x == parseFloat(x); } +function flatten(x) { + if (typeof x !== 'object') return x; + var ret = []; + for (var i = 0; i < x.length; i++) { + ret = ret.concat(flatten(x[i])); + } + return ret; +} + |