diff options
-rwxr-xr-x | emscripten.py | 19 | ||||
-rw-r--r-- | src/jsifier.js | 4 | ||||
-rw-r--r-- | src/library.js | 7 | ||||
-rw-r--r-- | src/utility.js | 8 | ||||
-rw-r--r-- | tests/test_other.py | 14 |
5 files changed, 35 insertions, 17 deletions
diff --git a/emscripten.py b/emscripten.py index 907e88ce..ae46ca07 100755 --- a/emscripten.py +++ b/emscripten.py @@ -804,6 +804,13 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, if DEBUG: logging.debug('emscript: js compiler glue') + # Settings changes + assert settings['TARGET_LE32'] == 1 + settings['TARGET_LE32'] = 2 + if 'i64Add' in metadata['declares']: # TODO: others, once we split them up + settings['PRECISE_I64_MATH'] = 2 + metadata['declares'] = filter(lambda i64_func: i64_func not in ['getHigh32', 'setHigh32', '__muldi3', '__divdi3', '__remdi3', '__udivdi3', '__uremdi3'], metadata['declares']) # FIXME: do these one by one as normal js lib funcs + # Integrate info from backend settings['DEFAULT_LIBRARY_FUNCS_TO_INCLUDE'] = list( set(settings['DEFAULT_LIBRARY_FUNCS_TO_INCLUDE'] + map(shared.JS.to_nice_ident, metadata['declares'])).difference( @@ -811,10 +818,6 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, ) ) + map(lambda x: x[1:], metadata['externs']) - # Settings changes - assert settings['TARGET_LE32'] == 1 - settings['TARGET_LE32'] = 2 - # Save settings to a file to work around v8 issue 1579 settings_file = temp_files.get('.txt').name def save_settings(): @@ -885,18 +888,14 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, #if DEBUG: outfile.write('// funcs\n') if settings.get('ASM_JS'): - #print >> sys.stderr, '<<<<<<', post, '>>>>>>' - post_funcs = '' #, post_rest = post.split('// EMSCRIPTEN_END_FUNCS\n') - #post = post_rest - # Move preAsms to their right place def move_preasm(m): contents = m.groups(0)[0] outfile.write(contents + '\n') return '' - post_funcs = re.sub(r'/\* PRE_ASM \*/(.*)\n', lambda m: move_preasm(m), post_funcs) + funcs_js[1] = re.sub(r'/\* PRE_ASM \*/(.*)\n', lambda m: move_preasm(m), funcs_js[1]) - funcs_js += ['\n' + post_funcs + '// EMSCRIPTEN_END_FUNCS\n'] + funcs_js += ['\n// EMSCRIPTEN_END_FUNCS\n'] simple = os.environ.get('EMCC_SIMPLE_ASM') class Counter: diff --git a/src/jsifier.js b/src/jsifier.js index 907855e7..b5502741 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1859,10 +1859,10 @@ function JSify(data, functionsOnly, givenFunctions) { // first row are utilities called from generated code, second are needed from fastLong ['i64Add', 'i64Subtract', 'bitshift64Shl', 'bitshift64Lshr', 'bitshift64Ashr', 'llvm_ctlz_i32', 'llvm_cttz_i32'].forEach(function(func) { - if (!Functions.libraryFunctions[func]) { + if (!Functions.libraryFunctions[func] || (phase == 'glue' && func[0] === 'l')) { // TODO: one-by-one in fastcomp glue mode print(processLibraryFunction(LibraryManager.library[func], func)); // must be first to be close to generated code Functions.implementedFunctions['_' + func] = LibraryManager.library[func + '__sig']; - Functions.libraryFunctions[func] = 1; + Functions.libraryFunctions[func] = phase == 'glue' ? 2 : 1; // XXX // limited dependency handling var deps = LibraryManager.library[func + '__deps']; if (deps) { diff --git a/src/library.js b/src/library.js index 26d766e9..1e8c6ba6 100644 --- a/src/library.js +++ b/src/library.js @@ -1868,14 +1868,13 @@ LibraryManager.library = { #endif #if USE_TYPED_ARRAYS == 2 } else if (type == 'i64') { - -#if TARGET_LE32 +#if TARGET_LE32 == 1 ret = [{{{ makeGetValue('varargs', 'argIndex', 'i32', undefined, undefined, true) }}}, {{{ makeGetValue('varargs', 'argIndex+8', 'i32', undefined, undefined, true) }}}]; argIndex += {{{ STACK_ALIGN }}}; // each 32-bit chunk is in a 64-bit block #else - ret = [{{{ makeGetValue('varargs', 'argIndex', 'i32', undefined, undefined, true) }}}, - {{{ makeGetValue('varargs', 'argIndex+4', 'i32', undefined, undefined, true) }}}]; + ret = [{{{ makeGetValue('varargs', 'argIndex', 'i32', undefined, undefined, true, 4) }}}, + {{{ makeGetValue('varargs', 'argIndex+4', 'i32', undefined, undefined, true, 4) }}}]; #endif #else diff --git a/src/utility.js b/src/utility.js index cd27b209..178c596b 100644 --- a/src/utility.js +++ b/src/utility.js @@ -346,13 +346,19 @@ function sortedJsonCompare(x, y) { return true; } +function escapeJSONKey(x) { + if (/^[\d\w_]+$/.exec(x) || x[0] === '"' || x[0] === "'") return x; + assert(x.indexOf("'") < 0, 'cannot have internal single quotes in keys: ' + x); + return "'" + x + "'"; +} + function stringifyWithFunctions(obj) { if (typeof obj === 'function') return obj.toString(); if (obj === null || typeof obj !== 'object') return JSON.stringify(obj); if (isArray(obj)) { return '[' + obj.map(stringifyWithFunctions).join(',') + ']'; } else { - return '{' + keys(obj).map(function(key) { return key + ':' + stringifyWithFunctions(obj[key]) }).join(',') + '}'; + return '{' + keys(obj).map(function(key) { return escapeJSONKey(key) + ':' + stringifyWithFunctions(obj[key]) }).join(',') + '}'; } } diff --git a/tests/test_other.py b/tests/test_other.py index 5100db72..b10ae13b 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -2136,3 +2136,17 @@ int main() assert 'test.o' in head, 'Invalid dependency target' assert 'test.cpp' in tail and 'test.hpp' in tail, 'Invalid dependencies generated' + def test_quoted_js_lib_key(self): + open('lib.js', 'w').write(r''' +mergeInto(LibraryManager.library, { + __internal_data:{ + '<' : 0, + 'white space' : 1 + }, + printf__deps: ['__internal_data', 'fprintf'] +}); +''') + + Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp'), '--js-library', 'lib.js']).communicate() + self.assertContained('hello, world!', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + |