aboutsummaryrefslogtreecommitdiff
path: root/src/jsifier.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-04-11 21:18:37 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-04-11 21:18:37 -0700
commit9e7a712c6b6186792f186ed6bd6d6af31d36a434 (patch)
treeed0b51d1f165dc80278aedf9f3f768fe303aff15 /src/jsifier.js
parentfd301b105745a855e4cb231e217e8acf40df1858 (diff)
infrastructure for supporting exceptions in asm.js, by going through invoke_* calls
Diffstat (limited to 'src/jsifier.js')
-rw-r--r--src/jsifier.js25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 0786f622..af07539f 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1156,12 +1156,13 @@ function JSify(data, functionsOnly, givenFunctions) {
makeFuncLineActor('invoke', function(item) {
// Wrapping in a function lets us easily return values if we are
// in an assignment
+ var disabled = DISABLE_EXCEPTION_CATCHING == 2 && !(item.funcData.ident in EXCEPTION_CATCHING_WHITELIST);
var phiSets = calcPhiSets(item);
- var call_ = makeFunctionCall(item.ident, item.params, item.funcData, item.type);
-
+ var call_ = makeFunctionCall(item.ident, item.params, item.funcData, item.type, ASM_JS && !disabled);
+
var ret;
- if (DISABLE_EXCEPTION_CATCHING == 2 && !(item.funcData.ident in EXCEPTION_CATCHING_WHITELIST)) {
+ if (disabled || ASM_JS) { // TODO: EXCEPTION_DEBUG for asm.js
ret = call_ + ';';
} else {
ret = '(function() { try { __THREW__ = 0; return '
@@ -1173,7 +1174,6 @@ function JSify(data, functionsOnly, givenFunctions) {
+ 'return null } })();';
}
-
if (item.assignTo) {
ret = 'var ' + item.assignTo + ' = ' + ret;
if (USE_TYPED_ARRAYS == 2 && isIllegalType(item.type)) {
@@ -1291,7 +1291,7 @@ function JSify(data, functionsOnly, givenFunctions) {
return ret;
});
- function makeFunctionCall(ident, params, funcData, type) {
+ function makeFunctionCall(ident, params, funcData, type, forceByPointer) {
// We cannot compile assembly. See comment in intertyper.js:'Call'
assert(ident != 'asm', 'Inline assembly cannot be compiled to JavaScript!');
@@ -1319,6 +1319,11 @@ function JSify(data, functionsOnly, givenFunctions) {
var hasVarArgs = isVarArgsFunctionType(type);
var normalArgs = (hasVarArgs && !useJSArgs) ? countNormalArgs(type) : -1;
var byPointer = getVarData(funcData, ident);
+ var byPointerForced = false;
+
+ if (forceByPointer && !byPointer) {
+ byPointer = byPointerForced = true;
+ }
params.forEach(function(param, i) {
var val = finalizeParam(param);
@@ -1421,12 +1426,18 @@ function JSify(data, functionsOnly, givenFunctions) {
var sig = Functions.getSignature(returnType, argsTypes, hasVarArgs);
if (ASM_JS) {
assert(returnType.search(/\("'\[,/) == -1); // XXX need isFunctionType(type, out)
- callIdent = '(' + callIdent + ')&{{{ FTM_' + sig + ' }}}'; // the function table mask is set in emscripten.py
+ if (!forceByPointer) {
+ callIdent = '(' + callIdent + ')&{{{ FTM_' + sig + ' }}}'; // the function table mask is set in emscripten.py
+ } else {
+ // add initial argument for invoke. note: no need to update argsTypes at this point
+ args.unshift(byPointerForced ? Functions.getIndex(callIdent) : callIdent);
+ callIdent = 'invoke_' + sig;
+ }
} else if (SAFE_DYNCALLS) {
assert(!ASM_JS, 'cannot emit safe dyncalls in asm');
callIdent = '(tempInt=' + callIdent + ',tempInt < 0 || tempInt >= FUNCTION_TABLE.length-1 || !FUNCTION_TABLE[tempInt] ? abort("dyncall error: ' + sig + ' " + FUNCTION_TABLE_NAMES[tempInt]) : tempInt)';
}
- callIdent = Functions.getTable(sig) + '[' + callIdent + ']';
+ if (!byPointerForced) callIdent = Functions.getTable(sig) + '[' + callIdent + ']';
}
var ret = callIdent + '(' + args.join(', ') + ')';