refactor and calculate new imports

This commit is contained in:
Alon Zakai 2013-06-24 16:59:39 -07:00
Родитель 0af083b4a0
Коммит 754ba99108
2 изменённых файлов: 24 добавлений и 11 удалений

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

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

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

@ -10614,17 +10614,17 @@ f.close()
return 0;
}
''')
open(os.path.join(self.get_dir(), 'lib.cpp'), 'w').write('''
open(os.path.join(self.get_dir(), 'side.cpp'), 'w').write('''
#include <stdio.h>
void printey() {
printf("hello from lib\\n");
printf("hello from side\\n");
}
''')
Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'lib.cpp'), '-o', 'lib.js', '-s', 'SIDE_MODULE=1', '-O2']).communicate()
Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'side.cpp'), '-o', 'side.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'))
Popen([PYTHON, EMLINK, 'main.js', 'side.js', 'together.js'])
self.assertContained('hello from side', run_js('together.js'))
def test_symlink(self):
if os.name == 'nt':