aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-01-25 18:40:31 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-01-25 18:40:31 -0800
commitd57236a76b95d15f77d98db827a567c40d87f173 (patch)
tree0871454cfc4f78dc8daadf533b22fbbf8b8eea46 /src
parent55ea32242febfd83841d39d1b53d6e2f190db67c (diff)
parent01e21e541251d271d28e92b2c6b28a8290994470 (diff)
Merge branch 'master' into llvmopts
Diffstat (limited to 'src')
-rw-r--r--src/intertyper.js4
-rw-r--r--src/jsifier.js18
-rw-r--r--src/parseTools.js3
-rw-r--r--src/preamble.js2
-rw-r--r--src/preamble_sharedlib.js1
5 files changed, 24 insertions, 4 deletions
diff --git a/src/intertyper.js b/src/intertyper.js
index d295a872..ae9794b8 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -83,10 +83,12 @@ function intertyper(data, sidePass, baseLineNums) {
var global = /([@%\w\d\.\" ]+) = .*/.exec(line);
var globalIdent = toNiceIdent(global[1]);
var testAlias = /[@%\w\d\.\" ]+ = alias .*/.exec(line);
+ var testString = /^[^"]+c\"[^"]+"/.exec(line);
Variables.globals[globalIdent] = {
name: globalIdent,
alias: !!testAlias,
- impl: VAR_EMULATED
+ impl: VAR_EMULATED,
+ isString : !!testString
};
unparsedGlobals.lines.push(line);
} else {
diff --git a/src/jsifier.js b/src/jsifier.js
index 846cb4c1..7bff588c 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -247,7 +247,8 @@ function JSify(data, functionsOnly, givenFunctions) {
substrate.addActor('GlobalVariable', {
processItem: function(item) {
function needsPostSet(value) {
- return value[0] in UNDERSCORE_OPENPARENS || value.substr(0, 14) === 'CHECK_OVERFLOW';
+ return value[0] in UNDERSCORE_OPENPARENS || value.substr(0, 14) === 'CHECK_OVERFLOW'
+ || value.substr(0, 13) === 'STRING_TABLE.';
}
item.intertype = 'GlobalVariableStub';
@@ -264,7 +265,9 @@ function JSify(data, functionsOnly, givenFunctions) {
// they would shadow similarly-named globals in the parent.
item.JS = '';
} else {
- item.JS = 'var ' + item.ident + ';';
+ if (!(item.ident in Variables.globals) || !Variables.globals[item.ident].isString) {
+ item.JS = 'var ' + item.ident + ';';
+ }
}
var constant = null;
if (item.external) {
@@ -313,7 +316,16 @@ function JSify(data, functionsOnly, givenFunctions) {
// allocations in a shared library.
constant = makePointer(constant, null, BUILD_AS_SHARED_LIB ? 'ALLOC_NORMAL' : 'ALLOC_STATIC', item.type);
- var js = item.ident + '=' + constant + ';';
+ var js;
+
+ // Strings are held in STRING_TABLE, to not clutter up the main namespace (in some cases we have
+ // many many strings, possibly exceeding the js engine limit on global vars).
+ if (Variables.globals[item.ident].isString) {
+ js = 'STRING_TABLE.' + item.ident + '=' + constant + ';';
+ } else {
+ js = item.ident + '=' + constant + ';';
+ }
+
// Special case: class vtables. We make sure they are null-terminated, to allow easy runtime operations
if (item.ident.substr(0, 5) == '__ZTV') {
js += '\n' + makePointer('[0]', null, BUILD_AS_SHARED_LIB ? 'ALLOC_NORMAL' : 'ALLOC_STATIC', ['void*']) + ';';
diff --git a/src/parseTools.js b/src/parseTools.js
index d956ccfb..49e5b411 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -1439,6 +1439,9 @@ function finalizeLLVMParameter(param, noIndexizeFunctions) {
}
} else if (param.intertype == 'value') {
ret = param.ident;
+ if (ret in Variables.globals && Variables.globals[ret].isString) {
+ ret = "STRING_TABLE." + ret;
+ }
if (param.type == 'i64' && I64_MODE == 1) {
ret = parseI64Constant(ret);
}
diff --git a/src/preamble.js b/src/preamble.js
index 051bb8d4..94add7f4 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -771,6 +771,8 @@ function intArrayToString(array) {
}
Module['intArrayToString'] = intArrayToString;
+var STRING_TABLE = [];
+
{{{ unSign }}}
{{{ reSign }}}
diff --git a/src/preamble_sharedlib.js b/src/preamble_sharedlib.js
index 2a071f6b..af204e2f 100644
--- a/src/preamble_sharedlib.js
+++ b/src/preamble_sharedlib.js
@@ -16,6 +16,7 @@ function callRuntimeCallbacks(callbacks) {
}
var __ATINIT__ = []; // functions called during startup
+var STRING_TABLE = [];
function initRuntime() {
callRuntimeCallbacks(__ATINIT__);