OLD | NEW |
---|---|
1 # Taken from utils/lit/tests in the LLVM tree and hacked together to support | 1 # Taken from utils/lit/tests in the LLVM tree and hacked together to support |
2 # our tests. | 2 # our tests. |
3 # | |
4 # Note: For X2i and ifX commands, the following values are allowed for X | |
5 # (i.e. compiler setup): | |
6 # | |
7 # m : Run when llvm2ice corresponds to minimal Subzero | |
jvoung (off chromium)
2014/10/15 21:57:06
Clarify "minimal Subzero... building ICE from PNaC
Karl
2014/10/16 16:51:48
I wanted to keep the usage simple, by not forcing
| |
8 # p : Run when llvm2ice corresponds to Subzero building ICE from PNaCl | |
9 # bitcode directly. | |
10 # l : Run when llvm2ice corresponds to Subzero building ICE by reading | |
11 # PNaCL bitcode into LLVM IR, and converting to ICE. | |
12 # lc : Runwhen llvm2ice corresponds to Subzero parsing LLVM source into | |
13 # LLVM IR, and converting to ICE. | |
3 | 14 |
4 # -*- Python -*- | 15 # -*- Python -*- |
5 | 16 |
6 import os | 17 import os |
7 import re | 18 import re |
8 import sys | 19 import sys |
9 | 20 |
10 import lit.formats | 21 import lit.formats |
11 | 22 |
12 sys.path.insert(0, 'pydir') | 23 sys.path.insert(0, 'pydir') |
13 from utils import FindBaseNaCl | 24 from utils import FindBaseNaCl |
25 from ifatts import GetFileAttributes | |
14 | 26 |
15 # name: The name of this test suite. | 27 # name: The name of this test suite. |
16 config.name = 'subzero' | 28 config.name = 'subzero' |
17 | 29 |
18 # testFormat: The test format to use to interpret tests. | 30 # testFormat: The test format to use to interpret tests. |
19 config.test_format = lit.formats.ShTest() | 31 config.test_format = lit.formats.ShTest() |
20 | 32 |
21 # suffixes: A list of file extensions to treat as test files. | 33 # suffixes: A list of file extensions to treat as test files. |
22 config.suffixes = ['.ll'] | 34 config.suffixes = ['.ll'] |
23 | 35 |
24 # test_source_root: The root path where tests are located. | 36 # test_source_root: The root path where tests are located. |
25 config.test_source_root = os.path.dirname(__file__) | 37 config.test_source_root = os.path.dirname(__file__) |
26 config.test_exec_root = config.test_source_root | 38 config.test_exec_root = config.test_source_root |
27 config.target_triple = '(unused)' | 39 config.target_triple = '(unused)' |
28 | 40 |
29 src_root = os.path.join(FindBaseNaCl(), 'toolchain_build/src/subzero') | 41 src_root = os.path.join(FindBaseNaCl(), 'toolchain_build/src/subzero') |
30 bin_root = src_root | 42 bin_root = src_root |
31 config.substitutions.append(('%{src_root}', src_root)) | 43 config.substitutions.append(('%{src_root}', src_root)) |
32 config.substitutions.append(('%{python}', sys.executable)) | 44 config.substitutions.append(('%{python}', sys.executable)) |
33 | 45 |
34 pydir = os.path.join(bin_root, 'pydir') | 46 pydir = os.path.join(bin_root, 'pydir') |
35 | 47 |
36 # Finding LLVM binary tools. All tools used in the tests must be listed in | 48 # Finding LLVM binary tools. All tools used in the tests must be listed in |
37 # the llvmbintools list. | 49 # the llvmbintools list. |
38 llvmbinpath = os.path.abspath(os.environ.get('LLVM_BIN_PATH')) | 50 llvmbinpath = os.path.abspath(os.environ.get('LLVM_BIN_PATH')) |
39 | 51 |
40 # Finding Subzero tools | 52 # Define the location of the llvm2ice tool. |
41 llvm2icetool = os.path.join(bin_root, 'llvm2ice') | 53 llvm2icetool = os.path.join(bin_root, 'llvm2ice') |
54 llvm2icetoolatts = os.path.join(bin_root, 'llvm2ice.build_atts') | |
42 | 55 |
43 # Convert LLVM source to PNaCl bitcode, read using the | 56 # Add build attributes of llvm2ice tool to the set of available features. |
44 # Subzero bitcode reader, and then translate. | 57 config.available_features.update(GetFileAttributes(llvm2icetoolatts)) |
45 config.substitutions.append( | |
46 ('%p2i', ' '.join([os.path.join(pydir, 'run-llvm2ice.py'), | |
47 '--llvm2ice', llvm2icetool, | |
48 '--llvm-bin-path', llvmbinpath | |
49 ]))) | |
50 | 58 |
51 # Convert LLVM source to PNaCl bitcode, read using the PNaCl bitcode reader, | 59 # Base command for testing build attributes |
52 # convert to ICE using the ICE Converter, and then translate. | 60 if_atts_cmd = [os.path.join(pydir, 'ifatts.py'), llvm2icetoolatts] |
53 # TODO(kschimpf) Deprecated, remove once p2i working. | 61 ifm_atts_cmd = if_atts_cmd + ['--att=minimal', '--att=p2i', '--command'] |
54 config.substitutions.append( | 62 ifp_atts_cmd = if_atts_cmd + ['--att=p2i', '--command'] |
55 ('%l2i', ' '.join([os.path.join(pydir, 'run-llvm2ice.py'), | 63 ifl_atts_cmd = if_atts_cmd + ['--att=l2i', '--command'] |
56 '--llvm', '--llvm2ice', llvm2icetool, | 64 iflc_atts_cmd = if_atts_cmd + ['--att=lc2i', '--command'] |
57 '--llvm-bin-path', llvmbinpath | |
58 ]))) | |
59 | 65 |
60 # Read LLVM source, convert to ICE using the ICE converter, and then translate. | 66 # Base command for running llvm2ice |
61 # Note: l2i is preferred over lc2i, since it uses PNaCl bitcode. | 67 llvm2ice_cmd = [os.path.join(pydir, 'run-llvm2ice.py'), |
62 # TODO(kschimpf) Deprecated, remove once p2i working. | 68 '--llvm2ice', llvm2icetool, |
63 config.substitutions.append( | 69 '--llvm-bin-path', llvmbinpath] |
64 ('%lc2i', ' '.join([os.path.join(pydir, 'run-llvm2ice.py'), | 70 |
65 '--llvm-source', '--llvm2ice', llvm2icetool, | 71 # Run commands only if corresponding build attributes apply, including |
66 '--llvm-bin-path', llvmbinpath | 72 # for each compiler setup. |
67 ]))) | 73 config.substitutions.append(('%ifm', ' '.join(ifm_atts_cmd))) |
74 config.substitutions.append(('%ifp', ' '.join(ifp_atts_cmd))) | |
75 config.substitutions.append(('%iflc', ' '.join(iflc_atts_cmd))) | |
76 config.substitutions.append(('%ifl', ' '.join(ifl_atts_cmd))) | |
77 config.substitutions.append(('%if', ' '.join(if_atts_cmd))) | |
78 | |
79 # Translate LLVM source for each compiler setup. | |
80 config.substitutions.append(('%m2i', ' '.join(ifm_atts_cmd + llvm2ice_cmd))) | |
jvoung (off chromium)
2014/10/15 21:57:06
a bit of bikeshedding here:
m2i seems to indicate
Karl
2014/10/16 16:51:48
Correct. p2i runs in any case. Clearing this up by
| |
81 config.substitutions.append(('%p2i', ' '.join(ifp_atts_cmd + llvm2ice_cmd))) | |
82 config.substitutions.append(('%l2i', ' '.join(ifl_atts_cmd + llvm2ice_cmd | |
83 + ['--llvm']))) | |
84 config.substitutions.append(('%lc2i', ' '.join(iflc_atts_cmd + llvm2ice_cmd | |
85 + ['--llvm-source']))) | |
68 | 86 |
69 config.substitutions.append(('%llvm2ice', llvm2icetool)) | 87 config.substitutions.append(('%llvm2ice', llvm2icetool)) |
70 config.substitutions.append(('%szdiff', os.path.join(pydir, 'szdiff.py'))) | 88 config.substitutions.append(('%szdiff', os.path.join(pydir, 'szdiff.py'))) |
71 | 89 |
72 llvmbintools = [r"\bFileCheck\b", r"\bllvm-as\b", r"\bllvm-mc\b", | 90 llvmbintools = [r"\bFileCheck\b", r"\bllvm-as\b", r"\bllvm-mc\b", |
73 r"\bllvm-objdump\b", r"\bnot\b", r"\bpnacl-freeze\b", | 91 r"\bllvm-objdump\b", r"\bnot\b", r"\bpnacl-freeze\b", |
74 r"\bpnacl-bcdis\b"] | 92 r"\bpnacl-bcdis\b"] |
75 | 93 |
76 for tool in llvmbintools: | 94 for tool in llvmbintools: |
77 # The re.sub() line is adapted from one of LLVM's lit.cfg files. | 95 # The re.sub() line is adapted from one of LLVM's lit.cfg files. |
78 # Extract the tool name from the pattern. This relies on the tool | 96 # Extract the tool name from the pattern. This relies on the tool |
79 # name being surrounded by \b word match operators. If the | 97 # name being surrounded by \b word match operators. If the |
80 # pattern starts with "| ", include it in the string to be | 98 # pattern starts with "| ", include it in the string to be |
81 # substituted. | 99 # substituted. |
82 substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$", | 100 substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$", |
83 r"\2" + llvmbinpath + "/" + r"\4", | 101 r"\2" + llvmbinpath + "/" + r"\4", |
84 tool) | 102 tool) |
85 config.substitutions.append((tool, substitution)) | 103 config.substitutions.append((tool, substitution)) |
86 | 104 |
87 # Add a feature to detect the Python version. | 105 # Add a feature to detect the Python version. |
88 config.available_features.add("python%d.%d" % (sys.version_info[0], | 106 config.available_features.add("python%d.%d" % (sys.version_info[0], |
89 sys.version_info[1])) | 107 sys.version_info[1])) |
90 | 108 |
91 # Debugging output | 109 # Debugging output |
92 def dbg(s): | 110 def dbg(s): |
93 print '[DBG] %s' % s | 111 print '[DBG] %s' % s |
94 | 112 |
95 dbg('bin_root = %s' % bin_root) | 113 dbg('bin_root = %s' % bin_root) |
96 dbg('llvmbinpath = %s' % llvmbinpath) | 114 dbg('llvmbinpath = %s' % llvmbinpath) |
OLD | NEW |