Skip to content
Snippets Groups Projects
Commit a75825f5 authored by viniciusmioto's avatar viniciusmioto
Browse files

chamada de procedimento por valor + atribuicao indirate (ARMI)

parent 81b8ced9
No related branches found
No related tags found
No related merge requests found
...@@ -5,13 +5,15 @@ R01: ENPR 1 ...@@ -5,13 +5,15 @@ R01: ENPR 1
AMEM 1 AMEM 1
DSVS R02 DSVS R02
R02: NADA R02: NADA
CRVL 1,-4 CRVI 1,-5
ARMZ 1,0 ARMZ 1,0
CRCT 1
ARMI 1,-5
DMEM 1 DMEM 1
R00: NADA R00: NADA
CRCT 8 CRCT 8
ARMZ 0,0 ARMZ 0,0
CRVL 0,0 CREN 0,0
CRCT 2 CRCT 2
CHPR R01,0 CHPR R01,0
DMEM 0 DMEM 0
......
This diff is collapsed.
...@@ -25,6 +25,7 @@ custom_stack_t *rot; ...@@ -25,6 +25,7 @@ custom_stack_t *rot;
custom_stack_t *proc; custom_stack_t *proc;
int val_ou_ref; int val_ou_ref;
int atr_indireto;
%} %}
...@@ -211,7 +212,10 @@ secao_pfs: VAR ...@@ -211,7 +212,10 @@ secao_pfs: VAR
val_ou_ref = REF; val_ou_ref = REF;
} }
lista_id_pf DOIS_PONTOS tipo lista_id_pf DOIS_PONTOS tipo
{ num_param += num_vars;} {
num_param += num_vars;
val_ou_ref = VLR;
}
| { | {
num_vars = 0; num_vars = 0;
val_ou_ref = VLR; val_ou_ref = VLR;
...@@ -266,13 +270,20 @@ atribuicao: { ...@@ -266,13 +270,20 @@ atribuicao: {
if (l_elem == NULL) { if (l_elem == NULL) {
yyerror("Variável de destino não declarada"); yyerror("Variável de destino não declarada");
} else { } else {
if (l_elem->categ == PF && l_elem->info.pf.passagem == REF)
atr_indireto = REF;
else atr_indireto = VLR;
destino_nivel = l_elem->nivel; destino_nivel = l_elem->nivel;
destino_desloc = l_elem->info.vs.desloc; destino_desloc = l_elem->info.vs.desloc;
} }
} ATRIBUICAO expressao_simples { } ATRIBUICAO expressao_simples {
// Gera código ARMZ para armazenar valor // Gera código ARMZ para armazenar valor
char buffer[50]; char buffer[50];
if (atr_indireto == REF) {
sprintf(buffer, "ARMI %d,%d", destino_nivel, destino_desloc);
} else {
sprintf(buffer, "ARMZ %d,%d", destino_nivel, destino_desloc); sprintf(buffer, "ARMZ %d,%d", destino_nivel, destino_desloc);
}
geraCodigo(NULL, buffer); geraCodigo(NULL, buffer);
}; };
...@@ -291,7 +302,6 @@ chamada_procedimento: ...@@ -291,7 +302,6 @@ chamada_procedimento:
lista_parametros lista_parametros
{ {
char buffer[50]; char buffer[50];
mostra_ts(ts); mostra_ts(ts);
desempilha(buffer, proc); desempilha(buffer, proc);
...@@ -317,11 +327,26 @@ lista_parametros: ABRE_PARENTESES ...@@ -317,11 +327,26 @@ lista_parametros: ABRE_PARENTESES
| |
; ;
lista_parametros_parenteses: lista_parametros_parenteses VIRGULA expressao_simples lista_parametros_parenteses: lista_parametros_parenteses VIRGULA
{
char buffer[50];
desempilha(buffer,proc);
l_elem = busca(buffer,ts);
val_ou_ref = l_elem->info.pr.param[num_param][1];
empilha(buffer,proc);
}
expressao_simples
{ {
num_param++; // Incrementa para cada parâmetro real num_param++; // Incrementa para cada parâmetro real
} }
| expressao_simples | {
char buffer[50];
desempilha(buffer,proc);
l_elem = busca(buffer,ts);
val_ou_ref = l_elem->info.pr.param[num_param][1];
empilha(buffer,proc);
}
expressao_simples
{ {
num_param++; // Conta o primeiro parâmetro real num_param++; // Conta o primeiro parâmetro real
} }
...@@ -400,8 +425,17 @@ fator: IDENT { ...@@ -400,8 +425,17 @@ fator: IDENT {
yyerror("Variável não declarada"); yyerror("Variável não declarada");
} else { } else {
char buffer[50]; char buffer[50];
if (val_ou_ref == REF) {
sprintf(buffer, "CREN %d,%d", l_elem->nivel, l_elem->info.vs.desloc);
}
else if (l_elem->categ == PF && l_elem->info.pf.passagem == REF) {
sprintf(buffer, "CRVI %d,%d", l_elem->nivel, l_elem->info.vs.desloc);
}
else {
sprintf(buffer, "CRVL %d,%d", l_elem->nivel, l_elem->info.vs.desloc); sprintf(buffer, "CRVL %d,%d", l_elem->nivel, l_elem->info.vs.desloc);
}
geraCodigo(NULL, buffer); geraCodigo(NULL, buffer);
val_ou_ref = VLR;
} }
} }
| NUMERO { | NUMERO {
......
...@@ -4,6 +4,7 @@ program proc1 (input, output); ...@@ -4,6 +4,7 @@ program proc1 (input, output);
var z: integer; var z: integer;
begin begin
z := a; z := a;
a := 1;
end; end;
begin begin
x := 8; x := 8;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment