~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tools/exec_llvm.py

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python2
 
2
 
 
3
'''
 
4
Small utility to execute some llvm bitcode.
 
5
 
 
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.
 
11
 
 
12
We cannot just use lli, since code built with debug
 
13
symbols will crash it due to
 
14
 
 
15
  http://llvm.org/bugs/show_bug.cgi?id=6981
 
16
 
 
17
So we must get around that.
 
18
 
 
19
To use this, change the Makefile so that instead of
 
20
running
 
21
 
 
22
  /bin/sh THE_FILE PARAMS
 
23
 
 
24
it runs
 
25
 
 
26
  python $(EMSCRIPTEN_TOOLS)/exec_llvm.py THE_FILE PARAMS
 
27
 
 
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.
 
31
'''
 
32
 
 
33
import os, sys
 
34
from subprocess import Popen, PIPE, STDOUT
 
35
 
 
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 *
 
41
 
 
42
Popen([LLVM_OPT, sys.argv[1], '-strip-debug', '-o=' + sys.argv[1]+'.clean.bc']).communicate()[0]
 
43
 
 
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]
 
46
 
 
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]
 
50