OLD | NEW |
---|---|
1 # -*- Python -*- | |
1 # Taken from utils/lit/tests in the LLVM tree and hacked together to support | 2 # Taken from utils/lit/tests in the LLVM tree and hacked together to support |
2 # our tests. | 3 # our tests. |
3 | 4 # |
4 # -*- Python -*- | 5 # Note: This configuration has simple commands to run Subzero's translator. |
6 # They have the form %X2i (i.e. %p2i, %l2i, and %lc2i) where X is defined | |
7 # as follows: | |
8 # | |
9 # p : Run Subzero's translator, building ICE from PNaCl bitcode directly. | |
10 # l : Run Subzero's translator, converting the .ll file to a PNaCl bitcode | |
11 # file, reading in the bitcode file and generating LLVM IR, and | |
12 # then convert LLVM IR to ICE IR. | |
13 # lc : Run Subzero's translator, directly parsing the .ll file into LLVM IR, | |
14 # and then convert it to ICE IR. | |
15 # | |
16 # These commands can be used in RUN lines by FileCheck. If the Subzero build, | |
Jim Stichnoth
2014/10/20 16:44:29
How about something like this:
If the Subzero bui
Karl
2014/10/20 21:00:42
Done.
| |
17 # that is being tested, doesn't build the corresponding Subzero translator, | |
18 # the command will simply return successfully, generating no output. This | |
19 # allows translation tests to be able to conditionally test the translator, | |
20 # based on the translator built. | |
21 # | |
22 # This conditional handling of translation introduces potential problems | |
23 # when the output is piped to another command on a RUN line. Executables | |
24 # like FileCheck expect non-empty input. | |
25 # | |
26 # To handle the problem that the pipe is conditional, any command that | |
27 # doesn't accept empty input should be prefixed by a corresponding %ifX | |
28 # (i.e. %ifp, %ifl, or %ifpc). | |
29 # | |
30 # Note: Currently, all build targets allow %p2i. Hence it is not necessary | |
31 # to specify %ifp. However, if you want to be safe about future changes | |
32 # to build targets, use %ifp. Currently, %ifp is implemented as a nop. | |
5 | 33 |
6 import os | 34 import os |
7 import re | 35 import re |
8 import sys | 36 import sys |
9 | 37 |
10 import lit.formats | 38 import lit.formats |
11 | 39 |
12 sys.path.insert(0, 'pydir') | 40 sys.path.insert(0, 'pydir') |
13 from utils import FindBaseNaCl | 41 from utils import FindBaseNaCl |
42 from ifatts import GetFileAttributes | |
14 | 43 |
15 # name: The name of this test suite. | 44 # name: The name of this test suite. |
16 config.name = 'subzero' | 45 config.name = 'subzero' |
17 | 46 |
18 # testFormat: The test format to use to interpret tests. | 47 # testFormat: The test format to use to interpret tests. |
19 config.test_format = lit.formats.ShTest() | 48 config.test_format = lit.formats.ShTest() |
20 | 49 |
21 # suffixes: A list of file extensions to treat as test files. | 50 # suffixes: A list of file extensions to treat as test files. |
22 config.suffixes = ['.ll'] | 51 config.suffixes = ['.ll'] |
23 | 52 |
24 # test_source_root: The root path where tests are located. | 53 # test_source_root: The root path where tests are located. |
25 config.test_source_root = os.path.dirname(__file__) | 54 config.test_source_root = os.path.dirname(__file__) |
26 config.test_exec_root = config.test_source_root | 55 config.test_exec_root = config.test_source_root |
27 config.target_triple = '(unused)' | 56 config.target_triple = '(unused)' |
28 | 57 |
29 src_root = os.path.join(FindBaseNaCl(), 'toolchain_build/src/subzero') | 58 src_root = os.path.join(FindBaseNaCl(), 'toolchain_build/src/subzero') |
30 bin_root = src_root | 59 bin_root = src_root |
31 config.substitutions.append(('%{src_root}', src_root)) | 60 config.substitutions.append(('%{src_root}', src_root)) |
32 config.substitutions.append(('%{python}', sys.executable)) | 61 config.substitutions.append(('%{python}', sys.executable)) |
33 | 62 |
34 pydir = os.path.join(bin_root, 'pydir') | 63 pydir = os.path.join(bin_root, 'pydir') |
35 | 64 |
36 # Finding LLVM binary tools. All tools used in the tests must be listed in | 65 # Finding LLVM binary tools. All tools used in the tests must be listed in |
37 # the llvmbintools list. | 66 # the llvmbintools list. |
38 llvmbinpath = os.path.abspath(os.environ.get('LLVM_BIN_PATH')) | 67 llvmbinpath = os.path.abspath(os.environ.get('LLVM_BIN_PATH')) |
39 | 68 |
40 # Finding Subzero tools | 69 # Define the location of the llvm2ice tool. |
41 llvm2icetool = os.path.join(bin_root, 'llvm2ice') | 70 llvm2icetool = os.path.join(bin_root, 'llvm2ice') |
71 llvm2icetoolatts = os.path.join(bin_root, 'llvm2ice.build_atts') | |
42 | 72 |
43 # Convert LLVM source to PNaCl bitcode, read using the | 73 # Add build attributes of llvm2ice tool to the set of available features. |
44 # Subzero bitcode reader, and then translate. | 74 config.available_features.update(GetFileAttributes(llvm2icetoolatts)) |
Karl
2014/10/16 16:51:48
Here is the code that defines what symbols will be
| |
45 config.substitutions.append( | |
46 ('%p2i', ' '.join([os.path.join(pydir, 'run-llvm2ice.py'), | |
47 '--llvm2ice', llvm2icetool, | |
48 '--llvm-bin-path', llvmbinpath | |
49 ]))) | |
50 | 75 |
51 # Convert LLVM source to PNaCl bitcode, read using the PNaCl bitcode reader, | 76 # Base command for testing build attributes |
52 # convert to ICE using the ICE Converter, and then translate. | 77 if_atts_cmd = [os.path.join(pydir, 'ifatts.py'), llvm2icetoolatts] |
53 # TODO(kschimpf) Deprecated, remove once p2i working. | 78 ifp_atts_cmd = if_atts_cmd + ['--command'] |
54 config.substitutions.append( | 79 ifnm_atts_cmd = if_atts_cmd + ['--att=nonminal', '--command'] |
Jim Stichnoth
2014/10/20 18:06:03
nonminimal
Karl
2014/10/20 21:00:42
Removed, since we no longer treat minimal/nonminim
| |
55 ('%l2i', ' '.join([os.path.join(pydir, 'run-llvm2ice.py'), | |
56 '--llvm', '--llvm2ice', llvm2icetool, | |
57 '--llvm-bin-path', llvmbinpath | |
58 ]))) | |
59 | 80 |
60 # Read LLVM source, convert to ICE using the ICE converter, and then translate. | 81 # Base command for running llvm2ice |
61 # Note: l2i is preferred over lc2i, since it uses PNaCl bitcode. | 82 llvm2ice_cmd = [os.path.join(pydir, 'run-llvm2ice.py'), |
62 # TODO(kschimpf) Deprecated, remove once p2i working. | 83 '--llvm2ice', llvm2icetool, |
63 config.substitutions.append( | 84 '--llvm-bin-path', llvmbinpath] |
64 ('%lc2i', ' '.join([os.path.join(pydir, 'run-llvm2ice.py'), | 85 |
65 '--llvm-source', '--llvm2ice', llvm2icetool, | 86 # Run commands only if corresponding build attributes apply, including |
66 '--llvm-bin-path', llvmbinpath | 87 # for each compiler setup. |
67 ]))) | 88 config.substitutions.append(('%ifp', ' ')) |
89 config.substitutions.append(('%iflc', ' '.join(ifnm_atts_cmd))) | |
90 config.substitutions.append(('%ifl', ' '.join(ifnm_atts_cmd))) | |
91 config.substitutions.append(('%if', ' '.join(if_atts_cmd))) | |
92 | |
93 # Translate LLVM source for each compiler setup. | |
94 config.substitutions.append(('%p2i', ' '.join(llvm2ice_cmd))) | |
95 config.substitutions.append(('%l2i', ' '.join(ifnm_atts_cmd + llvm2ice_cmd | |
96 + ['--llvm']))) | |
97 config.substitutions.append(('%lc2i', ' '.join(ifnm_atts_cmd + llvm2ice_cmd | |
98 + ['--llvm-source']))) | |
68 | 99 |
69 config.substitutions.append(('%llvm2ice', llvm2icetool)) | 100 config.substitutions.append(('%llvm2ice', llvm2icetool)) |
70 config.substitutions.append(('%szdiff', os.path.join(pydir, 'szdiff.py'))) | 101 config.substitutions.append(('%szdiff', os.path.join(pydir, 'szdiff.py'))) |
71 | 102 |
72 llvmbintools = [r"\bFileCheck\b", r"\bllvm-as\b", r"\bllvm-mc\b", | 103 llvmbintools = [r"\bFileCheck\b", r"\bllvm-as\b", r"\bllvm-mc\b", |
73 r"\bllvm-objdump\b", r"\bnot\b", r"\bpnacl-freeze\b", | 104 r"\bllvm-objdump\b", r"\bnot\b", r"\bpnacl-freeze\b", |
74 r"\bpnacl-bcdis\b"] | 105 r"\bpnacl-bcdis\b"] |
75 | 106 |
76 for tool in llvmbintools: | 107 for tool in llvmbintools: |
77 # The re.sub() line is adapted from one of LLVM's lit.cfg files. | 108 # 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 | 109 # Extract the tool name from the pattern. This relies on the tool |
79 # name being surrounded by \b word match operators. If the | 110 # name being surrounded by \b word match operators. If the |
80 # pattern starts with "| ", include it in the string to be | 111 # pattern starts with "| ", include it in the string to be |
81 # substituted. | 112 # substituted. |
82 substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$", | 113 substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$", |
83 r"\2" + llvmbinpath + "/" + r"\4", | 114 r"\2" + llvmbinpath + "/" + r"\4", |
84 tool) | 115 tool) |
85 config.substitutions.append((tool, substitution)) | 116 config.substitutions.append((tool, substitution)) |
86 | 117 |
87 # Add a feature to detect the Python version. | 118 # Add a feature to detect the Python version. |
88 config.available_features.add("python%d.%d" % (sys.version_info[0], | 119 config.available_features.add("python%d.%d" % (sys.version_info[0], |
89 sys.version_info[1])) | 120 sys.version_info[1])) |
90 | 121 |
91 # Debugging output | 122 # Debugging output |
92 def dbg(s): | 123 def dbg(s): |
93 print '[DBG] %s' % s | 124 print '[DBG] %s' % s |
94 | 125 |
95 dbg('bin_root = %s' % bin_root) | 126 dbg('bin_root = %s' % bin_root) |
96 dbg('llvmbinpath = %s' % llvmbinpath) | 127 dbg('llvmbinpath = %s' % llvmbinpath) |
OLD | NEW |