Browse Source

Normalement tout bon mais moche

Tali Elies 2 years ago
parent
commit
1ec1d418b7

+ 5
- 6
Documentation/transcription_opcodes.md View File

@@ -60,17 +60,16 @@ Va mettre à l'adresse @X ce qui est à l'addresse contenue à l'adresse @Y (on
60 60
 
61 61
 ## WR @X @Y
62 62
 
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).
63
+Va mettre le contenu de @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_arg addr_ret
66
-
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.
65
+##CALL lig taille_pile_fonction_appelante
68 66
 
67
+Appelle la fonction dont la première ligne est lig et taille_pile_fonction_appelante est la taille de la zone mémoire utilisée par la fonction appelante (avant le push des args !)
69 68
 ##RET
70 69
 
71 70
 Bouge BP et saute à l'adresse de retour (selon les valeur qui sont dans la pile de contrôle).
72 71
 
73
-##COPR @X taille
72
+##STOP
74 73
 
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).
74
+Arrete le processeur (à mettre à la fin de l'ASM)
76 75
 

+ 14
- 4
Fichiers_Tests/progC View File

@@ -1,9 +1,19 @@
1
-int fonction(int * p){ 
2
-	int b =  *p + 2;
1
+int g(int y[]){
2
+    int u;
3
+    y[1] = 2;
4
+    return 15;
5
+}
6
+
7
+
8
+int fonction(int p[]){ 
9
+    g(p);
3 10
 	return 1;
4 11
 }
5 12
 
6 13
 int main(){
7
-	int b = 1;
8
-	fonction(&b);
14
+	int b[2];
15
+	int c = fonction(b);
16
+    c = get();
17
+    b[0] = 25;
18
+    printf(b[0]);
9 19
 }

+ 1
- 0
Lex_Yacc/al.lex View File

@@ -31,6 +31,7 @@ yyerror (char const *s)
31 31
 "&"         { return tADDR;}
32 32
 "["         { return tOCROCH;}
33 33
 "]" 		{ return tCCROCH;}
34
+"get"       { return tGET;}
34 35
 
35 36
 
36 37
 [0-9]+	{ yylval.nombre = atoi(yytext); return tNB; }

+ 1030
- 0
Lex_Yacc/as.dot
File diff suppressed because it is too large
View File


BIN
Lex_Yacc/as.pdf View File


+ 26
- 23
Lex_Yacc/as.y View File

@@ -30,13 +30,13 @@ int nbs_instructions_to_patch[10];
30 30
 %token tMUL tDIV tADD tSUB tEQ
31 31
 %token<nombre> tNB tNBEXP
32 32
 %token<id> tID
33
-%token tPRINTF
33
+%token tPRINTF tGET
34 34
 %token tERROR
35 35
 %token<nombre> tIF tWHILE tELSE
36 36
 %token tRETURN
37 37
 %token tLT tGT tEQCOND
38 38
 %token tAND tOR
39
-%token tADDR
39
+%token tADDR 
40 40
 
41 41
 %left tLT tGT
42 42
 %left tEQCOND
@@ -45,7 +45,7 @@ int nbs_instructions_to_patch[10];
45 45
 %left tADD tSUB
46 46
 %left tMUL tDIV
47 47
 
48
-%type<nombre> E DebutAff SuiteAffPointeur DebutAffPointeur EBis Invocation Args ArgSuite Arg SuiteParams Params
48
+%type<nombre> E DebutAff SuiteAffPointeur DebutAffPointeur EBis Invocation Args ArgSuite Arg SuiteParams Params Get
49 49
 
50 50
 
51 51
 
@@ -57,51 +57,51 @@ int nbs_instructions_to_patch[10];
57 57
 
58 58
 
59 59
 
60
-C : Fonction Fonctions;
60
+C : Fonction Fonctions {add_operation(STOP,0,0,0); create_asm();};
61 61
 
62 62
 Fonctions : Fonction Fonctions;
63 63
 Fonctions : ;
64 64
 
65
-Main : tINT {printf("Déclaration du main\n");} tMAIN tOBRACE Args tCBRACE Body { print(); create_asm();} ; 
65
+Main : tINT {printf("Déclaration du main\n"); create_jump_to_main(get_current_index());} tMAIN tOBRACE Args tCBRACE Body { print(); } ; 
66 66
 
67 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);} ;
68 68
 Fonction : Main {print_fonctions();};
69 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(); };
70
+Get : tGET tOBRACE tCBRACE {int addr = push("0_TEMPORARY", 0, integer); add_operation(GET,addr,0,0); $$ = addr;};
71
+
72
+Return : tRETURN E tPV {add_operation(COP,0,$2,0); pop(); };
71 73
 
72 74
 Args : Arg ArgSuite {$$ = $1 + $2; printf("Les arguments de la fonctions vont avoir une taille dans la pile de : %d\n",$$);};
73 75
 Args : {$$ = 0;};
74 76
 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];}};
75
-Arg : Type tID tOCROCH tCCROCH {int addr = push($2,1, type_courant); $$ = taille_types[INT];};
77
+Arg : Type tID tOCROCH tCCROCH {type_courant.isTab = 2; int addr = push($2,1, type_courant); $$ = taille_types[INT];};
76 78
 ArgSuite : tCOMA Arg ArgSuite {$$ = $2 + $3;} ;
77 79
 ArgSuite : {$$ = 0;}; 
78 80
 
79 81
 
80
-Body : tOBRACKET {inc_prof();} Instructions tCBRACKET {print(); reset_prof();} ;
82
+Body : tOBRACKET {inc_prof();} Instructions tCBRACKET {print(); reset_prof();};
81 83
 
82 84
 
83 85
 Instructions : Instruction Instructions ;
84 86
 Instructions : ;
85 87
 Instruction : Aff {};
86 88
 Instruction : Decl {};
87
-Instruction : Invocation tPV{};
89
+Instruction : Invocation tPV{pop();};
88 90
 Instruction : If {};
89 91
 Instruction : While {};
90 92
 Instruction : Return {};
91 93
 
92 94
 
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
+Invocation : tID tOBRACE {struct fonction_t fonc = get_fonction($1);}
96
+Params tCBRACE {struct fonction_t fonc = get_fonction($1); multiple_pop($4);
97
+add_operation(CALL,fonc.first_instruction_line, get_last_addr(),0); if (fonc.return_type.pointeur_level > 0 || fonc.return_type.isTab){
98
+ $$ = push("0_TEMPORARY_RETURN", 0, integer); 
95 99
 }
96 100
 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;};
101
+$$ = push("0_TEMPORARY_RETURN", 0, fonc.return_type); 
102
+}};
102 103
 
103
-
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?)
104
+Invocation : tPRINTF tOBRACE E tCBRACE{add_operation(PRI,$3,0,0); pop();};
105 105
 
106 106
 Params : {$$ = 0; printf("Sans Params\n"); } ;
107 107
 Params : Param SuiteParams {$$ = $2 + 1;};
