aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xemscripten.py5
-rw-r--r--src/jsifier.js37
-rw-r--r--src/modules.js2
3 files changed, 23 insertions, 21 deletions
diff --git a/emscripten.py b/emscripten.py
index db58ffd4..4bb30257 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -94,10 +94,12 @@ def emscript(infile, settings, outfile, libraries=[]):
funcs[-1].append(line)
if line.startswith('}'):
in_func = False
+ pre.append(line) # pre needs it to, so we know about all implemented functions
else:
if line.startswith('define '):
in_func = True
funcs.append([line])
+ pre.append(line) # pre needs it to, so we know about all implemented functions
elif line.find(' = type { ') > 0:
pre.append(line) # type
elif line.startswith('!'):
@@ -152,9 +154,6 @@ def emscript(infile, settings, outfile, libraries=[]):
#print >> sys.stderr, 'f', '\n\n' + json.dumps(forwarded_json) + '\n\n'
#print >> sys.stderr, 'c', '\n\n' + json.dumps(curr_forwarded_json) + '\n\n'
forwarded_json['Types']['preciseI64MathUsed'] = forwarded_json['Types']['preciseI64MathUsed'] or curr_forwarded_json['Types']['preciseI64MathUsed']
- forwarded_json['Functions']['implementedFunctions'] = forwarded_json['Functions']['implementedFunctions'] or {}
- for key, value in curr_forwarded_json['Functions']['implementedFunctions'].iteritems():
- forwarded_json['Functions']['implementedFunctions'][key] = value
for key, value in curr_forwarded_json['Functions']['blockAddresses'].iteritems():
forwarded_json['Functions']['blockAddresses'][key] = value
for key in curr_forwarded_json['Functions']['indexedFunctions'].iterkeys():
diff --git a/src/jsifier.js b/src/jsifier.js
index dcf4e3fa..68bf35ab 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -40,7 +40,7 @@ function JSify(data, functionsOnly, givenFunctions) {
var preFile = BUILD_AS_SHARED_LIB ? 'preamble_sharedlib.js' : 'preamble.js';
var pre = processMacros(preprocess(read(preFile).replace('{{RUNTIME}}', getRuntime())));
print(pre);
- } else if (phase == 'funcs') {
+
Functions.implementedFunctions = set(data.unparsedFunctions.map(function(func) { return func.ident }));
}
}
@@ -90,6 +90,7 @@ function JSify(data, functionsOnly, givenFunctions) {
Functions.currExternalFunctions = !mainPass ? givenFunctions.currExternalFunctions : {};
// Now that first-pass analysis has completed (so we have basic types, etc.), we can get around to handling unparsedFunctions
+ // XXX do we need this?
(!mainPass ? data.functions : data.unparsedFunctions.concat(data.functions)).forEach(function(func) {
// Save just what we need, to save memory
Functions.currFunctions[func.ident] = {
@@ -110,24 +111,26 @@ function JSify(data, functionsOnly, givenFunctions) {
}
});
- var MAX_BATCH_FUNC_LINES = 1000;
- while (data.unparsedFunctions.length > 0) {
- var currFuncLines = [];
- var currBaseLineNums = [];
- while (currFuncLines.length == 0 ||
- (data.unparsedFunctions.length > 0 && currFuncLines.length + data.unparsedFunctions[0].lines.length <= MAX_BATCH_FUNC_LINES)) {
- currBaseLineNums.push([currFuncLines.length, data.unparsedFunctions[0].lineNum-1]);
- currFuncLines = currFuncLines.concat(data.unparsedFunctions[0].lines); // for first one, assign, do not concat?
- data.unparsedFunctions.shift();
+ if (phase == 'funcs') { // pre has function shells, just to defined implementedFunctions
+ var MAX_BATCH_FUNC_LINES = 1000;
+ while (data.unparsedFunctions.length > 0) {
+ var currFuncLines = [];
+ var currBaseLineNums = [];
+ while (currFuncLines.length == 0 ||
+ (data.unparsedFunctions.length > 0 && currFuncLines.length + data.unparsedFunctions[0].lines.length <= MAX_BATCH_FUNC_LINES)) {
+ currBaseLineNums.push([currFuncLines.length, data.unparsedFunctions[0].lineNum-1]);
+ currFuncLines = currFuncLines.concat(data.unparsedFunctions[0].lines); // for first one, assign, do not concat?
+ data.unparsedFunctions.shift();
+ }
+ dprint('unparsedFunctions','====================\n// Processing function batch of ' + currBaseLineNums.length +
+ ' functions, ' + currFuncLines.length + ' lines, functions left: ' + data.unparsedFunctions.length);
+ if (DEBUG_MEMORY) MemoryDebugger.tick('pre-func');
+ JSify(analyzer(intertyper(currFuncLines, true, currBaseLineNums), true), true, Functions);
+ if (DEBUG_MEMORY) MemoryDebugger.tick('post-func');
}
- dprint('unparsedFunctions','====================\n// Processing function batch of ' + currBaseLineNums.length +
- ' functions, ' + currFuncLines.length + ' lines, functions left: ' + data.unparsedFunctions.length);
- if (DEBUG_MEMORY) MemoryDebugger.tick('pre-func');
- JSify(analyzer(intertyper(currFuncLines, true, currBaseLineNums), true), true, Functions);
- if (DEBUG_MEMORY) MemoryDebugger.tick('post-func');
+ currFuncLines = currBaseLineNums = null; // Do not hold on to anything from inside that loop (JS function scoping..)
+ data.unparsedFunctions = null;
}
- currFuncLines = currBaseLineNums = null; // Do not hold on to anything from inside that loop (JS function scoping..)
- data.unparsedFunctions = null;
// Actors
diff --git a/src/modules.js b/src/modules.js
index 97dbe223..e955ed71 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -216,7 +216,7 @@ var Functions = {
currFunctions: [],
// All functions that will be implemented in this file
- implementedFunctions: [],
+ implementedFunctions: {},
indexedFunctions: {},
nextIndex: 2, // Start at a non-0 (even, see below) value