aboutsummaryrefslogtreecommitdiff
path: root/src/tpc.y
diff options
context:
space:
mode:
Diffstat (limited to 'src/tpc.y')
-rw-r--r--src/tpc.y20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/tpc.y b/src/tpc.y
index 979e696..fedd193 100644
--- a/src/tpc.y
+++ b/src/tpc.y
@@ -23,6 +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;
27static char fname[64];
26%} 28%}
27 29
28%union { 30%union {
@@ -88,14 +90,14 @@ DeclFoncts:
88; 90;
89DeclFonct: 91DeclFonct:
90 EnTeteFonct { scope = LOCAL; } 92 EnTeteFonct { scope = LOCAL; }
91 Corps { gen_function_end_declaration(); scope = GLOBAL; return_type = VOID_T; } 93 Corps { gen_function_end_declaration(fname,return_type,nb_param); scope = GLOBAL; return_type = VOID_T; }
92; 94;
93EnTeteFonct: 95EnTeteFonct:
94 TYPE IDENT PrologueCont '(' Parametres ')' { return_type = gen_function_declaration($<ident>2, $<type>1, $5); } 96 TYPE IDENT PrologueCont {strcpy(fname,$<ident>2); return_type = gen_function_declaration($<ident>2, $<type>1);} '(' Parametres ')' { nb_param = $<num>6 ; scope = GLOBAL;}
95| VOID IDENT PrologueCont '(' Parametres ')' { return_type = gen_function_declaration($<ident>2, VOID_T, $5); } 97| VOID IDENT PrologueCont {strcpy(fname,$<ident>2); return_type = gen_function_declaration($<ident>2, VOID_T);} '(' Parametres ')' { nb_param = $<num>6 ; scope = GLOBAL; }
96; 98;
97 99
98PrologueCont: {gen_prologue_continue(&bss_done);}; 100PrologueCont: {scope = LOCAL;gen_prologue_continue(&bss_done);};
99 101
100Parametres: 102Parametres:
101 VOID {$$ = 0;} 103 VOID {$$ = 0;}
@@ -106,7 +108,7 @@ ListTypVar:
106| TYPE IDENT { gen_declaration($<ident>2, $<type>1, scope); $<num>$ = 1; } 108| TYPE IDENT { gen_declaration($<ident>2, $<type>1, scope); $<num>$ = 1; }
107; 109;
108Corps: 110Corps:
109 '{' DeclConsts DeclVars SuiteInstr '}' 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 '}'
110; 112;
111SuiteInstr: 113SuiteInstr:
112 SuiteInstr Instr 114 SuiteInstr Instr
@@ -115,8 +117,8 @@ SuiteInstr:
115Instr: 117Instr:
116 Exp ';' 118 Exp ';'
117| ';' 119| ';'
118| RETURN Exp ';' { gen_function_return(return_type, $<type>2); scope = GLOBAL; return_type = VOID_T; } 120| RETURN Exp ';' { gen_function_return(return_type, $<type>2); }
119| RETURN ';' { gen_function_return(return_type, VOID_T); scope = GLOBAL; return_type = VOID_T; } 121| RETURN ';' { gen_function_return(return_type, VOID_T);}
120| READE '(' IDENT ')' ';' { gen_reade($<ident>3); } 122| READE '(' IDENT ')' ';' { gen_reade($<ident>3); }
121| READC '(' IDENT ')' ';' { gen_readc($<ident>3); } 123| READC '(' IDENT ')' ';' { gen_readc($<ident>3); }
122| PRINT '(' Exp ')' ';' { gen_print($<type>3);} 124| PRINT '(' Exp ')' ';' { gen_print($<type>3);}
@@ -166,8 +168,8 @@ F:
166| IDENT '(' Arguments ')' { $$ = gen_function_call($<ident>1,$<num>3); } 168| IDENT '(' Arguments ')' { $$ = gen_function_call($<ident>1,$<num>3); }
167; 169;
168LValue: 170LValue:
169 IDENT { $$ = $1; gen_check($<ident>1, scope); } 171 IDENT { gen_check($<ident>1, scope); }
170| IDENT '[' Exp ']' { $$ = $1; gen_check($<ident>1, scope); } 172| IDENT '[' Exp ']' { gen_check($<ident>1, scope); }
171; 173;
172Arguments: 174Arguments:
173 ListExp 175 ListExp