From 8d53fec332c633f57910a5679ce3ae68f5f35969 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 11 Mar 2013 17:36:46 -0700 Subject: [PATCH] add ASSERTIONS to asm2g, and fix assertions for asm --- src/jsifier.js | 4 ++-- src/library.js | 2 ++ src/runtime.js | 8 ++++---- tests/runner.py | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/jsifier.js b/src/jsifier.js index ee54f17c6..d36f26ce2 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -735,7 +735,7 @@ function JSify(data, functionsOnly, givenFunctions) { return indent + ' case ' + getLabelId(label.ident) + ': ' + (SHOW_LABELS ? '// ' + getOriginalLabelId(label.ident) : '') + '\n' + getLabelLines(label, indent + ' '); }).join('\n') + '\n'; - if (ASSERTIONS) ret += indent + ' default: assert(0, "bad label: " + label);\n'; + if (ASSERTIONS) ret += indent + ' default: assert(0' + (ASM_JS ? '' : ', "bad label: " + label') + ');\n'; ret += indent + '}\n'; if (func.setjmpTable) { ret += ' } catch(e) { if (!e.longjmp || !(e.id in mySetjmpIds)) throw(e); setjmpTable[setjmpLabels[e.id]](e.value) }'; @@ -1454,7 +1454,7 @@ function JSify(data, functionsOnly, givenFunctions) { makeFuncLineActor('unreachable', function(item) { if (ASSERTIONS) { - return 'throw "Reached an unreachable!"'; + return ASM_JS ? 'abort()' : 'throw "Reached an unreachable!"'; } else { return ';'; } diff --git a/src/library.js b/src/library.js index d787e30c0..12e550ff4 100644 --- a/src/library.js +++ b/src/library.js @@ -4155,7 +4155,9 @@ LibraryManager.library = { memcpy__inline: function (dest, src, num, align) { var ret = ''; #if ASSERTIONS +#if ASM_JS == 0 ret += "assert(" + num + " % 1 === 0);"; //, 'memcpy given ' + " + num + " + ' bytes to copy. Problem with quantum=1 corrections perhaps?');"; +#endif #endif ret += makeCopyValues(dest, src, num, 'null', null, align); return ret; diff --git a/src/runtime.js b/src/runtime.js index 8352ade1d..d5c0fabc4 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -27,7 +27,7 @@ var RuntimeGenerator = { // The stack is always QUANTUM SIZE aligned, so we may not need to force alignment here var ret = RuntimeGenerator.alloc(size, 'STACK', false, sep, USE_TYPED_ARRAYS != 2 || (isNumber(size) && parseInt(size) % {{{ QUANTUM_SIZE }}} == 0)); if (ASSERTIONS) { - ret += sep + 'assert(STACKTOP|0 < STACK_MAX|0)'; + ret += sep + 'assert(' + asmCoercion('(STACKTOP|0) < (STACK_MAX|0)', 'i32') + ')'; } return ret; }, @@ -38,12 +38,12 @@ var RuntimeGenerator = { if (initial > 0) ret += '; STACKTOP = (STACKTOP + ' + initial + ')|0'; if (USE_TYPED_ARRAYS == 2) { assert(initial % QUANTUM_SIZE == 0); - if (ASSERTIONS) { - ret += '; assert(STACKTOP|0 % {{{ QUANTUM_SIZE }}} == 0)'; + if (ASSERTIONS && QUANTUM_SIZE == 4) { + ret += '; assert(' + asmCoercion('!(STACKTOP&3)', 'i32') + ')'; } } if (ASSERTIONS) { - ret += '; assert(STACKTOP < STACK_MAX)'; + ret += '; assert(' + asmCoercion('(STACKTOP|0) < (STACK_MAX|0)', 'i32') + ')'; } if (false) { ret += '; _memset(' + asmCoercion('__stackBase__', 'i32') + ', 0, ' + initial + ')'; diff --git a/tests/runner.py b/tests/runner.py index b8b539f7b..e5e12b1e2 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -8635,7 +8635,7 @@ TT = %s # asm.js exec('asm2 = make_run("asm2", compiler=CLANG, emcc_args=["-O2", "-s", "ASM_JS=1"])') - exec('asm2g = make_run("asm2g", compiler=CLANG, emcc_args=["-O2", "-s", "ASM_JS=1", "-g"])') + exec('asm2g = make_run("asm2g", compiler=CLANG, emcc_args=["-O2", "-s", "ASM_JS=1", "-g", "-s", "ASSERTIONS=1"])') # Make custom runs with various options for compiler, quantum, embetter, typed_arrays, llvm_opts in [