1616
1717mc_LIKE_TOOLS = [
1818 "llvm-mc" ,
19- "not llvm-mc" ,
2019]
2120ERROR_RE = re .compile (r":\d+: (warning|error): .*" )
2221ERROR_CHECK_RE = re .compile (r"# COM: .*" )
2322OUTPUT_SKIPPED_RE = re .compile (r"(.text)" )
2423COMMENT = {"asm" : "//" , "dasm" : "#" }
2524
2625
27- def invoke_tool (exe , cmd_args , testline , verbose = False ):
26+ def invoke_tool (exe , checkRC , cmd_args , testline , verbose = False ):
2827 if isinstance (cmd_args , list ):
2928 args = [applySubstitutions (a , substitutions ) for a in cmd_args ]
3029 else :
@@ -33,7 +32,15 @@ def invoke_tool(exe, cmd_args, testline, verbose=False):
3332 cmd = 'echo "' + testline + '" | ' + exe + " " + args
3433 if verbose :
3534 print ("Command: " , cmd )
36- out = subprocess .check_output (cmd , shell = True )
35+
36+ out = subprocess .run (
37+ cmd ,
38+ shell = True ,
39+ check = checkRC ,
40+ stdout = subprocess .PIPE ,
41+ stderr = subprocess .DEVNULL ,
42+ ).stdout
43+
3744 # Fix line endings to unix CR style.
3845 return out .decode ().replace ("\r \n " , "\n " )
3946
@@ -102,8 +109,16 @@ def getStdCheckLine(prefix, output, mc_mode):
102109 return o
103110
104111
105- def getErrCheckLine (prefix , output , mc_mode ):
106- 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+ )
107122
108123
109124def main ():
@@ -174,11 +189,19 @@ def main():
174189 assert len (commands ) >= 2
175190 mc_cmd = " | " .join (commands [:- 1 ])
176191 filecheck_cmd = commands [- 1 ]
177- mc_tool = mc_cmd .split (" " )[0 ]
178192
179193 # special handling for negating exit status
180- if mc_tool == "not" :
181- mc_tool = mc_tool + " " + mc_cmd .split (" " )[1 ]
194+ # if not is used in runline, disable rc check, since
195+ # the command might or might not
196+ # return non-zero code on a single line run
197+ checkRC = True
198+ mc_cmd_args = mc_cmd .strip ().split ()
199+ if mc_cmd_args [0 ] == "not" :
200+ checkRC = False
201+ mc_tool = mc_cmd_args [1 ]
202+ mc_cmd = mc_cmd [len (mc_cmd_args [0 ]) :].strip ()
203+ else :
204+ mc_tool = mc_cmd_args [0 ]
182205
183206 triple_in_cmd = None
184207 m = common .TRIPLE_ARG_RE .search (mc_cmd )
@@ -211,6 +234,7 @@ def main():
211234 (
212235 check_prefixes ,
213236 mc_tool ,
237+ checkRC ,
214238 mc_cmd_args ,
215239 triple_in_cmd ,
216240 march_in_cmd ,
@@ -231,6 +255,7 @@ def main():
231255 for (
232256 prefixes ,
233257 mc_tool ,
258+ checkRC ,
234259 mc_args ,
235260 triple_in_cmd ,
236261 march_in_cmd ,
@@ -249,6 +274,7 @@ def main():
249274 # get output for each testline
250275 out = invoke_tool (
251276 ti .args .llvm_mc_binary or mc_tool ,
277+ checkRC ,
252278 mc_args ,
253279 line ,
254280 verbose = ti .args .verbose ,
@@ -305,6 +331,9 @@ def main():
305331 # each run_id can only be used once
306332 gen_prefix = ""
307333 used_runid = set ()
334+
335+ # line number diff between generated prefix and testline
336+ line_offset = 1
308337 for prefix , tup in p_dict_sorted .items ():
309338 o , run_ids = tup
310339
@@ -321,9 +350,13 @@ def main():
321350 used_prefixes .add (prefix )
322351
323352 if hasErr (o ):
324- gen_prefix + = getErrCheckLine (prefix , o , mc_mode )
353+ newline = getErrCheckLine (prefix , o , mc_mode , line_offset )
325354 else :
326- gen_prefix += getStdCheckLine (prefix , o , mc_mode )
355+ newline = getStdCheckLine (prefix , o , mc_mode )
356+
357+ if newline :
358+ gen_prefix += newline
359+ line_offset += 1
327360
328361 generated_prefixes [input_line ] = gen_prefix .rstrip ("\n " )
329362
0 commit comments