@@ -15,27 +15,54 @@ import subprocess
15
15
import shlex
16
16
17
17
# run programs with
18
- # sycl-clang.py <file> <cgeist flags> 2> /dev/null
18
+ # sycl-clang.py <file> <cgeist flags> -XClang<optnl> <clang args> 2> /dev/null
19
19
20
20
def main ():
21
21
bin_path = "@CMAKE_RUNTIME_OUTPUT_DIRECTORY@"
22
22
mlir_tool = bin_path + "/cgeist"
23
23
clang_tool = bin_path + "/clang++"
24
24
arg_file = sys .argv [1 ]
25
25
26
+ # help message
27
+ if len (sys .argv ) == 1 and (arg_file == "-h" or arg_file == "--help" ):
28
+ print ("Usage: sycl-clang.py <file> <cgeist flags> -XClang<optional> \
29
+ <both clang and cgeist args>" )
30
+ sys .exit (0 )
31
+
26
32
# Invoke clang, capture the command line produced by clang.
27
- clang_args = [clang_tool , "-###" , "-fsycl" , "-fsycl-device-only" , "-D__SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__" ]
28
- clang_args .extend (sys .argv [1 :2 ])
33
+ clang_args = [clang_tool , "-###" , "-fsycl" , "-fsycl-device-only" , \
34
+ "-D__SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__" ]
35
+ # Add the file name to process
36
+ clang_args .append (arg_file )
37
+ # extract respective flags
38
+ both_args = []
39
+ cgeist_args = []
40
+ if '-XClang' in sys .argv :
41
+ both_args .extend (sys .argv [sys .argv .index ('-XClang' )+ 1 :])
42
+ clang_args .extend (both_args )
43
+ # extract arguments upto the point where clang args begin
44
+ cgeist_args .extend (sys .argv [2 :sys .argv .index ('-XClang' )])
45
+ else :
46
+ cgeist_args .extend (sys .argv [2 :])
47
+
29
48
clang_res = subprocess .Popen (clang_args , stderr = subprocess .PIPE )
30
49
output = clang_res .stderr .readlines ()
31
50
expanded_clang_args = output [5 ].decode ("utf-8" )
32
51
split_output = shlex .split (expanded_clang_args )
33
52
34
- # Form the cgeist invocation command. Append the MLIR flags first, then append the clang flags after "--args".
35
- mlir_args = [mlir_tool ]
36
- mlir_args .extend (sys .argv [2 :])
53
+ # Form the cgeist invocation command. Append the cgeist flags first, then
54
+ # append the clang flags and common flags (passed through -XClang)
55
+ # after "--args".
56
+ mlir_args = [mlir_tool ]
37
57
mlir_args .append (arg_file )
58
+
59
+ # append cgeist arguments as passed through command line
60
+ mlir_args .extend (cgeist_args )
61
+
38
62
mlir_args .append ("--args" )
63
+ # common arguments as passed through -XClang command line will already be
64
+ # there in split_output, so we extract and append clang internal arguments
65
+ # and common arguments from split_output.
39
66
mlir_args .extend (split_output [1 :])
40
67
41
68
# print("mlir_args: ", mlir_args)
0 commit comments