| 1 |
""" |
| 2 |
Script to disassembles a bitcode file and run FileCheck on the output with the |
| 3 |
provided arguments. The first 2 arguments are the paths to the llvm-dis and |
| 4 |
FileCheck binaries, followed by arguments to be passed to FileCheck. The last |
| 5 |
argument is the bitcode file to disassemble. |
| 6 |
|
| 7 |
Usage: |
| 8 |
python llvm-dis-and-filecheck.py |
| 9 |
<path to llvm-dis> <path to FileCheck> |
| 10 |
[arguments passed to FileCheck] <path to bitcode file> |
| 11 |
|
| 12 |
""" |
| 13 |
|
| 14 |
|
| 15 |
import sys |
| 16 |
import os |
| 17 |
import subprocess |
| 18 |
|
| 19 |
llvm_dis = sys.argv[1] |
| 20 |
filecheck = sys.argv[2] |
| 21 |
filecheck_args = [ |
| 22 |
filecheck, |
| 23 |
] |
| 24 |
filecheck_args.extend(sys.argv[3:-1]) |
| 25 |
bitcode_file = sys.argv[-1] |
| 26 |
ir_file = bitcode_file + ".ll" |
| 27 |
|
| 28 |
disassemble = subprocess.Popen([llvm_dis, "--preserve-ll-uselistorder", "-o", ir_file, bitcode_file]) |
| 29 |
if os.path.exists(ir_file + ".0"): |
| 30 |
ir_file = ir_file + ".0" |
| 31 |
|
| 32 |
disassemble.communicate() |
| 33 |
|
| 34 |
if disassemble.returncode != 0: |
| 35 |
print("stderr:") |
| 36 |
print(disassemble.stderr) |
| 37 |
print("stdout:") |
| 38 |
print(disassemble.stdout) |
| 39 |
sys.exit(1) |
| 40 |
|
| 41 |
check = None |
| 42 |
with open(ir_file, "r") as ir: |
| 43 |
check = subprocess.Popen(filecheck_args, stdin=ir, stdout=sys.stdout) |
| 44 |
check.communicate() |
| 45 |
sys.exit(check.returncode) |