Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python2 |
| 2 | 2 |
| 3 import argparse | 3 import argparse |
| 4 import os | 4 import os |
| 5 import subprocess | 5 import subprocess |
| 6 import sys | 6 import sys |
| 7 import tempfile | 7 import tempfile |
| 8 | 8 |
| 9 from utils import shellcmd | 9 from utils import shellcmd |
| 10 from utils import FindBaseNaCl | 10 from utils import FindBaseNaCl |
| 11 | 11 |
| 12 def main(): | 12 def main(): |
| 13 """Builds a cross-test binary that allows functions translated by | 13 """Builds a cross-test binary that allows functions translated by |
| 14 Subzero and llc to be compared. | 14 Subzero and llc to be compared. |
| 15 | 15 |
| 16 Each --test argument is compiled once by llc and once by Subzero. | 16 Each --test argument is compiled once by llc and once by Subzero. |
| 17 C/C++ tests are first compiled down to PNaCl bitcode by the | 17 C/C++ tests are first compiled down to PNaCl bitcode by the |
| 18 build-pnacl-ir.py script. The --prefix argument ensures that | 18 build-pnacl-ir.py script. The --prefix argument ensures that |
|
jvoung (off chromium)
2015/03/09 17:34:21
see question about build-pnacl-ir
Jim Stichnoth
2015/03/09 18:16:16
Ah, nice catch, updated the documentation.
| |
| 19 symbol names are different between the two object files, to avoid | 19 symbol names are different between the two object files, to avoid |
| 20 linking errors. | 20 linking errors. |
| 21 | 21 |
| 22 There is also a --driver argument that specifies the C/C++ file | 22 There is also a --driver argument that specifies the C/C++ file |
| 23 that calls the test functions with a variety of interesting inputs | 23 that calls the test functions with a variety of interesting inputs |
| 24 and compares their results. | 24 and compares their results. |
| 25 """ | 25 """ |
| 26 # arch_map maps a Subzero target string to an llvm-mc -triple string. | 26 # arch_map maps a Subzero target string to an llvm-mc -triple string. |
| 27 arch_map = { 'x8632':'i686', 'x8664':'x86_64', 'arm':'armv7a' } | 27 arch_map = { 'x8632':'i686', 'x8664':'x86_64', 'arm':'armv7a' } |
| 28 desc = 'Build a cross-test that compares Subzero and llc translation.' | 28 desc = 'Build a cross-test that compares Subzero and llc translation.' |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 ' Default %(default)d.') | 69 ' Default %(default)d.') |
| 70 argparser.add_argument('--filetype', default='obj', dest='filetype', | 70 argparser.add_argument('--filetype', default='obj', dest='filetype', |
| 71 choices=['obj', 'asm', 'iasm'], | 71 choices=['obj', 'asm', 'iasm'], |
| 72 help='Output file type. Default %(default)s.') | 72 help='Output file type. Default %(default)s.') |
| 73 args = argparser.parse_args() | 73 args = argparser.parse_args() |
| 74 | 74 |
| 75 nacl_root = FindBaseNaCl() | 75 nacl_root = FindBaseNaCl() |
| 76 bindir = ('{root}/toolchain/linux_x86/pnacl_newlib/bin' | 76 bindir = ('{root}/toolchain/linux_x86/pnacl_newlib/bin' |
| 77 .format(root=nacl_root)) | 77 .format(root=nacl_root)) |
| 78 triple = arch_map[args.target] + ('-nacl' if args.sandbox else '') | 78 triple = arch_map[args.target] + ('-nacl' if args.sandbox else '') |
| 79 mypath = os.path.abspath(os.path.dirname(sys.argv[0])) | |
| 79 | 80 |
| 80 objs = [] | 81 objs = [] |
| 81 for arg in args.test: | 82 for arg in args.test: |
| 83 # Construct a "unique key" for each test so that tests can be run in | |
| 84 # parallel without race conditions on temporary file creation. | |
| 85 key = '{target}.{sb}.O{opt}.{attr}'.format( | |
| 86 target=args.target, sb='sb' if args.sandbox else 'nat', | |
| 87 opt=args.optlevel, attr=args.attr) | |
| 82 base, ext = os.path.splitext(arg) | 88 base, ext = os.path.splitext(arg) |
| 83 if ext == '.ll': | 89 if ext == '.ll': |
| 84 bitcode = arg | 90 bitcode = arg |
| 85 else: | 91 else: |
| 86 bitcode = os.path.join(args.dir, base + '.pnacl.ll') | 92 # Use pnacl-clang and pnacl-opt to produce PNaCl bitcode. |
| 87 shellcmd(['../pydir/build-pnacl-ir.py', '--disable-verify', | 93 bitcode_nonfinal = os.path.join(args.dir, base + '.' + key + '.bc') |
|
jvoung (off chromium)
2015/03/09 17:34:21
Is build-pnacl-ir still useful after this change?
Jim Stichnoth
2015/03/09 18:16:16
It isn't used by our scripts, but it's still kind
jvoung (off chromium)
2015/03/09 20:34:59
Hmm, up to you. I guess it could be a useful short
Jim Stichnoth
2015/03/09 20:37:48
Heh, that's where all those .pnacl.ll lit tests (a
| |
| 88 '--dir', args.dir, arg]) | 94 bitcode = os.path.join(args.dir, base + '.' + key + '.pnacl.ll') |
| 95 shellcmd(['{bin}/pnacl-clang'.format(bin=bindir), | |
| 96 '-O2', '-c', arg, '-o', bitcode_nonfinal]) | |
| 97 shellcmd(['{bin}/pnacl-opt'.format(bin=bindir), | |
| 98 '-pnacl-abi-simplify-preopt', | |
| 99 '-pnacl-abi-simplify-postopt', | |
| 100 '-pnaclabi-allow-debug-metadata', | |
| 101 bitcode_nonfinal, '-S', '-o', bitcode]) | |
| 89 | 102 |
| 90 base_sz = '{base}.{sb}.O{opt}.{attr}.{target}'.format( | 103 base_sz = '{base}.{key}'.format(base=base, key=key) |
| 91 base=base, sb='sb' if args.sandbox else 'nat', opt=args.optlevel, | |
| 92 attr=args.attr, target=args.target) | |
| 93 asm_sz = os.path.join(args.dir, base_sz + '.sz.s') | 104 asm_sz = os.path.join(args.dir, base_sz + '.sz.s') |
| 94 obj_sz = os.path.join(args.dir, base_sz + '.sz.o') | 105 obj_sz = os.path.join(args.dir, base_sz + '.sz.o') |
| 95 obj_llc = os.path.join(args.dir, base_sz + '.llc.o') | 106 obj_llc = os.path.join(args.dir, base_sz + '.llc.o') |
| 96 shellcmd(['../pnacl-sz', | 107 shellcmd(['{path}/pnacl-sz'.format(path=os.path.dirname(mypath)), |
| 97 '-O' + args.optlevel, | 108 '-O' + args.optlevel, |
| 98 '-mattr=' + args.attr, | 109 '-mattr=' + args.attr, |
| 99 '--target=' + args.target, | 110 '--target=' + args.target, |
| 100 '--sandbox=' + str(args.sandbox), | 111 '--sandbox=' + str(args.sandbox), |
| 101 '--prefix=' + args.prefix, | 112 '--prefix=' + args.prefix, |
| 102 '-allow-uninitialized-globals', | 113 '-allow-uninitialized-globals', |
| 103 '-externalize', | 114 '-externalize', |
| 104 '-filetype=' + args.filetype, | 115 '-filetype=' + args.filetype, |
| 105 '-o=' + (obj_sz if args.filetype == 'obj' else asm_sz), | 116 '-o=' + (obj_sz if args.filetype == 'obj' else asm_sz), |
| 106 bitcode]) | 117 bitcode]) |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 137 bin=bindir, prefix='pnacl-' if args.sandbox else '', | 148 bin=bindir, prefix='pnacl-' if args.sandbox else '', |
| 138 cc='clang' if pure_c else 'clang++') | 149 cc='clang' if pure_c else 'clang++') |
| 139 sb_native_args = (['-O0', '--pnacl-allow-native', '-arch', 'x8632'] | 150 sb_native_args = (['-O0', '--pnacl-allow-native', '-arch', 'x8632'] |
| 140 if args.sandbox else | 151 if args.sandbox else |
| 141 ['-g', '-m32', '-lm', '-lpthread']) | 152 ['-g', '-m32', '-lm', '-lpthread']) |
| 142 shellcmd([compiler, args.driver] + objs + | 153 shellcmd([compiler, args.driver] + objs + |
| 143 ['-o', os.path.join(args.dir, args.output)] + sb_native_args) | 154 ['-o', os.path.join(args.dir, args.output)] + sb_native_args) |
| 144 | 155 |
| 145 if __name__ == '__main__': | 156 if __name__ == '__main__': |
| 146 main() | 157 main() |
| OLD | NEW |