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 , prefix_not , 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,20 @@ 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
+ # 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
+
36
48
# Fix line endings to unix CR style.
37
49
return out .decode ().replace ("\r \n " , "\n " )
38
50
@@ -97,8 +109,16 @@ def getStdCheckLine(prefix, output, mc_mode):
97
109
return o
98
110
99
111
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
+ )
102
122
103
123
104
124
def main ():
@@ -151,11 +171,16 @@ def main():
151
171
assert len (commands ) >= 2
152
172
mc_cmd = " | " .join (commands [:- 1 ])
153
173
filecheck_cmd = commands [- 1 ]
154
- mc_tool = mc_cmd .split (" " )[0 ]
155
174
156
175
# 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 ]
159
184
160
185
triple_in_cmd = None
161
186
m = common .TRIPLE_ARG_RE .search (mc_cmd )
@@ -188,6 +213,7 @@ def main():
188
213
(
189
214
check_prefixes ,
190
215
mc_tool ,
216
+ prefix_not ,
191
217
mc_cmd_args ,
192
218
triple_in_cmd ,
193
219
march_in_cmd ,
@@ -204,6 +230,7 @@ def main():
204
230
for (
205
231
prefixes ,
206
232
mc_tool ,
233
+ prefix_not ,
207
234
mc_args ,
208
235
triple_in_cmd ,
209
236
march_in_cmd ,
@@ -222,6 +249,7 @@ def main():
222
249
# get output for each testline
223
250
out = invoke_tool (
224
251
ti .args .llvm_mc_binary or mc_tool ,
252
+ prefix_not ,
225
253
mc_args ,
226
254
line ,
227
255
verbose = ti .args .verbose ,
@@ -278,6 +306,9 @@ def main():
278
306
# each run_id can only be used once
279
307
gen_prefix = ""
280
308
used_runid = set ()
309
+
310
+ # line number diff between generated prefix and testline
311
+ line_offset = 1
281
312
for prefix , tup in p_dict_sorted .items ():
282
313
o , run_ids = tup
283
314
@@ -294,10 +325,12 @@ def main():
294
325
used_prefixes .add (prefix )
295
326
296
327
if hasErr (o ):
297
- gen_prefix += getErrCheckLine (prefix , o , mc_mode )
328
+ gen_prefix += getErrCheckLine (prefix , o , mc_mode , line_offset )
298
329
else :
299
330
gen_prefix += getStdCheckLine (prefix , o , mc_mode )
300
331
332
+ line_offset += 1
333
+
301
334
generated_prefixes .append (gen_prefix .rstrip ("\n " ))
302
335
303
336
# write output
0 commit comments