From 733e278a3c20988cfe1ae386fe057945a805bbb3 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sat, 10 Mar 2018 22:53:48 +0000 Subject: [Doc] Writing more --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ makefile | 2 +- run_test_deliverable.sh | 4 ++-- test_compiler.sh | 10 +++++----- test_lexer.sh | 2 +- test_parser.sh | 22 +++++++++++----------- 6 files changed, 62 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 2b88787..f15e758 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,48 @@ # Compiler +## Structure + +The project is structured in three directories. + +- `c_compiler` contains the main compiler, together with the final parser and lexer. +- `c_parser` contains the first parser that was written and covered a very simple c-like syntax. +- `c_lexer` contains the first lexer for the C syntax. + + +## Usage + +To use the compiler and test it out, together with the lexer and parser, the [`makefile`](/makefile) can +be used. The main compiler can be built using the following commands. + +``` shell +# build all the targets +make + +# Building the main compiler +make bin/c_compiler + +# Building the parser +make bin/c_parser + +# Building the lexer +make bin/c_lexer +``` + +These can then be tested using the following shell scripts. + +``` shell +# Running tests for the compiler +./run_test_deliverable.sh + +# Running tests for the parser +./test_parser.sh + +# Running tests for the lexer +./test_lexer.sh +``` + + ## Functionality Implemented compiler functionality following the C89 Spec. diff --git a/makefile b/makefile index 3bedb39..83c4076 100644 --- a/makefile +++ b/makefile @@ -15,7 +15,7 @@ COMPINC := -Ic_compiler/include COMPBUILDDIR := c_compiler/build COMPSRCDIR := c_compiler/src -all : bin/c_lexer bin/c_parser +all : bin/c_lexer bin/c_parser bin/c_compiler # Make the c_lexer bin/c_lexer : $(LEXBUILDDIR)/main.o $(LEXBUILDDIR)/c_lexer.o $(LEXBUILDDIR)/c_lexer.yy.o diff --git a/run_test_deliverable.sh b/run_test_deliverable.sh index 32809ff..a825bfd 100755 --- a/run_test_deliverable.sh +++ b/run_test_deliverable.sh @@ -44,7 +44,7 @@ for DRIVER in test_deliverable/testcases/*_driver.c ; do # Link driver object and assembly into executable mips-linux-gnu-gcc -static working/${NAME}.s working/${NAME}_driver.o -o working/${NAME}.elf 2> working/${NAME}.link.stderr if [[ $? -ne 0 ]]; then - printf "\e[1;31mError\e[0m : Linker returned error message.\n" + printf "\e[1;31mError\e[0m : Linker returned error message.\n" continue fi @@ -53,7 +53,7 @@ for DRIVER in test_deliverable/testcases/*_driver.c ; do RESULT=$? if [[ "$RESULT" -ne 0 ]]; then printf "\e[1;31mError\e[0m : Testcase returned $RESULT, but expected 0.\n" - continue + continue fi printf "\e[1;32mPass\e[0m\n" diff --git a/test_compiler.sh b/test_compiler.sh index 23e2749..cae3988 100755 --- a/test_compiler.sh +++ b/test_compiler.sh @@ -10,7 +10,7 @@ echo " Force building lexer" make -B bin/c_compiler if [[ "$?" -ne 0 ]]; then - echo "Build failed."; + echo "Build failed."; fi echo "" @@ -26,15 +26,15 @@ mkdir -p c_compiler/test/ref for i in c_compiler/test/in/*.c; do echo "===========================" - echo "" - echo "Input file : ${i}" + echo "" + echo "Input file : ${i}" BASENAME=$(basename $i .c); - cat $i | ./bin/c_compiler > c_compiler/test/out/$BASENAME.s 2> c_compiler/test/out/$BASENAME.stderr.txt + cat $i | ./bin/c_compiler > c_compiler/test/out/$BASENAME.s 2> c_compiler/test/out/$BASENAME.stderr.txt mips-linux-gnu-gcc -O0 -S -c c_compiler/test/in/$BASENAME.c -o c_compiler/test/ref/$BASENAME.s mips-linux-gnu-gcc -O0 -static c_compiler/test/ref/$BASENAME.s -o c_compiler/test/ref/$BASENAME - mips-linux-gnu-gcc -O0 -static c_compiler/test/out/$BASENAME.s -o c_compiler/test/out/$BASENAME + mips-linux-gnu-gcc -O0 -static c_compiler/test/out/$BASENAME.s -o c_compiler/test/out/$BASENAME qemu-mips c_compiler/test/ref/$BASENAME REFOUTPUT=$? diff --git a/test_lexer.sh b/test_lexer.sh index c9904ee..ee61e18 100755 --- a/test_lexer.sh +++ b/test_lexer.sh @@ -17,4 +17,4 @@ echo " Testing lexer" cpp c_lexer/test/test_lex.c c_lexer/test/pre_processed_test_lex.c cat c_lexer/test/pre_processed_test_lex.c | bin/c_lexer | tee c_lexer/test/output.json -#cat test/test_lex.c | ./bin/c_lexer | tee test/output.json +# cat test/test_lex.c | ./bin/c_lexer | tee test/output.json diff --git a/test_parser.sh b/test_parser.sh index cddc491..3e56054 100755 --- a/test_parser.sh +++ b/test_parser.sh @@ -9,7 +9,7 @@ echo " Force building lexer" make -B bin/c_parser if [[ "$?" -ne 0 ]]; then - echo "Build failed."; + echo "Build failed."; fi echo "" @@ -22,19 +22,19 @@ CHECKED=0 for i in c_parser/test/in/*.c; do echo "===========================" - echo "" - echo "Input file : ${i}" + echo "" + echo "Input file : ${i}" BASENAME=$(basename $i .c); - cat $i | ./bin/c_parser > c_parser/test/out/$BASENAME.stdout.xml 2> c_parser/test/out/$BASENAME.stderr.txt + cat $i | ./bin/c_parser > c_parser/test/out/$BASENAME.stdout.xml 2> c_parser/test/out/$BASENAME.stderr.txt tidy -xml -i -q -o c_parser/test/out/$BASENAME.pretty.xml c_parser/test/out/$BASENAME.stdout.xml - diff <(cat c_parser/test/ref/$BASENAME.stdout.xml | tidy -xml -i -q) <(cat c_parser/test/out/$BASENAME.stdout.xml | tidy -xml -i -q) > c_parser/test/out/$BASENAME.diff.txt - if [[ "$?" -ne "0" ]]; then - echo -e "\nERROR" - else - PASSED=$(( ${PASSED}+1 )); - fi - CHECKED=$(( ${CHECKED}+1 )); + diff <(cat c_parser/test/ref/$BASENAME.stdout.xml | tidy -xml -i -q) <(cat c_parser/test/out/$BASENAME.stdout.xml | tidy -xml -i -q) > c_parser/test/out/$BASENAME.diff.txt + if [[ "$?" -ne "0" ]]; then + echo -e "\nERROR" + else + PASSED=$(( ${PASSED}+1 )); + fi + CHECKED=$(( ${CHECKED}+1 )); done echo "########################################" -- cgit