💎💎💎💎💎
This commit is contained in:
46
genx.sh
46
genx.sh
@ -76,31 +76,39 @@ appendStd() {
|
|||||||
mv "$temp_file" "$1"
|
mv "$temp_file" "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ass() {
|
||||||
if [ $# -eq 1 ]; then
|
gcc "$1" library/alpha_lib_reg.s library/alpha_driver.s -no-pie -o binaries/${2}
|
||||||
if [ -f "$1" ]; then
|
|
||||||
if [[ "$1" == *.alpha ]]; then
|
|
||||||
appendStd "$1"
|
|
||||||
./alpha -cg "$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
|
if [ $? -eq 0 ]; then
|
||||||
echo -e "${GREEN}[GenX] ${WHITE}Generated executable file."
|
echo -e "${GREEN}[GenX] ${WHITE}Executable file: binaries/${2}"
|
||||||
echo -e "${GREEN}[GenX] ${WHITE}Executable file: binaries/${filename}"
|
|
||||||
echo -e "${GREEN}[GenX] ${WHITE}Done!"
|
echo -e "${GREEN}[GenX] ${WHITE}Done!"
|
||||||
else
|
else
|
||||||
echo -e "${RED}[GenX] ${YELLOW}Error generating executable file!${WHITE}"
|
echo -e "${RED}[GenX] ${YELLOW}Error generating executable file!${WHITE}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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 -ir -tc -asc -cg -st "$1"
|
||||||
|
backup_file="${1}.bak"
|
||||||
|
if [ -f "$backup_file" ]; then
|
||||||
|
mv "$backup_file" "$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${GREEN}[GenX] ${WHITE}Generated .s file."
|
||||||
|
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
|
else
|
||||||
echo -e "${RED}[GenX] ${YELLOW}File $1 is not a .alpha file!${WHITE}"
|
echo -e "${RED}[GenX] ${YELLOW}File $1 is not a .alpha file!${WHITE}"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -306,7 +306,9 @@ function_declaration:
|
|||||||
if(getAdInfoType(table_lookup(cur, $4))==TYPE_FUNCTION_TYPE){
|
if(getAdInfoType(table_lookup(cur, $4))==TYPE_FUNCTION_TYPE){
|
||||||
//printf("%s\n",$2);
|
//printf("%s\n",$2);
|
||||||
//printf("%s\n",getName(table_lookup(cur, $4)));
|
//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{
|
else{
|
||||||
throw_error(ERROR_TYPE, "Function declatation (%s) is not a valid function type", $2);
|
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
|
| EXTERNAL FUNCTION ID COLON ID
|
||||||
{
|
{
|
||||||
if(getAdInfoType(look_up(cur, $5))==TYPE_FUNCTION_TYPE){
|
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{
|
else{
|
||||||
throw_error(ERROR_TYPE, "Function declatation (%s) is not a valid function type", $3);
|
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) {
|
if (asc_flag) {
|
||||||
/* yyerror(""); */
|
yyerror("");
|
||||||
int needed = snprintf(NULL, 0, " LINE (%d:%d) ** %s ERROR: ", line, column, error_name);
|
int needed = snprintf(NULL, 0, " LINE (%d:%d) ** %s ERROR: ", line, column, error_name);
|
||||||
char *error_message = malloc(needed + 1);
|
char *error_message = malloc(needed + 1);
|
||||||
snprintf(error_message, needed + 1, " LINE (%d:%d) ** %s ERROR: ", line, column, error_name);
|
snprintf(error_message, needed + 1, " LINE (%d:%d) ** %s ERROR: ", line, column, error_name);
|
||||||
|
Reference in New Issue
Block a user