2024-02-06 09:29:19 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
INFILE=${2}
|
2024-07-11 23:46:00 -04:00
|
|
|
OUTFILE=${3}
|
2024-02-06 09:29:19 -05:00
|
|
|
|
|
|
|
usage() {
|
|
|
|
printf "${0} - compiler for HELL programming language\n"
|
|
|
|
printf "usage: ${0} INFILE GCCOPTS\n"
|
|
|
|
printf "\n"
|
|
|
|
printf "Note: Since hellc is a frontend for GCC, any GCC option can be used.\n"
|
|
|
|
printf "\n"
|
|
|
|
printf "Hellc is free software.\n"
|
|
|
|
printf "See the GNU GPL version 3 for details.\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
usage_small() {
|
2024-07-11 23:46:00 -04:00
|
|
|
printf "usage: ${0} [-h] [-c] INFILE OUTFILE\n"
|
2024-02-06 09:29:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
case ${1} in
|
|
|
|
-h|--help)
|
|
|
|
usage "$@"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-c|--compile)
|
|
|
|
if [[ -z "${INFILE}" ]]; then
|
|
|
|
printf "${0}: no input file\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
printf "running HELL preprocessor for ${INFILE}\n"
|
|
|
|
cat ${INFILE} | hellp > ${INFILE}.new
|
|
|
|
if [ "$?" != 0 ]; then
|
|
|
|
printf "${0}: error: HELL preprocessor failed to run\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-07-11 23:46:00 -04:00
|
|
|
printf "${0}: hellp: ran successfully\n"
|
2024-02-06 09:29:19 -05:00
|
|
|
|
|
|
|
printf "compiling ${INFILE}\n"
|
2024-07-11 23:46:00 -04:00
|
|
|
gcc -x c ${INFILE}.new -o ${OUTFILE}
|
2024-02-06 09:29:19 -05:00
|
|
|
if [ "$?" != 0 ]; then
|
|
|
|
printf "${0}: error: C compiler failed to run\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-07-11 23:46:00 -04:00
|
|
|
printf "cleaning up\n"
|
|
|
|
rm -v ${INFILE}.new
|
|
|
|
|
2024-02-06 09:29:19 -05:00
|
|
|
printf "finished compiling\n"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-*|--*)
|
|
|
|
usage_small "$@"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
usage_small "$@"
|
|
|
|
exit 1
|