aboutsummaryrefslogtreecommitdiff
path: root/src/parseTools.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-07-03 15:50:45 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-07-03 15:50:45 -0700
commitdea79e5f6113e2f7c3152cea463b8c0ab948eefd (patch)
treefe7ce36778f4b818141c15cc5fc7a658000d019f /src/parseTools.js
parent0774a0acf974a7ef87bd1dfc19e06150611703c7 (diff)
parse i64-to-ptr conversions of constants at compile time
Diffstat (limited to 'src/parseTools.js')
-rw-r--r--src/parseTools.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index 68f61fa0..dfd4b7ed 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -2147,7 +2147,11 @@ function processMathop(item) {
}
case 'select': return idents[0] + ' ? ' + makeCopyI64(idents[1]) + ' : ' + makeCopyI64(idents[2]);
case 'ptrtoint': return makeI64(idents[0], 0);
- case 'inttoptr': return '(' + idents[0] + '[0])'; // just directly truncate the i64 to a 'pointer', which is an i32
+ case 'inttoptr': {
+ var m = /\(?\[(\d+),\d+\]\)?/.exec(idents[0]);
+ if (m) return m[1]; // constant, can just parse it right now
+ return '(' + idents[0] + '[0])'; // just directly truncate the i64 to a 'pointer', which is an i32
+ }
// Dangerous, rounded operations. TODO: Fully emulate
case 'add': {
if (PRECISE_I64_MATH) {