2010-11-23 08:40:35 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# convert ptx assembly output into
|
|
|
|
# a c-style string constant written
|
|
|
|
# in portable posix shell script.
|
|
|
|
# requires: sed, rm, mv
|
|
|
|
#
|
|
|
|
# Author: Axel Kohlmeyer, Temple University
|
2010-11-24 03:52:03 +08:00
|
|
|
|
2010-11-23 08:40:35 +08:00
|
|
|
num_args=$#
|
|
|
|
|
2011-12-02 23:51:43 +08:00
|
|
|
# Check command-line arguments
|
|
|
|
if [ $num_args -gt 9 ]; then
|
|
|
|
echo "$0 can only take 9 arguments; not $num_args"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $num_args -lt 3 ]; then
|
|
|
|
echo "Not enough arguments."
|
|
|
|
echo "$0 name_for_string input_file1 input_file2 ... output"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Name is first arg, output file is last argument
|
|
|
|
string_name=$1
|
|
|
|
eval output=\${$num_args}
|
|
|
|
shift
|
2010-11-23 08:40:35 +08:00
|
|
|
|
|
|
|
# remove temporary file in case we're interrupted.
|
|
|
|
cleanup () {
|
2011-12-02 23:51:43 +08:00
|
|
|
rm -f $output
|
2010-11-23 08:40:35 +08:00
|
|
|
}
|
|
|
|
trap cleanup INT QUIT TERM
|
|
|
|
|
|
|
|
# loop over arguments and convert to
|
2011-12-02 23:51:43 +08:00
|
|
|
# string constant.
|
|
|
|
i=2
|
|
|
|
echo "const char * $string_name = " > $output
|
2010-11-23 08:40:35 +08:00
|
|
|
while [ $i -lt $num_args ]
|
|
|
|
do \
|
|
|
|
src=$1
|
|
|
|
krn=${src##*/}
|
|
|
|
krn=${krn%.*}
|
2011-12-02 23:51:43 +08:00
|
|
|
echo "Converting $src to a c-style string"
|
2010-11-23 08:40:35 +08:00
|
|
|
sed -e 's/\\/\\\\/g' \
|
|
|
|
-e 's/"/\\"/g' \
|
|
|
|
-e 's/ *\/\/.*$//' \
|
|
|
|
-e '/\.file/D' \
|
|
|
|
-e '/^[ ]*$/D' \
|
|
|
|
-e 's/^\(.*\)$/"\1\\n"/' $src >> $output
|
|
|
|
shift
|
|
|
|
i=`expr $i + 1`
|
|
|
|
done
|
2011-12-02 23:51:43 +08:00
|
|
|
echo ';' >> $output
|