emscripten/tools/exec_llvm.py

51 строка
1.5 KiB
Python
Исходник Обычный вид История

2011-03-22 05:50:03 +03:00
#!/usr/bin/python
2011-03-13 00:37:44 +03:00
'''
Small utility to execute some llvm bitcode.
The use case is a Makefile that builds some executable
and runs it as part of the build process. With emmaken,
the Makefile will generate llvm bitcode, so we can't
just execute it directly. This script will get that
code into a runnable form, and run it.
We cannot just use lli, since code built with debug
symbols will crash it due to
http://llvm.org/bugs/show_bug.cgi?id=6981
2011-03-13 22:13:21 +03:00
So we must get around that.
2011-03-13 00:37:44 +03:00
To use this, change the Makefile so that instead of
running
/bin/sh THE_FILE PARAMS
it runs
python $(EMSCRIPTEN_TOOLS)/exec_llvm.py THE_FILE PARAMS
2011-08-14 05:23:04 +04:00
An alternative solution to this problem is to compile
2012-01-25 22:27:21 +04:00
the .ll into native code, see nativize_llvm.py. That is
useful when this fails.
2011-03-13 00:37:44 +03:00
'''
import os, sys
from subprocess import Popen, PIPE, STDOUT
2012-01-31 02:10:57 +04:00
__rootpath__ = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
2011-03-13 00:37:44 +03:00
def path_from_root(*pathelems):
2011-10-05 22:12:45 +04:00
return os.path.join(__rootpath__, *pathelems)
2012-01-31 02:10:57 +04:00
sys.path += [path_from_root('')]
from tools.shared import *
2011-03-13 00:37:44 +03:00
2011-03-13 22:13:21 +03:00
Popen([LLVM_OPT, sys.argv[1], '-strip-debug', '-o=' + sys.argv[1]+'.clean.bc']).communicate()[0]
2011-03-22 05:50:03 +03:00
# Execute with empty environment - just like the JS script will have
Popen([LLVM_INTERPRETER, sys.argv[1]+'.clean.bc'] + sys.argv[2:], env={'HOME': '.'}).communicate()[0]
2011-03-13 22:13:21 +03:00
#Popen([LLVM_COMPILER, '-march=c', sys.argv[1], '-o=' + sys.argv[1]+'.cbe.c']).communicate()[0]
#Popen(['gcc', sys.argv[1]+'.cbe.c', '-lstdc++']).communicate()[0]
#Popen(['./a.out'] + sys.argv[2:]).communicate()[0]
2011-03-13 00:37:44 +03:00