diff --git a/genx.sh b/genx.sh index 8da7039..b902a82 100755 --- a/genx.sh +++ b/genx.sh @@ -76,31 +76,39 @@ appendStd() { mv "$temp_file" "$1" } +ass() { + gcc "$1" library/alpha_lib_reg.s library/alpha_driver.s -no-pie -o binaries/${2} + if [ $? -eq 0 ]; then + echo -e "${GREEN}[GenX] ${WHITE}Executable file: binaries/${2}" + echo -e "${GREEN}[GenX] ${WHITE}Done!" + else + echo -e "${RED}[GenX] ${YELLOW}Error generating executable file!${WHITE}" + exit 1 + fi +} + if [ $# -eq 1 ]; then if [ -f "$1" ]; then + filename=$(basename -- "$1") if [[ "$1" == *.alpha ]]; then + filename="${filename:0:${#filename}-6}" + s_name="out/${filename}.s" appendStd "$1" - ./alpha -cg "$1" + ./alpha -ir -tc -asc -cg -st "$1" backup_file="${1}.bak" if [ -f "$backup_file" ]; then mv "$backup_file" "$1" - echo -e "${GREEN}[GenX] ${WHITE}Reverted $1 to its original state." fi - filename=$(basename -- "$1") - filename="${filename:0:${#filename}-6}" - s_name="out/${filename}.s" echo -e "${GREEN}[GenX] ${WHITE}Generated .s file." - gcc ${s_name} library/alpha_lib_reg.s library/alpha_driver.s -no-pie -o binaries/${filename} - if [ $? -eq 0 ]; then - echo -e "${GREEN}[GenX] ${WHITE}Generated executable file." - echo -e "${GREEN}[GenX] ${WHITE}Executable file: binaries/${filename}" - echo -e "${GREEN}[GenX] ${WHITE}Done!" - else - echo -e "${RED}[GenX] ${YELLOW}Error generating executable file!${WHITE}" - exit 1 - fi + ass "$s_name" "$filename" + elif [[ "$1" == *.s ]]; then + filename="${filename:0:${#filename}-2}" + s_name="out/${filename}.s" + echo -e "${GREEN}[GenX] ${WHITE}File $1 is a .s file! (Skipping compiler)${WHITE}" + ass "$s_name" "$filename" + exit 1 else echo -e "${RED}[GenX] ${YELLOW}File $1 is not a .alpha file!${WHITE}" exit 1 diff --git a/src/grammar.y b/src/grammar.y index a70ee74..6fd864c 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -306,7 +306,9 @@ function_declaration: if(getAdInfoType(table_lookup(cur, $4))==TYPE_FUNCTION_TYPE){ //printf("%s\n",$2); //printf("%s\n",getName(table_lookup(cur, $4))); - CreateEntry(cur,TYPE_FUNCTION_DECLARATION, table_lookup(cur, $4), $2, CreateFunctionDeclarationInfo(-1, false,NULL)); + if (CreateEntry(cur,TYPE_FUNCTION_DECLARATION, table_lookup(cur, $4), $2, CreateFunctionDeclarationInfo(-1, false,NULL)) == undefined) { + throw_error(ERROR_TYPE, "Duplicate defination of function in function declaration"); + } } else{ throw_error(ERROR_TYPE, "Function declatation (%s) is not a valid function type", $2); @@ -318,7 +320,9 @@ function_declaration: | EXTERNAL FUNCTION ID COLON ID { if(getAdInfoType(look_up(cur, $5))==TYPE_FUNCTION_TYPE){ - CreateEntry(cur,TYPE_FUNCTION_DECLARATION, look_up(cur, $5), $3, CreateFunctionDeclarationInfo(-1, false,NULL)); + if (CreateEntry(cur,TYPE_FUNCTION_DECLARATION, look_up(cur, $5), $3, CreateFunctionDeclarationInfo(-1, false,NULL)) == undefined) { + throw_error(ERROR_TYPE, "Duplicate defination of function in function declaration"); + } } else{ throw_error(ERROR_TYPE, "Function declatation (%s) is not a valid function type", $3); @@ -1579,7 +1583,7 @@ void throw_error(ErrorType error_type, const char *format, ...) { } if (asc_flag) { - /* yyerror(""); */ + yyerror(""); int needed = snprintf(NULL, 0, " LINE (%d:%d) ** %s ERROR: ", line, column, error_name); char *error_message = malloc(needed + 1); snprintf(error_message, needed + 1, " LINE (%d:%d) ** %s ERROR: ", line, column, error_name);