diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-11-27 20:02:42 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-11-27 20:02:42 -0800 |
commit | ee0c41b39bcaf80144b8112d3e307d3e4630c077 (patch) | |
tree | b1c40a03e904dd2258f97989380bb3c651fa81b7 | |
parent | bdef7bf784d5765ffb4b64c51426eb1c517c33ea (diff) |
do not index globals referred to by name in library
-rw-r--r-- | src/jsifier.js | 9 | ||||
-rw-r--r-- | src/modules.js | 3 | ||||
-rw-r--r-- | src/parseTools.js | 15 |
3 files changed, 22 insertions, 5 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index 74dec1e4..ce094e1e 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -298,8 +298,8 @@ function JSify(data, functionsOnly, givenFunctions) { } return ret; } else { - if (!NAMED_GLOBALS) { - index = makeGlobalUse(item.ident); + if (!NAMED_GLOBALS && isIndexableGlobal(item.ident)) { + index = makeGlobalUse(item.ident); // index !== null indicates we are indexing this allocator = 'ALLOC_NONE'; } constant = parseConst(item.value, item.type, item.ident); @@ -324,11 +324,11 @@ function JSify(data, functionsOnly, givenFunctions) { constant = makePointer(constant, null, allocator, item.type, index); var js; - js = (index !== null ? '' : item.ident + '=') + constant + ';'; // '\n Module.print("' + item.ident + ' :" + ' + makeGlobalUse(item.ident) + ');'; + js = (index !== null ? '' : item.ident + '=') + constant + ';'; // \n Module.print("' + item.ident + ' :" + ' + makeGlobalUse(item.ident) + ');'; // Special case: class vtables. We make sure they are null-terminated, to allow easy runtime operations if (item.ident.substr(0, 5) == '__ZTV') { - if (!NAMED_GLOBALS) { + if (index !== null) { index = getFastValue(index, '+', Runtime.alignMemory(calcAllocatedSize(Variables.globals[item.ident].type))); } js += '\n' + makePointer('[0]', null, allocator, ['void*'], index) + ';'; @@ -1302,6 +1302,7 @@ function JSify(data, functionsOnly, givenFunctions) { if (!NAMED_GLOBALS) { sortGlobals(globalsData.globalVariables).forEach(function(g) { var ident = g.ident; + if (!isIndexableGlobal(ident)) return; Variables.indexedGlobals[ident] = Variables.nextIndexedOffset; Variables.nextIndexedOffset += Runtime.alignMemory(calcAllocatedSize(Variables.globals[ident].type)); if (ident.substr(0, 5) == '__ZTV') { // leave room for null-terminating the vtable diff --git a/src/modules.js b/src/modules.js index f939395b..fd0ec35e 100644 --- a/src/modules.js +++ b/src/modules.js @@ -266,6 +266,7 @@ var Functions = { var LibraryManager = { library: null, + loaded: false, load: function() { assert(!this.library); @@ -274,6 +275,8 @@ var LibraryManager = { for (var i = 0; i < libraries.length; i++) { eval(processMacros(preprocess(read(libraries[i])))); } + + this.loaded = true; }, // Given an ident, see if it is an alias for something, and so forth, returning diff --git a/src/parseTools.js b/src/parseTools.js index 627bde77..558f5440 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -356,9 +356,17 @@ function hasVarArgs(params) { return false; } +var UNINDEXABLE_GLOBALS = set( + '_llvm_global_ctors' // special-cased +); + +function noticePtr(ptr) { + if (!LibraryManager.loaded) UNINDEXABLE_GLOBALS[ptr] = 1; // we cannot index globals referred to in the library, since they are used there by name +} + function isIndexableGlobal(ident) { if (!(ident in Variables.globals)) return false; - if (ident == '_llvm_global_ctors') return false; + if (ident in UNINDEXABLE_GLOBALS) return false; var data = Variables.globals[ident]; return !data.alias && !data.external; } @@ -932,6 +940,7 @@ function getHeapOffset(offset, type) { // See makeSetValue function makeGetValue(ptr, pos, type, noNeedFirst, unsigned, ignore, align, noSafe) { + noticePtr(ptr); if (UNALIGNED_MEMORY) align = 1; if (isStructType(type)) { var typeData = Types.types[type]; @@ -1012,6 +1021,7 @@ function indexizeFunctions(value, type) { //! which means we should write to all slabs, ignore type differences if any on reads, etc. //! @param noNeedFirst Whether to ignore the offset in the pointer itself. function makeSetValue(ptr, pos, value, type, noNeedFirst, ignore, align, noSafe, sep, forcedAlign) { + noticePtr(ptr); if (UNALIGNED_MEMORY && !forcedAlign) align = 1; sep = sep || ';'; if (isStructType(type)) { @@ -1083,6 +1093,7 @@ var SEEK_OPTIMAL_ALIGN_MIN = 20; var UNROLL_LOOP_MAX = 8; function makeSetValues(ptr, pos, value, type, num, align) { + noticePtr(ptr); function unroll(type, num, jump, value$) { jump = jump || 1; value$ = value$ || value; @@ -1132,6 +1143,8 @@ function makeSetValues(ptr, pos, value, type, num, align) { var TYPED_ARRAY_SET_MIN = Infinity; // .set() as memcpy seems to just slow us down function makeCopyValues(dest, src, num, type, modifier, align, sep) { + noticePtr(dest); + noticePtr(src); sep = sep || ';'; function unroll(type, num, jump) { jump = jump || 1; |