aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2010-11-27 13:12:21 -0800
committerAlon Zakai <azakai@mozilla.com>2010-11-27 13:12:21 -0800
commit7d1dcece2b37f5d7b75695b229f06f204766b647 (patch)
tree8842c70f10531ba22dce8def0b066a206d7bc894
parent64ad6c85cf525d80187bbcc279674a1ba2475558 (diff)
proper memory initialization with or without typed arrays; additional lua tests
-rw-r--r--src/preamble.js13
-rw-r--r--src/runtime.js13
-rw-r--r--tests/runner.py9
3 files changed, 21 insertions, 14 deletions
diff --git a/src/preamble.js b/src/preamble.js
index 833e64e4..83dac618 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -178,26 +178,27 @@ var STATICTOP;
// Mangled |new| and |free| (various manglings, for int, long params; new and new[], etc.
var _malloc, _free, __Znwj, __Znaj, __Znam, __Znwm, __ZdlPv, __ZdaPv;
+var HAS_TYPED_ARRAYS = false;
+var TOTAL_MEMORY = 50*1024*1024;
+
function __initializeRuntime__() {
// If we don't have malloc/free implemented, use a simple implementation.
Module['_malloc'] = _malloc = __Znwj = __Znaj = __Znam = __Znwm = Module['_malloc'] ? Module['_malloc'] : Runtime.staticAlloc;
Module['_free'] = _free = __ZdlPv = __ZdaPv = Module['_free'] ? Module['_free'] : function() { };
+ // TODO: Remove one of the 3 heaps!
HEAP = intArrayFromString('(null)'); // So printing %s of NULL gives '(null)'
// Also this ensures we leave 0 as an invalid address, 'NULL'
#if USE_TYPED_ARRAYS
- if (!this['TOTAL_MEMORY']) TOTAL_MEMORY = 50*1024*1024;
- if (this['Int32Array']) { // check for engine support
+ HAS_TYPED_ARRAYS = this['Int32Array'] && this['Float64Array']; // check for engine support
+ if (HAS_TYPED_ARRAYS) {
IHEAP = new Int32Array(TOTAL_MEMORY);
for (var i = 0; i < HEAP.length; i++) {
IHEAP[i] = HEAP[i];
}
- } else {
- IHEAP = HEAP; // fallback
- }
- if (this['Float64Array']) { // check for engine support
FHEAP = new Float64Array(TOTAL_MEMORY);
} else {
+ IHEAP = HEAP; // fallback
FHEAP = HEAP; // fallback
}
#else
diff --git a/src/runtime.js b/src/runtime.js
index 2e76af39..cb79b68d 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -6,11 +6,13 @@ RuntimeGenerator = {
alloc: function(size, type) {
var ret = type + 'TOP';
if (GUARD_MEMORY) {
- //if (!USE_TYPED_ARRAYS) { // No need for typed arrays - per the spec, initialized to 0 anyhow
- // ret += '; for (var i = 0; i < ' + size + '; i++) HEAP[' + type + 'TOP+i] = 0';
- //}
ret += '; assert(' + size + ' > 0)';
}
+ var initMemory = 'for (var i = 0; i < ' + size + '; i++) HEAP[' + type + 'TOP+i] = 0';
+ if (USE_TYPED_ARRAYS) { // No need for typed arrays - per the spec, initialized to 0 anyhow
+ initMemory = 'if (!HAS_TYPED_ARRAYS) { ' + initMemory + '}';
+ }
+ ret += '; ' + initMemory;
ret += '; ' + type + 'TOP += ' + size;
if (QUANTUM_SIZE > 1) {
ret += ';' + RuntimeGenerator.alignMemory(type + 'TOP', QUANTUM_SIZE);
@@ -36,6 +38,11 @@ RuntimeGenerator = {
if (GUARD_MEMORY) {
ret += '; assert(STACKTOP < STACK_MAX)';
}
+ var initMemory = 'for (var i = __stackBase__; i < STACKTOP; i++) HEAP[i] = 0';
+ if (USE_TYPED_ARRAYS) { // No need for typed arrays - per the spec, initialized to 0 anyhow
+ initMemory = 'if (!HAS_TYPED_ARRAYS) { ' + initMemory + '}';
+ }
+ ret += '; ' + initMemory;
return ret;
},
diff --git a/tests/runner.py b/tests/runner.py
index 4749cea6..0620481e 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -120,7 +120,7 @@ if 'benchmark' not in sys.argv:
#shutil.rmtree(dirname) # TODO: leave no trace in memory. But for now nice for debugging
# No building - just process an existing .ll file
- def do_ll_test(self, ll_file, output, args=[], f_opt_ll_file=None, js_engines=[V8_ENGINE]):
+ def do_ll_test(self, ll_file, output, args=[], f_opt_ll_file=None, js_engines=None):
if COMPILER != LLVM_GCC: return # We use existing .ll, so which compiler is unimportant
if F_OPTS:
return # TODO: enable the lines below
@@ -1083,10 +1083,9 @@ if 'benchmark' not in sys.argv:
def test_lua(self):
self.do_ll_test(path_from_root(['tests', 'lua', 'lua.ll']),
- 'hello lua world!\n\n\n17',
- args=['-e', '''print("hello lua world!");print(17)'''],
- f_opt_ll_file=path_from_root(['tests', 'lua', 'lua.Os.ll']),
- js_engines=[SPIDERMONKEY_ENGINE])
+ 'hello lua world!\n\n\n17.00000000000\n\n\n1.00000000000\n\n\n2.00000000000\n\n\n3.00000000000\n\n\n4.00000000000',
+ args=['-e', '''print("hello lua world!");print(17);for x = 1,4 do print(x) end'''],
+ f_opt_ll_file=path_from_root(['tests', 'lua', 'lua.Os.ll']))
### Test cases in separate files