Browse Source

Les tableaux c'est ENFIN bon normalement

Elies Tali 2 years ago
parent
commit
2001f717a6

+ 1
- 2
Fichiers_Tests/progC View File

@@ -1,6 +1,5 @@
1 1
 int main(){
2 2
 	int b[3];
3
-	int a;
4
-	a = b[1];
5 3
 	int * c = &b[2];
4
+	int * f = &b[1];
6 5
 }

+ 7
- 7
Lex_Yacc/as.y View File

@@ -113,7 +113,7 @@ DebutAff : tID {struct symbole_t * symbole  = get_variable($1); symbole->initial
113 113
 DebutAffPointeur : tMUL SuiteAffPointeur {add_operation(READ, $2, $2, 0); $$=$2;};
114 114
 DebutAffPointeur : SuiteAffPointeur {$$=$1;};
115 115
 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;};
116
-SuiteAffPointeur : tID tOCROCH E tCCROCH {struct symbole_t * symbole  = get_variable($1); int addr = push("0_TEMPORARY", 1, symbole->type); add_operation(AFC, 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();};
116
+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();};
117 117
 
118 118
 
119 119
 E : tNB { int addr = push("0_TEMPORARY", 1, integer); add_operation(AFC, addr,$1,0); $$ = addr;};
@@ -134,16 +134,16 @@ E : E tOR E {add_operation(ADD,$1,$1,$3); $$ = $1; pop();} ;
134 134
 E : tMUL E { add_operation(READ, $2, $2, 0); $$=$2;};
135 135
 E : tADDR EBis {add_operation(COPA,$2, $2,0); $$=$2;};
136 136
 E : tADDR ETer {add_operation(COPA,$2, $2,0); $$=$2;};
137
-E : tID  tID { printf("Id\n"); struct symbole_t * symbole  = get_variable($1); int addr = allocate_mem_temp_var(symbole->type.base); add_operation(COP, addr,symbole->adresse,0); $$=addr;};
138
-E : tID tOCROCH E tCCROCH {struct symbole_t * symbole  = get_variable($1); int addr = allocate_mem_temp_var(symbole->type.base); add_operation(AFC, addr,symbole->adresse,0); int addr2 = allocate_mem_temp_var(INT); add_operation(AFC, addr2, taille_types[symbole->type.base],0); add_operation(MUL,$3,addr2,$3); add_operation(ADD,$3,addr,$3); add_operation(READ,$3,$3,0); $$=$3; decrement_temp_var(); decrement_temp_var();};
137
+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;};
138
+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); add_operation(ADD,$3,addr,$3); add_operation(READ,$3,$3,0); $$=$3; pop(); pop();};
139 139
 
140
+EBis : 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); add_operation(ADD,$3,addr,$3); $$=$3; pop(); pop();};
141
+ETer : 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); add_operation(AFCA, addr,symbole->adresse,0); $$=addr;};
140 142
 
141
-EBeforeAddr : tID tOCROCH E tCCROCH {struct symbole_t * symbole  = get_variable($1); int addr = push("0_TEMPORARY", 1, symbole->type); add_operation(AFC, 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); add_operation(READ,$3,$3,0); $$=$3; pop(); pop();};
142
-EBeforeAddr : tID { printf("Id\n"); struct symbole_t * symbole  = get_variable($1); int addr = push("0_TEMPORARY", 1, symbole->type); add_operation(COP, addr,symbole->adresse,0); $$=addr;};
143 143
 
144 144
 
145 145
 //Créer un champ isConst dans la table des symboles
146
-Type : tINT {type_courant.base = INT; type_courant.pointeur_level = 0; type_courant.nb_blocs = 1; printf("Type int\n");} ;
146
+Type : tINT {type_courant.base = INT; type_courant.pointeur_level = 0; type_courant.isTab = 0; type_courant.nb_blocs = 1; printf("Type int\n");} ;
147 147
 Type : Type tMUL {type_courant.pointeur_level++;  printf("Type int *\n");};
148 148
 //SuiteType : tMUL SuiteType {type_courant.pointeur_level++; printf(" * en plus\n");} ; 
149 149
 //SuiteType : ;
@@ -153,7 +153,7 @@ Decl : tCONST Type SuiteDeclConst FinDeclConst;
153 153
 
154 154
 SuiteDecl : tID {push($1, 0, type_courant); printf("Suite Decl\n");};
155 155
 SuiteDecl : tID tEQ E {pop(); int addr = push($1,1, type_courant);};
156
-SuiteDecl : tID tOCROCH tNB tCCROCH {type_courant.pointeur_level++; type_courant.nb_blocs = $3; push($1, 0, type_courant);} ;
156
+SuiteDecl : tID tOCROCH tNB tCCROCH {type_courant.isTab = 1; type_courant.nb_blocs = $3; push($1, 0, type_courant);} ;
157 157
 FinDecl : tPV { printf("Fin Decl\n");};
