29
29
ADVERT = '// NOTE: Assertions have been autogenerated by '
30
30
31
31
CHECK_RE = re .compile (r'^\s*//\s*([^:]+?)(?:-NEXT|-NOT|-DAG|-LABEL)?:' )
32
- RUN_LINE_RE = re .compile (r'^//\s*RUN:\s*(.*)$' )
33
32
34
33
SUBST = {
35
34
'%clang' : [],
38
37
}
39
38
40
39
def get_line2spell_and_mangled (args , clang_args ):
41
- def debug_mangled (* print_args , ** kwargs ):
42
- if args .verbose :
43
- print (* print_args , file = sys .stderr , ** kwargs )
44
40
ret = {}
45
41
# Use clang's JSON AST dump to get the mangled name
46
42
json_dump_args = [args .clang , * clang_args , '-fsyntax-only' , '-o' , '-' ]
@@ -49,7 +45,7 @@ def debug_mangled(*print_args, **kwargs):
49
45
# -Xclang -ast-dump=json instead:
50
46
json_dump_args .append ('-Xclang' )
51
47
json_dump_args .append ('-ast-dump=json' )
52
- debug_mangled ('Running' , ' ' .join (json_dump_args ))
48
+ common . debug ('Running' , ' ' .join (json_dump_args ))
53
49
status = subprocess .run (json_dump_args , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
54
50
if status .returncode != 0 :
55
51
sys .stderr .write ('Failed to run ' + ' ' .join (json_dump_args ) + '\n ' )
@@ -67,20 +63,19 @@ def debug_mangled(*print_args, **kwargs):
67
63
if node ['kind' ] != 'FunctionDecl' :
68
64
continue
69
65
if node .get ('isImplicit' ) is True and node .get ('storageClass' ) == 'extern' :
70
- debug_mangled ('Skipping builtin function:' , node ['name' ], '@' , node ['loc' ])
66
+ common . debug ('Skipping builtin function:' , node ['name' ], '@' , node ['loc' ])
71
67
continue
72
- debug_mangled ('Found function:' , node ['kind' ], node ['name' ], '@' , node ['loc' ])
68
+ common . debug ('Found function:' , node ['kind' ], node ['name' ], '@' , node ['loc' ])
73
69
line = node ['loc' ].get ('line' )
74
70
# If there is no line it is probably a builtin function -> skip
75
71
if line is None :
76
- debug_mangled ('Skipping function without line number:' , node ['name' ], '@' , node ['loc' ])
72
+ common . debug ('Skipping function without line number:' , node ['name' ], '@' , node ['loc' ])
77
73
continue
78
74
spell = node ['name' ]
79
75
mangled = node .get ('mangledName' , spell )
80
76
ret [int (line )- 1 ] = (spell , mangled )
81
- if args .verbose :
82
- for line , func_name in sorted (ret .items ()):
83
- print ('line {}: found function {}' .format (line + 1 , func_name ), file = sys .stderr )
77
+ for line , func_name in sorted (ret .items ()):
78
+ common .debug ('line {}: found function {}' .format (line + 1 , func_name ), file = sys .stderr )
84
79
if not ret :
85
80
common .warn ('Did not find any functions using' , ' ' .join (json_dump_args ))
86
81
return ret
@@ -191,19 +186,7 @@ def main():
191
186
continue
192
187
193
188
# Extract RUN lines.
194
- raw_lines = [m .group (1 )
195
- for m in [RUN_LINE_RE .match (l ) for l in input_lines ] if m ]
196
- run_lines = [raw_lines [0 ]] if len (raw_lines ) > 0 else []
197
- for l in raw_lines [1 :]:
198
- if run_lines [- 1 ].endswith ("\\ " ):
199
- run_lines [- 1 ] = run_lines [- 1 ].rstrip ("\\ " ) + " " + l
200
- else :
201
- run_lines .append (l )
202
-
203
- if args .verbose :
204
- print ('Found {} RUN lines:' .format (len (run_lines )), file = sys .stderr )
205
- for l in run_lines :
206
- print (' RUN: ' + l , file = sys .stderr )
189
+ run_lines = common .find_run_lines (filename , input_lines )
207
190
208
191
# Build a list of clang command lines and check prefixes from RUN lines.
209
192
run_list = []
@@ -260,9 +243,8 @@ def main():
260
243
for prefix in prefixes :
261
244
func_dict .update ({prefix : dict ()})
262
245
for prefixes , clang_args , extra_commands , triple_in_cmd in run_list :
263
- if args .verbose :
264
- print ('Extracted clang cmd: clang {}' .format (clang_args ), file = sys .stderr )
265
- print ('Extracted FileCheck prefixes: {}' .format (prefixes ), file = sys .stderr )
246
+ common .debug ('Extracted clang cmd: clang {}' .format (clang_args ))
247
+ common .debug ('Extracted FileCheck prefixes: {}' .format (prefixes ))
266
248
267
249
get_function_body (args , filename , clang_args , extra_commands , prefixes , triple_in_cmd , func_dict )
268
250
0 commit comments