diff options
author | alon@honor <none@none> | 2010-09-06 10:38:33 -0700 |
---|---|---|
committer | alon@honor <none@none> | 2010-09-06 10:38:33 -0700 |
commit | fb18f94135ce2354ee3a225ffc2d73341139b6a8 (patch) | |
tree | f5a7fefe68e4f03356d115ef614ee3b45b47dd9c /src/parser.js | |
parent | 3109ce8f1c903653a982d44c471cf7f5bab975b1 (diff) |
preprocessor + example use in SAFE_HEAP
Diffstat (limited to 'src/parser.js')
-rw-r--r-- | src/parser.js | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/src/parser.js b/src/parser.js index b9873175..19e073bc 100644 --- a/src/parser.js +++ b/src/parser.js @@ -6,10 +6,6 @@ * * Re-use variables (of the same kind, native/nativized vs. emulated). */ -// Options - -LINEDEBUG = 0; - // Prep - allow this to run in both SpiderMonkey and V8 if (!this['load']) { @@ -26,6 +22,34 @@ load('snippets.js'); // Tools +// Simple #if/else/endif preprocessing for a file. Checks if the +// ident checked is true in our global. +function preprocess(text) { + var lines = text.split('\n'); + var ret = ''; + var show = true; + for (var i = 0; i < lines.length; i++) { + var line = lines[i]; + if (line[0] != '#') { + if (show) { + ret += line + '\n'; + } + } else { + if (line[1] == 'i') { // if + var ident = line.substr(4); + show = !!this[ident]; + } else if (line[2] == 'l') { // else + show = !show; + } else if (line[2] == 'n') { // endif + show = true; + } else { + throw "Unclear preprocessor command: " + line; + } + } + } + return ret; +} + function addPointing(type) { return type + '*' } function removePointing(type, num) { if (num === 0) return type; @@ -1829,7 +1853,11 @@ function JSify(data) { } function makeSetValue(ptr, pos, value, noNeedFirst) { - return makeGetSlab(ptr) + '[' + (noNeedFirst ? '0' : makeGetPos(ptr)) + (pos ? ' + ' + pos : '') + '] = ' + value; + if (SAFE_HEAP) { + return 'SAFE_HEAP_STORE(' + (noNeedFirst ? '0' : makeGetPos(ptr)) + (pos ? ' + ' + pos : '') + ', ' + value + ')'; + } else { + return makeGetSlab(ptr) + '[' + (noNeedFirst ? '0' : makeGetPos(ptr)) + (pos ? ' + ' + pos : '') + '] = ' + value; + } } function makeEmptyStruct(type) { @@ -2390,7 +2418,11 @@ function JSify(data) { // Special cases if (ident == '_llvm_va_start') { - return 'HEAP[' + params[0].ident + '] = Pointer_make(Array.prototype.slice.call(arguments, 1).concat([0]), 0)'; // XXX 1 + if (SAFE_HEAP) { + return 'SAFE_HEAP_STORE(' + params[0].ident + ', Pointer_make(Array.prototype.slice.call(arguments, 1).concat([0]), 0))'; + } else { + return 'HEAP[' + params[0].ident + '] = Pointer_make(Array.prototype.slice.call(arguments, 1).concat([0]), 0)'; // XXX 1 + } } else if (ident == '_llvm_va_end') { return ';' } @@ -2438,7 +2470,7 @@ function JSify(data) { return ret.map(function(item) { return item.JS }).join('\n'); } - return read('preamble.js') + finalCombiner(substrate.solve()) + read('postamble.js'); + return preprocess(read('preamble.js')) + finalCombiner(substrate.solve()) + read('postamble.js'); // return finalCombiner(substrate.solve()); } |