| 1 |
""" |
| 2 |
Script to assemble a text IR file and run FileCheck on the output with the |
| 3 |
provided arguments. The first 2 arguments are the paths to the llvm-as and |
| 4 |
FileCheck binaries, followed by arguments to be passed to FileCheck. The last |
| 5 |
argument is the text IR file to disassemble. |
| 6 |
|
| 7 |
Usage: |
| 8 |
python llvm-as-and-filecheck.py |
| 9 |
<path to llvm-as> <path to FileCheck> |
| 10 |
[arguments passed to FileCheck] <path to text IR file> |
| 11 |
|
| 12 |
""" |
| 13 |
import sys |
| 14 |
import os |
| 15 |
import subprocess |
| 16 |
|
| 17 |
llvm_as = sys.argv[1] |
| 18 |
filecheck = sys.argv[2] |
| 19 |
filecheck_args = [ |
| 20 |
filecheck |
| 21 |
] |
| 22 |
|
| 23 |
filecheck_args.extend(sys.argv[3:-1]) |
| 24 |
ir_file = sys.argv[-1] |
| 25 |
bitcode_file = ir_file + ".bc" |
| 26 |
|
| 27 |
# Verify the IR actually parses since FileCheck is too dumb to know. |
| 28 |
assemble = subprocess.Popen([llvm_as, "-o", bitcode_file, ir_file]) |
| 29 |
assemble.communicate() |
| 30 |
|
| 31 |
if assemble.returncode != 0: |
| 32 |
print("stderr:") |
| 33 |
print(assemble.stderr) |
| 34 |
print("stdout:") |
| 35 |
print(assemble.stdout) |
| 36 |
sys.exit(0) |
| 37 |
|
| 38 |
filecheck_args.append("--input-file") |
| 39 |
filecheck_args.append(ir_file) |
| 40 |
|
| 41 |
check = subprocess.Popen(filecheck_args) |
| 42 |
check.communicate() |
| 43 |
sys.exit(check.returncode) |