aboutsummaryrefslogtreecommitdiff
path: root/src/preamble.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-01-16 11:25:22 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-01-16 11:27:39 -0800
commita3108271317e8242830113a2c87ceed1ec4ac02d (patch)
tree08ba8e81eb189666c727374275e3abd01b069aec /src/preamble.js
parente14e6ea75cc7afb68e8be6c6994a1602250611ee (diff)
enable a form of safe heap in asm, using js optimizer pass to ensure full coverage and support for fastcomp
Diffstat (limited to 'src/preamble.js')
-rw-r--r--src/preamble.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/preamble.js b/src/preamble.js
index ac6ee7b3..d70ef4b1 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -21,6 +21,7 @@ Module.print = Module.printErr = function(){};
#endif
#if SAFE_HEAP
+#if ASM_JS == 0
//========================================
// Debugging tools - Heap
//========================================
@@ -166,6 +167,38 @@ function SAFE_HEAP_FILL_HISTORY(from, to, type) {
}
//==========================================
+#else
+// ASM_JS safe heap
+
+function getSafeHeapType(bytes, isFloat) {
+ switch (bytes) {
+ case 1: return 'i8';
+ case 2: return 'i16';
+ case 4: return isFloat ? 'float' : 'i32';
+ case 8: return 'double';
+ default: assert(0);
+ }
+}
+
+function SAFE_HEAP_STORE(dest, value, bytes, isFloat) {
+#if SAFE_HEAP_LOG
+ Module.print('SAFE_HEAP store: ' + [dest, value, bytes, isFloat]);
+#endif
+ assert(dest > 0, 'segmentation fault');
+ assert(dest % bytes === 0);
+ setValue(dest, value, getSafeHeapType(bytes, isFloat), 1);
+}
+
+function SAFE_HEAP_LOAD(dest, bytes, isFloat) {
+#if SAFE_HEAP_LOG
+ Module.print('SAFE_HEAP load: ' + [dest, bytes, isFloat]);
+#endif
+ assert(dest > 0, 'segmentation fault');
+ assert(dest % bytes === 0);
+ return getValue(dest, getSafeHeapType(bytes, isFloat), 1);
+}
+
+#endif
#endif
#if CHECK_HEAP_ALIGN