Browse Source

Fonctions ok mais pas forcement juste faut tester

Elies Tali 2 years ago
parent
commit
24b08129bb

+ 10
- 2
Documentation/transcription_opcodes.md View File

@@ -62,7 +62,15 @@ Va mettre à l'adresse @X ce qui est à l'addresse contenue à l'adresse @Y (on
62 62
 
63 63
 Va mettre le contenue dans @Y dans l'adresse qui est la valeur dans @X (on considère que @X est un pointeur et on écrit dans l'adresse qui est contenue dans @X). Attention, considérer des addresses globales (pas relatives).
64 64
 
65
-##CALL lig taille
65
+##CALL lig taille_arg addr_ret
66 66
 
67
-Appelle la fonction dont la première ligne est lig est dont la taille des arguments est en @Y (afin de pouvoir bouger ebp).
67
+Appelle la fonction dont la première ligne est lig est dont la taille des arguments en 2ème (pour bouger BP) et en trois l'addresse de retour.
68
+
69
+##RET
70
+
71
+Bouge BP et saute à l'adresse de retour (selon les valeur qui sont dans la pile de contrôle).
72
+
73
+##COPR @X taille
74
+
75
+Va copier dans l'emplacement réservé à la valeur de retour la valeur contenue dans @X (on copie à l'addresse BP - taille en gros car on a reservé en avance cet emplacement mémoire).
68 76
 

+ 3
- 4
Fichiers_Tests/progC View File

@@ -1,10 +1,9 @@
1
-
2 1
 int fonction(int * p){ 
3 2
 	int b =  *p + 2;
3
+	return 1;
4 4
 }
5 5
 
6 6
 int main(){
7
-	int a = 255;
8
-	fonction(&a);
7
+	int b = 1;
8
+	fonction(&b);
9 9
 }
10
-

+ 1
- 1
Lex_Yacc/al.lex View File

@@ -4,7 +4,6 @@ int yywrap(void){return 1;}
4 4
 void
5 5
 yyerror (char const *s)
6 6
 {
7
-
8 7
   fprintf (stderr, "%s\n", s);
9 8
 }
10 9
 
@@ -22,6 +21,7 @@ yyerror (char const *s)
22 21
 "printf"    { return tPRINTF; } //Degeu mais à degager
23 22
 "if"        { return tIF; }
24 23
 "while"     { return tWHILE; }
24
+"return"    {return tRETURN; }
25 25
 "<"         { return tLT; }
26 26
 ">"         { return tGT; }
27 27
 "=="        { return tEQCOND; }

+ 18
- 5
Lex_Yacc/as.y View File

@@ -14,6 +14,7 @@
14 14
 struct type_t type_courant;
15 15
 struct type_t return_type_fonc;
16 16
 
17
+
17 18
 int instructions_ligne_to_patch[10][20];
18 19
 int nbs_instructions_to_patch[10];
19 20
 
@@ -21,7 +22,7 @@ int nbs_instructions_to_patch[10];
21 22
 
22 23
 %token tMAIN
23 24
 %token tOBRACKET tCBRACKET
24
-%token tOBRACE tCBRACE
25
+%token<nombre> tOBRACE tCBRACE
25 26
 %token tOCROCH tCCROCH
26 27
 %token tINT
27 28
 %token tCONST
@@ -32,6 +33,7 @@ int nbs_instructions_to_patch[10];
32 33
 %token tPRINTF
33 34
 %token tERROR
34 35
 %token<nombre> tIF tWHILE tELSE
36
+%token tRETURN
35 37
 %token tLT tGT tEQCOND
36 38
 %token tAND tOR
37 39
 %token tADDR
@@ -62,9 +64,11 @@ Fonctions : ;
62 64
 
63 65
 Main : tINT {printf("Déclaration du main\n");} tMAIN tOBRACE Args tCBRACE Body { print(); create_asm();} ; 
64 66
 
