aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-04-21 13:17:24 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-04-21 13:17:24 -0700
commite1de4d430a370a9cbf72e949307639b50f399c75 (patch)
tree2957bcdc35d8d52c9d302854620ca9584507d8e3 /src
parent3d4cc9e9312a954a79ee7df7ffe0fc0495c37b24 (diff)
line-specific exceptions to SAFE_HEAP
Diffstat (limited to 'src')
-rw-r--r--src/compiler.js18
-rw-r--r--src/jsifier.js4
-rw-r--r--src/parseTools.js18
-rw-r--r--src/preamble.js17
-rw-r--r--src/settings.js3
5 files changed, 38 insertions, 22 deletions
diff --git a/src/compiler.js b/src/compiler.js
index 53e2b020..fc9ae7fc 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -36,6 +36,9 @@ if (CORRECT_OVERFLOWS === 2) {
if (CORRECT_ROUNDINGS === 2) {
CORRECT_ROUNDINGS_LINES = set(CORRECT_ROUNDINGS_LINES); // for fast checking
}
+if (SAFE_HEAP === 2) {
+ SAFE_HEAP_LINES = set(SAFE_HEAP_LINES); // for fast checking
+}
EXPORTED_FUNCTIONS = set(EXPORTED_FUNCTIONS);
@@ -49,12 +52,6 @@ load('analyzer.js');
load('jsifier.js');
load('runtime.js');
-// Load library, with preprocessing and macros
-
-for (suffix in set('', '_sdl', '_gl')) {
- eval(processMacros(preprocess(read('library' + suffix + '.js'), CONSTANTS)));
-}
-
//===============================
// Main
//===============================
@@ -71,5 +68,12 @@ do {
// Do it
-JSify(analyzer(intertyper(lines)));
+var inter = intertyper(lines);
+
+// Load library, with preprocessing and macros. Must be done after intertyper, so we know if we have debug info or not
+for (suffix in set('', '_sdl', '_gl')) {
+ eval(processMacros(preprocess(read('library' + suffix + '.js'), CONSTANTS)));
+}
+
+JSify(analyzer(inter));
diff --git a/src/jsifier.js b/src/jsifier.js
index 09a29656..1901409e 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -39,7 +39,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
if (data.unparsedFunctions.length > 0) {
// We are now doing the final JS generation
dprint('unparsedFunctions', '== Completed unparsedFunctions ==\n');
- Debugging.clear(); // Save some memory, before the final heavy lifting
+ //Debugging.clear(); // Save some memory, before the final heavy lifting
}
// Actors
@@ -670,7 +670,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
// varargs - we received a pointer to the varargs as a final 'extra' parameter
var data = 'arguments[' + Framework.currItem.funcData.ident + '.length]';
if (SAFE_HEAP) {
- return 'SAFE_HEAP_STORE(' + params[0].ident + ', ' + data + ', null)';
+ return 'SAFE_HEAP_STORE(' + params[0].ident + ', ' + data + ', null, ' + !checkSafeHeap() + ')';
} else {
return 'IHEAP[' + params[0].ident + '] = ' + data;
}
diff --git a/src/parseTools.js b/src/parseTools.js
index fde8e703..ca6a44b2 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -577,7 +577,7 @@ function indentify(text, indent) {
function correctSpecificSign() {
assert(!(CORRECT_SIGNS === 2 && !Debugging.on), 'Need debugging for line-specific corrections');
- return CORRECT_SIGNS === 2 && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_SIGNS_LINES;
+ return CORRECT_SIGNS === 2 && Framework.currItem && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_SIGNS_LINES;
}
function correctSigns() {
return CORRECT_SIGNS === 1 || correctSpecificSign();
@@ -585,7 +585,7 @@ function correctSigns() {
function correctSpecificOverflow() {
assert(!(CORRECT_OVERFLOWS === 2 && !Debugging.on), 'Need debugging for line-specific corrections');
- return CORRECT_OVERFLOWS === 2 && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_OVERFLOWS_LINES;
+ return CORRECT_OVERFLOWS === 2 && Framework.currItem && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_OVERFLOWS_LINES;
}
function correctOverflows() {
return CORRECT_OVERFLOWS === 1 || correctSpecificOverflow();
@@ -593,12 +593,20 @@ function correctOverflows() {
function correctSpecificRounding() {
assert(!(CORRECT_ROUNDINGS === 2 && !Debugging.on), 'Need debugging for line-specific corrections');
- return CORRECT_ROUNDINGS === 2 && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_ROUNDINGS_LINES;
+ return CORRECT_ROUNDINGS === 2 && Framework.currItem && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_ROUNDINGS_LINES;
}
function correctRoundings() {
return CORRECT_ROUNDINGS === 1 || correctSpecificRounding();
}
+function checkSpecificSafeHeap() {
+ assert(!(SAFE_HEAP === 2 && !Debugging.on), 'Need debugging for line-specific checks');
+ return SAFE_HEAP === 2 && Framework.currItem && !(Debugging.getIdentifier(Framework.currItem.lineNum) in SAFE_HEAP_LINES);
+}
+function checkSafeHeap() {
+ return SAFE_HEAP === 1 || checkSpecificSafeHeap();
+}
+
// See makeSetValue
function makeGetValue(ptr, pos, type, noNeedFirst) {
@@ -614,7 +622,7 @@ function makeGetValue(ptr, pos, type, noNeedFirst) {
var offset = calcFastOffset(ptr, pos, noNeedFirst);
if (SAFE_HEAP) {
if (type !== 'null') type = '"' + safeQuote(type) + '"';
- return 'SAFE_HEAP_LOAD(' + offset + ', ' + type + ')';
+ return 'SAFE_HEAP_LOAD(' + offset + ', ' + type + ', ' + !checkSafeHeap() + ')';
} else {
return makeGetSlabs(ptr, type)[0] + '[' + offset + ']';
}
@@ -651,7 +659,7 @@ function makeSetValue(ptr, pos, value, type, noNeedFirst) {
var offset = calcFastOffset(ptr, pos, noNeedFirst);
if (SAFE_HEAP) {
if (type !== 'null') type = '"' + safeQuote(type) + '"';
- return 'SAFE_HEAP_STORE(' + offset + ', ' + value + ', ' + type + ');';
+ return 'SAFE_HEAP_STORE(' + offset + ', ' + value + ', ' + type + ', ' + !checkSafeHeap() + ');';
} else {
return makeGetSlabs(ptr, type, true).map(function(slab) { return slab + '[' + offset + ']=' + value }).join('; ') + ';';
}
diff --git a/src/preamble.js b/src/preamble.js
index 1755767a..5e3e2210 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -25,7 +25,7 @@ function SAFE_HEAP_COPY_HISTORY(dest, src) {
#endif
}
-function SAFE_HEAP_ACCESS(dest, type, store) {
+function SAFE_HEAP_ACCESS(dest, type, store, ignore) {
#if SAFE_HEAP_LOG
//if (dest === A_NUMBER) print ([dest, type, store] + ' ' + new Error().stack); // Something like this may be useful, in debugging
#endif
@@ -41,11 +41,12 @@ function SAFE_HEAP_ACCESS(dest, type, store) {
if (type === null) return;
var history = HEAP_HISTORY[dest];
if (history === null) return;
- assert(history, 'Must have a history for a safe heap load! ' + dest + ':' + type); // Warning - bit fields in C structs cause loads+stores for each store, so
- // they will show up here...
+ if (!ignore)
+ assert(history, 'Must have a history for a safe heap load! ' + dest + ':' + type); // Warning - bit fields in C structs cause loads+stores for each store, so
+ // they will show up here...
// assert((history && history[0]) /* || HEAP[dest] === 0 */, "Loading from where there was no store! " + dest + ',' + HEAP[dest] + ',' + type + ', \n\n' + new Error().stack + '\n');
// if (history[0].type !== type) {
- if (history !== type) {
+ if (history !== type && !ignore) {
print('Load-store consistency assumption failure! ' + dest);
print('\n');
print(JSON.stringify(history));
@@ -57,14 +58,14 @@ function SAFE_HEAP_ACCESS(dest, type, store) {
}
}
}
-function SAFE_HEAP_STORE(dest, value, type) {
+function SAFE_HEAP_STORE(dest, value, type, ignore) {
#if SAFE_HEAP_LOG
print('store: ' + dest + ' [' + type + '] |' + value + '|');
#endif
if (!value && value !== 0 && value !== false) { // false can be the result of a mathop comparator
throw('Warning: Writing an invalid value of ' + JSON.stringify(value) + ' at ' + dest + ' :: ' + new Error().stack + '\n');
}
- SAFE_HEAP_ACCESS(dest, type, true);
+ SAFE_HEAP_ACCESS(dest, type, true, ignore);
if (dest in HEAP_WATCHED) {
print((new Error()).stack);
throw "Bad store!" + dest;
@@ -78,8 +79,8 @@ function SAFE_HEAP_STORE(dest, value, type) {
IHEAP[dest] = value;
}
}
-function SAFE_HEAP_LOAD(dest, type) {
- SAFE_HEAP_ACCESS(dest, type);
+function SAFE_HEAP_LOAD(dest, type, ignore) {
+ SAFE_HEAP_ACCESS(dest, type, ignore);
if (type in Runtime.FLOAT_TYPES) {
#if SAFE_HEAP_LOG
print('load : ' + dest + ' [' + type + '] |' + FHEAP[dest] + '|');
diff --git a/src/settings.js b/src/settings.js
index fc86edcf..7fd9f17c 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -41,6 +41,9 @@ USE_TYPED_ARRAYS = 0; // Try to use typed arrays for the heap
// Generated code debugging options
SAFE_HEAP = 0; // Check each write to the heap against a list of blocked addresses
+ // If equal to 2, done on a line-by-line basis according to
+ // SAFE_HEAP_LINES (note that these are the lines to *exclude*
+ // from checking - the opposite of what CORRECT_*_LINES mean)
SAFE_HEAP_LOG = 0; // Print out every single heap read and write (LOTS of output)
LABEL_DEBUG = 0; // Print out labels and functions as we enter them
EXCEPTION_DEBUG = 1; // Print out exceptions in emscriptened code