aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-11-29 10:22:52 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-12-07 14:23:19 -0800
commit098716f2517a1536a8eab615d1ee14f9939fcec9 (patch)
treec8d7e441ab1620ea5b4a342503b0875914ed4215
parenta917909969156e0033286b2788f8415a0bb7f5a1 (diff)
asm.js function parameter preamble
-rw-r--r--src/jsifier.js7
-rw-r--r--src/parseTools.js15
2 files changed, 17 insertions, 5 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 9b7e9dc7..0d962dc9 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -541,6 +541,13 @@ function JSify(data, functionsOnly, givenFunctions) {
func.JS += 'function ' + func.ident + '(' + paramIdents.join(', ') + ') {\n';
+ if (ASM_JS) {
+ // spell out argument types
+ func.params.forEach(function(param) {
+ func.JS += ' ' + param.ident + ' = ' + asmCoercion(param.ident, param.type) + ';\n';
+ });
+ }
+
if (PROFILE) {
func.JS += ' if (PROFILING) { '
+ 'var __parentProfilingNode__ = PROFILING_NODE; PROFILING_NODE = PROFILING_NODE.children["' + func.ident + '"]; '
diff --git a/src/parseTools.js b/src/parseTools.js
index 0a86abc1..7a8637a0 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -930,6 +930,7 @@ if (ASM_JS) {
var decMemoryMask = (TOTAL_MEMORY-1).toString();
var memoryMask = hexMemoryMask.length <= decMemoryMask.length ? hexMemoryMask : decMemoryMask;
}
+
function getHeapOffset(offset, type) {
if (USE_TYPED_ARRAYS !== 2) {
return offset;
@@ -948,6 +949,14 @@ function getHeapOffset(offset, type) {
}
}
+function asmCoercion(value, type) {
+ if (type in Runtime.INT_TYPES) {
+ return value + '|0';
+ } else {
+ return '+' + value;
+ }
+}
+
// See makeSetValue
function makeGetValue(ptr, pos, type, noNeedFirst, unsigned, ignore, align, noSafe) {
noticePtr(ptr);
@@ -1005,11 +1014,7 @@ function makeGetValue(ptr, pos, type, noNeedFirst, unsigned, ignore, align, noSa
} else {
var ret = makeGetSlabs(ptr, type, false, unsigned)[0] + '[' + getHeapOffset(offset, type) + ']';
if (ASM_JS && phase == 'funcs') {
- if (type in Runtime.INT_TYPES) {
- ret = ret + '|0';
- } else {
- ret = '+' + ret;
- }
+ ret = asmCoercion(ret, type);
}
return ret;
}