forked from ROCm/hcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclamp-preprocess.in
executable file
·66 lines (56 loc) · 1.67 KB
/
clamp-preprocess.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# check if we have 2 arguments
if [ "$#" -ne 2 ]; then
echo "Usage: $0 input_source output_source" >&2
exit 1
fi
if [ ! -f $1 ]; then
echo "Input source $1 is not valid!" >&2
exit 1
fi
# include paths:
# - C++AMP header
# - libc++ header
# - Bolt source header
# - Bolt header generated
# - Boost header
# tools search priority:
# 1) $HCC_HOME
# 2) @LLVM_TOOLS_DIR@ : build directory
# 3) @CMAKE_INSTALL_PREFIX@ : default install directory
if [ -n "$HCC_HOME" ] && [ -e "$HCC_HOME" ]; then
CLANG=$HCC_HOME/bin/clang++
CLAMP_CONFIG=$HCC_HOME/bin/clamp-config
CLAMP_CONFIG_FLAGS="--bolt --cxxflags"
REWRITE=$HCC_HOME/lib/libStmtRewriter.so
elif [ -d @LLVM_TOOLS_DIR@ ]; then
CLANG=@PROJECT_BINARY_DIR@/compiler/bin/clang++
CLAMP_CONFIG=@PROJECT_BINARY_DIR@/build/@CMAKE_BUILD_TYPE@/bin/clamp-config
CLAMP_CONFIG_FLAGS="--bolt --build --cxxflags"
REWRITE=@PROJECT_BINARY_DIR@/build/@CMAKE_BUILD_TYPE@/lib/libStmtRewriter.so
elif [ -e @CMAKE_INSTALL_PREFIX@ ]; then
CLANG=@CMAKE_INSTALL_PREFIX@/bin/clang++
CLAMP_CONFIG=@CMAKE_INSTALL_PREFIX@/bin/clamp-config
CLAMP_CONFIG_FLAGS="--bolt --cxxflags"
REWRITE=@CMAKE_INSTALL_PREFIX@/lib/libStmtRewriter.so
else
echo "ERROR: Can NOT locate HCC tools! Please specify with $HCC_HOME environmental variable." >&2
exit 1
fi
# copy input file to a temp directory
TEMP_DIR=`mktemp -d`
cp $1 $TEMP_DIR/input.cpp
# do preprocess
$CLANG \
`$CLAMP_CONFIG $CLAMP_CONFIG_FLAGS` \
-stdlib=libc++ \
-Xclang -load -Xclang $REWRITE \
-Xclang -plugin -Xclang StmtRewriter \
-E $1
# save the output
cp $1 $2
# restore input back
cp $TEMP_DIR/input.cpp $1
# remove temp files
rm $TEMP_DIR/input.cpp
rmdir $TEMP_DIR