diff options
author | Chad Austin <chad@imvu.com> | 2013-01-29 18:07:16 -0800 |
---|---|---|
committer | Chad Austin <chad@imvu.com> | 2013-03-04 19:08:33 -0800 |
commit | 74b72bba490d30824ce444d84a02c7fee8881140 (patch) | |
tree | 5c0c45a2204bdc63b52b5fe88234587f69c3e07e | |
parent | cc9cc70e87d8f4b00aa869453802bf7eee718a4d (diff) |
Kill compiler_engine global variable and use the specified compiler engine for every invocation in emscripten.py
-rwxr-xr-x | emscripten.py | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/emscripten.py b/emscripten.py index 2ada0b0d..1ce3625f 100755 --- a/emscripten.py +++ b/emscripten.py @@ -9,7 +9,7 @@ header files (so that the JS compiler can see the constants in those headers, for the libc implementation in JS). ''' -import os, sys, json, optparse, subprocess, re, time, multiprocessing +import os, sys, json, optparse, subprocess, re, time, multiprocessing, functools from tools import shared @@ -23,7 +23,6 @@ def path_from_root(*pathelems): configuration = shared.Configuration(environ=os.environ) temp_files = shared.make_temp_files() -compiler_engine = None jcache = False def scan(ll, settings): @@ -39,21 +38,20 @@ NUM_CHUNKS_PER_CORE = 1.25 MIN_CHUNK_SIZE = 1024*1024 MAX_CHUNK_SIZE = float(os.environ.get('EMSCRIPT_MAX_CHUNK_SIZE') or 'inf') # configuring this is just for debugging purposes -def process_funcs(args): - i, funcs, meta, settings_file, compiler, forwarded_file, libraries = args +def process_funcs((i, funcs, meta, settings_file, compiler, forwarded_file, libraries, compiler_engine)): ll = ''.join(funcs) + '\n' + meta funcs_file = temp_files.get('.func_%d.ll' % i).name open(funcs_file, 'w').write(ll) out = shared.run_js( compiler, - engine=os.path.abspath(compiler_engine), + engine=compiler_engine, args=[settings_file, funcs_file, 'funcs', forwarded_file] + libraries, stdout=subprocess.PIPE, cwd=path_from_root('src')) shared.try_delete(funcs_file) return out -def emscript(configuration, infile, settings, outfile, libraries=[]): +def emscript(configuration, infile, settings, outfile, libraries=[], compiler_engine=None): """Runs the emscripten LLVM-to-JS compiler. We parallelize as much as possible Args: @@ -162,7 +160,7 @@ def emscript(configuration, infile, settings, outfile, libraries=[]): if out and DEBUG: print >> sys.stderr, ' loading pre from jcache' if not out: open(pre_file, 'w').write(pre_input) - out = shared.run_js(compiler, shared.COMPILER_ENGINE, [settings_file, pre_file, 'pre'] + libraries, stdout=subprocess.PIPE, cwd=path_from_root('src')) + out = shared.run_js(compiler, compiler_engine, [settings_file, pre_file, 'pre'] + libraries, stdout=subprocess.PIPE, cwd=path_from_root('src')) if jcache: if DEBUG: print >> sys.stderr, ' saving pre to jcache' shared.JCache.set(shortkey, keys, out) @@ -218,12 +216,16 @@ def emscript(configuration, infile, settings, outfile, libraries=[]): if DEBUG: print >> sys.stderr, ' emscript: phase 2 working on %d chunks %s (intended chunk size: %.2f MB, meta: %.2f MB, forwarded: %.2f MB, total: %.2f MB)' % (len(chunks), ('using %d cores' % cores) if len(chunks) > 1 else '', chunk_size/(1024*1024.), len(meta)/(1024*1024.), len(forwarded_data)/(1024*1024.), total_ll_size/(1024*1024.)) commands = [ - (i, chunks[i], meta, settings_file, compiler, forwarded_file, libraries) - for i in range(len(chunks))] + (i, chunk, meta, settings_file, compiler, forwarded_file, libraries, compiler_engine) + for i, chunk in enumerate(chunks) + ] if len(chunks) > 1: pool = multiprocessing.Pool(processes=cores) - outputs = pool.map(process_funcs, commands, chunksize=1) + outputs = pool.map( + process_funcs, + commands, + chunksize=1) elif len(chunks) == 1: outputs = [process_funcs(commands[0])] else: @@ -310,7 +312,7 @@ def emscript(configuration, infile, settings, outfile, libraries=[]): if DEBUG: t = time.time() post_file = temp_files.get('.post.ll').name open(post_file, 'w').write('\n') # no input, just processing of forwarded data - out = shared.run_js(compiler, shared.COMPILER_ENGINE, [settings_file, post_file, 'post', forwarded_file] + libraries, stdout=subprocess.PIPE, cwd=path_from_root('src')) + out = shared.run_js(compiler, compiler_engine, [settings_file, post_file, 'post', forwarded_file] + libraries, stdout=subprocess.PIPE, cwd=path_from_root('src')) post, last_forwarded_data = out.split('//FORWARDED_DATA:') # if this fails, perhaps the process failed prior to printing forwarded data? last_forwarded_json = json.loads(last_forwarded_data) @@ -495,7 +497,7 @@ Runtime.stackRestore = function(top) { asm.stackRestore(top) }; outfile.close() -def main(args): +def main(args, compiler_engine=None): # Prepare settings for serialization to JSON. settings = {} for setting in args.settings: @@ -571,7 +573,7 @@ def main(args): # Compile the assembly to Javascript. if settings.get('RELOOP'): shared.Building.ensure_relooper() - emscript(configuration, args.infile, settings, args.outfile, libraries) + emscript(configuration, args.infile, settings, args.outfile, libraries, compiler_engine=compiler_engine) def _main(environ): parser = optparse.OptionParser( @@ -628,13 +630,12 @@ WARNING: You should normally never use this! Use emcc instead. shared.RELOOPER = os.path.abspath(keywords.relooper) keywords.settings.append("RELOOPER=" + json.dumps(shared.RELOOPER)) - global compiler_engine - compiler_engine = keywords.compiler - global jcache jcache = keywords.jcache - temp_files.run_and_clean(lambda: main(keywords)) + temp_files.run_and_clean(lambda: main( + keywords, + compiler_engine=os.path.abspath(keywords.compiler))) if __name__ == '__main__': _main(environ=os.environ) |