diff options
Diffstat (limited to 'emscripten.py')
-rwxr-xr-x | emscripten.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/emscripten.py b/emscripten.py index d61d84ab..5bd245eb 100755 --- a/emscripten.py +++ b/emscripten.py @@ -11,21 +11,22 @@ exec(open(path_from_root('tools', 'shared.py'), 'r').read()) COMPILER = path_from_root('src', 'compiler.js') -def emscripten(filename, settings): +def emscripten(filename, settings, outfile): data = open(filename, 'r').read() try: cwd = os.getcwd() except: cwd = None os.chdir(os.path.dirname(COMPILER)) - subprocess.Popen(COMPILER_ENGINE + [COMPILER], stdin=subprocess.PIPE).communicate(settings+'\n'+data)[0] + subprocess.Popen(COMPILER_ENGINE + [COMPILER], stdin=subprocess.PIPE, stdout=outfile, stderr=subprocess.STDOUT).communicate(settings+'\n'+data) + if outfile: outfile.close() if cwd is not None: os.chdir(cwd) if __name__ == '__main__': - if sys.argv.__len__() not in [2,3,4]: + if sys.argv.__len__() not in range(2,6): print ''' -Emscripten usage: emscripten.py INFILE [PATH-TO-JS-ENGINE] [SETTINGS] +Emscripten usage: emscripten.py INFILE [PATH-TO-JS-ENGINE] [SETTINGS] [OUTPUT_FILE] INFILE must be in human-readable LLVM disassembly form (i.e., as text, not binary). @@ -35,9 +36,13 @@ Emscripten usage: emscripten.py INFILE [PATH-TO-JS-ENGINE] [SETTINGS] issue. If you do not provide this parameter, you should define COMPILER_ENGINE = ... in a file at ~/.emscripten. SETTINGS is an optional set of compiler settings, overriding the defaults. + OUTPUT_FILE is the file to create with the output. If not given, we write + to stdout ''' else: if len(sys.argv) >= 3: COMPILER_ENGINE = [sys.argv[2]] - emscripten(sys.argv[1], sys.argv[3] if len(sys.argv) == 4 else "{}") + settings = sys.argv[3] if len(sys.argv) >= 4 else "{}" + outfile = open(sys.argv[4], 'w') if len(sys.argv) >= 5 else None + emscripten(sys.argv[1], settings, outfile) |