brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 2244542 Raw
46 lines · python
1"""2Script to disassembles a bitcode file and run FileCheck on the output with the3provided arguments. The first 2 arguments are the paths to the llvm-dis and4FileCheck binaries, followed by arguments to be passed to FileCheck. The last5argument is the bitcode file to disassemble.6 7Usage:8    python llvm-dis-and-filecheck.py9      <path to llvm-dis> <path to FileCheck>10      [arguments passed to FileCheck] <path to bitcode file>11 12"""13 14 15import sys16import os17import subprocess18 19llvm_dis = sys.argv[1]20filecheck = sys.argv[2]21filecheck_args = [22    filecheck,23]24filecheck_args.extend(sys.argv[3:-1])25bitcode_file = sys.argv[-1]26ir_file = bitcode_file + ".ll"27 28disassemble = subprocess.Popen([llvm_dis, "--preserve-ll-uselistorder", "-o", ir_file, bitcode_file])29if os.path.exists(ir_file + ".0"):30    ir_file = ir_file + ".0"31 32disassemble.communicate()33 34if disassemble.returncode != 0:35    print("stderr:")36    print(disassemble.stderr)37    print("stdout:")38    print(disassemble.stdout)39    sys.exit(1)40 41check = None42with open(ir_file, "r") as ir:43    check = subprocess.Popen(filecheck_args, stdin=ir, stdout=sys.stdout)44check.communicate()45sys.exit(check.returncode)46