aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/intertyper.js2
-rw-r--r--src/jsifier.js15
-rw-r--r--src/modules.js1
-rw-r--r--src/parseTools.js10
-rw-r--r--src/settings.js7
5 files changed, 16 insertions, 19 deletions
diff --git a/src/intertyper.js b/src/intertyper.js
index dbd5f458..124dbeb8 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -507,7 +507,7 @@ function intertyper(data, sidePass, baseLineNums) {
private_: private_,
lineNum: item.lineNum
};
- if (NUM_NAMED_GLOBALS >= 0) {
+ if (!NAMED_GLOBALS) {
Variables.globals[ret.ident].type = ret.type;
}
Types.needAnalysis[ret.type] = 0;
diff --git a/src/jsifier.js b/src/jsifier.js
index d62fa788..e218df05 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -250,7 +250,7 @@ function JSify(data, functionsOnly, givenFunctions) {
processItem: function(item) {
function needsPostSet(value) {
return value[0] in UNDERSCORE_OPENPARENS || value.substr(0, 14) === 'CHECK_OVERFLOW'
- || false; // TODO: interact with output of makeGlobalUse/makeGlobalDef
+ || value.substr(0, 6) === 'GLOBAL';
}
item.intertype = 'GlobalVariableStub';
@@ -265,16 +265,9 @@ function JSify(data, functionsOnly, givenFunctions) {
var constant = null;
var allocator = (BUILD_AS_SHARED_LIB && !item.external) ? 'ALLOC_NORMAL' : 'ALLOC_STATIC';
var index = null;
- if (NUM_NAMED_GLOBALS >= 0) {
- if (Variables.seenGlobals < NUM_NAMED_GLOBALS) {
- Variables.seenGlobals++; // named
- } else {
- // indexed
- Variables.indexedGlobals[item.ident] = Variables.nextIndexedOffset;
- index = makeGlobalUse(item.ident);
- Variables.nextIndexedOffset += Runtime.alignMemory(calcAllocatedSize(Variables.globals[item.ident].type));
- allocator = 'ALLOC_NONE';
- }
+ if (!NAMED_GLOBALS) {
+ index = makeGlobalUse(item.ident);
+ allocator = 'ALLOC_NONE';
}
if (item.external && BUILD_AS_SHARED_LIB) {
// External variables in shared libraries should not be declared as
diff --git a/src/modules.js b/src/modules.js
index 4f7fc784..68626b57 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -178,7 +178,6 @@ var Variables = {
indexedGlobals: {}, // for indexed globals, ident ==> index
// Used in calculation of indexed globals
nextIndexedOffset: 0,
- seenGlobals: 0,
};
var Types = {
diff --git a/src/parseTools.js b/src/parseTools.js
index 786d55c8..5770a0d7 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -357,12 +357,18 @@ function hasVarArgs(params) {
}
function makeGlobalDef(ident) {
- if (ident in Variables.indexedGlobals) return '';
+ if (!NAMED_GLOBALS) return '';
return 'var ' + ident + ';'; // TODO: add option for namespacing or offsetting to allow reducing the number of globals
}
function makeGlobalUse(ident) {
- if (ident in Variables.indexedGlobals) return getFastValue('GLOBAL_BASE', '+', Variables.indexedGlobals[ident]);
+ if (!NAMED_GLOBALS) {
+ 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]);
+ }
return ident; // TODO: add option for namespacing or offsetting to allow reducing the number of globals
}
diff --git a/src/settings.js b/src/settings.js
index 4881e149..1d8805a8 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -194,10 +194,9 @@ var PGO = 0; // Profile-guided optimization.
// All CORRECT_* options default to 1 with PGO builds.
// See https://github.com/kripken/emscripten/wiki/Optimizing-Code for more info
-var NUM_NAMED_GLOBALS = -1; // If >= 0, the number of globals we allow to be named. Other globals
- // are then referred to by a base plus an offset (called an indexed global),
- // saving global variables but adding runtime overhead. If -1, then we
- // allow all globals to be named.
+var NAMED_GLOBALS = 1; // If 1, we use global variables for globals. Otherwise
+ // they are referred to by a base plus an offset (called an indexed global),
+ // saving global variables but adding runtime overhead.
var PROFILE = 0; // Enables runtime profiling. See test_profiling for a usage example.