@@ -154,7 +154,7 @@ DebutAff : tID {struct symbole_t * symbole  = get_variable($1); symbole->initial
154 154
 DebutAffPointeur : tMUL SuiteAffPointeur {add_operation(READ, $2, $2, 0); $$=$2;};
155 155
 DebutAffPointeur : SuiteAffPointeur {$$=$1;};
156 156
 SuiteAffPointeur : tMUL tID {struct symbole_t * symbole  = get_variable($2); int addr = push("0_TEMPORARY", 1, symbole->type); add_operation(COP, addr,symbole->adresse,0); $$=addr;};
157
-SuiteAffPointeur : tID tOCROCH E tCCROCH {struct symbole_t * symbole  = get_variable($1); int addr = push("0_TEMPORARY", 1, symbole->type); if (symbole->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); add_operation(ADD,$3,addr,$3); $$=$3; pop(); pop();};
157
+SuiteAffPointeur : tID tOCROCH E tCCROCH {struct symbole_t * symbole  = get_variable($1); int addr = push("0_TEMPORARY", 1, symbole->type); if (symbole->type.isTab == 2){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); add_operation(ADD,$3,addr,$3); $$=$3; pop(); pop();};
158 158
 
159 159
 
160 160
 E : tNB { int addr = push("0_TEMPORARY", 1, integer); add_operation(AFC, addr,$1,0); $$ = addr;};
@@ -173,15 +173,18 @@ E : tNOT E { printf("!\n"); };
173 173
 E : E tAND E {add_operation(MUL,$1,$1,$3); $$ = $1; pop();};
174 174
 E : E tOR E {add_operation(ADD,$1,$1,$3); $$ = $1; pop();} ;
175 175
 E : tMUL E { add_operation(READ, $2, $2, 0); $$=$2;};
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;};
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);
178
- add_operation(ADD,$3,addr,$3); add_operation(READ,$3,$3,0); $$=$3; pop(); pop();};
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 == 1){add_operation(AFCA, addr,symbole->adresse,0);} else{add_operation(COP, addr,symbole->adresse,0);} $$=addr;};
177
+
178
+
179
+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.isTab == 2) {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);
180
+add_operation(ADD,$3,addr,$3); add_operation(READ,$3,$3,0); $$=$3; pop(); pop();};
179 181
 E : tADDR EBis {$$=$2;};
182
+E : Get {$$ = $1;};
180 183
 
