1
- #!/usr/bin/env python3
1
+ #!/usr/bin/env python
2
2
'''A utility to update LLVM IR CHECK lines in C/C++ FileCheck test files.
3
3
4
4
Example RUN lines in .c/.cc test files:
12
12
% utils/update_cc_test_checks.py --clang=release/bin/clang /tmp/c/a.cc
13
13
'''
14
14
15
+ from __future__ import print_function
16
+
15
17
import argparse
16
18
import collections
17
19
import distutils .spawn
37
39
def get_line2spell_and_mangled (args , clang_args ):
38
40
ret = {}
39
41
# Use clang's JSON AST dump to get the mangled name
40
- json_dump_args = [args .clang , * clang_args , '-fsyntax-only' , '-o' , '-' ]
42
+ json_dump_args = [args .clang ] + clang_args + [ '-fsyntax-only' , '-o' , '-' ]
41
43
if '-cc1' not in json_dump_args :
42
44
# For tests that invoke %clang instead if %clang_cc1 we have to use
43
45
# -Xclang -ast-dump=json instead:
44
46
json_dump_args .append ('-Xclang' )
45
47
json_dump_args .append ('-ast-dump=json' )
46
48
common .debug ('Running' , ' ' .join (json_dump_args ))
47
- status = subprocess .run (json_dump_args , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
48
- if status .returncode != 0 :
49
+
50
+ popen = subprocess .Popen (json_dump_args , stdout = subprocess .PIPE ,
51
+ stderr = subprocess .PIPE , universal_newlines = True )
52
+ stdout , stderr = popen .communicate ()
53
+ if popen .returncode != 0 :
49
54
sys .stderr .write ('Failed to run ' + ' ' .join (json_dump_args ) + '\n ' )
50
- sys .stderr .write (status . stderr . decode () )
51
- sys .stderr .write (status . stdout . decode () )
55
+ sys .stderr .write (stderr )
56
+ sys .stderr .write (stdout )
52
57
sys .exit (2 )
53
58
54
59
# Parse the clang JSON and add all children of type FunctionDecl.
@@ -75,7 +80,7 @@ def parse_clang_ast_json(node):
75
80
mangled = node .get ('mangledName' , spell )
76
81
ret [int (line )- 1 ] = (spell , mangled )
77
82
78
- ast = json .loads (status . stdout . decode () )
83
+ ast = json .loads (stdout )
79
84
if ast ['kind' ] != 'TranslationUnitDecl' :
80
85
common .error ('Clang AST dump JSON format changed?' )
81
86
sys .exit (2 )
0 commit comments