diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-06-24 16:59:39 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-07-03 15:31:03 -0700 |
commit | 754ba991083952041418df4da54d01d85f9d73f1 (patch) | |
tree | 932d50cc313848d21af8897db3e7b4b12907bb9a /emlink.py | |
parent | 0af083b4a07ea912f7d6e1b558fde0e38086da06 (diff) |
refactor and calculate new imports
Diffstat (limited to 'emlink.py')
-rw-r--r-- | emlink.py | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -29,19 +29,32 @@ print 'Output:', out class AsmModule(): def __init__(self, filename): self.js = open(filename).read() + + start_asm = self.js.find(js_optimizer.start_asm_marker) + start_funcs = self.js.find(js_optimizer.start_funcs_marker) + end_funcs = self.js.rfind(js_optimizer.end_funcs_marker) + end_asm = self.js.rfind(js_optimizer.end_asm_marker) + # imports - imports_js = self.js[self.js.find(js_optimizer.start_asm_marker):self.js.rfind(js_optimizer.start_funcs_marker)] - self.imports = [m.group(0) for m in js_optimizer.import_sig.finditer(imports_js)] + self.imports_js = self.js[start_asm:start_funcs] + self.imports = [m.group(0) for m in js_optimizer.import_sig.finditer(self.imports_js)] #print 'imports', self.imports # funcs - 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)] + self.funcs_js = self.js[start_funcs:end_funcs] + self.funcs = [m.group(2) for m in js_optimizer.func_sig.finditer(self.funcs_js)] #print 'funcs', self.funcs - # exports + # tables and exports + self.post_js = self.js[end_funcs:end_asm] def relocate(self, main): + # imports + main_imports = set(main.imports) + new_imports = [imp for imp in self.imports if imp not in main_imports] + print 'new imports', new_imports + main.imports_js += '\n'.join(new_imports) + # Find function name replacements TODO: do not rename duplicate names with duplicate contents, just merge them main_funcs = set(main.funcs) replacements = {} @@ -50,7 +63,7 @@ class AsmModule(): while rep in main_funcs: rep += '_' replacements[func] = rep - print replacements + #print replacements def write(self, out): open(out, 'w').write(self.js) |