1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#!/usr/bin/env python
import os, sys
import subprocess
import re
def isLinkCommand():
# Look for '-Wl,' as a signal that we are calling the linker. What a hack.
for arg in sys.argv:
if arg.startswith('-Wl,'):
return True
link_exact_filter = ['-g', '-W', '-O', '-D', '-f',
'-fnested-functions', '-pthread', '-fPIC', '-g',
'-pedantic', '-shared', '-rdynamic', '-nodefaultlibs']
link_regexp_filter_patts = ['^-Wl.*', '^-l.*', '^-W.*', '^-O\d', '^-gg.*',
'^-mtune.*', '^-std=c.*', '^-f.*frame-pointer',
'^-fvisibility.*']
link_regexp_filters = []
for patt in link_regexp_filter_patts:
prog = re.compile(patt)
link_regexp_filters.append(prog)
def main():
llvm_path = subprocess.Popen(["llvm-config", "--bindir"], stdout=subprocess.PIPE).communicate()[0].strip()
if not isLinkCommand():
os.execvp(llvm_path+"/clang", ["clang", "-emit-llvm", "-c"] + sys.argv[1:])
return 1
# Otherwise, strip out arguments that llvm-ld doesn't understand. I don't
# want my previous explicit declaration of hackyness to imply that this bit
# of code here is not also a complete and total hack, it is.
args = sys.argv[1:]
linkArgs = []
for a in args:
a = a.strip()
if a in link_exact_filter:
continue
match = False
for filt in link_regexp_filters:
# print "matching %s on filter" % a
if filt.match(a):
# print "MATCHED %s" % a
match = True
break
if match:
continue
if a in linkArgs:
continue
linkArgs.append(a)
os.execvp(llvm_path+"/llvm-link", [llvm_path+"/llvm-link"] + linkArgs)
return 1
if __name__ == '__main__':
main()
|