aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtools/exec_llvm.py7
-rw-r--r--tools/nativize_llvm.py31
2 files changed, 33 insertions, 5 deletions
diff --git a/tools/exec_llvm.py b/tools/exec_llvm.py
index 1b1bba1b..5cf55e46 100755
--- a/tools/exec_llvm.py
+++ b/tools/exec_llvm.py
@@ -26,11 +26,8 @@ it runs
python $(EMSCRIPTEN_TOOLS)/exec_llvm.py THE_FILE PARAMS
An alternative solution to this problem is to compile
-the .ll into native code. This can be done as follows:
-
- * Use llc to generate x86 asm
- * Use as to generate an object file
- * Use g++ to link it to an executable
+the .ll into native code, see nativize_llvm.py. That is
+useful when this fails.
'''
import os, sys
diff --git a/tools/nativize_llvm.py b/tools/nativize_llvm.py
new file mode 100644
index 00000000..a053b56c
--- /dev/null
+++ b/tools/nativize_llvm.py
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+
+'''
+Small utility to build some llvm bitcode into native code. Useful when lli (called
+from exec_llvm) fails for some reason.
+
+ * Use llc to generate x86 asm
+ * Use as to generate an object file
+ * Use g++ to link it to an executable
+'''
+
+import os, sys
+from subprocess import Popen, PIPE, STDOUT
+
+__rootpath__ = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
+def path_from_root(*pathelems):
+ return os.path.join(__rootpath__, *pathelems)
+exec(open(path_from_root('tools', 'shared.py'), 'r').read())
+
+filename = sys.argv[1]
+libs = sys.argv[2:] # e.g.: dl for dlopen/dlclose, util for openpty/forkpty
+
+print 'bc => clean bc'
+Popen([LLVM_OPT, filename, '-strip-debug', '-o=' + filename + '.clean.bc']).communicate()[0]
+print 'bc => s'
+Popen([LLVM_COMPILER, filename + '.clean.bc', '-o=' + filename + '.s']).communicate()[0]
+print 's => o'
+Popen(['as', filename + '.s', '-o', filename + '.o']).communicate()[0]
+print 'o => runnable'
+Popen(['g++', filename + '.o', '-o', filename + '.run'] + ['-l' + lib for lib in libs]).communicate()[0]
+