aboutsummaryrefslogtreecommitdiff
path: root/emscripten.py
diff options
context:
space:
mode:
authoralon@honor <none@none>2010-09-12 15:11:43 -0700
committeralon@honor <none@none>2010-09-12 15:11:43 -0700
commita8d7622f69054a6970906b2512f3107ea1e29c58 (patch)
tree476f08925d542d6c8bcfc04353950115cb13c4b2 /emscripten.py
parent7c92cce36b6fe2e02ea471741295befa9dbb7a89 (diff)
allow emscripten.py to read ~/.emscripten for settings
Diffstat (limited to 'emscripten.py')
-rwxr-xr-xemscripten.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/emscripten.py b/emscripten.py
index 46e44605..1d14b81e 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -3,27 +3,35 @@
import os, sys, subprocess
COMPILER = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'src', 'parser.js')
+CONFIG_FILE = os.path.expanduser('~/.emscripten')
+JS_ENGINE = None
-def emscripten(filename, js_engine, settings):
+if os.path.exists(CONFIG_FILE):
+ exec(open(CONFIG_FILE, 'r').read())
+
+def emscripten(filename, settings):
data = open(filename, 'r').read()
cwd = os.getcwd()
os.chdir(os.path.dirname(COMPILER))
- subprocess.Popen([js_engine, COMPILER], stdin=subprocess.PIPE).communicate(settings+'\n'+data)[0]
+ subprocess.Popen([JS_ENGINE, COMPILER], stdin=subprocess.PIPE).communicate(settings+'\n'+data)[0]
os.chdir(cwd)
if __name__ == '__main__':
- if sys.argv.__len__() not in [3,4]:
+ if sys.argv.__len__() not in [2,3,4]:
print '''
-Emscripten usage: emscripten.py INFILE PATH-TO-JS-ENGINE [SETTINGS]
+Emscripten usage: emscripten.py [INFILE PATH-TO-JS-ENGINE] [SETTINGS]
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
- issue.
+ issue. If you do not provide this parameter, you should define
+ JS_ENGINE = ... in a file at ~/.emscripten.
SETTINGS is an optional set of compiler settings, overriding the defaults.
'''
else:
- emscripten(sys.argv[1], sys.argv[2], sys.argv[3] if len(sys.argv) == 4 else "{}")
+ if len(sys.argv) >= 3:
+ JS_ENGINE = sys.argv[2]
+ emscripten(sys.argv[1], sys.argv[3] if len(sys.argv) == 4 else "{}")