diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-03-24 20:23:11 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-03-24 20:23:11 -0700 |
commit | 5817cd8af0036d6593f6e0fb314a291f40e8056a (patch) | |
tree | 51457d9f89b0eef4983d93ca996006c327194709 | |
parent | 63ed033209d1880d6f8f6b47c5e1bedb01f0b330 (diff) |
--emit-symbol-map option
-rwxr-xr-x | emcc | 16 | ||||
-rw-r--r-- | tests/test_other.py | 13 | ||||
-rw-r--r-- | tools/js_optimizer.py | 15 |
3 files changed, 43 insertions, 1 deletions
@@ -242,6 +242,14 @@ Options that are modified or new in %s include: performance and otherwise might not be performed in -g2. + --emit-symbol-map Save a map file between the minified + global names and the original function names. + This allows you to reconstruct meaningful + stack traces, for example. (This is only + relevant when minifying global names, which + happens in -O2 and above, and when no -g + option to prevent minification was specified.) + --typed-arrays <mode> 0: No typed arrays 1: Parallel typed arrays 2: Shared (C-like) typed arrays (default) @@ -778,6 +786,7 @@ try: opt_level = 0 debug_level = 0 profiling = False + emit_symbol_map = False js_opts = None llvm_opts = None llvm_lto = None @@ -902,6 +911,9 @@ try: debug_level = 2 profiling = True newargs[i] = '' + elif newargs[i] == '--emit-symbol-map': + emit_symbol_map = True + newargs[i] = '' elif newargs[i] == '--bind': bind = True newargs[i] = '' @@ -1718,7 +1730,9 @@ try: js_optimizer_queue += ['registerize'] if opt_level >= 2: - if debug_level < 2 and shared.Settings.ASM_JS: js_optimizer_queue += ['minifyNames'] + if debug_level < 2 and shared.Settings.ASM_JS: + js_optimizer_queue += ['minifyNames'] + if emit_symbol_map: js_optimizer_queue += ['symbolMap='+target+'.symbols'] if debug_level == 0: js_optimizer_queue += ['minifyWhitespace'] if closure and shared.Settings.ASM_JS: diff --git a/tests/test_other.py b/tests/test_other.py index f9b0009d..9146888c 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -2669,3 +2669,16 @@ int main() } ''', [3, 1, 1]) + def test_symbol_map(self): + for m in [0, 1]: + self.clear() + cmd = [PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-O2'] + if m: cmd += ['--emit-symbol-map'] + print cmd + stdout, stderr = Popen(cmd, stderr=PIPE).communicate() + assert ('''wrote symbol map file''' in stderr) == m, stderr + assert (os.path.exists('a.out.js.symbols') == m), stderr + if m: + symbols = open('a.out.js.symbols').read() + assert ':_main' in symbols + diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py index 4821cc81..d0284528 100644 --- a/tools/js_optimizer.py +++ b/tools/js_optimizer.py @@ -32,6 +32,7 @@ class Minifier: def __init__(self, js, js_engine): self.js = js self.js_engine = js_engine + self.symbols_file = None def minify_shell(self, shell, minify_whitespace, source_map=False): # Run through js-optimizer.js to find and minify the global symbols @@ -61,6 +62,14 @@ class Minifier: #print >> sys.stderr, "minified SHELL 3333333333333333", output, "\n44444444444444444444" code, metadata = output.split('// EXTRA_INFO:') self.globs = json.loads(metadata) + + if self.symbols_file: + mapfile = open(self.symbols_file, 'w') + for key, value in self.globs.iteritems(): + mapfile.write(value + ':' + key + '\n') + mapfile.close() + print >> sys.stderr, 'wrote symbol map file to', self.symbols_file + return code.replace('13371337', '0.0') @@ -162,6 +171,12 @@ EMSCRIPTEN_FUNCS(); # we assume there is a maximum of one new name per line minifier = Minifier(js, js_engine) + def check_symbol_mapping(p): + if p.startswith('symbolMap='): + minifier.symbols_file = p.split('=')[1] + return False + return True + passes = filter(check_symbol_mapping, passes) asm_shell_pre, asm_shell_post = minifier.minify_shell(asm_shell, 'minifyWhitespace' in passes, source_map).split('EMSCRIPTEN_FUNCS();'); asm_shell_post = asm_shell_post.replace('});', '})'); pre += asm_shell_pre + '\n' + start_funcs_marker |