| 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 |
| 17 # build being tested lacks any required attributes (e.g., the ability |
| 18 # to parse .ll files), the command will simply return successfully, |
| 19 # generating no output. This allows translation tests to be able to |
| 20 # conditionally test the translator, 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 |
| 28 # %ifX (i.e. %p2i, %ifl, or %ifpc). Note: %p2i should always work, and |
| 29 # hence %ifp is not necessary (i.e. it is a nop). |
| 30 # |
| 31 # If you need to check other build attributes (other than the |
| 32 # existence of %l2i and %lc2i), you can use the %if command (which is |
| 33 # a short hand for using pydir/ifatts.py). |
| 5 | 34 |
| 6 import os | 35 import os |
| 7 import re | 36 import re |
| 8 import sys | 37 import sys |
| 9 | 38 |
| 10 import lit.formats | 39 import lit.formats |
| 11 | 40 |
| 12 sys.path.insert(0, 'pydir') | 41 sys.path.insert(0, 'pydir') |
| 13 from utils import FindBaseNaCl | 42 from utils import FindBaseNaCl |
| 43 from ifatts import GetFileAttributes |
| 14 | 44 |
| 15 # name: The name of this test suite. | 45 # name: The name of this test suite. |
| 16 config.name = 'subzero' | 46 config.name = 'subzero' |
| 17 | 47 |
| 18 # testFormat: The test format to use to interpret tests. | 48 # testFormat: The test format to use to interpret tests. |
| 19 config.test_format = lit.formats.ShTest() | 49 config.test_format = lit.formats.ShTest() |
| 20 | 50 |
| 21 # suffixes: A list of file extensions to treat as test files. | 51 # suffixes: A list of file extensions to treat as test files. |
| 22 config.suffixes = ['.ll'] | 52 config.suffixes = ['.ll'] |
| 23 | 53 |
| 24 # test_source_root: The root path where tests are located. | 54 # test_source_root: The root path where tests are located. |
| 25 config.test_source_root = os.path.dirname(__file__) | 55 config.test_source_root = os.path.dirname(__file__) |
| 26 config.test_exec_root = config.test_source_root | 56 config.test_exec_root = config.test_source_root |
| 27 config.target_triple = '(unused)' | 57 config.target_triple = '(unused)' |
| 28 | 58 |
| 29 src_root = os.path.join(FindBaseNaCl(), 'toolchain_build/src/subzero') | 59 src_root = os.path.join(FindBaseNaCl(), 'toolchain_build/src/subzero') |
| 30 bin_root = src_root | 60 bin_root = src_root |
| 31 config.substitutions.append(('%{src_root}', src_root)) | 61 config.substitutions.append(('%{src_root}', src_root)) |
| 32 config.substitutions.append(('%{python}', sys.executable)) | 62 config.substitutions.append(('%{python}', sys.executable)) |
| 33 | 63 |
| 34 pydir = os.path.join(bin_root, 'pydir') | 64 pydir = os.path.join(bin_root, 'pydir') |
| 35 | 65 |
| 36 # Finding LLVM binary tools. All tools used in the tests must be listed in | 66 # Finding LLVM binary tools. All tools used in the tests must be listed in |
| 37 # the llvmbintools list. | 67 # the llvmbintools list. |
| 38 llvmbinpath = os.path.abspath(os.environ.get('LLVM_BIN_PATH')) | 68 llvmbinpath = os.path.abspath(os.environ.get('LLVM_BIN_PATH')) |
| 39 | 69 |
| 40 # Finding Subzero tools | 70 # Define the location of the llvm2ice tool. |
| 41 llvm2icetool = os.path.join(bin_root, 'llvm2ice') | 71 llvm2icetool = os.path.join(bin_root, 'llvm2ice') |
| 72 llvm2icetoolatts = os.path.join(bin_root, 'llvm2ice.build_atts') |
| 42 | 73 |
| 43 # Convert LLVM source to PNaCl bitcode, read using the | 74 # Add build attributes of llvm2ice tool to the set of available features. |
| 44 # Subzero bitcode reader, and then translate. | 75 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 | 76 |
| 51 # Convert LLVM source to PNaCl bitcode, read using the PNaCl bitcode reader, | 77 # Base command for testing build attributes |
| 52 # convert to ICE using the ICE Converter, and then translate. | 78 if_atts_base = [os.path.join(pydir, 'ifatts.py'), llvm2icetoolatts] |
| 53 # TODO(kschimpf) Deprecated, remove once p2i working. | 79 if_atts_cmd = if_atts_base + ['--command'] |
| 54 config.substitutions.append( | 80 ifl2i_atts_cmd = if_atts_base + ['--att=allow_llvm_ir', '--command'] |
| 55 ('%l2i', ' '.join([os.path.join(pydir, 'run-llvm2ice.py'), | 81 iflc2i_atts_cmd = if_atts_base + ['--att=allow_llvm_ir', |
| 56 '--llvm', '--llvm2ice', llvm2icetool, | 82 '--att=allow_llvm_ir_as_input', |
| 57 '--llvm-bin-path', llvmbinpath | 83 '--command'] |
| 58 ]))) | |
| 59 | 84 |
| 60 # Read LLVM source, convert to ICE using the ICE converter, and then translate. | 85 # Base command for running llvm2ice |
| 61 # Note: l2i is preferred over lc2i, since it uses PNaCl bitcode. | 86 llvm2ice_cmd = [os.path.join(pydir, 'run-llvm2ice.py'), |
| 62 # TODO(kschimpf) Deprecated, remove once p2i working. | 87 '--llvm2ice', llvm2icetool, |
| 63 config.substitutions.append( | 88 '--llvm-bin-path', llvmbinpath] |
| 64 ('%lc2i', ' '.join([os.path.join(pydir, 'run-llvm2ice.py'), | 89 |
| 65 '--llvm-source', '--llvm2ice', llvm2icetool, | 90 # Run commands only if corresponding build attributes apply, including |
| 66 '--llvm-bin-path', llvmbinpath | 91 # for each compiler setup. |
| 67 ]))) | 92 config.substitutions.append(('%ifp', ' ')) |
| 93 config.substitutions.append(('%iflc', ' '.join(iflc2i_atts_cmd))) |
| 94 config.substitutions.append(('%ifl', ' '.join(ifl2i_atts_cmd))) |
| 95 config.substitutions.append(('%if', ' '.join(if_atts_cmd))) |
| 96 |
| 97 # Translate LLVM source for each compiler setup. |
| 98 config.substitutions.append(('%p2i', ' '.join(llvm2ice_cmd))) |
| 99 config.substitutions.append(('%l2i', ' '.join(ifl2i_atts_cmd + llvm2ice_cmd |
| 100 + ['--llvm']))) |
| 101 config.substitutions.append(('%lc2i', ' '.join(iflc2i_atts_cmd + llvm2ice_cmd |
| 102 + ['--llvm-source']))) |
| 68 | 103 |
| 69 config.substitutions.append(('%llvm2ice', llvm2icetool)) | 104 config.substitutions.append(('%llvm2ice', llvm2icetool)) |
| 70 config.substitutions.append(('%szdiff', os.path.join(pydir, 'szdiff.py'))) | 105 config.substitutions.append(('%szdiff', os.path.join(pydir, 'szdiff.py'))) |
| 71 | 106 |
| 72 llvmbintools = [r"\bFileCheck\b", r"\bllvm-as\b", r"\bllvm-mc\b", | 107 llvmbintools = [r"\bFileCheck\b", r"\bllvm-as\b", r"\bllvm-mc\b", |
| 73 r"\bllvm-objdump\b", r"\bnot\b", r"\bpnacl-freeze\b", | 108 r"\bllvm-objdump\b", r"\bnot\b", r"\bpnacl-freeze\b", |
| 74 r"\bpnacl-bcdis\b"] | 109 r"\bpnacl-bcdis\b"] |
| 75 | 110 |
| 76 for tool in llvmbintools: | 111 for tool in llvmbintools: |
| 77 # The re.sub() line is adapted from one of LLVM's lit.cfg files. | 112 # 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 | 113 # Extract the tool name from the pattern. This relies on the tool |
| 79 # name being surrounded by \b word match operators. If the | 114 # name being surrounded by \b word match operators. If the |
| 80 # pattern starts with "| ", include it in the string to be | 115 # pattern starts with "| ", include it in the string to be |
| 81 # substituted. | 116 # substituted. |
| 82 substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$", | 117 substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$", |
| 83 r"\2" + llvmbinpath + "/" + r"\4", | 118 r"\2" + llvmbinpath + "/" + r"\4", |
| 84 tool) | 119 tool) |
| 85 config.substitutions.append((tool, substitution)) | 120 config.substitutions.append((tool, substitution)) |
| 86 | 121 |
| 87 # Add a feature to detect the Python version. | 122 # Add a feature to detect the Python version. |
| 88 config.available_features.add("python%d.%d" % (sys.version_info[0], | 123 config.available_features.add("python%d.%d" % (sys.version_info[0], |
| 89 sys.version_info[1])) | 124 sys.version_info[1])) |
| 90 | 125 |
| 91 # Debugging output | 126 # Debugging output |
| 92 def dbg(s): | 127 def dbg(s): |
| 93 print '[DBG] %s' % s | 128 print '[DBG] %s' % s |
| 94 | 129 |
| 95 dbg('bin_root = %s' % bin_root) | 130 dbg('bin_root = %s' % bin_root) |
| 96 dbg('llvmbinpath = %s' % llvmbinpath) | 131 dbg('llvmbinpath = %s' % llvmbinpath) |
| OLD | NEW |