diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-06-24 16:36:05 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-07-03 15:31:03 -0700 |
commit | f2178dcdd562f49c9f668c6afae20386168c72b6 (patch) | |
tree | 404b92ed52d97f6508df14526ac90b5e5ee5e92f | |
parent | c8ba74664f1ce245918cbcd4e5a9b7dc41fc404f (diff) |
start to parse asm modules
-rw-r--r-- | emlink.py | 24 | ||||
-rwxr-xr-x | tests/runner.py | 1 | ||||
-rw-r--r-- | tools/js_optimizer.py | 9 |
3 files changed, 30 insertions, 4 deletions
@@ -14,6 +14,7 @@ side modules into a main module that way. import os, subprocess, sys from tools import shared +from tools import js_optimizer try: me, main, side, out = sys.argv[:4] @@ -25,3 +26,26 @@ print 'Main module:', main print 'Side module:', side print 'Output:', out +class AsmModule(): + def __init__(self, filename): + self.js = open(filename).read() + funcs_js = self.js[self.js.find(js_optimizer.start_funcs_marker):self.js.rfind(js_optimizer.end_funcs_marker)] + self.funcs = [m.group(2) for m in js_optimizer.func_sig.finditer(funcs_js)] + print filename, self.funcs + + def relocate(self, main): + # Find function name replacements TODO: do not rename duplicate names with duplicate contents, just merge them + main_funcs = set(main.funcs) + replacements = {} + for i in range(len(self.funcs)): + rep = func = self.funcs[i] + while rep in main_funcs: + rep += '_' + replacements[func] = rep + print replacements + +main = AsmModule(main) +side = AsmModule(side) + +side.relocate(main) + diff --git a/tests/runner.py b/tests/runner.py index 2c06c02f..e2545dee 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -10621,6 +10621,7 @@ f.close() } ''') Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'lib.cpp'), '-o', 'lib.js', '-s', 'SIDE_MODULE=1', '-O2']).communicate() + # TODO: test with and without DISABLE_GL_EMULATION, check that file sizes change Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '-o', 'main.js', '-s', 'MAIN_MODULE=1', '-O2', '-s', 'DISABLE_GL_EMULATION=1']).communicate() Popen([PYTHON, EMLINK, 'main.js', 'lib.js', 'together.js']) self.assertContained('hello from lib', run_js('together.js')) diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py index 905ae835..58b0af6d 100644 --- a/tools/js_optimizer.py +++ b/tools/js_optimizer.py @@ -95,6 +95,11 @@ class Minifier: 'globals': self.globs }) +start_funcs_marker = '// EMSCRIPTEN_START_FUNCS\n' +end_funcs_marker = '// EMSCRIPTEN_END_FUNCS\n' +start_asm_marker = '// EMSCRIPTEN_START_ASM\n' +end_asm_marker = '// EMSCRIPTEN_END_ASM\n' + def run_on_chunk(command): filename = command[2] # XXX hackish #print >> sys.stderr, 'running js optimizer command', ' '.join(command), '""""', open(filename).read() @@ -129,8 +134,6 @@ def run_on_js(filename, passes, js_engine, jcache, source_map=False): generated = set(eval(suffix[len(suffix_marker)+1:])) # Find markers - start_funcs_marker = '// EMSCRIPTEN_START_FUNCS\n' - end_funcs_marker = '// EMSCRIPTEN_END_FUNCS\n' start_funcs = js.find(start_funcs_marker) end_funcs = js.rfind(end_funcs_marker) #assert (start_funcs >= 0) == (end_funcs >= 0) == (not not suffix) @@ -138,8 +141,6 @@ def run_on_js(filename, passes, js_engine, jcache, source_map=False): minify_globals = 'registerizeAndMinify' in passes and 'asm' in passes if minify_globals: passes = map(lambda p: p if p != 'registerizeAndMinify' else 'registerize', passes) - start_asm_marker = '// EMSCRIPTEN_START_ASM\n' - end_asm_marker = '// EMSCRIPTEN_END_ASM\n' start_asm = js.find(start_asm_marker) end_asm = js.rfind(end_asm_marker) assert (start_asm >= 0) == (end_asm >= 0) |