Skip to content

Commit

Permalink
Repaired bugs on simulate and test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jefersonla committed Nov 9, 2016
1 parent 3df3508 commit 47e1fc7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@ analisador_semantico
# Debug status
debug.y.output

# Binary output files
*.mips

# Temp files
*.swp
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ BISON_HEADER_FILE=y.tab.h
# Codigos fontes
SOURCES=$(FLEX_SRC) $(FLEX_HEADER_FILE) $(BISON_SRC) $(BISON_HEADER_FILE)
# Package files
PKG_FILES=analisador-lexico.l analisador-semantico.y lexical.defs.h parser.defs.h token_struct.h utils.h codegen_functions.h $(LIBS_SRC) $(TODO_WARN)
PKG_FILES=$(FLEX_SRC) $(BISON_SRC) $(LIBS_SRC) $(LIBS_HEADERS)
# Libs sources
LIBS_SRC=token_struct.c utils.c codegen_models.c codegen_functions.c
# Libs sources headers
LIBS_HEADERS=lexical.defs.h parser.defs.h token_struct.h utils.h codegen_functions.h
# Comment this to ignore TODO WARNINGS!
TODO_WARN=-Wno-unused-parameter

Expand Down Expand Up @@ -63,7 +65,7 @@ debug_codegen_executable: debug.lex.yy.c debug.y.tab.c
$(CC) $(CFLAGS) -o $(EXECUTABLE) -g debug.y.tab.c debug.lex.yy.c $(LIBS_SRC) $(TODO_WARN) $(CFLAGS_PARSER) -D DEBUG_MODE

# Executavel Gerador de código
$(EXECUTABLE): lex.yy.c y.tab.c
$(EXECUTABLE): lex.yy.c y.tab.c $(LIBS_SRC) $(LIBS_HEADERS)
$(CC) $(CFLAGS) -o $(EXECUTABLE) y.tab.c lex.yy.c $(LIBS_SRC) $(TODO_WARN) $(CFLAGS_PARSER)

# Compilação Analisador Sintático/Semântico
Expand All @@ -85,7 +87,7 @@ debug_parser_executable: debug.lex.yy.c debug.y.tab.c
$(CC) $(CFLAGS) -o $(PARSER_EXECUTABLE) -g debug.y.tab.c debug.lex.yy.c $(LIBS_SRC) $(TODO_WARN) $(CFLAGS_PARSER) -D DEBUG_MODE -D SEMANTIC_ANALYSER

# Executavel Analisador Semantico/Sintatico
$(PARSER_EXECUTABLE): lex.yy.c y.tab.c
$(PARSER_EXECUTABLE): lex.yy.c y.tab.c $(LIBS_SRC) $(LIBS_HEADERS)
$(CC) $(CFLAGS) -o $(PARSER_EXECUTABLE) y.tab.c lex.yy.c $(LIBS_SRC) $(TODO_WARN) $(CFLAGS_PARSER) -D SEMANTIC_ANALYSER

# Compilação Analisador Léxico
Expand All @@ -107,7 +109,7 @@ debug_lexical_executable: debug.y.tab.c debug.lex.yy.c
$(CC) $(CFLAGS) debug.lex.yy.c $(LIBS_SRC) $(TODO_WARN) -o $(LEXICAL_EXECUTABLE) -g $(CFLAGS_LEXICAL) -D LEXICAL_ANALYSER -D DEBUG_MODE

# Executavel Analisador Lexico
$(LEXICAL_EXECUTABLE): y.tab.c lex.yy.c
$(LEXICAL_EXECUTABLE): y.tab.c lex.yy.c $(LIBS_SRC) $(LIBS_HEADERS)
$(CC) $(CFLAGS) lex.yy.c $(LIBS_SRC) $(TODO_WARN) -o $(LEXICAL_EXECUTABLE) $(CFLAGS_LEXICAL) -D LEXICAL_ANALYSER

# Realiza os testes nos executaveis
Expand Down Expand Up @@ -171,11 +173,9 @@ check-final:
awk '{ \
for(i = 1; i <= NF; i++) { \
split($$1,a,"-"); \
param2="test-"a[2] ;\
param3="exec-"a[2] ; \
param4="code-"a[2] ; \
command="./$(EXECUTABLE) tests/input/"$$1" tests/testing/"param2" > /dev/null 2>&1 && "\
"./test.sh simulate.sh tests/testing/"param2" tests/testing/"param3" tests/executed/"param4; \
param2="exec-"a[2] ; \
param3="code-"a[2] ; \
command="./test.sh simulate.sh tests/input/"$$1" tests/testing/"param2" tests/executed/"param3; \
system(command); \
} \
}'
Expand Down
41 changes: 39 additions & 2 deletions simulate.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
#!/bin/bash
# Execute spim and put output to a file
spim -f "$1" | tail -n +6 | head -n 10000 > "$2"

# Show help usage
if [ "$#" -eq "0" ] || [ "$#" -gt "2" ]
then
printf "Usage: \n\t./simulate.sh input output\n"
exit 0
fi

# Check if there are a input file
if [ -z "$1" ]
then
echo "[ERROR] NOT SPECIFIED INPUT FILE!"
exit 1
fi

# Check if output file is specified
if [ -z "$2" ]
then
echo "[ERROR] NOT SPECIFIED OUTPUT FILE!"
exit 1
fi

# Check if compiler exists and can be executed
if [ -e "compilador" ] && [ -s "compilador" ] && [ -x "compilador" ] && [ -e "$1" ]
then
echo "Compiling and testing program..."
else
echo "[ERROR] COMPILER OR INPUT FILE DON'T EXIST, IS EMPTY OR CAN'T BE EXECUTABLE!"
exit 1
fi

# Execute compiler, generate mips code pass this to spim and put the output in a file
( ./compilador "$1" "$2.mips" > /dev/null 2>&1 && \
spim -f "$2.mips" | tail -n +6 | head -n 10000 > "$2" ) || \
( echo "Failed to compile program" && exit 1 )

# Program simulated with success
echo "Simulation Finished!"
exit 0
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Show help usage
if [ "$#" -eq "0" ]
if [ "$#" -eq "0" ] || [ "$#" -gt "3" ]
then
printf "Usage: \n\t./test.sh executable input [output] [expected]\n"
exit 0
Expand Down

0 comments on commit 47e1fc7

Please sign in to comment.