Skip to content

Commit a38438e

Browse files
arnamoy10etiotto
authored andcommitted
Adding ways to pass arguments (#28)
[FIX][sycl-clang] Adding ways to pass arguments specific to cgeist and arguments common to clang and cgeist.
1 parent ab49061 commit a38438e

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

polygeist/tools/cgeist/sycl-clang.py.in

+33-6
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,54 @@ import subprocess
1515
import shlex
1616

1717
# 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
1919

2020
def main():
2121
bin_path = "@CMAKE_RUNTIME_OUTPUT_DIRECTORY@"
2222
mlir_tool = bin_path + "/cgeist"
2323
clang_tool = bin_path + "/clang++"
2424
arg_file = sys.argv[1]
2525

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+
2632
# 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+
2948
clang_res = subprocess.Popen(clang_args, stderr=subprocess.PIPE)
3049
output = clang_res.stderr.readlines()
3150
expanded_clang_args = output[5].decode("utf-8")
3251
split_output = shlex.split(expanded_clang_args)
3352

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]
3757
mlir_args.append(arg_file)
58+
59+
# append cgeist arguments as passed through command line
60+
mlir_args.extend(cgeist_args)
61+
3862
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.
3966
mlir_args.extend(split_output[1:])
4067

4168
# print("mlir_args: ", mlir_args)

0 commit comments

Comments
 (0)