diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-05-25 13:12:21 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-05-25 13:12:21 -0700 |
commit | e1b8b28863ee7fea3117d0d10d7ab0a679dfb8ca (patch) | |
tree | 46e8d536ebe4093e3554d6ed93859d03ce6489b0 | |
parent | 2f07663738e2441a14b941e90495fe0c74f33fd0 (diff) |
shortcut for 32 bit unSign
-rw-r--r-- | src/parseTools.js | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/parseTools.js b/src/parseTools.js index 03b88c0f..a2f946bc 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -81,6 +81,16 @@ function toNiceIdentCarefully(ident) { return ident; } +// Returns true if ident is a niceIdent (see toNiceIdent). If loose +// is true, then also allow () and spaces. +function isNiceIdent(ident, loose) { + if (loose) { + return /^[\w$_ ()]+$/.test(ident); + } else { + return /^[\w$_]+$/.test(ident); + } +} + function isStructPointerType(type) { // This test is necessary for clang - in llvm-gcc, we // could check for %struct. The downside is that %1 can @@ -852,7 +862,7 @@ function finalizeLLVMParameter(param) { } } -function makeSignOp(value, type, op) { // TODO: If value isNumber, do this at compile time +function makeSignOp(value, type, op) { if (!value) return value; if (!correctSigns() && !CHECK_SIGNS) return value; if (type in Runtime.INT_TYPES) { @@ -866,7 +876,11 @@ function makeSignOp(value, type, op) { // TODO: If value isNumber, do this at co if (op === 're') { return '((' + value + ')|0)'; } else { - // TODO: figure out something here along the lines of return '(' + Math.pow(2, 32) + '+((' + value + ')|0))'; + // If this is an ident, we can shortcut. If not, our shortcut could + // lead to multiple evaluation, so give up + if (isNiceIdent(value, true)) { + return '(' + value + ' >= 0 ? ' + value + ' : (' + value + '+' + (2*Math.abs(1 << 31)) + '))'; + } } } return op + 'Sign(' + value + ', ' + bits + ', ' + Math.floor(correctSpecificSign()) + ')'; // If we are correcting a specific sign here, do not check for it |