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