2010-09-10 07:03:24 +04:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import os, sys, subprocess
|
|
|
|
|
2010-09-21 05:59:15 +04:00
|
|
|
COMPILER = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'src', 'compiler.js')
|
2010-09-13 02:11:43 +04:00
|
|
|
CONFIG_FILE = os.path.expanduser('~/.emscripten')
|
|
|
|
JS_ENGINE = None
|
2010-09-10 07:03:24 +04:00
|
|
|
|
2010-09-13 02:11:43 +04:00
|
|
|
if os.path.exists(CONFIG_FILE):
|
|
|
|
exec(open(CONFIG_FILE, 'r').read())
|
|
|
|
|
|
|
|
def emscripten(filename, settings):
|
2010-09-10 10:22:10 +04:00
|
|
|
data = open(filename, 'r').read()
|
2010-09-10 07:03:24 +04:00
|
|
|
cwd = os.getcwd()
|
|
|
|
os.chdir(os.path.dirname(COMPILER))
|
2010-09-13 02:11:43 +04:00
|
|
|
subprocess.Popen([JS_ENGINE, COMPILER], stdin=subprocess.PIPE).communicate(settings+'\n'+data)[0]
|
2010-09-10 07:03:24 +04:00
|
|
|
os.chdir(cwd)
|
|
|
|
|
2010-09-10 10:36:52 +04:00
|
|
|
if __name__ == '__main__':
|
2010-09-13 02:11:43 +04:00
|
|
|
if sys.argv.__len__() not in [2,3,4]:
|
2010-09-12 10:14:16 +04:00
|
|
|
print '''
|
2010-09-27 02:59:54 +04:00
|
|
|
Emscripten usage: emscripten.py INFILE [PATH-TO-JS-ENGINE] [SETTINGS]
|
2010-09-12 10:14:16 +04:00
|
|
|
|
|
|
|
INFILE must be in human-readable LLVM disassembly form (i.e., as text,
|
|
|
|
not binary).
|
|
|
|
PATH-TO-JS-ENGINE should be a path to the JavaScript engine used to
|
|
|
|
run the compiler (which is in JavaScript itself). You can later use
|
|
|
|
the same engine to run the code, or another one, that is a separate
|
2010-09-13 02:11:43 +04:00
|
|
|
issue. If you do not provide this parameter, you should define
|
|
|
|
JS_ENGINE = ... in a file at ~/.emscripten.
|
2010-09-12 10:14:16 +04:00
|
|
|
SETTINGS is an optional set of compiler settings, overriding the defaults.
|
|
|
|
'''
|
2010-09-10 07:03:24 +04:00
|
|
|
else:
|
2010-09-13 02:11:43 +04:00
|
|
|
if len(sys.argv) >= 3:
|
|
|
|
JS_ENGINE = sys.argv[2]
|
|
|
|
emscripten(sys.argv[1], sys.argv[3] if len(sys.argv) == 4 else "{}")
|
2010-09-10 07:03:24 +04:00
|
|
|
|