This commit is contained in:
Alon Zakai 2014-03-24 20:23:11 -07:00
Родитель 63ed033209
Коммит 5817cd8af0
3 изменённых файлов: 43 добавлений и 1 удалений

16
emcc
Просмотреть файл

@ -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:

Просмотреть файл

@ -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

Просмотреть файл

@ -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