aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/UpdateTestChecks/common.py
diff options
context:
space:
mode:
authorAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>2021-04-21 12:19:08 +0100
committerAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>2021-04-28 12:19:19 +0100
commit9692811b264600b7fcb52a1f4fcf938d198567cb (patch)
tree1a5d3bc3976d72c35e1a4e7b0bf7c5934788e3b1 /llvm/utils/UpdateTestChecks/common.py
parentd0c521da3f0cfd1bd01696773349f1b723d8b057 (diff)
downloadllvm-9692811b264600b7fcb52a1f4fcf938d198567cb.zip
llvm-9692811b264600b7fcb52a1f4fcf938d198567cb.tar.gz
llvm-9692811b264600b7fcb52a1f4fcf938d198567cb.tar.bz2
[update_(llc_)test_checks.py] Support pre-processing commands
This has been rather useful in our downstream CHERI target where we want to run tests both with addrspace(0) and addrspace(200) pointers. With this patch we can prefix the opt command with `sed -e 's/addrspace(200)/addrspace(0)/g' -e 's/-A200-P200-G200//g'` to test both cases using the same IR input. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D95137
Diffstat (limited to 'llvm/utils/UpdateTestChecks/common.py')
-rw-r--r--llvm/utils/UpdateTestChecks/common.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 4598475..449ccb0 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -2,6 +2,7 @@ from __future__ import print_function
import copy
import glob
+import os
import re
import subprocess
import sys
@@ -141,11 +142,23 @@ def should_add_line_to_output(input_line, prefix_set, skip_global_checks = False
return True
# Invoke the tool that is being tested.
-def invoke_tool(exe, cmd_args, ir):
+def invoke_tool(exe, cmd_args, ir, preprocess_cmd=None, verbose=False):
with open(ir) as ir_file:
# TODO Remove the str form which is used by update_test_checks.py and
# update_llc_test_checks.py
# The safer list form is used by update_cc_test_checks.py
+ if preprocess_cmd:
+ # Allow pre-processing the IR file (e.g. using sed):
+ assert isinstance(preprocess_cmd, str) # TODO: use a list instead of using shell
+ preprocess_cmd = preprocess_cmd.replace('%s', ir).strip()
+ if verbose:
+ print('Pre-processing input file: ', ir, " with command '",
+ preprocess_cmd, "'", sep="", file=sys.stderr)
+ # Python 2.7 doesn't have subprocess.DEVNULL:
+ with open(os.devnull, 'w') as devnull:
+ pp = subprocess.Popen(preprocess_cmd, shell=True, stdin=devnull,
+ stdout=subprocess.PIPE)
+ ir_file = pp.stdout
if isinstance(cmd_args, list):
stdout = subprocess.check_output([exe] + cmd_args, stdin=ir_file)
else: