aboutsummaryrefslogtreecommitdiff
path: root/src/runtime.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime.js')
-rw-r--r--src/runtime.js50
1 files changed, 44 insertions, 6 deletions
diff --git a/src/runtime.js b/src/runtime.js
index cd3afb4b..97de7473 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -49,7 +49,7 @@ var RuntimeGenerator = {
stackExit: function(initial, force) {
if (initial === 0 && SKIP_STACK_IN_SMALL && !force) return '';
var ret = '';
- if (SAFE_HEAP) {
+ if (SAFE_HEAP && !ASM_JS) {
ret += 'var i = sp; while ((i|0) < (STACKTOP|0)) { SAFE_HEAP_CLEAR(i|0); i = (i+1)|0 }';
}
return ret += 'STACKTOP=sp';
@@ -185,10 +185,10 @@ var Runtime = {
// type can be a native type or a struct (or null, for structs we only look at size here)
getAlignSize: function(type, size, vararg) {
// we align i64s and doubles on 64-bit boundaries, unlike x86
-#if TARGET_LE32 == 1
+#if TARGET_ASMJS_UNKNOWN_EMSCRIPTEN == 1
if (vararg) return 8;
#endif
-#if TARGET_LE32
+#if TARGET_ASMJS_UNKNOWN_EMSCRIPTEN
if (!vararg && (type == 'i64' || type == 'double')) return 8;
if (!type) return Math.min(size, 8); // align structures internally to 64 bits
#endif
@@ -336,6 +336,9 @@ var Runtime = {
#if ASM_JS
if (!args.splice) args = Array.prototype.slice.call(args);
args.splice(0, 0, ptr);
+#if ASSERTIONS
+ assert(('dynCall_' + sig) in Module, 'bad function pointer type - no table for sig \'' + sig + '\'');
+#endif
return Module['dynCall_' + sig].apply(null, args);
#else
return FUNCTION_TABLE[ptr].apply(null, args);
@@ -345,6 +348,9 @@ var Runtime = {
assert(sig.length == 1);
#endif
#if ASM_JS
+#if ASSERTIONS
+ assert(('dynCall_' + sig) in Module, 'bad function pointer type - no table for sig \'' + sig + '\'');
+#endif
return Module['dynCall_' + sig].call(null, ptr);
#else
return FUNCTION_TABLE[ptr]();
@@ -393,7 +399,17 @@ var Runtime = {
for (var i = 0; i < numArgs; i++) {
args.push(String.fromCharCode(36) + i); // $0, $1 etc
}
- return Runtime.asmConstCache[code] = eval('(function(' + args.join(',') + '){ ' + Pointer_stringify(code) + ' })'); // new Function does not allow upvars in node
+ code = Pointer_stringify(code);
+ if (code[0] === '"') {
+ // tolerate EM_ASM("..code..") even though EM_ASM(..code..) is correct
+ if (code.indexOf('"', 1) === code.length-1) {
+ code = code.substr(1, code.length-2);
+ } else {
+ // something invalid happened, e.g. EM_ASM("..code($0)..", input)
+ abort('invalid EM_ASM input |' + code + '|. Please use EM_ASM(..code..) (no quotes) or EM_ASM({ ..code($0).. }, input) (to input values)');
+ }
+ }
+ return Runtime.asmConstCache[code] = eval('(function(' + args.join(',') + '){ ' + code + ' })'); // new Function does not allow upvars in node
},
warnOnce: function(text) {
@@ -477,6 +493,19 @@ var Runtime = {
}
},
+#if RETAIN_COMPILER_SETTINGS
+ compilerSettings: {},
+#endif
+
+ getCompilerSetting: function(name) {
+#if RETAIN_COMPILER_SETTINGS == 0
+ throw 'You must build with -s RETAIN_COMPILER_SETTINGS=1 for Runtime.getCompilerSetting or emscripten_get_compiler_setting to work';
+#else
+ if (!(name in Runtime.compilerSettings)) return 'invalid compiler setting: ' + name;
+ return Runtime.compilerSettings[name];
+#endif
+ },
+
#if RUNTIME_DEBUG
debug: true, // Switch to false at runtime to disable logging at the right times
@@ -555,7 +584,7 @@ function getRuntime() {
// Converts a value we have as signed, into an unsigned value. For
// example, -1 in int32 would be a very large number as unsigned.
-function unSign(value, bits, ignore, sig) {
+function unSign(value, bits, ignore) {
if (value >= 0) {
return value;
}
@@ -568,7 +597,7 @@ function unSign(value, bits, ignore, sig) {
// Converts a value we have as unsigned, into a signed value. For
// example, 200 in a uint8 would be a negative number.
-function reSign(value, bits, ignore, sig) {
+function reSign(value, bits, ignore) {
if (value <= 0) {
return value;
}
@@ -602,3 +631,12 @@ function reSign(value, bits, ignore, sig) {
// Then 'dynamic' memory for sbrk.
Runtime.GLOBAL_BASE = Runtime.alignMemory(1);
+if (RETAIN_COMPILER_SETTINGS) {
+ var blacklist = set('RELOOPER', 'STRUCT_INFO');
+ for (var x in this) {
+ try {
+ if (x[0] !== '_' && !(x in blacklist) && x == x.toUpperCase() && (typeof this[x] === 'number' || typeof this[x] === 'string' || this.isArray())) Runtime.compilerSettings[x] = this[x];
+ } catch(e){}
+ }
+}
+