aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/jsifier.js18
-rw-r--r--src/parseTools.js69
2 files changed, 52 insertions, 35 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 4ad5a76c..f22d3d88 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1499,16 +1499,30 @@ function JSify(data, functionsOnly, givenFunctions) {
}
}
var generated = itemsDict.function.concat(itemsDict.type).concat(itemsDict.GlobalVariableStub).concat(itemsDict.GlobalVariable);
- if (!DEBUG_MEMORY) print(generated.map(function(item) { return item.JS }).join('\n'));
+ print(generated.map(function(item) { return item.JS }).join('\n'));
if (phase == 'pre') {
if (memoryInitialization.length > 0) {
+ /*
+ // apply postsets directly into the big memory initialization
+ itemsDict.GlobalVariablePostSet = itemsDict.GlobalVariablePostSet.filter(function(item) {
+ var m
+ if (m = /^HEAPU?(\d+)\[([()>\d]+)\] *= *([()|\d]+);?$/.exec(item.JS)) {
+ var bits = +m[1];
+ var target = eval(m[2]) << log2(bits/8);
+ var value = eval(m[3]);
+ writeInt8s(memoryInitialization, target - TOTAL_STACK, value, 'i' + bits); // XXX floats
+ return false;
+ }
+ return true;
+ });
+ */
// write out the singleton big memory initialization value
print('/* memory initializer */ ' + makePointer(memoryInitialization, null, 'ALLOC_NONE', 'i8', 'TOTAL_STACK', true)); // we assert on TOTAL_STACK == GLOBAL_BASE
}
}
- if (!DEBUG_MEMORY) print(itemsDict.GlobalVariablePostSet.map(function(item) { return item.JS }).join('\n'));
+ print(itemsDict.GlobalVariablePostSet.map(function(item) { return item.JS }).join('\n'));
return;
}
diff --git a/src/parseTools.js b/src/parseTools.js
index cec9afb3..a3b6f79c 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -1457,8 +1457,43 @@ function makeGetPos(ptr) {
var IHEAP_FHEAP = set('IHEAP', 'IHEAPU', 'FHEAP');
+var temp64f = new Float64Array(1);
+var temp32f = new Float32Array(temp64f.buffer);
+var temp32 = new Uint32Array(temp64f.buffer);
+var temp16 = new Uint16Array(temp64f.buffer);
+var temp8 = new Uint8Array(temp64f.buffer);
var memoryInitialization = [];
+function writeInt8s(slab, i, value, type) {
+ var currSize;
+ switch (type) {
+ case 'i1':
+ case 'i8': temp8[0] = value; currSize = 1; break;
+ case 'i16': temp16[0] = value; currSize = 2; break;
+ case 'i64': // fall through, i64 is two i32 chunks
+ case 'i32': temp32[0] = value; currSize = 4; break;
+ case 'float': temp32f[0] = value; currSize = 4; break;
+ case 'double': temp64f[0] = value; currSize = 8; break;
+ default: {
+ if (type[type.length-1] == '*') {
+ if (!isNumber(value)) { // function table stuff, etc.
+ slab[i] = value;
+ slab[i+1] = slab[i+2] = slab[i+3] = 0;
+ return 4;
+ }
+ temp32[0] = value;
+ currSize = 4;
+ } else {
+ throw 'what? ' + types[i];
+ }
+ }
+ }
+ for (var j = 0; j < currSize; j++) {
+ slab[i+j] = temp8[j];
+ }
+ return currSize;
+}
+
function makePointer(slab, pos, allocator, type, ptr, finalMemoryInitialization) {
assert(type, 'makePointer requires type info');
if (typeof slab == 'string' && (slab.substr(0, 4) === 'HEAP' || (USE_TYPED_ARRAYS == 1 && slab in IHEAP_FHEAP))) return pos;
@@ -1500,42 +1535,10 @@ function makePointer(slab, pos, allocator, type, ptr, finalMemoryInitialization)
} else { // USE_TYPED_ARRAYS == 2
// XXX This heavily assumes the target endianness is the same as our current endianness! XXX
var i = 0;
- var temp64f = new Float64Array(1);
- var temp32f = new Float32Array(temp64f.buffer);
- var temp32 = new Uint32Array(temp64f.buffer);
- var temp16 = new Uint16Array(temp64f.buffer);
- var temp8 = new Uint8Array(temp64f.buffer);
while (i < slab.length) {
var currType = types[i];
if (!currType) { i++; continue }
- var currSize = 0, currValue = slab[i];
- switch (currType) {
- case 'i1':
- case 'i8': i++; continue;
- case 'i16': temp16[0] = currValue; currSize = 2; break;
- case 'i64': // fall through, i64 is two i32 chunks
- case 'i32': temp32[0] = currValue; currSize = 4; break;
- case 'float': temp32f[0] = currValue; currSize = 4; break;
- case 'double': temp64f[0] = currValue; currSize = 8; break;
- default: {
- if (currType[currType.length-1] == '*') {
- if (!isNumber(currValue)) { // function table stuff, etc.
- slab[i] = currValue;
- slab[i+1] = slab[i+2] = slab[i+3] = 0;
- i += 4;
- continue;
- }
- temp32[0] = currValue;
- currSize = 4;
- } else {
- throw 'what? ' + types[i];
- }
- }
- }
- for (var j = 0; j < currSize; j++) {
- slab[i+j] = temp8[j];
- }
- i += currSize;
+ i += writeInt8s(slab, i, slab[i], currType);
}
types = 'i8';
}