aboutsummaryrefslogtreecommitdiff
path: root/src/parseTools.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-04-04 17:26:59 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-04-04 17:26:59 -0700
commit6bf571940d90914453b820153f7f2e2dd5c26e21 (patch)
treed2824baa8167b2871d725306b04bc60eb33c2363 /src/parseTools.js
parent783a1be067b07e311622c8f3263e6e69dc08856e (diff)
refactor slab writing in makePointer
Diffstat (limited to 'src/parseTools.js')
-rw-r--r--src/parseTools.js69
1 files changed, 36 insertions, 33 deletions
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';
}