aboutsummaryrefslogtreecommitdiff
path: root/src/tpc.y
diff options
context:
space:
mode:
authorAdam NAILI2018-06-05 21:05:22 +0200
committerAdam NAILI2018-06-05 21:05:22 +0200
commit56e31e3b8a1a569f42140547ffda5a91ef451b47 (patch)
treeab7412ef90736f1ccc386670b024b48b593f34b0 /src/tpc.y
parenta67cd40065f790383776ec3fffa364f6443f7ee7 (diff)
downloadtpc-compiler-56e31e3b8a1a569f42140547ffda5a91ef451b47.tar.gz
Fix call of call of functions with parameters
Diffstat (limited to 'src/tpc.y')
-rw-r--r--src/tpc.y11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/tpc.y b/src/tpc.y
index fedd193..9878ce7 100644
--- a/src/tpc.y
+++ b/src/tpc.y
@@ -23,7 +23,8 @@ static Type return_type = VOID_T;
23static int bss_done = 0; 23static int bss_done = 0;
24static int num_label = 0; 24static int num_label = 0;
25static int num_if = 0; 25static int num_if = 0;
26static int nb_param = 0; 26static int nb_param[255];
27static int num_scope = -1;
27static char fname[64]; 28static char fname[64];
28%} 29%}
29 30
@@ -90,11 +91,11 @@ DeclFoncts:
90; 91;
91DeclFonct: 92DeclFonct:
92 EnTeteFonct { scope = LOCAL; } 93 EnTeteFonct { scope = LOCAL; }
93 Corps { gen_function_end_declaration(fname,return_type,nb_param); scope = GLOBAL; return_type = VOID_T; } 94 Corps { gen_function_end_declaration(fname,return_type,nb_param[num_scope]); scope = GLOBAL; return_type = VOID_T; num_scope--; loc_clean_table(); }
94; 95;
95EnTeteFonct: 96EnTeteFonct:
96 TYPE IDENT PrologueCont {strcpy(fname,$<ident>2); return_type = gen_function_declaration($<ident>2, $<type>1);} '(' Parametres ')' { nb_param = $<num>6 ; scope = GLOBAL;} 97 TYPE IDENT PrologueCont {strcpy(fname,$<ident>2); return_type = gen_function_declaration($<ident>2, $<type>1);} '(' Parametres ')' { nb_param[++num_scope] = $<num>6 ; scope = GLOBAL;}
97| VOID IDENT PrologueCont {strcpy(fname,$<ident>2); return_type = gen_function_declaration($<ident>2, VOID_T);} '(' Parametres ')' { nb_param = $<num>6 ; scope = GLOBAL; } 98| VOID IDENT PrologueCont {strcpy(fname,$<ident>2); return_type = gen_function_declaration($<ident>2, VOID_T);} '(' Parametres ')' { nb_param[++num_scope] = $<num>6 ; scope = GLOBAL; }
98; 99;
99 100
100PrologueCont: {scope = LOCAL;gen_prologue_continue(&bss_done);}; 101PrologueCont: {scope = LOCAL;gen_prologue_continue(&bss_done);};
@@ -108,7 +109,7 @@ ListTypVar:
108| TYPE IDENT { gen_declaration($<ident>2, $<type>1, scope); $<num>$ = 1; } 109| TYPE IDENT { gen_declaration($<ident>2, $<type>1, scope); $<num>$ = 1; }
109; 110;
110Corps: 111Corps:
111 '{' {int i; for(i=1;i<=nb_param;i++){fprintf(output, "mov r8, [rbp + %d]\nmov [rbp - %d], r8\n", (nb_param-i+2)*8, i*8);} } DeclConsts DeclVars SuiteInstr '}' 112 '{' {int i; for(i=1;i<=nb_param[num_scope];i++){fprintf(output, "mov r8, [rbp + %d]\nmov [rbp - %d], r8\n", (nb_param[num_scope]-i+2)*8, i*8);} } DeclConsts DeclVars SuiteInstr '}'
112; 113;
113SuiteInstr: 114SuiteInstr:
114 SuiteInstr Instr 115 SuiteInstr Instr