summaryrefslogtreecommitdiffstats
path: root/llvm/utils/UpdateTestChecks/asm.py
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2018-02-10 05:01:33 +0000
committerFangrui Song <maskray@google.com>2018-02-10 05:01:33 +0000
commit4f0f426d1fffc145f8defce6c7a85d17f4428908 (patch)
tree10ba329b16698b53e586d16f4e2ebe95ca9d7445 /llvm/utils/UpdateTestChecks/asm.py
parent3da72051149e61f14cc1639b953049630f0c2a59 (diff)
downloadbcm5719-llvm-4f0f426d1fffc145f8defce6c7a85d17f4428908.tar.gz
bcm5719-llvm-4f0f426d1fffc145f8defce6c7a85d17f4428908.zip
[utils] Refactor utils/update_{,llc_}test_checks.py to share more code
Summary: This revision refactors 1. parser 2. CHECK line adder of utils/update_{,llc_}test_checks.py so that thir functionality can be re-used by other utility scripts (e.g. D42712) Reviewers: asb, craig.topper, RKSimon, echristo Subscribers: llvm-commits, spatel Differential Revision: https://reviews.llvm.org/D42805 llvm-svn: 324803
Diffstat (limited to 'llvm/utils/UpdateTestChecks/asm.py')
-rw-r--r--llvm/utils/UpdateTestChecks/asm.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/llvm/utils/UpdateTestChecks/asm.py b/llvm/utils/UpdateTestChecks/asm.py
index 7630be459ba..4b2d3ac518b 100644
--- a/llvm/utils/UpdateTestChecks/asm.py
+++ b/llvm/utils/UpdateTestChecks/asm.py
@@ -1,10 +1,18 @@
import re
-import string
+import sys
from . import common
+if sys.version_info[0] > 2:
+ class string:
+ expandtabs = str.expandtabs
+else:
+ import string
+
# RegEx: this is where the magic happens.
+##### Assembly parser
+
ASM_FUNCTION_X86_RE = re.compile(
r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@(?P=func)\n[^:]*?'
r'(?P<body>^##?[ \t]+[^:]+:.*?)\s*'
@@ -197,3 +205,29 @@ def build_function_body_dictionary_for_triple(args, raw_tool_output, triple, pre
common.build_function_body_dictionary(
function_re, scrubber, [args], raw_tool_output, prefixes,
func_dict, args.verbose)
+
+##### Generator of assembly CHECK lines
+
+def add_asm_checks(output_lines, comment_marker, run_list, func_dict, func_name):
+ printed_prefixes = []
+ for p in run_list:
+ checkprefixes = p[0]
+ for checkprefix in checkprefixes:
+ if checkprefix in printed_prefixes:
+ break
+ # TODO func_dict[checkprefix] may be None, '' or not exist.
+ # Fix the call sites.
+ if func_name not in func_dict[checkprefix] or not func_dict[checkprefix][func_name]:
+ continue
+ # Add some space between different check prefixes.
+ if len(printed_prefixes) != 0:
+ output_lines.append(comment_marker)
+ printed_prefixes.append(checkprefix)
+ output_lines.append('%s %s-LABEL: %s:' % (comment_marker, checkprefix, func_name))
+ func_body = func_dict[checkprefix][func_name].splitlines()
+ output_lines.append('%s %s: %s' % (comment_marker, checkprefix, func_body[0]))
+ for func_line in func_body[1:]:
+ output_lines.append('%s %s-NEXT: %s' % (comment_marker, checkprefix, func_line))
+ # Add space between different check prefixes and the first line of code.
+ # output_lines.append(';')
+ break
OpenPOWER on IntegriCloud