181 184
 EBis : tID tOCROCH E tCCROCH {struct symbole_t * symbole  = get_variable($1); 
182 185
 struct type_t type = symbole->type; type.nb_blocs = 1; 
183 186
 int addr = push("0_TEMPORARY", 1, type); 
184
-if(type.pointeur_level > 0) {
187
+if(type.isTab == 2) {
185 188
 add_operation(COP, addr,symbole->adresse,0);
186 189
 }
187 190
  else{

+ 2
- 2
Makefile View File

@@ -21,7 +21,7 @@ clean_Lex_Yacc:
21 21
 	@rm -f Lex_Yacc/as.output Lex_Yacc/as.tab.* Lex_Yacc/lex.yy.*
22 22
 
23 23
 build : clean build_Symboles build_Instructions build_Lex_Yacc build_Fonctions
24
-	gcc Lex_Yacc/as.tab.o Lex_Yacc/lex.yy.o Tables/Instructions/tab_instruc.o Tables/Symboles/table_symboles.o Tables/Fonctions/tab_fonctions.o -ll -o rondoudou_gcc
24
+	gcc Lex_Yacc/as.tab.o Lex_Yacc/lex.yy.o Tables/Instructions/tab_instruc.o Tables/Symboles/table_symboles.o Tables/Fonctions/tab_fonctions.o -ly -o rondoudou_gcc
25 25
 
26 26
 build_Symboles: clean_Symboles
27 27
 	gcc -c Tables/Symboles/table_symboles.c -o Tables/Symboles/table_symboles.o
@@ -33,7 +33,7 @@ build_Fonctions : clean_Fonctions
33 33
 	gcc -c Tables/Fonctions/tab_fonctions.c -o Tables/Fonctions/tab_fonctions.o
34 34
 
35 35
 build_Lex_Yacc: clean_Lex_Yacc
36
-	bison -d -t -b Lex_Yacc/as Lex_Yacc/as.y
36
+	bison -g -v -d -t -b Lex_Yacc/as Lex_Yacc/as.y
37 37
 	flex -o Lex_Yacc/lex.yy.c Lex_Yacc/al.lex
38 38
 	gcc -c Lex_Yacc/as.tab.c -o Lex_Yacc/as.tab.o
39 39
 	gcc -c Lex_Yacc/lex.yy.c -o Lex_Yacc/lex.yy.o

BIN
Tables/Fonctions/tab_fonctions.o View File


+ 12
- 8
Tables/Instructions/tab_instruc.c View File

@@ -1,5 +1,5 @@
1 1
 #include "tab_instruc.h"
2
-int current_index = 0;
2
+int current_index = 1;
3 3
 struct operation_t tab_op[MAXTAILLE];
4 4
 
5 5
 void add_operation(enum opcode_t opcode, int arg1, int arg2, int arg3){
@@ -13,6 +13,10 @@ void add_operation(enum opcode_t opcode, int arg1, int arg2, int arg3){
13 13
 	}
14 14
 }
15 15
 
16
+void create_jump_to_main(int line){
17
+    struct operation_t new_op = {JMP,line, 0, 0};
18
+    tab_op[0] = new_op;
19
+}
16 20
 
17 21
 
18 22
 char * get_asm_line_from_op(struct operation_t op){
@@ -39,9 +43,6 @@ char * get_asm_line_from_op(struct operation_t op){
39 43
 		case (AFCA):
40 44
 			sprintf(buffer,"AFCA %d %d\n",op.arg1, op.arg2);
41 45
 			break;
42
-		case (COPA):
43
-			sprintf(buffer,"COPA %d %d\n",op.arg1, op.arg2);
44
-			break;
45 46
 		case (JMP):
46 47
 			sprintf(buffer,"JMP %d\n",op.arg1);
47 48
 			break;
@@ -67,14 +68,17 @@ char * get_asm_line_from_op(struct operation_t op){
67 68
 			sprintf(buffer,"WR %d %d\n",op.arg1, op.arg2);
68 69
 			break;
69 70
 		case (CALL):
70
-			sprintf(buffer,"CALL %d %d %d\n",op.arg1, op.arg2, op.arg3);
71
+			sprintf(buffer,"CALL %d %d\n",op.arg1, op.arg2);
71 72
 			break;
72 73
 		case (RET):
73 74
 			sprintf(buffer,"RET\n");
74 75
 			break;
75
-		case (COPR):
76
-			sprintf(buffer,"COPR %d %d\n",op.arg1, op.arg2);
77
-			break;
76
+        case (GET):
77
+            sprintf(buffer,"GET %d\n",op.arg1);
78
+            break;
79
+        case (STOP):
80
+            sprintf(buffer,"STOP\n");
81
+            break;
78 82
 	}
79 83
 	return buffer;
80 84
 }

+ 3
- 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,RET,COPR};
10
+enum opcode_t {ADD,MUL,SOU,DIV,COP,AFC,AFCA,JMP,JMF,INF,SUP,EQU,PRI,READ,WR,CALL,RET,GET,STOP};
11 11
 
12 12
 struct operation_t {
13 13
 	enum opcode_t opcode;
@@ -24,5 +24,7 @@ int get_current_index();
24 24
 void patch(int index, int arg);
25 25
 //Ecrit la table des intructions dans un fichier ASM
26 26
 void create_asm();
27
+//Crée la ligne assembleur en 1er dans le fichier pour sauter au main
28
+void create_jump_to_main(int line);
27 29
 
28 30
 #endif

+ 1
- 2
Tables/Symboles/table_symboles.h View File

@@ -56,9 +56,8 @@ struct type_t {
56 56
     int pointeur_level;
57 57
     //Si il s'agit d'un tableau, on enregistre sa taille (nombre de cases) (même si c'est une variable on met quand même un nb_blocs à) 
58 58
 	int nb_blocs;
59
-	//Si c'est un tableau, cette valeur est à 1
59
+	//Si c'est un tableau addressale directement, cette valeur est à 1. Si c'est un pointeur vers un tableau, valeur à 2.
60 60
 	int isTab;
61
-	 
62 61
 };
63 62
 
64 63
 //REtourne la représentation d'un type en string

Loading…
Cancel
Save