Skip to content

Commit

Permalink
Merge pull request #64 from udem-dlteam/laurent/changes-for-TCC
Browse files Browse the repository at this point in the history
More preprocessor changes
  • Loading branch information
laurenthuberdeau authored Sep 2, 2024
2 parents e01e389 + f845ac9 commit f9b88d7
Show file tree
Hide file tree
Showing 21 changed files with 739 additions and 606 deletions.
4 changes: 2 additions & 2 deletions debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ void print_tok(int tok, int val) {
else if (tok == DOUBLE_KW) putstr("double");
else if (tok == ELSE_KW) putstr("else");
else if (tok == ENUM_KW) putstr("enum");
else if (tok == ERROR_KW) putstr("error");
else if (tok == EXTERN_KW) putstr("extern");
else if (tok == FLOAT_KW) putstr("float");
else if (tok == FOR_KW) putstr("for");
Expand All @@ -56,6 +55,7 @@ void print_tok(int tok, int val) {

else if (tok == AMP_AMP) putstr("&&");
else if (tok == AMP_EQ) putstr("&=");
else if (tok == ARROW) putstr("->");
else if (tok == BAR_BAR) putstr("||");
else if (tok == BAR_EQ) putstr("|=");
else if (tok == CARET_EQ) putstr("^=");
Expand Down Expand Up @@ -127,7 +127,6 @@ void print_tok_type(int tok) {
else if (tok == DOUBLE_KW) putstr("double");
else if (tok == ELSE_KW) putstr("else");
else if (tok == ENUM_KW) putstr("enum");
else if (tok == ERROR_KW) putstr("error");
else if (tok == EXTERN_KW) putstr("extern");
else if (tok == FLOAT_KW) putstr("float");
else if (tok == FOR_KW) putstr("for");
Expand All @@ -152,6 +151,7 @@ void print_tok_type(int tok) {

else if (tok == AMP_AMP) putstr("&&");
else if (tok == AMP_EQ) putstr("&=");
else if (tok == ARROW) putstr("->");
else if (tok == BAR_BAR) putstr("||");
else if (tok == BAR_EQ) putstr("|=");
else if (tok == CARET_EQ) putstr("^=");
Expand Down
35 changes: 27 additions & 8 deletions examples/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,43 @@ echo "Compiling examples"

PNUT_SH_OPTIONS="-DRELEASE_PNUT_SH -DRT_COMPACT"

gcc -o build/pnut-sh-base.exe $PNUT_SH_OPTIONS pnut.c # Compile pnut.exe
# Compile pnut.exe
gcc -o build/pnut-sh-base.exe $PNUT_SH_OPTIONS pnut.c 2> /dev/null || fail "Error: Failed to compile pnut"

compile_options() {
echo `sed -n -e "/\/\/ pnut-options:/p" "$1" | sed -e "s/^\/\/ pnut-options://" | tr '\n' ',' | sed -e 's/,$//'`
}

fail() { echo "$1"; exit $2; }

failed=0

generate_executable_with() {
if ./build/$1 $file > $COMP_DIR/$filename.sh; then
chmod +x $COMP_DIR/$filename.sh
printf "✅\n"
else
printf "Failed to compile ❌\n"
failed=1
fi
}

for file in $(find examples -type f -name "*.c" | sort); do
filename=$(basename $file .c);
file_opts=$(compile_options $file)
# To speed up the compilation process, we only compile pnut.exe if there are specific options
if [ -z "$file_opts" ]; then
echo "Compiling $filename"
./build/pnut-sh-base.exe $file > $COMP_DIR/$filename.sh
printf "Compiling $filename: "
generate_executable_with "pnut-sh-base.exe"
else
echo "Compiling $filename with $file_opts"
gcc -o build/pnut-sh-opt.exe $PNUT_SH_OPTIONS $file_opts pnut.c # Compile pnut.exe with specific options
./build/pnut-sh-opt.exe $file $file_opts > $COMP_DIR/$filename.sh
printf "Compiling $filename with $file_opts: "
# Compile pnut.exe with specific options
gcc -o build/pnut-sh-opt.exe $PNUT_SH_OPTIONS $file_opts pnut.c 2> /dev/null || fail "Error: Failed to compile pnut with $file_opts"
generate_executable_with "pnut-sh-opt.exe"
fi
chmod +x $COMP_DIR/$filename.sh

done

if [ $failed -eq 1 ]; then
echo "##### Some examples failed to compile #####"
exit 1
fi
Loading

0 comments on commit f9b88d7

Please sign in to comment.