[Frontend] Remove unused includes (NFC) (#116927)
[llvm-project.git] / llvm / test / tools / llvm-reduce / Inputs / llvm-dis-and-filecheck.py
blob2244542d9b2dc7a779dab67281276781b16a9cf3
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.
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>
12 """
15 import sys
16 import os
17 import subprocess
19 llvm_dis = sys.argv[1]
20 filecheck = sys.argv[2]
21 filecheck_args = [
22 filecheck,
24 filecheck_args.extend(sys.argv[3:-1])
25 bitcode_file = sys.argv[-1]
26 ir_file = bitcode_file + ".ll"
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"
32 disassemble.communicate()
34 if disassemble.returncode != 0:
35 print("stderr:")
36 print(disassemble.stderr)
37 print("stdout:")
38 print(disassemble.stdout)
39 sys.exit(1)
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)