16
16
17
17
mc_LIKE_TOOLS = [
18
18
"llvm-mc" ,
19
- "not llvm-mc" ,
20
19
]
21
20
ERROR_RE = re .compile (r":\d+: (warning|error): .*" )
22
21
ERROR_CHECK_RE = re .compile (r"# COM: .*" )
23
22
OUTPUT_SKIPPED_RE = re .compile (r"(.text)" )
24
23
COMMENT = {"asm" : "//" , "dasm" : "#" }
25
24
26
25
27
- def invoke_tool (exe , cmd_args , testline , verbose = False ):
26
+ def invoke_tool (exe , checkRC , cmd_args , testline , verbose = False ):
28
27
if isinstance (cmd_args , list ):
29
28
args = [applySubstitutions (a , substitutions ) for a in cmd_args ]
30
29
else :
@@ -33,7 +32,15 @@ def invoke_tool(exe, cmd_args, testline, verbose=False):
33
32
cmd = 'echo "' + testline + '" | ' + exe + " " + args
34
33
if verbose :
35
34
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
+
37
44
# Fix line endings to unix CR style.
38
45
return out .decode ().replace ("\r \n " , "\n " )
39
46
@@ -102,8 +109,16 @@ def getStdCheckLine(prefix, output, mc_mode):
102
109
return o
103
110
104
111
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
+ )
107
122
108
123
109
124
def main ():
@@ -174,11 +189,19 @@ def main():
174
189
assert len (commands ) >= 2
175
190
mc_cmd = " | " .join (commands [:- 1 ])
176
191
filecheck_cmd = commands [- 1 ]
177
- mc_tool = mc_cmd .split (" " )[0 ]
178
192
179
193
# 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 ]
182
205
183
206
triple_in_cmd = None
184
207
m = common .TRIPLE_ARG_RE .search (mc_cmd )
@@ -211,6 +234,7 @@ def main():
211
234
(
212
235
check_prefixes ,
213
236
mc_tool ,
237
+ checkRC ,
214
238
mc_cmd_args ,
215
239
triple_in_cmd ,
216
240
march_in_cmd ,
@@ -231,6 +255,7 @@ def main():
231
255
for (
232
256
prefixes ,
233
257
mc_tool ,
258
+ checkRC ,
234
259
mc_args ,
235
260
triple_in_cmd ,
236
261
march_in_cmd ,
@@ -249,6 +274,7 @@ def main():
249
274
# get output for each testline
250
275
out = invoke_tool (
251
276
ti .args .llvm_mc_binary or mc_tool ,
277
+ checkRC ,
252
278
mc_args ,
253
279
line ,
254
280
verbose = ti .args .verbose ,
@@ -305,6 +331,9 @@ def main():
305
331
# each run_id can only be used once
306
332
gen_prefix = ""
307
333
used_runid = set ()
334
+
335
+ # line number diff between generated prefix and testline
336
+ line_offset = 1
308
337
for prefix , tup in p_dict_sorted .items ():
309
338
o , run_ids = tup
310
339
@@ -321,9 +350,13 @@ def main():
321
350
used_prefixes .add (prefix )
322
351
323
352
if hasErr (o ):
324
- gen_prefix + = getErrCheckLine (prefix , o , mc_mode )
353
+ newline = getErrCheckLine (prefix , o , mc_mode , line_offset )
325
354
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
327
360
328
361
generated_prefixes [input_line ] = gen_prefix .rstrip ("\n " )
329
362
0 commit comments