65
-Fonction : Type tID {return_type_fonc = type_courant; printf("Déclaration de la fonction  %s\n", $2);} tOBRACE {inc_prof();} Args {decrement_prof(); push_fonction($2,return_type_fonc,get_current_index(), $6);} tCBRACE Body { print_fonctions();} ;
67
+Fonction : Type tID {return_type_fonc = type_courant; printf("Déclaration de la fonction  %s\n", $2);} tOBRACE {inc_prof();} Args {decrement_prof(); push_fonction($2,return_type_fonc,get_current_index(), $6);} tCBRACE Body { print_fonctions(); add_operation(RET,0,0,0);} ;
66 68
 Fonction : Main {print_fonctions();};
67 69
 
70
+Return : tRETURN E tPV {if (return_type_fonc.pointeur_level > 0 || return_type_fonc.isTab){add_operation(COPR,$2, taille_types[INT],0);} else {add_operation(COPR,$2,taille_types[return_type_fonc.base],0);} pop(); };
71
+
68 72
 Args : Arg ArgSuite {$$ = $1 + $2; printf("Les arguments de la fonctions vont avoir une taille dans la pile de : %d\n",$$);};
69 73
 Args : {$$ = 0;};
70 74
 Arg : Type tID {int addr = push($2,1, type_courant); if (type_courant.pointeur_level > 0){$$ = taille_types[INT];} else{$$ = taille_types[type_courant.base];}};
@@ -83,9 +87,18 @@ Instruction : Decl {};
83 87
 Instruction : Invocation tPV{};
84 88
 Instruction : If {};
85 89
 Instruction : While {};
90
+Instruction : Return {};
86 91
 
87 92
 
88
-Invocation : tID tOBRACE Params tCBRACE {multiple_pop($3); struct fonction_t fonc = get_fonction($1); add_operation(CALL,fonc.first_instruction_line, fonc.taille_args,0);};
93
+Invocation : tID tOBRACE {struct fonction_t fonc = get_fonction($1); if (fonc.return_type.pointeur_level > 0 || fonc.return_type.isTab){
94
+ $2 = push("0_TEMPORARY_RETURN", 0, integer); 
95
+}
96
+else{
97
+$2 = push("0_TEMPORARY_RETURN", 0, fonc.return_type); 
98
+}}
99
+
100
+Params tCBRACE {struct fonction_t fonc = get_fonction($1); multiple_pop($4);
101
+add_operation(CALL,fonc.first_instruction_line, fonc.taille_args,get_current_index() + 1); $$ = $2;};
89 102
 
90 103
 
91 104
 //Pour les tableaux quand on les passe en arguments, il faudra faire gaffe à bien les passer comme un pointeur vers un tableau et pas juste un tableau car sinon in ne pourra pas accéder au tableau de base depuis la fonction appellée. Il faut pour cela peut être rajouter un nouveau champ (isArg) dans la table des symboles (ou autre idée?)
@@ -150,7 +163,7 @@ E : E tMUL E { printf("Mul\n"); add_operation(MUL,$1,$1,$3); $$ = $1; pop();};
150 163
 E : E tDIV E { printf("Div\n");  add_operation(DIV, $1,$1,$3); $$ = $1; pop();};
151 164
 E : E tSUB E { printf("Sub\n"); add_operation(SOU,$1,$1,$3); $$ = $1; pop();};
152 165
 E : E tADD E { printf("Add\n"); add_operation(ADD,$1,$1,$3); $$ = $1; pop();};
153
-E : Invocation { printf("Invoc\n"); int addr = push("0_TEMPORARY", 1, integer); add_operation(AFC, addr,$1,0); $$ = addr;};
166
+E : Invocation {$$ = $1;};
154 167
 E : tOBRACE E tCBRACE { printf("Parentheses\n"); $$=$2;};
155 168
 E : tSUB E { printf("Moins\n");  int addr = push("0_TEMPORARY", 1, integer);  add_operation(AFC, addr,0,0); add_operation(SOU, $2,$2,addr);  $$ = $2; pop();};
