diff options
Diffstat (limited to 'src/parseTools.js')
-rw-r--r-- | src/parseTools.js | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/src/parseTools.js b/src/parseTools.js index 6e0d6e32..6a2089ad 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -78,6 +78,7 @@ function toNiceIdent(ident) { assert(ident); if (parseFloat(ident) == ident) return ident; if (ident == 'null') return '0'; // see parseNumerical + if (ident == 'undef') return '0'; return ident.replace('%', '$').replace(/["&\\ \.@:<>,\*\[\]\(\)-]/g, '_'); } @@ -984,18 +985,24 @@ function checkSafeHeap() { function getHeapOffset(offset, type, forceAsm) { if (USE_TYPED_ARRAYS !== 2) { return offset; - } else { - if (Runtime.getNativeFieldSize(type) > 4) { - type = 'i32'; // XXX we emulate 64-bit values as 32 - } - var shifts = Math.log(Runtime.getNativeTypeSize(type))/Math.LN2; - offset = '(' + offset + ')'; - if (shifts != 0) { - return '(' + offset + '>>' + shifts + ')'; + } + + if (Runtime.getNativeFieldSize(type) > 4) { + type = 'i32'; // XXX we emulate 64-bit values as 32 + } + + var sz = Runtime.getNativeTypeSize(type); + var shifts = Math.log(sz)/Math.LN2; + offset = '(' + offset + ')'; + if (shifts != 0) { + if (CHECK_HEAP_ALIGN) { + return '(CHECK_ALIGN_' + sz + '(' + offset + ')>>' + shifts + ')'; } else { - // we need to guard against overflows here, HEAP[U]8 expects a guaranteed int - return isJSVar(offset) ? offset : '(' + offset + '|0)'; + return '(' + offset + '>>' + shifts + ')'; } + } else { + // we need to guard against overflows here, HEAP[U]8 expects a guaranteed int + return isJSVar(offset) ? offset : '(' + offset + '|0)'; } } @@ -1364,11 +1371,15 @@ var TWO_TWENTY = Math.pow(2, 20); function getFastValue(a, op, b, type) { a = a.toString(); b = b.toString(); + a = a == 'true' ? '1' : (a == 'false' ? '0' : a); + b = b == 'true' ? '1' : (b == 'false' ? '0' : b); if (isNumber(a) && isNumber(b)) { if (op == 'pow') { return Math.pow(a, b).toString(); } else { - return eval(a + op + '(' + b + ')').toString(); // parens protect us from "5 - -12" being seen as "5--12" which is "(5--)12" + var value = eval(a + op + '(' + b + ')'); // parens protect us from "5 - -12" being seen as "5--12" which is "(5--)12" + if (op == '/' && type in Runtime.INT_TYPES) value = value|0; // avoid emitting floats + return value.toString(); } } if (op == 'pow') { @@ -1829,9 +1840,10 @@ function makeSignOp(value, type, op, force, ignore) { if (!CHECK_SIGNS || ignore) { if (bits === 32) { if (op === 're') { - return '((' + value + ')|0)'; + return '(' + getFastValue(value, '|', '0') + ')'; } else { - return '((' + value + ')>>>0)'; + + return '(' + getFastValue(value, '>>>', '0') + ')'; // Alternatively, we can consider the lengthier // return makeInlineCalculation('VALUE >= 0 ? VALUE : ' + Math.pow(2, bits) + ' + VALUE', value, 'tempBigInt'); // which does not always turn us into a 32-bit *un*signed value @@ -1840,7 +1852,7 @@ function makeSignOp(value, type, op, force, ignore) { if (op === 're') { return makeInlineCalculation('(VALUE << ' + (32-bits) + ') >> ' + (32-bits), value, 'tempInt'); } else { - return '((' + value + ')&' + (Math.pow(2, bits)-1) + ')'; + return '(' + getFastValue(value, '&', Math.pow(2, bits)-1) + ')'; } } else { // bits > 32 if (op === 're') { |