| 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 re | 5 import re |
| 6 import subprocess | 6 import subprocess |
| 7 import sys | 7 import sys |
| 8 import tempfile | 8 import tempfile |
| 9 | 9 |
| 10 from utils import shellcmd | 10 from utils import shellcmd |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 argparser.add_argument('--dir', required=False, default='.', | 58 argparser.add_argument('--dir', required=False, default='.', |
| 59 metavar='OUTPUT_DIR', | 59 metavar='OUTPUT_DIR', |
| 60 help='Output directory for all files.' + | 60 help='Output directory for all files.' + |
| 61 ' Default "%(default)s".') | 61 ' Default "%(default)s".') |
| 62 argparser.add_argument('--crosstest-bitcode', required=False, | 62 argparser.add_argument('--crosstest-bitcode', required=False, |
| 63 default=1, type=int, | 63 default=1, type=int, |
| 64 help='Compile non-subzero crosstest object file ' + | 64 help='Compile non-subzero crosstest object file ' + |
| 65 'from the same bitcode as the subzero object. ' + | 65 'from the same bitcode as the subzero object. ' + |
| 66 'If 0, then compile it straight from source.' + | 66 'If 0, then compile it straight from source.' + |
| 67 ' Default %(default)d.') | 67 ' Default %(default)d.') |
| 68 argparser.add_argument('--elf', dest='elf', | 68 argparser.add_argument('--filetype', default='obj', dest='filetype', |
| 69 action='store_true', | 69 choices=['obj', 'asm', 'iasm'], |
| 70 help='Directly generate ELF output') | 70 help='Output file type. Default %(default)s.') |
| 71 args = argparser.parse_args() | 71 args = argparser.parse_args() |
| 72 | 72 |
| 73 nacl_root = FindBaseNaCl() | 73 nacl_root = FindBaseNaCl() |
| 74 # Prepend PNaCl bin to $PATH. | 74 # Prepend PNaCl bin to $PATH. |
| 75 os.environ['PATH'] = nacl_root + \ | 75 os.environ['PATH'] = nacl_root + \ |
| 76 '/toolchain/linux_x86/pnacl_newlib/bin' + \ | 76 '/toolchain/linux_x86/pnacl_newlib/bin' + \ |
| 77 os.pathsep + os.environ['PATH'] | 77 os.pathsep + os.environ['PATH'] |
| 78 | 78 |
| 79 objs = [] | 79 objs = [] |
| 80 remove_internal = re.compile('^define internal ') | 80 remove_internal = re.compile('^define internal ') |
| (...skipping 20 matching lines...) Expand all Loading... |
| 101 base_sz = '%s.O%s.%s.%s' % (base, args.optlevel, args.attr, args.target) | 101 base_sz = '%s.O%s.%s.%s' % (base, args.optlevel, args.attr, args.target) |
| 102 asm_sz = os.path.join(args.dir, base_sz + '.sz.s') | 102 asm_sz = os.path.join(args.dir, base_sz + '.sz.s') |
| 103 obj_sz = os.path.join(args.dir, base_sz + '.sz.o') | 103 obj_sz = os.path.join(args.dir, base_sz + '.sz.o') |
| 104 obj_llc = os.path.join(args.dir, base + '.llc.o') | 104 obj_llc = os.path.join(args.dir, base + '.llc.o') |
| 105 shellcmd(['../llvm2ice', | 105 shellcmd(['../llvm2ice', |
| 106 '-O' + args.optlevel, | 106 '-O' + args.optlevel, |
| 107 '-mattr=' + args.attr, | 107 '-mattr=' + args.attr, |
| 108 '--target=' + args.target, | 108 '--target=' + args.target, |
| 109 '--prefix=' + args.prefix, | 109 '--prefix=' + args.prefix, |
| 110 '-allow-uninitialized-globals', | 110 '-allow-uninitialized-globals', |
| 111 '-o=' + (obj_sz if args.elf else asm_sz), | 111 '-filetype=' + args.filetype, |
| 112 bitcode] + | 112 '-o=' + (obj_sz if args.filetype == 'obj' else asm_sz), |
| 113 (['-elf-writer'] if args.elf else [])) | 113 bitcode]) |
| 114 if not args.elf: | 114 if args.filetype != 'obj': |
| 115 shellcmd(['llvm-mc', | 115 shellcmd(['llvm-mc', |
| 116 '-arch=' + arch_map[args.target], | 116 '-arch=' + arch_map[args.target], |
| 117 '-filetype=obj', | 117 '-filetype=obj', |
| 118 '-o=' + obj_sz, | 118 '-o=' + obj_sz, |
| 119 asm_sz]) | 119 asm_sz]) |
| 120 objs.append(obj_sz) | 120 objs.append(obj_sz) |
| 121 # Each original bitcode file needs to be translated by the | 121 # Each original bitcode file needs to be translated by the |
| 122 # LLVM toolchain and have its object file linked in. There | 122 # LLVM toolchain and have its object file linked in. There |
| 123 # are two ways to do this: explicitly use llc, or include the | 123 # are two ways to do this: explicitly use llc, or include the |
| 124 # .ll file in the link command. It turns out that these two | 124 # .ll file in the link command. It turns out that these two |
| (...skipping 23 matching lines...) Expand all Loading... |
| 148 objs.append(( | 148 objs.append(( |
| 149 '{root}/toolchain_build/src/subzero/runtime/szrt.{ext}' | 149 '{root}/toolchain_build/src/subzero/runtime/szrt.{ext}' |
| 150 ).format(root=nacl_root, ext='c' if pure_c else 'cpp')) | 150 ).format(root=nacl_root, ext='c' if pure_c else 'cpp')) |
| 151 objs.append(( | 151 objs.append(( |
| 152 '{root}/toolchain_build/src/subzero/runtime/szrt_i686.ll' | 152 '{root}/toolchain_build/src/subzero/runtime/szrt_i686.ll' |
| 153 ).format(root=nacl_root)) | 153 ).format(root=nacl_root)) |
| 154 linker = 'clang' if pure_c else 'clang++' | 154 linker = 'clang' if pure_c else 'clang++' |
| 155 shellcmd([linker, '-g', '-m32', args.driver] + | 155 shellcmd([linker, '-g', '-m32', args.driver] + |
| 156 objs + | 156 objs + |
| 157 ['-lm', '-lpthread', '-o', os.path.join(args.dir, args.output)]) | 157 ['-lm', '-lpthread', '-o', os.path.join(args.dir, args.output)]) |
| OLD | NEW |