156 169
 E : E tEQCOND E { printf("==\n"); add_operation(EQU,$1,$1,$3); $$ = $1; pop();};
@@ -163,7 +176,7 @@ E : tMUL E { add_operation(READ, $2, $2, 0); $$=$2;};
163 176
 E : tID { printf("Id\n"); struct symbole_t * symbole  = get_variable($1); struct type_t type = symbole->type; type.nb_blocs = 1; int addr = push("0_TEMPORARY", 1, type); if (symbole->type.isTab){add_operation(AFCA, addr,symbole->adresse,0); } else{add_operation(COP, addr,symbole->adresse,0);} $$=addr;};
164 177
 E : tID tOCROCH E tCCROCH {struct symbole_t * symbole  = get_variable($1); struct type_t type = symbole->type; type.nb_blocs = 1; int addr = push("0_TEMPORARY", 1, type); if(type.pointeur_level > 0) {add_operation(COP, addr,symbole->adresse,0);} else{add_operation(AFCA, addr,symbole->adresse,0);} int addr2 = push("0_TEMPORARY", 1, integer); add_operation(AFC, addr2, taille_types[symbole->type.base],0); add_operation(MUL,$3,addr2,$3);
165 178
  add_operation(ADD,$3,addr,$3); add_operation(READ,$3,$3,0); $$=$3; pop(); pop();};
166
-E : tADDR EBis {add_operation(COPA,$2, $2,0); $$=$2;};
179
+E : tADDR EBis {$$=$2;};
167 180
 
168 181
 EBis : tID tOCROCH E tCCROCH {struct symbole_t * symbole  = get_variable($1); 
169 182
 struct type_t type = symbole->type; type.nb_blocs = 1; 

+ 1
- 1
Makefile View File

@@ -64,6 +64,6 @@ edit_Progs:
64 64
 	pluma Fichiers_Tests/progC &
65 65
 
66 66
 edit_Fonctions :
67
-	pluma Tables/Fonctions/tab_fonctions.c Tables/Fonctions/tab_fonctions.h
67
+	pluma Tables/Fonctions/tab_fonctions.c Tables/Fonctions/tab_fonctions.h &
68 68
 
69 69
 edit: edit_Lex_Yacc edit_Symboles edit_Instructions edit_Progs edit_Fonctions

+ 7
- 1
Tables/Instructions/tab_instruc.c View File

@@ -67,7 +67,13 @@ char * get_asm_line_from_op(struct operation_t op){
67 67
 			sprintf(buffer,"WR %d %d\n",op.arg1, op.arg2);
68 68
 			break;
69 69
 		case (CALL):
70
-			sprintf(buffer,"CALL %d %d\n",op.arg1, op.arg2);
70
+			sprintf(buffer,"CALL %d %d %d\n",op.arg1, op.arg2, op.arg3);
71
+			break;
72
+		case (RET):
73
+			sprintf(buffer,"RET\n");
74
+			break;
75
+		case (COPR):
76
+			sprintf(buffer,"COPR %d %d\n",op.arg1, op.arg2);
71 77
 			break;
72 78
 	}
73 79
 	return buffer;

+ 1
- 1
Tables/Instructions/tab_instruc.h View File

@@ -7,7 +7,7 @@
7 7
 #include <stdio.h>
8 8
 
9 9
 
10
-enum opcode_t {ADD,MUL,SOU,DIV,COP,AFC,AFCA,COPA,JMP,JMF,INF,SUP,EQU,PRI,READ,WR,CALL};
10
+enum opcode_t {ADD,MUL,SOU,DIV,COP,AFC,AFCA,COPA,JMP,JMF,INF,SUP,EQU,PRI,READ,WR,CALL,RET,COPR};
11 11
 
12 12
 struct operation_t {
13 13
 	enum opcode_t opcode;

Loading…
Cancel
Save