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 )
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 )
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
@@ -151,11 +163,16 @@ def main():
151
163
assert len (commands ) >= 2
152
164
mc_cmd = " | " .join (commands [:- 1 ])
153
165
filecheck_cmd = commands [- 1 ]
154
- mc_tool = mc_cmd .split (" " )[0 ]
155
166
156
167
# special handling for negating exit status
157
- if mc_tool == "not" :
158
- mc_tool = mc_tool + " " + mc_cmd .split (" " )[1 ]
168
+ prefix_not = ""
169
+ mc_cmd_args = mc_cmd .split (" " )
170
+ if mc_cmd_args [0 ] == "not" :
171
+ prefix_not = mc_cmd_args [0 ]
172
+ mc_tool = mc_cmd_args [1 ]
173
+ mc_cmd = mc_cmd [len (mc_cmd_args [0 ]) :].strip ()
174
+ else :
175
+ mc_tool = mc_cmd_args [0 ]
159
176
160
177
triple_in_cmd = None
161
178
m = common .TRIPLE_ARG_RE .search (mc_cmd )
@@ -188,6 +205,7 @@ def main():
188
205
(
189
206
check_prefixes ,
190
207
mc_tool ,
208
+ prefix_not ,
191
209
mc_cmd_args ,
192
210
triple_in_cmd ,
193
211
march_in_cmd ,
@@ -204,6 +222,7 @@ def main():
204
222
for (
205
223
prefixes ,
206
224
mc_tool ,
225
+ prefix_not ,
207
226
mc_args ,
208
227
triple_in_cmd ,
209
228
march_in_cmd ,
@@ -222,6 +241,7 @@ def main():
222
241
# get output for each testline
223
242
out = invoke_tool (
224
243
ti .args .llvm_mc_binary or mc_tool ,
244
+ prefix_not ,
225
245
mc_args ,
226
246
line ,
227
247
verbose = ti .args .verbose ,
0 commit comments