-
Notifications
You must be signed in to change notification settings - Fork 428
/
Copy pathchpl_llvm.py
executable file
·65 lines (54 loc) · 1.95 KB
/
chpl_llvm.py
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 optparse
import os
import sys
import chpl_bin_subdir, chpl_compiler, chpl_platform, overrides
from chpl_home_utils import get_chpl_third_party
from utils import memoize
@memoize
def get_uniq_cfg_path_for(llvm_val):
if llvm_val == "llvm":
# put platform-arch-compiler for included llvm
host_bin_subdir = chpl_bin_subdir.get('host')
host_compiler = chpl_compiler.get('host')
llvm_target_dir = '{0}-{1}'.format(host_bin_subdir, host_compiler)
else:
# just put 'system' for system llvm
llvm_target_dir = llvm_val
return llvm_target_dir
@memoize
def get_uniq_cfg_path():
llvm_val = get()
return get_uniq_cfg_path_for(llvm_val)
@memoize
def get():
llvm_val = overrides.get('CHPL_LLVM')
if not llvm_val:
# compute a default based on if the included llvm is built
chpl_third_party = get_chpl_third_party()
llvm_target_dir = get_uniq_cfg_path_for('llvm')
llvm_subdir = os.path.join(chpl_third_party, 'llvm', 'install',
llvm_target_dir)
llvm_header = os.path.join(llvm_subdir, 'include', 'llvm',
'PassSupport.h')
if os.path.exists(llvm_header):
llvm_val = 'llvm'
else:
llvm_val = 'none'
return llvm_val
def _main():
llvm_val = get()
parser = optparse.OptionParser(usage='usage: %prog [--needs-llvm-runtime]')
parser.add_option('--needs-llvm-runtime', dest='needsllvm',
action='store_const',
const='needsllvm', default='')
(options, args) = parser.parse_args()
#if --needs-llvm-runtime is set, print out llvm if runtime is needed,
# and print out nothing if it is not.
if options.needsllvm:
if llvm_val == 'system' or llvm_val == 'llvm':
sys.stdout.write("llvm\n");
else:
sys.stdout.write("{0}\n".format(llvm_val))
if __name__ == '__main__':
_main()