1515
1616mc_LIKE_TOOLS = [
1717 "llvm-mc" ,
18- "not llvm-mc" ,
1918]
2019ERROR_RE = re .compile (r":\d+: (warning|error): .*" )
2120ERROR_CHECK_RE = re .compile (r"# COM: .*" )
2221OUTPUT_SKIPPED_RE = re .compile (r"(.text)" )
2322COMMENT = {"asm" : "//" , "dasm" : "#" }
2423
2524
26- def invoke_tool (exe , cmd_args , testline , verbose = False ):
25+ def invoke_tool (exe , prefix_not , cmd_args , testline , verbose = False ):
2726 if isinstance (cmd_args , list ):
2827 args = [applySubstitutions (a , substitutions ) for a in cmd_args ]
2928 else :
@@ -32,7 +31,20 @@ def invoke_tool(exe, cmd_args, testline, verbose=False):
3231 cmd = 'echo "' + testline + '" | ' + exe + " " + args
3332 if verbose :
3433 print ("Command: " , cmd )
35- out = subprocess .check_output (cmd , shell = True )
34+
35+ # if not is used in runline, the command might or might not
36+ # return non-zero code on a single line run
37+ try :
38+ out = subprocess .check_output (cmd , shell = True , stderr = subprocess .DEVNULL )
39+ except :
40+ if prefix_not :
41+ cmd = 'echo "' + testline + '" | ' + "not " + exe + " " + args
42+ if verbose :
43+ print ("Command: " , cmd )
44+ out = subprocess .check_output (cmd , shell = True , stderr = subprocess .DEVNULL )
45+ else :
46+ raise Exception ("Command '{}' return non-zero value" .format (cmd ))
47+
3648 # Fix line endings to unix CR style.
3749 return out .decode ().replace ("\r \n " , "\n " )
3850
@@ -97,8 +109,16 @@ def getStdCheckLine(prefix, output, mc_mode):
97109 return o
98110
99111
100- def getErrCheckLine (prefix , output , mc_mode ):
101- return COMMENT [mc_mode ] + " " + prefix + ": " + ":[[@LINE-1]]" + output + "\n "
112+ def getErrCheckLine (prefix , output , mc_mode , line_offset = 1 ):
113+ return (
114+ COMMENT [mc_mode ]
115+ + " "
116+ + prefix
117+ + ": "
118+ + ":[[@LINE-{}]]" .format (line_offset )
119+ + output
120+ + "\n "
121+ )
102122
103123
104124def main ():
@@ -151,11 +171,16 @@ def main():
151171 assert len (commands ) >= 2
152172 mc_cmd = " | " .join (commands [:- 1 ])
153173 filecheck_cmd = commands [- 1 ]
154- mc_tool = mc_cmd .split (" " )[0 ]
155174
156175 # special handling for negating exit status
157- if mc_tool == "not" :
158- mc_tool = mc_tool + " " + mc_cmd .split (" " )[1 ]
176+ prefix_not = ""
177+ mc_cmd_args = mc_cmd .split (" " )
178+ if mc_cmd_args [0 ] == "not" :
179+ prefix_not = mc_cmd_args [0 ]
180+ mc_tool = mc_cmd_args [1 ]
181+ mc_cmd = mc_cmd [len (mc_cmd_args [0 ]) :].strip ()
182+ else :
183+ mc_tool = mc_cmd_args [0 ]
159184
160185 triple_in_cmd = None
161186 m = common .TRIPLE_ARG_RE .search (mc_cmd )
@@ -188,6 +213,7 @@ def main():
188213 (
189214 check_prefixes ,
190215 mc_tool ,
216+ prefix_not ,
191217 mc_cmd_args ,
192218 triple_in_cmd ,
193219 march_in_cmd ,
@@ -204,6 +230,7 @@ def main():
204230 for (
205231 prefixes ,
206232 mc_tool ,
233+ prefix_not ,
207234 mc_args ,
208235 triple_in_cmd ,
209236 march_in_cmd ,
@@ -222,6 +249,7 @@ def main():
222249 # get output for each testline
223250 out = invoke_tool (
224251 ti .args .llvm_mc_binary or mc_tool ,
252+ prefix_not ,
225253 mc_args ,
226254 line ,
227255 verbose = ti .args .verbose ,
@@ -278,6 +306,9 @@ def main():
278306 # each run_id can only be used once
279307 gen_prefix = ""
280308 used_runid = set ()
309+
310+ # line number diff between generated prefix and testline
311+ line_offset = 1
281312 for prefix , tup in p_dict_sorted .items ():
282313 o , run_ids = tup
283314
@@ -294,9 +325,13 @@ def main():
294325 used_prefixes .add (prefix )
295326
296327 if hasErr (o ):
297- gen_prefix + = getErrCheckLine (prefix , o , mc_mode )
328+ newline = getErrCheckLine (prefix , o , mc_mode , line_offset )
298329 else :
299- gen_prefix += getStdCheckLine (prefix , o , mc_mode )
330+ newline = getStdCheckLine (prefix , o , mc_mode )
331+
332+ if newline :
333+ gen_prefix += newline
334+ line_offset += 1
300335
301336 generated_prefixes .append (gen_prefix .rstrip ("\n " ))
302337
0 commit comments