158 158
 FinDecl : tCOMA SuiteDecl FinDecl ;
159 159
 

+ 1
- 1
Makefile View File

@@ -17,7 +17,7 @@ clean_Lex_Yacc:
17 17
 	@rm -f Lex_Yacc/as.output Lex_Yacc/as.tab.* Lex_Yacc/lex.yy.*
18 18
 
19 19
 build : clean build_Symboles build_Instructions build_Lex_Yacc
20
-	gcc Lex_Yacc/as.tab.o Lex_Yacc/lex.yy.o Tables/Instructions/tab_instruc.o Tables/Symboles/table_symboles.o -ly -o rondoudou_gcc
20
+	gcc Lex_Yacc/as.tab.o Lex_Yacc/lex.yy.o Tables/Instructions/tab_instruc.o Tables/Symboles/table_symboles.o -ll -o rondoudou_gcc
21 21
 
22 22
 build_Symboles: clean_Symboles
23 23
 	gcc -c Tables/Symboles/table_symboles.c -o Tables/Symboles/table_symboles.o

+ 3
- 0
Tables/Instructions/tab_instruc.c View File

@@ -36,6 +36,9 @@ char * get_asm_line_from_op(struct operation_t op){
36 36
 		case (AFC):
37 37
 			sprintf(buffer,"AFC %d %d\n",op.arg1, op.arg2);
38 38
 			break;
39
+		case (AFCA):
40
+			sprintf(buffer,"AFCA %d %d\n",op.arg1, op.arg2);
41
+			break;
39 42
 		case (COPA):
40 43
 			sprintf(buffer,"COPA %d %d\n",op.arg1, op.arg2);
41 44
 			break;

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

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

+ 4
- 4
Tables/Symboles/table_symboles.c View File

@@ -67,9 +67,9 @@ char * type_to_string(struct type_t type) {
67 67
 void print_symbole(struct symbole_t symbole) {
68 68
     char * type = type_to_string(symbole.type);
69 69
     if (symbole.initialized) {
70
-		printf("\t\t{nom:%s, adresse:%ld, type:%s, initialized:OUI, profondeur : %d}\n", symbole.nom, symbole.adresse, type, symbole.profondeur);
70
+		printf("\t\t{nom:%s, adresse:%ld, type:%s, initialized:OUI, profondeur : %d, isTab : %d}\n", symbole.nom, symbole.adresse, type, symbole.profondeur,symbole.type.isTab);
71 71
 	} else {
72
-		printf("\t\t{nom:%s, adresse:%ld, type:%s, initialized:NON, profondeur : %d}\n", symbole.nom, symbole.adresse, type,symbole.profondeur);
72
+		printf("\t\t{nom:%s, adresse:%ld, type:%s, initialized:NON, profondeur : %d, isTab : %d}\n", symbole.nom, symbole.adresse, type,symbole.profondeur,symbole.type.isTab);
73 73
 	}
74 74
     free(type);
75 75
 }
@@ -130,9 +130,9 @@ void print() {
130 130
 	int i;
131 131
 	for (i=0; i < pile->taille; i++) {
132 132
 		if (aux->symbole.initialized) {
133
-			printf("\t\t{nom:%s, adresse:%ld, type:%s, initialized:OUI, profondeur : %d}\n", aux->symbole.nom, aux->symbole.adresse, type_to_string(aux->symbole.type), aux->symbole.profondeur);
133
+			printf("\t\t{nom:%s, adresse:%ld, type:%s, initialized:OUI, profondeur : %d, isTab : %d}\n", aux->symbole.nom, aux->symbole.adresse, type_to_string(aux->symbole.type), aux->symbole.profondeur, aux->symbole.type.isTab);
134 134
 		} else {
135
-			printf("\t\t{nom:%s, adresse:%ld, type:%s, initialized:NON, profondeur : %d}\n", aux->symbole.nom, aux->symbole.adresse, type_to_string(aux->symbole.type), aux->symbole.profondeur);
135
+			printf("\t\t{nom:%s, adresse:%ld, type:%s, initialized:NON, profondeur : %d, isTab : %d}\n", aux->symbole.nom, aux->symbole.adresse, type_to_string(aux->symbole.type), aux->symbole.profondeur, aux->symbole.type.isTab);
136 136
 		}
137 137
 		aux = aux->suivant;
138 138
 	}

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

@@ -51,8 +51,11 @@ struct type_t {
51 51
     enum base_type_t base;
52 52
     //Si la variable est un pointeur, on enregitre son niveau (nombre de *)
53 53
     int pointeur_level;
54
-    //Si il s'agit d'un tableau, on enregistre sa taille (nombre de cases)
54
+    //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 à) 
55 55
 	int nb_blocs;
56
+	//Si c'est un tableau, cette valeur est à 1
57
+	int isTab;
58
+	 
56 59
 };
57 60
 //Constante pour les entiers
58 61
 extern const struct type_t integer;

Loading…
Cancel
Save