diff options
95 files changed, 2727 insertions, 1077 deletions
@@ -24,7 +24,7 @@ a license to everyone to use it as detailed in LICENSE.) * Pierre Renaux <pierre@talansoft.com> * Brian Anderson <banderson@mozilla.com> * Jon Bardin <diclophis@gmail.com> -* Jukka Jylänki <jujjyl@gmail.com> +* Jukka Jylänki <jujjyl@gmail.com> * Aleksander Guryanov <caiiiycuk@gmail.com> * Chad Austin <chad@chadaustin.me> (copyright owned by IMVU) * nandhp <nandhp@gmail.com> @@ -46,7 +46,7 @@ a license to everyone to use it as detailed in LICENSE.) * Anthony Liot <wolfviking0@yahoo.com> * Michael Riss <Michael.Riss@gmx.de> * Jasper St. Pierre <jstpierre@mecheye.net> -* Manuel Schölling <manuel.schoelling@gmx.de> +* Manuel Schölling <manuel.schoelling@gmx.de> * Bruce Mitchener, Jr. <bruce.mitchener@gmail.com> * Michael Bishop <mbtyke@gmail.com> * Roger Braun <roger@rogerbraun.net> @@ -55,5 +55,8 @@ a license to everyone to use it as detailed in LICENSE.) * Tobias Doerffel <tobias.doerffel@gmail.com> * Martin von Gagern <martin@von-gagern.net> * Ting-Yuan Huang <thuang@mozilla.com> +* Felix H. Dahlke <fhd@ubercode.de> +* Éloi Rivard <azmeuk@gmail.com> * Alexander Gladysh <ag@logiceditor.com> + diff --git a/emscripten.py b/emscripten.py index d41aaa2c..8f68ee77 100755 --- a/emscripten.py +++ b/emscripten.py @@ -20,6 +20,15 @@ def path_from_root(*pathelems): """ return os.path.join(__rootpath__, *pathelems) +def get_configuration(): + if hasattr(get_configuration, 'configuration'): + return get_configuration.configuration + + from tools import shared + configuration = shared.Configuration(environ=os.environ) + get_configuration.configuration = configuration + return configuration + def scan(ll, settings): # blockaddress(@main, %23) blockaddrs = [] @@ -299,7 +308,12 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None, indexing = forwarded_json['Functions']['indexedFunctions'] def indexize(js): - return re.sub(r"'{{ FI_([\w\d_$]+) }}'", lambda m: str(indexing.get(m.groups(0)[0]) or 0), js) + # In the global initial allocation, we need to split up into Uint8 format + def split_32(x): + x = int(x) + return '%d,%d,%d,%d' % (x&255, (x >> 8)&255, (x >> 16)&255, (x >> 24)&255) + ret = re.sub(r"\"?'?{{ FI_([\w\d_$]+) }}'?\"?,0,0,0", lambda m: split_32(indexing.get(m.groups(0)[0]) or 0), js) + return re.sub(r"'{{ FI_([\w\d_$]+) }}'", lambda m: str(indexing.get(m.groups(0)[0]) or 0), ret) blockaddrs = forwarded_json['Functions']['blockAddresses'] def blockaddrsize(js): @@ -683,15 +697,6 @@ WARNING: You should normally never use this! Use emcc instead. else: relooper = None # use the cache - def get_configuration(): - if hasattr(get_configuration, 'configuration'): - return get_configuration.configuration - - from tools import shared - configuration = shared.Configuration(environ=os.environ) - get_configuration.configuration = configuration - return configuration - if keywords.temp_dir is None: temp_files = get_configuration().get_temp_files() else: diff --git a/src/jsifier.js b/src/jsifier.js index 69d9842a..ce089334 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -231,12 +231,11 @@ function JSify(data, functionsOnly, givenFunctions) { if (value.intertype in PARSABLE_LLVM_FUNCTIONS) { return [finalizeLLVMFunctionCall(value)]; } else if (Runtime.isNumberType(type) || pointingLevels(type) >= 1) { - return makeGlobalUse(indexizeFunctions(parseNumerical(value.value), type)); + return [makeGlobalUse(indexizeFunctions(parseNumerical(value.value), type))]; } else if (value.intertype === 'emptystruct') { return makeEmptyStruct(type); } else if (value.intertype === 'string') { - return JSON.stringify(parseLLVMString(value.text)) + - ' /* ' + value.text.substr(0, 20).replace(/[*<>]/g, '_') + ' */'; // make string safe for inclusion in comment + return parseLLVMString(value.text); } else { return alignStruct(handleSegments(value.contents), type); } @@ -244,9 +243,7 @@ function JSify(data, functionsOnly, givenFunctions) { function parseConst(value, type, ident) { var constant = makeConst(value, type); - if (typeof constant === 'object') { - constant = flatten(constant).map(function(x) { return parseNumerical(x) }) - } + constant = flatten(constant).map(function(x) { return parseNumerical(x) }) return constant; } @@ -254,6 +251,7 @@ function JSify(data, functionsOnly, givenFunctions) { substrate.addActor('GlobalVariable', { processItem: function(item) { function needsPostSet(value) { + if (typeof value !== 'string') return false; return value[0] in UNDERSCORE_OPENPARENS || value.substr(0, 14) === 'CHECK_OVERFLOW' || value.substr(0, 6) === 'GLOBAL'; } @@ -266,105 +264,82 @@ function JSify(data, functionsOnly, givenFunctions) { item.ctors.map(function(ctor) { return ' { func: function() { ' + ctor + '() } }' }).join(',\n') + '\n]);\n'; return ret; + } + + var constant = null; + var allocator = (BUILD_AS_SHARED_LIB && !item.external) ? 'ALLOC_NORMAL' : 'ALLOC_STATIC'; + var index = null; + if (item.external && BUILD_AS_SHARED_LIB) { + // External variables in shared libraries should not be declared as + // they would shadow similarly-named globals in the parent. + item.JS = ''; } else { - var constant = null; - var allocator = (BUILD_AS_SHARED_LIB && !item.external) ? 'ALLOC_NORMAL' : 'ALLOC_STATIC'; - var index = null; - if (item.external && BUILD_AS_SHARED_LIB) { - // External variables in shared libraries should not be declared as - // they would shadow similarly-named globals in the parent. - item.JS = ''; - } else { - item.JS = makeGlobalDef(item.ident); - } + item.JS = makeGlobalDef(item.ident); + } - if (item.external && !ASM_JS) { // ASM_JS considers externs to be globals - // Import external global variables from the library if available. - var shortident = item.ident.slice(1); - if (LibraryManager.library[shortident] && - LibraryManager.library[shortident].length && - !BUILD_AS_SHARED_LIB) { - if (addedLibraryItems[shortident]) return ret; - var val = LibraryManager.library[shortident]; - var padding; - if (Runtime.isNumberType(item.type) || isPointerType(item.type)) { - padding = [item.type].concat(zeros(Runtime.getNativeFieldSize(item.type)-1)); - } else { - padding = makeEmptyStruct(item.type); - } - var padded = val.concat(padding.slice(val.length)); - var js = item.ident + '=' + makePointer(padded, null, allocator, item.type, index) + ';' - if (LibraryManager.library[shortident + '__postset']) { - js += '\n' + LibraryManager.library[shortident + '__postset']; - } - ret.push({ - intertype: 'GlobalVariablePostSet', - JS: js - }); - } - return ret; + if (!NAMED_GLOBALS && isIndexableGlobal(item.ident)) { + index = makeGlobalUse(item.ident); // index !== null indicates we are indexing this + allocator = 'ALLOC_NONE'; + } + if (item.external) { + if (Runtime.isNumberType(item.type) || isPointerType(item.type)) { + constant = zeros(Runtime.getNativeFieldSize(item.type)); } else { - if (!NAMED_GLOBALS && isIndexableGlobal(item.ident)) { - index = makeGlobalUse(item.ident); // index !== null indicates we are indexing this - allocator = 'ALLOC_NONE'; - } - if (item.external) { - assert(ASM_JS); - if (Runtime.isNumberType(item.type) || isPointerType(item.type)) { - constant = zeros(Runtime.getNativeFieldSize(item.type)); - } else { - constant = makeEmptyStruct(item.type); - } - constant = JSON.stringify(constant); - } else { - constant = parseConst(item.value, item.type, item.ident); - } - if (typeof constant === 'string' && constant[0] != '[') { - constant = [constant]; // A single item. We may need a postset for it. - } - if (typeof constant === 'object') { - // This is a flattened object. We need to find its idents, so they can be assigned to later - constant.forEach(function(value, i) { - if (needsPostSet(value)) { // ident, or expression containing an ident - ret.push({ - intertype: 'GlobalVariablePostSet', - JS: makeSetValue(makeGlobalUse(item.ident), i, value, 'i32', false, true) + ';' // ignore=true, since e.g. rtti and statics cause lots of safe_heap errors |