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 , checkRC , 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,15 @@ 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+ out = subprocess .run (
36+ cmd ,
37+ shell = True ,
38+ check = checkRC ,
39+ stdout = subprocess .PIPE ,
40+ stderr = subprocess .DEVNULL ,
41+ ).stdout
42+
3643 # Fix line endings to unix CR style.
3744 return out .decode ().replace ("\r \n " , "\n " )
3845
@@ -97,8 +104,16 @@ def getStdCheckLine(prefix, output, mc_mode):
97104 return o
98105
99106
100- def getErrCheckLine (prefix , output , mc_mode ):
101- return COMMENT [mc_mode ] + " " + prefix + ": " + ":[[@LINE-1]]" + output + "\n "
107+ def getErrCheckLine (prefix , output , mc_mode , line_offset = 1 ):
108+ return (
109+ COMMENT [mc_mode ]
110+ + " "
111+ + prefix
112+ + ": "
113+ + ":[[@LINE-{}]]" .format (line_offset )
114+ + output
115+ + "\n "
116+ )
102117
103118
104119def main ():
@@ -151,11 +166,19 @@ def main():
151166 assert len (commands ) >= 2
152167 mc_cmd = " | " .join (commands [:- 1 ])
153168 filecheck_cmd = commands [- 1 ]
154- mc_tool = mc_cmd .split (" " )[0 ]
155169
156170 # special handling for negating exit status
157- if mc_tool == "not" :
158- mc_tool = mc_tool + " " + mc_cmd .split (" " )[1 ]
171+ # if not is used in runline, disable rc check, since
172+ # the command might or might not
173+ # return non-zero code on a single line run
174+ checkRC = True
175+ mc_cmd_args = mc_cmd .strip ().split ()
176+ if mc_cmd_args [0 ] == "not" :
177+ checkRC = False
178+ mc_tool = mc_cmd_args [1 ]
179+ mc_cmd = mc_cmd [len (mc_cmd_args [0 ]) :].strip ()
180+ else :
181+ mc_tool = mc_cmd_args [0 ]
159182
160183 triple_in_cmd = None
161184 m = common .TRIPLE_ARG_RE .search (mc_cmd )
@@ -188,6 +211,7 @@ def main():
188211 (
189212 check_prefixes ,
190213 mc_tool ,
214+ checkRC ,
191215 mc_cmd_args ,
192216 triple_in_cmd ,
193217 march_in_cmd ,
@@ -204,6 +228,7 @@ def main():
204228 for (
205229 prefixes ,
206230 mc_tool ,
231+ checkRC ,
207232 mc_args ,
208233 triple_in_cmd ,
209234 march_in_cmd ,
@@ -222,6 +247,7 @@ def main():
222247 # get output for each testline
223248 out = invoke_tool (
224249 ti .args .llvm_mc_binary or mc_tool ,
250+ checkRC ,
225251 mc_args ,
226252 line ,
227253 verbose = ti .args .verbose ,
@@ -278,6 +304,9 @@ def main():
278304 # each run_id can only be used once
279305 gen_prefix = ""
280306 used_runid = set ()
307+
308+ # line number diff between generated prefix and testline
309+ line_offset = 1
281310 for prefix , tup in p_dict_sorted .items ():
282311 o , run_ids = tup
283312
@@ -294,9 +323,13 @@ def main():
294323 used_prefixes .add (prefix )
295324
296325 if hasErr (o ):
297- gen_prefix + = getErrCheckLine (prefix , o , mc_mode )
326+ newline = getErrCheckLine (prefix , o , mc_mode , line_offset )
298327 else :
299- gen_prefix += getStdCheckLine (prefix , o , mc_mode )
328+ newline = getStdCheckLine (prefix , o , mc_mode )
329+
330+ if newline :
331+ gen_prefix += newline
332+ line_offset += 1
300333
301334 generated_prefixes .append (gen_prefix .rstrip ("\n " ))
302335
0 commit comments