Skip to content

Commit

Permalink
Repaired empty return, only left value return
Browse files Browse the repository at this point in the history
  • Loading branch information
jefersonla committed Nov 10, 2016
1 parent 33c827e commit 13dd2fe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
13 changes: 12 additions & 1 deletion analisador-semantico.y
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,15 @@ comando_list : comando_list comando {
return EXIT_FAILURE;
}

/* Check if there are errors with the actual node */
/* Check if there are errors with the actual child list */
if($$->child_list == NULL){
printFatalError("FATAL ERROR ON CHILD LIST!");
return EXIT_FAILURE;
}

/* Add the last node */
listAddToken($$->child_list, $2);
nodeAddRootToken($2, $$);
}
| /* Empty */ {
/* Allocate Token and append childs */
Expand Down Expand Up @@ -566,6 +567,10 @@ term_elseif : term_elseif T_ELSEIF exp T_THEN bloco {
listAddToken($$->child_list, $3);
listAddToken($$->child_list, $4);
listAddToken($$->child_list, $5);
nodeAddRootToken($2, $$);
nodeAddRootToken($3, $$);
nodeAddRootToken($4, $$);
nodeAddRootToken($5, $$);
}
| /* Empty */ {
/* Allocate Token and append childs */
Expand Down Expand Up @@ -898,6 +903,7 @@ listadenomes : T_NAME {
/* Add the first child if the last child was a token */
else{
listAddToken($$->child_list, $1);
nodeAddRootToken($1, $$);
}

/* Check if there are errors with the actual node */
Expand All @@ -915,6 +921,8 @@ listadenomes : T_NAME {
/* Add the last nodes */
listAddToken($$->child_list, $2);
listAddToken($$->child_list, $3);
nodeAddRootToken($2, $$);
nodeAddRootToken($3, $$);
}
;

Expand All @@ -936,6 +944,7 @@ listaexp : exp {
/* Add the first child if the last child was a token */
else{
listAddToken($$->child_list, $1);
nodeAddRootToken($1, $$);
}

/* Check if there are errors with the actual node */
Expand All @@ -953,6 +962,8 @@ listaexp : exp {
/* Add the last nodes */
listAddToken($$->child_list, $2);
listAddToken($$->child_list, $3);
nodeAddRootToken($2, $$);
nodeAddRootToken($3, $$);
}
;

Expand Down
21 changes: 19 additions & 2 deletions codegen_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1425,11 +1425,13 @@ bool cgenCommand(TokenNode *command_token, SymbolTable *actual_symbol_table){
*/
bool cgenCommandReturn(TokenNode *command_return_token, SymbolTable *actual_symbol_table){
int num_exp;
int pop_size;
int return_shift;
char *function_name;
TokenNode *token_name;
TokenNode *root_token;
TokenNode *list_exp_token;
SymbolTable *symbol_table;

/* Check if token return command is valid */
if(command_return_token == NULL){
Expand Down Expand Up @@ -1482,15 +1484,30 @@ bool cgenCommandReturn(TokenNode *command_return_token, SymbolTable *actual_symb
*/
if(command_return_token->token_type == TI_RETURN){

/* Since we can be inside a lot of blocks of code, we need to pop all variables until the function definition */
/* First symbol table to check */
symbol_table = actual_symbol_table;

/* Initialize pop size */
pop_size = 0;

/* Recurse and count the size of the pop */
while(symbol_table != NULL){
pop_size += symbol_table->shift_address;
symbol_table = symbol_table->previous_scope;
}

/* Pop local variables on stack */
addInstructionMainQueueFormated(mips_pop_params, (actual_symbol_table->shift_address));
addInstructionMainQueueFormated(mips_pop_params, pop_size);

/* First root token */
root_token = command_return_token->root_token;

/* Recurse and get the name of the function which is being returned */
while(root_token != NULL){

printf("0x%X -- %s\n", root_token->token_type, root_token->token_str);
printf("0x%X --\n", root_token->token_type, root_token->token_str);

/* If the actual token is of the type we wanted stop */
if((root_token->token_type == TI_FUNCTION) || (root_token->token_type == TI_FUNCTION_PARAM)){
Expand Down
2 changes: 1 addition & 1 deletion codegen_models.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ const char mips_start_function_def2[] =

/* Empty return */
const char mips_end_of_function[] =
"end_function_%s: # Jump to the end of this void function\n";
"\tj end_function_%s # Jump to the end of this void function\n";

/* End of function definition */
const char mips_end_function_def[] =
Expand Down

0 comments on commit 13dd2fe

Please sign in to comment.