diff options
-rw-r--r-- | emlink.py | 2 | ||||
-rw-r--r-- | tools/asm_module.py | 7 | ||||
-rwxr-xr-x | tools/merge_asm.py | 26 | ||||
-rwxr-xr-x | tools/split_asm.py | 30 |
4 files changed, 61 insertions, 4 deletions
@@ -6,7 +6,7 @@ Fast static linker for emscripten outputs. Specifically this links asm.js module See https://github.com/kripken/emscripten/wiki/Linking ''' -import os, subprocess, sys +import sys from tools import shared from tools.asm_module import AsmModule diff --git a/tools/asm_module.py b/tools/asm_module.py index e3fc9a76..e54cfc21 100644 --- a/tools/asm_module.py +++ b/tools/asm_module.py @@ -14,8 +14,9 @@ class AsmModule(): self.end_funcs = self.js.rfind(js_optimizer.end_funcs_marker) self.end_asm = self.js.rfind(js_optimizer.end_asm_marker) - # pre + # pre and asm self.pre_js = self.js[:self.start_asm] + self.asm_js = self.js[self.start_asm:self.end_asm] # heap initializer self.staticbump = int(re.search(shared.JS.memory_staticbump_pattern, self.pre_js).group(1)) @@ -238,8 +239,8 @@ class AsmModule(): for part in parts: if '=' not in part: continue part = part.split('var ')[1] - name, data = part.split(' = ') - tables[name] = data + name, data = part.split('=') + tables[name.strip()] = data.strip() return tables def merge_tables(self, table, main, side, replacements, f_bases, f_sizes): diff --git a/tools/merge_asm.py b/tools/merge_asm.py new file mode 100755 index 00000000..fe143a89 --- /dev/null +++ b/tools/merge_asm.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python2 + +''' +Splits a compiler outputted program into the asm module and the surrounding shell. This +can be useful if you want to process the shell in some manner (e.g. minifiy it) in ways +that would be harmful to asm.js code. +''' + +import sys +import shared + +try: + me, in_shell, in_asm, outfile = sys.argv[:4] +except: + print >> sys.stderr, 'usage: emlink.py [input file] [shell output file] [asm output file]' + sys.exit(1) + +print 'Shell input:', in_shell +print 'Asm input:', in_asm +print 'Input file:', outfile + +shared.try_delete(outfile) + +pre, post = open(in_shell).read().split('// ASM_CODE\n') +open(outfile, 'w').write(pre + '\n' + open(in_asm).read() + '\n' + post) + diff --git a/tools/split_asm.py b/tools/split_asm.py new file mode 100755 index 00000000..39eaca00 --- /dev/null +++ b/tools/split_asm.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python2 + +''' +Splits a compiler outputted program into the asm module and the surrounding shell. This +can be useful if you want to process the shell in some manner (e.g. minifiy it) in ways +that would be harmful to asm.js code. +''' + +import sys +import shared +from asm_module import AsmModule + +try: + me, infile, out_shell, out_asm = sys.argv[:4] +except: + print >> sys.stderr, 'usage: emlink.py [input file] [shell output file] [asm output file]' + sys.exit(1) + +print 'Input file:', infile +print 'Shell output:', out_shell +print 'Asm output:', out_asm + +shared.try_delete(out_shell) +shared.try_delete(out_asm) + +module = AsmModule(infile) + +open(out_shell, 'w').write(module.pre_js + '\n// ASM_CODE\n' + module.post_js) +open(out_asm, 'w').write(module.asm_js) + |