aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-11-27 15:47:29 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-11-27 15:47:29 -0800
commitac5209f8f4bcceabd68e127b73996890715c596e (patch)
tree103240a165f9bbcbd2fd9a02e4d7fd153693a88b
parentcb88b99fc40e27ba503ba6f29f9f15d3d7f15f63 (diff)
do global indexing up front
-rw-r--r--src/jsifier.js13
-rw-r--r--src/modules.js2
-rw-r--r--src/parseTools.js8
3 files changed, 14 insertions, 9 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 714bd33c..591dccc4 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1293,7 +1293,18 @@ function JSify(data, functionsOnly, givenFunctions) {
// Print out global variables and postsets TODO: batching
if (phase == 'pre') {
legalizedI64s = false;
- JSify(analyzer(intertyper(data.unparsedGlobalss[0].lines, true), true), true, Functions);
+
+ var globalsData = analyzer(intertyper(data.unparsedGlobalss[0].lines, true), true);
+
+ if (!NAMED_GLOBALS) {
+ for (var ident in Variables.globals) {
+ Variables.indexedGlobals[ident] = Variables.nextIndexedOffset;
+ Variables.nextIndexedOffset += Runtime.alignMemory(calcAllocatedSize(Variables.globals[ident].type));
+ }
+ }
+
+ JSify(globalsData, true, Functions);
+ globalsData = null;
data.unparsedGlobalss = null;
var generated = itemsDict.functionStub.concat(itemsDict.GlobalVariablePostSet);
diff --git a/src/modules.js b/src/modules.js
index 68626b57..f939395b 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -177,7 +177,7 @@ var Variables = {
globals: {},
indexedGlobals: {}, // for indexed globals, ident ==> index
// Used in calculation of indexed globals
- nextIndexedOffset: 0,
+ nextIndexedOffset: 0
};
var Types = {
diff --git a/src/parseTools.js b/src/parseTools.js
index 350f36b7..78ff934e 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -368,13 +368,7 @@ function makeGlobalDef(ident) {
}
function makeGlobalUse(ident) {
- if (!NAMED_GLOBALS && isIndexableGlobal(ident)) {
- if (!(ident in Variables.indexedGlobals)) {
- Variables.indexedGlobals[ident] = Variables.nextIndexedOffset;
- Variables.nextIndexedOffset += Runtime.alignMemory(calcAllocatedSize(Variables.globals[ident].type));
- }
- return getFastValue('GLOBAL_BASE', '+', Variables.indexedGlobals[ident]);
- }
+ if (!NAMED_GLOBALS && isIndexableGlobal(ident)) return getFastValue('GLOBAL_BASE', '+', Variables.indexedGlobals[ident]);
return ident; // TODO: add option for namespacing or offsetting to allow reducing the number of globals
}