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