aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-01-28 13:59:39 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-01-28 13:59:39 -0800
commit496dd28973e6156773975fd6ad093cab271f46bb (patch)
treeadc0b8b761e97008123a3832d9b99a803eee150c
parent1712044102bdd9d48ed4b699d5cba6368a3beb16 (diff)
improve asm safe heap support and add ASM_HEAP_LOG
-rwxr-xr-xemscripten.py8
-rw-r--r--src/parseTools.js22
-rw-r--r--src/settings.js2
3 files changed, 21 insertions, 11 deletions
diff --git a/emscripten.py b/emscripten.py
index 5af2ac91..2ceb5e13 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -395,11 +395,11 @@ var i64Math_modulo = function(a, b, c, d, e) { i64Math.modulo(a, b, c, d, e) };
# finalize
funcs_js = '''
%s
-function asmPrintInt(x) {
- Module.print('int ' + x);// + ' ' + new Error().stack);
+function asmPrintInt(x, y) {
+ Module.print('int ' + x + ',' + y);// + ' ' + new Error().stack);
}
-function asmPrintFloat(x) {
- Module.print('float ' + x);// + ' ' + new Error().stack);
+function asmPrintFloat(x, y) {
+ Module.print('float ' + x + ',' + y);// + ' ' + new Error().stack);
}
var asm = (function(global, env, buffer) {
'use asm';
diff --git a/src/parseTools.js b/src/parseTools.js
index 994e391b..f5e2f33f 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -1079,6 +1079,8 @@ function makeSetTempDouble(i, type, value) {
return makeGetTempDouble(i, type, true) + '=' + asmEnsureFloat(value, type);
}
+var asmPrintCounter = 0;
+
// See makeSetValue
function makeGetValue(ptr, pos, type, noNeedFirst, unsigned, ignore, align, noSafe, forceAsm) {
if (UNALIGNED_MEMORY) align = 1;
@@ -1129,14 +1131,19 @@ function makeGetValue(ptr, pos, type, noNeedFirst, unsigned, ignore, align, noSa
var offset = calcFastOffset(ptr, pos, noNeedFirst);
if (SAFE_HEAP && !noSafe) {
- if (type !== 'null' && type[0] !== '#') type = '"' + safeQuote(type) + '"';
- if (type[0] === '#') type = type.substr(1);
- return 'SAFE_HEAP_LOAD(' + asmCoercion(offset, 'i32') + ', ' + (ASM_JS ? 0 : type) + ', ' + (!!unsigned+0) + ', ' + ((!checkSafeHeap() || ignore)|0) + ')';
+ var printType = type;
+ if (printType !== 'null' && printType[0] !== '#') printType = '"' + safeQuote(printType) + '"';
+ if (printType[0] === '#') printType = printType.substr(1);
+ return asmCoercion('SAFE_HEAP_LOAD(' + asmCoercion(offset, 'i32') + ', ' + (ASM_JS ? 0 : printType) + ', ' + (!!unsigned+0) + ', ' + ((!checkSafeHeap() || ignore)|0) + ')', type);
} else {
var ret = makeGetSlabs(ptr, type, false, unsigned)[0] + '[' + getHeapOffset(offset, type, forceAsm) + ']';
- if (ASM_JS && phase == 'funcs') {
+ if (ASM_JS && (phase == 'funcs' || forceAsm)) {
ret = asmCoercion(ret, type);
}
+ if (ASM_HEAP_LOG) {
+ ret = makeInlineCalculation('(asmPrint' + (type in Runtime.FLOAT_TYPES ? 'Float' : 'Int') + '(' + (asmPrintCounter++) + ',' + asmCoercion('VALUE', type) + '), VALUE)', ret,
+ 'temp' + (type in Runtime.FLOAT_TYPES ? 'Double' : 'Int'));
+ }
return ret;
}
}
@@ -1232,9 +1239,10 @@ function makeSetValue(ptr, pos, value, type, noNeedFirst, ignore, align, noSafe,
value = indexizeFunctions(value, type);
var offset = calcFastOffset(ptr, pos, noNeedFirst);
if (SAFE_HEAP && !noSafe) {
- if (type !== 'null' && type[0] !== '#') type = '"' + safeQuote(type) + '"';
- if (type[0] === '#') type = type.substr(1);
- return 'SAFE_HEAP_STORE(' + asmCoercion(offset, 'i32') + ', ' + asmCoercion(value, type) + ', ' + (ASM_JS ? 0 : type) + ', ' + ((!checkSafeHeap() || ignore)|0) + ')';
+ var printType = type;
+ if (printType !== 'null' && printType[0] !== '#') printType = '"' + safeQuote(printType) + '"';
+ if (printType[0] === '#') printType = printType.substr(1);
+ return 'SAFE_HEAP_STORE(' + asmCoercion(offset, 'i32') + ', ' + asmCoercion(value, type) + ', ' + (ASM_JS ? 0 : printType) + ', ' + ((!checkSafeHeap() || ignore)|0) + ')';
} else {
return makeGetSlabs(ptr, type, true).map(function(slab) { return slab + '[' + getHeapOffset(offset, type, forceAsm) + ']=' + value }).join(sep);
}
diff --git a/src/settings.js b/src/settings.js
index 6ffa8c33..26b649e0 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -132,6 +132,8 @@ var SAFE_HEAP = 0; // Check each write to the heap, for example, this will give
// that 3 is the option you usually want here.
var SAFE_HEAP_LOG = 0; // Log out all SAFE_HEAP operations
+var ASM_HEAP_LOG = 0; // Simple heap logging, like SAFE_HEAP_LOG but cheaper, and in asm.js
+
var LABEL_DEBUG = 0; // 1: Print out functions as we enter them
// 2: Also print out each label as we enter it
var LABEL_FUNCTION_FILTERS = []; // Filters for function label debug.