diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-11-26 21:14:00 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-11-26 21:14:00 -0800 |
commit | 81f82a6a0dd932344027a408ff7bf905de1d2e52 (patch) | |
tree | 9adc497b6b30f205f3ba25f03d92f81ff3eeed62 | |
parent | 3338428a606b6a0bd2fe71d915cc2e95b373ee1f (diff) |
fixes for 64-bit values in globals in i64 mode 1
-rw-r--r-- | src/jsifier.js | 34 | ||||
-rw-r--r-- | src/parseTools.js | 14 | ||||
-rw-r--r-- | tests/runner.py | 16 |
3 files changed, 53 insertions, 11 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index c6a58148..fc961351 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -117,24 +117,38 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { function alignStruct(values, type) { var typeData = Types.types[type]; assertTrue(typeData); - var ret = []; - var i = 0, soFar = 0; + var ret = new Array(typeData.flatSize); + var index = 0; + var i = 0; while (i < values.length) { // Pad until the right place var padded = typeData.flatFactor ? typeData.flatFactor*i : typeData.flatIndexes[i]; - while (soFar < padded) { - ret.push(0); - soFar++; + while (index < padded) { + ret[index++] = 0; } // Add current value(s) var currValue = flatten(values[i]); - ret.push(currValue); + if (I64_MODE == 1 && typeData.fields[i] == 'i64') { + // 'flatten' out the 64-bit value into two 32-bit halves + ret[index++] = currValue + '>>>0'; + ret[index++] = 0; + ret[index++] = 0; + ret[index++] = 0; + ret[index++] = 'Math.floor(' + currValue + '/4294967296)'; + ret[index++] = 0; + ret[index++] = 0; + ret[index++] = 0; + } else if (typeof currValue == 'object') { + for (var j = 0; j < currValue.length; j++) { + ret[index++] = currValue[j]; + } + } else { + ret[index++] = currValue; + } i += 1; - soFar += typeof currValue === 'object' ? currValue.length : 1; } - while (soFar < typeData.flatSize) { - ret.push(0); - soFar++; + while (index < typeData.flatSize) { + ret[index++] = 0; } return ret; } diff --git a/src/parseTools.js b/src/parseTools.js index 7060dc3e..9d4b48d2 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -785,6 +785,9 @@ function calcAllocatedSize(type) { function generateStructTypes(type) { if (isArray(type)) return type; // already in the form of [type, type,...] if (Runtime.isNumberType(type) || isPointerType(type)) { + if (I64_MODE == 1 && type == 'i64') { + return ['i64', 0, 0, 0, 'i32', 0, 0, 0]; + } return [type].concat(zeros(getNativeFieldSize(type))); } @@ -798,6 +801,17 @@ function generateStructTypes(type) { for (var i = 0; i < typeData.fields.length; i++) { var type = typeData.fields[i]; if (Runtime.isNumberType(type) || isPointerType(type)) { + if (I64_MODE == 1 && type == 'i64') { + ret[index++] = 'i64'; + ret[index++] = 0; + ret[index++] = 0; + ret[index++] = 0; + ret[index++] = 'i32'; + ret[index++] = 0; + ret[index++] = 0; + ret[index++] = 0; + continue; + } ret[index++] = type; } else { add(Types.types[type]); diff --git a/tests/runner.py b/tests/runner.py index f08c747b..884c0b94 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -426,6 +426,16 @@ if 'benchmark' not in str(sys.argv): return x < 3; } + struct IUB { + int c; + long long d; + }; + + IUB iub[] = { + { 55, 17179869184 }, + { 122, 25769803776 }, + }; + int main() { int64_t x1 = 0x1234def123450789ULL; @@ -446,6 +456,9 @@ if 'benchmark' not in str(sys.argv): modifier2(t); printf("*%Ld*\n", t); + // global structs with i64s + printf("*%d,%Ld*\n*%d,%Ld*\n", iub[0].c, iub[0].d, iub[1].c, iub[1].d); + // Basic (rounded, for now) math. Just check compilation. int64_t a = 0x1234def123450789ULL; a--; if (truthy()) a--; // confuse optimizer @@ -458,7 +471,8 @@ if 'benchmark' not in str(sys.argv): ''' self.do_run(src, '*1311918518731868200\n0,0,0,1,1\n1,0,1,0,1*\n*245127260211081*\n*245127260209443*\n' + '*18446744073709552000*\n*576460752303423500*\n' + - 'm1: 127\n*123*\n*127*\n') + 'm1: 127\n*123*\n*127*\n' + + '*55,17179869184*\n*122,25769803776*\n') Settings.CORRECT_SIGNS = 1 |