aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2010-12-29 21:33:56 -0800
committerAlon Zakai <azakai@mozilla.com>2010-12-29 21:33:56 -0800
commit091b6d662ee1e80dedc7d779d2b892acc95f7837 (patch)
treef77c64f2aa041a8bba42163f056412fe24396a83
parent1b7500b59c2a087850f06d36e41b17fb58435e62 (diff)
better slab selection with type info
-rw-r--r--src/intertyper.js2
-rw-r--r--src/jsifier.js17
-rw-r--r--src/parseTools.js11
3 files changed, 19 insertions, 11 deletions
diff --git a/src/intertyper.js b/src/intertyper.js
index 92276ce3..bf51cd8e 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -502,7 +502,7 @@ function intertyper(data, parseFunctions, baseLineNum) {
} } ];
var data = parseLLVMFunctionCall(segment);
item.intertype = 'getelementptr';
- item.type = '?'; // We need type info to determine this
+ item.type = '*'; // We need type info to determine this - all we know is it's a pointer
item.params = data.params;
item.ident = data.ident;
this.forwardItem(item, 'Reintegrator');
diff --git a/src/jsifier.js b/src/jsifier.js
index 4c0b1974..ba6cc232 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -47,17 +47,18 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria
return 'Pointer_make(' + slab + ', ' + (pos ? pos : 0) + (allocator ? ', ' + allocator : '') + ')';
}
- function makeGetSlab(ptr, type) {
+ function makeGetSlabs(ptr, type, allowMultiple) {
assert(type);
if (!USE_TYPED_ARRAYS) {
- return 'HEAP';
+ return ['HEAP'];
} else {
if (type in Runtime.FLOAT_TYPES || type === 'int64') {
- return 'FHEAP';
+ return ['FHEAP'];
} else if (type in Runtime.INT_TYPES || isPointerType(type)) {
- return 'IHEAP';
+ return ['IHEAP'];
} else {
- return 'HEAP';
+ assert(allowMultiple, 'Unknown slab type and !allowMultiple: ' + type);
+ return ['IHEAP', 'FHEAP']; // unknown, so assign to both typed arrays
}
}
}
@@ -85,7 +86,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria
if (SAFE_HEAP) {
return 'SAFE_HEAP_LOAD(' + offset + ', "' + safeQuote(type) + '")';
} else {
- return makeGetSlab(ptr, type) + '[' + offset + ']';
+ return makeGetSlabs(ptr, type)[0] + '[' + offset + ']';
}
}
@@ -111,7 +112,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria
if (SAFE_HEAP) {
return 'SAFE_HEAP_STORE(' + offset + ', ' + value + ', "' + safeQuote(type) + '")';
} else {
- return makeGetSlab(ptr, type) + '[' + offset + '] = ' + value;
+ return makeGetSlabs(ptr, type, true).map(function(slab) { return slab + '[' + offset + '] = ' + value }).join('; ');
}
}
@@ -851,7 +852,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria
function finalizeLLVMFunctionCall(item) {
switch(item.intertype) {
case 'getelementptr': // TODO finalizeLLVMParameter on the ident and the indexes?
- return makePointer(makeGetSlab(item.ident, item.type), getGetElementPtrIndexes(item), null, item.type);
+ return makePointer(makeGetSlabs(item.ident, item.type)[0], getGetElementPtrIndexes(item), null, item.type);
case 'bitcast':
case 'inttoptr':
case 'ptrtoint':
diff --git a/src/parseTools.js b/src/parseTools.js
index 1764773b..e9ca3e34 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -352,10 +352,17 @@ function parseLLVMFunctionCall(segment) {
segment.splice(2, 1); // Remove modifiers
if (!segment[2]) throw 'Invalid segment!';
}
+ var intertype = segment[1].text;
+ var type = segment[0].text;
+ if (type === '?') {
+ if (intertype === 'getelementptr') {
+ type = '*'; // a pointer, we can easily say, this is
+ }
+ }
var ret = {
- intertype: segment[1].text,
+ intertype: intertype,
variant: variant,
- type: segment[0].text,
+ type: type,
params: parseParamTokens(segment[2].item.tokens)
};
ret.ident = toNiceIdent(ret.params[0].ident);