15
15
16
16
mc_LIKE_TOOLS = [
17
17
"llvm-mc" ,
18
- "not llvm-mc" ,
19
18
]
20
19
ERROR_RE = re .compile (r":\d+: (warning|error): .*" )
21
20
ERROR_CHECK_RE = re .compile (r"# COM: .*" )
22
21
OUTPUT_SKIPPED_RE = re .compile (r"(.text)" )
23
22
COMMENT = {"asm" : "//" , "dasm" : "#" }
24
23
25
24
26
- def invoke_tool (exe , cmd_args , testline , verbose = False ):
25
+ def invoke_tool (exe , checkRC , cmd_args , testline , verbose = False ):
27
26
if isinstance (cmd_args , list ):
28
27
args = [applySubstitutions (a , substitutions ) for a in cmd_args ]
29
28
else :
@@ -32,7 +31,15 @@ def invoke_tool(exe, cmd_args, testline, verbose=False):
32
31
cmd = 'echo "' + testline + '" | ' + exe + " " + args
33
32
if verbose :
34
33
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
+
36
43
# Fix line endings to unix CR style.
37
44
return out .decode ().replace ("\r \n " , "\n " )
38
45
@@ -97,8 +104,16 @@ def getStdCheckLine(prefix, output, mc_mode):
97
104
return o
98
105
99
106
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
+ )
102
117
103
118
104
119
def main ():
@@ -151,11 +166,19 @@ def main():
151
166
assert len (commands ) >= 2
152
167
mc_cmd = " | " .join (commands [:- 1 ])
153
168
filecheck_cmd = commands [- 1 ]
154
- mc_tool = mc_cmd .split (" " )[0 ]
155
169
156
170
# 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 ]
159
182
160
183
triple_in_cmd = None
161
184
m = common .TRIPLE_ARG_RE .search (mc_cmd )
@@ -188,6 +211,7 @@ def main():
188
211
(
189
212
check_prefixes ,
190
213
mc_tool ,
214
+ checkRC ,
191
215
mc_cmd_args ,
192
216
triple_in_cmd ,
193
217
march_in_cmd ,
@@ -204,6 +228,7 @@ def main():
204
228
for (
205
229
prefixes ,
206
230
mc_tool ,
231
+ checkRC ,
207
232
mc_args ,
208
233
triple_in_cmd ,
209
234
march_in_cmd ,
@@ -222,6 +247,7 @@ def main():
222
247
# get output for each testline
223
248
out = invoke_tool (
224
249
ti .args .llvm_mc_binary or mc_tool ,
250
+ checkRC ,
225
251
mc_args ,
226
252
line ,
227
253
verbose = ti .args .verbose ,
@@ -278,6 +304,9 @@ def main():
278
304
# each run_id can only be used once
279
305
gen_prefix = ""
280
306
used_runid = set ()
307
+
308
+ # line number diff between generated prefix and testline
309
+ line_offset = 1
281
310
for prefix , tup in p_dict_sorted .items ():
282
311
o , run_ids = tup
283
312
@@ -294,9 +323,13 @@ def main():
294
323
used_prefixes .add (prefix )
295
324
296
325
if hasErr (o ):
297
- gen_prefix + = getErrCheckLine (prefix , o , mc_mode )
326
+ newline = getErrCheckLine (prefix , o , mc_mode , line_offset )
298
327
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
300
333
301
334
generated_prefixes .append (gen_prefix .rstrip ("\n " ))
302
335
0 commit comments