String constants are store in a table to limit variable count
This commit is contained in:
Родитель
61e4b6b9d4
Коммит
0040353a17
|
@ -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 {
|
||||
|
|
|
@ -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,13 @@ 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;
|
||||
|
||||
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*']) + ';';
|
||||
|
|
|
@ -1434,6 +1434,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);
|
||||
}
|
||||
|
|
|
@ -750,6 +750,8 @@ function intArrayToString(array) {
|
|||
}
|
||||
Module['intArrayToString'] = intArrayToString;
|
||||
|
||||
var STRING_TABLE = [];
|
||||
|
||||
{{{ unSign }}}
|
||||
{{{ reSign }}}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ function callRuntimeCallbacks(callbacks) {
|
|||
}
|
||||
|
||||
var __ATINIT__ = []; // functions called during startup
|
||||
var STRING_TABLE = [];
|
||||
|
||||
function initRuntime() {
|
||||
callRuntimeCallbacks(__ATINIT__);
|
||||
|
|
Загрузка…
Ссылка в новой задаче