4
Small utility to execute some llvm bitcode.
6
The use case is a Makefile that builds some executable
7
and runs it as part of the build process. With emmaken,
8
the Makefile will generate llvm bitcode, so we can't
9
just execute it directly. This script will get that
10
code into a runnable form, and run it.
12
We cannot just use lli, since code built with debug
13
symbols will crash it due to
15
http://llvm.org/bugs/show_bug.cgi?id=6981
17
So we must get around that.
19
To use this, change the Makefile so that instead of
22
/bin/sh THE_FILE PARAMS
26
python $(EMSCRIPTEN_TOOLS)/exec_llvm.py THE_FILE PARAMS
28
An alternative solution to this problem is to compile
29
the .ll into native code, see nativize_llvm.py. That is
30
useful when this fails.
34
from subprocess import Popen, PIPE, STDOUT
36
__rootpath__ = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
37
def path_from_root(*pathelems):
38
return os.path.join(__rootpath__, *pathelems)
39
sys.path += [path_from_root('')]
40
from tools.shared import *
42
Popen([LLVM_OPT, sys.argv[1], '-strip-debug', '-o=' + sys.argv[1]+'.clean.bc']).communicate()[0]
44
# Execute with empty environment - just like the JS script will have
45
Popen([LLVM_INTERPRETER, sys.argv[1]+'.clean.bc'] + sys.argv[2:], env={'HOME': '.'}).communicate()[0]
47
#Popen([LLVM_COMPILER, '-march=c', sys.argv[1], '-o=' + sys.argv[1]+'.cbe.c']).communicate()[0]
48
#Popen(['gcc', sys.argv[1]+'.cbe.c', '-lstdc++']).communicate()[0]
49
#Popen(['./a.out'] + sys.argv[2:]).communicate()[0]