|
@@ -21,16 +21,24 @@ FILE * file2;
|
21
|
21
|
|
22
|
22
|
%%
|
23
|
23
|
|
|
24
|
+// Un programme est une suite d'au moins une instruction
|
24
|
25
|
Programme : Instruction Programme;
|
25
|
26
|
Programme : Instruction;
|
26
|
27
|
|
27
|
|
-Instruction : tMUL tNB tNB tNB {increment_time();
|
28
|
|
- int added_instruction = 0;
|
29
|
|
- int reg_src1 = get_reg_read($3, &added_instruction);
|
30
|
|
- int reg_src2 = get_reg_read($4, &added_instruction);
|
31
|
|
- int reg_dest = get_reg_write($2, &added_instruction);
|
32
|
|
- add_instruction(MUL, reg_dest, reg_src1, reg_src2);
|
33
|
|
- new_instruction(added_instruction + 1);};
|
|
28
|
+
|
|
29
|
+// Liste de toutes les instructions et conversion
|
|
30
|
+
|
|
31
|
+// MUL, ADD, DIV.... -> 3 arguments
|
|
32
|
+Instruction : tMUL tNB tNB tNB {increment_time(); // On incrémente le temps, c'est a dire, une instruction de plus a été traduite (pour la politique LRU)
|
|
33
|
+ int added_instruction = 0; // On initialise le compteur d'instruction ajoutées (pour la traduction des sauts
|
|
34
|
+ int reg_src1 = get_reg_read($3, &added_instruction); // On demande un registre en lecture pour l'argument B de l'instruction (adresse)
|
|
35
|
+ // On passe l'adresse de la variable added_instruction pour savoir combien d'instruction ont été rajoutées
|
|
36
|
+ int reg_src2 = get_reg_read($4, &added_instruction); // On demande un registre en lecture pour l'argument C de l'instruction (adresse)
|
|
37
|
+ // On passe l'adresse de la variable added_instruction pour savoir combien d'instruction ont été rajoutées
|
|
38
|
+ int reg_dest = get_reg_write($2, &added_instruction); // On demande un registre en écriture pour l'argument A de l'instruction (adresse)
|
|
39
|
+ // On le fait après la demande en lecture TOUJOURS DEMANDER L'ECRITURE APRES LA LECTURE
|
|
40
|
+ add_instruction(MUL, reg_dest, reg_src1, reg_src2); // On ajoute la traduction de l'instruction MUL
|
|
41
|
+ new_instruction(added_instruction + 1);}; // On déclare le nombre d'instruction ajoutées
|
34
|
42
|
Instruction : tADD tNB tNB tNB {increment_time();
|
35
|
43
|
int added_instruction = 0;
|
36
|
44
|
int reg_src1 = get_reg_read($3, &added_instruction);
|
|
@@ -75,75 +83,138 @@ Instruction : tEQU tNB tNB tNB {increment_time();
|
75
|
83
|
new_instruction(added_instruction + 1);};
|
76
|
84
|
|
77
|
85
|
|
78
|
|
-Instruction : tAFC tNB tNB {increment_time();
|
79
|
|
- int added_instruction = 0;
|
80
|
|
- int reg_dest = get_reg_write($2, &added_instruction);
|
81
|
|
- add_instruction(AFC, reg_dest, $3, 0);
|
82
|
|
- new_instruction(added_instruction + 1);};
|
83
|
|
-Instruction : tCPY tNB tNB {increment_time();
|
84
|
|
- int added_instruction = 0;
|
85
|
|
- int reg_src = get_reg_read($3, &added_instruction);
|
86
|
|
- int reg_dest = get_reg_write($2, &added_instruction);
|
87
|
|
- add_instruction(CPY, reg_dest, reg_src, 0);
|
88
|
|
- new_instruction(added_instruction + 1);};
|
89
|
|
-Instruction : tAFCA tNB tNB {increment_time();
|
90
|
|
- int added_instruction = 0;
|
91
|
|
- int reg_aux = get_reg_write(-1, &added_instruction);
|
92
|
|
- add_instruction(AFC, reg_aux, $3, 0);
|
93
|
|
- add_instruction(STOREA, $2, reg_aux, 0);
|
94
|
|
- unlink($2);
|
95
|
|
- new_instruction(added_instruction + 2);};
|
96
|
86
|
|
97
|
87
|
|
98
|
|
-Instruction : tJMP tNB {increment_time();
|
99
|
|
- add_instruction(JMP, $2, 0, 0);
|
100
|
|
- new_instruction(1);};
|
101
|
|
-Instruction : tJMF tNB tNB {increment_time();
|
102
|
|
- int added_instruction = 0;
|
103
|
|
- int reg_src = get_reg_read($2, &added_instruction);
|
104
|
|
- int reg_aux = get_reg_write(-1, &added_instruction);
|
105
|
|
- add_instruction(SUB, reg_aux, reg_aux, reg_src);
|
106
|
|
- add_instruction(JMZ, $3, 0, 0);
|
107
|
|
- new_instruction(added_instruction + 2);};
|
108
|
88
|
|
109
|
|
-Instruction : tREAD tNB tNB {increment_time();
|
110
|
|
- int added_instruction = 0;
|
111
|
|
- int reg_addr = get_reg_read($3, &added_instruction);
|
112
|
|
- int reg_dest = get_reg_write($2, &added_instruction);
|
113
|
|
- add_instruction(LOADI, reg_dest, reg_addr, 0);
|
114
|
|
- new_instruction(added_instruction + 1);};
|
115
|
|
-Instruction : tWR tNB tNB {increment_time();
|
116
|
|
- int added_instruction = 0;
|
117
|
|
- int reg_addr = get_reg_read($2, &added_instruction);
|
118
|
|
- int reg_value = get_reg_read($3, &added_instruction);
|
119
|
|
- add_instruction(STOREI, reg_addr, reg_value, 0);
|
120
|
|
- new_instruction(added_instruction + 1);};
|
121
|
89
|
|
122
|
90
|
|
123
|
|
-Instruction : tGET tNB {increment_time();
|
124
|
|
- int added_instruction = 0;
|
125
|
|
- int reg_dest = get_reg_write($2, &added_instruction);
|
126
|
|
- add_instruction(GET, reg_dest, 0, 0);
|
127
|
|
- new_instruction(added_instruction + 1);};
|
128
|
|
-Instruction : tPRI tNB {increment_time();
|
129
|
|
- int added_instruction = 0;
|
130
|
|
- int reg_src = get_reg_read($2, &added_instruction);
|
131
|
|
- add_instruction(PRI, reg_src, 0, 0);
|
132
|
|
- new_instruction(added_instruction + 1);};
|
133
|
91
|
|
134
|
92
|
|
135
|
|
-Instruction : tCALL tNB tNB {increment_time();
|
136
|
|
- int added_instruction = flush_and_init(file);
|
137
|
|
- add_instruction(CALL, $2, $3, 0);
|
138
|
|
- new_instruction(added_instruction + 1);};
|
139
|
|
-Instruction : tRET {increment_time();
|
140
|
|
- int added_instruction = flush_and_init(file);
|
141
|
|
- add_instruction(RET, 0, 0, 0);
|
142
|
|
- new_instruction(added_instruction + 1);};
|
143
|
93
|
|
144
|
|
-Instruction : tSTOP tNB {increment_time();
|
145
|
|
- add_instruction(STOP, $2, 0, 0);
|
146
|
|
- new_instruction(1);};
|
|
94
|
+// AFC @ val -> AFC Ri val
|
|
95
|
+Instruction : tAFC tNB tNB {increment_time(); // On incrémente le temps, c'est a dire, une instruction de plus a été traduite (pour la politique LRU)
|
|
96
|
+ int added_instruction = 0; // On initialise le compteur d'instruction ajoutées (pour la traduction des sauts
|
|
97
|
+ int reg_dest = get_reg_write($2, &added_instruction); // On demande un registre en écriture pour l'argument A de l'instruction (adresse)
|
|
98
|
+ add_instruction(AFC, reg_dest, $3, 0); // On ajoute la traduction de l'instruction AFC
|
|
99
|
+ new_instruction(added_instruction + 1);}; // On déclare le nombre d'instruction ajoutées
|
|
100
|
+// CPY @ @ -> CPY Ri Rj
|
|
101
|
+Instruction : tCPY tNB tNB {increment_time(); // On incrémente le temps, c'est a dire, une instruction de plus a été traduite (pour la politique LRU)
|
|
102
|
+ int added_instruction = 0; // On initialise le compteur d'instruction ajoutées (pour la traduction des sauts
|
|
103
|
+ int reg_src = get_reg_read($3, &added_instruction); // On demande un registre en lecture pour l'argument B de l'instruction (adresse)
|
|
104
|
+ // On passe l'adresse de la variable added_instruction pour savoir combien d'instruction ont été rajoutées
|
|
105
|
+ int reg_dest = get_reg_write($2, &added_instruction); // On demande un registre en écriture pour l'argument A de l'instruction (adresse)
|
|
106
|
+ // On le fait après la demande en lecture TOUJOURS DEMANDER L'ECRITURE APRES LA LECTURE
|
|
107
|
+ add_instruction(CPY, reg_dest, reg_src, 0); // On ajoute la traduction de l'instruction CPY
|
|
108
|
+ new_instruction(added_instruction + 1);}; // On déclare le nombre d'instruction ajoutées
|
|
109
|
+// AFCA @ val -> AFC Rlamda val; STOREA @ Rlamda
|
|
110
|
+Instruction : tAFCA tNB tNB {increment_time(); // On incrémente le temps, c'est a dire, une instruction de plus a été traduite (pour la politique LRU)
|
|
111
|
+ int added_instruction = 0; // On initialise le compteur d'instruction ajoutées (pour la traduction des sauts
|
|
112
|
+ int reg_aux = get_reg_write(-1, &added_instruction); // On demande un registre en écriture
|
|
113
|
+ // On ne veut pas un registre associé a une adresse, juste un buffer d'où le -1
|
|
114
|
+ add_instruction(AFC, reg_aux, $3, 0); // On affecte la valeur dans un registre lamda, elle sera tout de suite enregistré en mémoire
|
|
115
|
+ add_instruction(STOREA, $2, reg_aux, 0); // On store la valeur en mémoire (avec un STOREA car AFCA, nous sommes donc obligé de le faire tout de suite)
|
|
116
|
+ unlink($2); // On casse l'eventuel lien entre l'adresse et un registre
|
|
117
|
+ // Si un registre était déjà associé a cette adresse, la valeur qu'il contient est obsolète, on le libère
|
|
118
|
+ new_instruction(added_instruction + 2);}; // On déclare le nombre d'instruction ajoutées
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+// JMP Ins -> JMP Ins
|
|
129
|
+Instruction : tJMP tNB {increment_time(); // On incrémente le temps, c'est a dire, une instruction de plus a été traduite (pour la politique LRU)
|
|
130
|
+ add_instruction(JMP, $2, 0, 0); // On traduit le JMP sans rien changer
|
|
131
|
+ new_instruction(1);}; // On déclare le nombre d'instruction ajoutées
|
|
132
|
+// JMF @ Ins -> AFC Rlamda 0; SUB Rlamda Rlamda Ri; JMZ Ins
|
|
133
|
+Instruction : tJMF tNB tNB {increment_time(); // On incrémente le temps, c'est a dire, une instruction de plus a été traduite (pour la politique LRU)
|
|
134
|
+ int added_instruction = 0; // On initialise le compteur d'instruction ajoutées (pour la traduction des sauts
|
|
135
|
+ int reg_src = get_reg_read($2, &added_instruction); // On demande un registre en lecture pour l'argument A de l'instruction (adresse)
|
|
136
|
+ int reg_aux = get_reg_write(-1, &added_instruction); // On demande un registre en écriture
|
|
137
|
+ // On ne veut pas un registre associé a une adresse, juste un buffer d'où le -1
|
|
138
|
+ add_instrcution(AFC, reg_aux, 0, 0); // On affecte 0 à un registre
|
|
139
|
+ add_instruction(SUB, reg_aux, reg_aux, reg_src); // On Soustrait la valeur à 0, flag 0 levé si la valeur vallait 0 donc condition fausse
|
|
140
|
+ add_instruction(JMZ, $3, 0, 0); // On ajoute le JMZ
|
|
141
|
+ new_instruction(added_instruction + 3);}; // On déclare le nombre d'instruction ajoutées
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+// READ @1 @2 -> LOADI @1 @2
|
|
152
|
+Instruction : tREAD tNB tNB {increment_time(); // On incrémente le temps, c'est a dire, une instruction de plus a été traduite (pour la politique LRU)
|
|
153
|
+ int added_instruction = 0; // On initialise le compteur d'instruction ajoutées (pour la traduction des sauts
|
|
154
|
+ int reg_addr = get_reg_read($3, &added_instruction); // On demande un registre en lecture pour l'adresse de la lecture en mémore
|
|
155
|
+ int reg_dest = get_reg_write($2, &added_instruction); // On demande un registre en écriture pour loader la valeur depuis la mémoire
|
|
156
|
+ add_instruction(LOADI, reg_dest, reg_addr, 0); // On traduit le READ
|
|
157
|
+ new_instruction(added_instruction + 1);}; // On déclare le nombre d'instruction ajoutées
|
|
158
|
+// WR @1 @2 -> STOREI @1 @2
|
|
159
|
+Instruction : tWR tNB tNB {increment_time(); // On incrémente le temps, c'est a dire, une instruction de plus a été traduite (pour la politique LRU)
|
|
160
|
+ int added_instruction = 0; // On initialise le compteur d'instruction ajoutées (pour la traduction des sauts
|
|
161
|
+ int reg_addr = get_reg_read($2, &added_instruction); // On demande un registre en lecture pour l'adresse de l'écriture en mémore
|
|
162
|
+ int reg_value = get_reg_read($3, &added_instruction); // On demande un registre en lecture pour la valeur à écrire en mémoire
|
|
163
|
+ add_instruction(STOREI, reg_addr, reg_value, 0); // On traduit le WR
|
|
164
|
+ new_instruction(added_instruction + 1);}; // On déclare le nombre d'instruction ajoutées
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+// GET @ -> GET Ri
|
|
175
|
+Instruction : tGET tNB {increment_time(); // On incrémente le temps, c'est a dire, une instruction de plus a été traduite (pour la politique LRU)
|
|
176
|
+ int added_instruction = 0; // On initialise le compteur d'instruction ajoutées (pour la traduction des sauts
|
|
177
|
+ int reg_dest = get_reg_write($2, &added_instruction); // On demande un registre en ecriture pour écrire la valeur lue
|
|
178
|
+ add_instruction(GET, reg_dest, 0, 0); // On traduit le GET
|
|
179
|
+ new_instruction(added_instruction + 1);}; // On déclare le nombre d'instruction ajoutées
|
|
180
|
+// PRI @ -> PRI Ri
|
|
181
|
+Instruction : tPRI tNB {increment_time(); // On incrémente le temps, c'est a dire, une instruction de plus a été traduite (pour la politique LRU)
|
|
182
|
+ int added_instruction = 0; // On initialise le compteur d'instruction ajoutées (pour la traduction des sauts
|
|
183
|
+ int reg_src = get_reg_read($2, &added_instruction); // On demande un registre en lecture pour sortir la valeur à afficher
|
|
184
|
+ add_instruction(PRI, reg_src, 0, 0); // On traduit le PRI
|
|
185
|
+ new_instruction(added_instruction + 1);}; // On déclare le nombre d'instruction ajoutées
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+// CALL Ins Val -> CALL Ins Val
|
|
196
|
+Instruction : tCALL tNB tNB {increment_time(); // On incrémente le temps, c'est a dire, une instruction de plus a été traduite (pour la politique LRU)
|
|
197
|
+ int added_instruction = flush_and_init(file); // On Store tous les registre en mémoire et réinitialise les correspondances
|
|
198
|
+ add_instruction(CALL, $2, $3, 0); // On traduit le CALL
|
|
199
|
+ new_instruction(added_instruction + 1);}; // On déclare le nombre d'instruction ajoutées
|
|
200
|
+// RET -> RET
|
|
201
|
+Instruction : tRET {increment_time(); // On incrémente le temps, c'est a dire, une instruction de plus a été traduite (pour la politique LRU)
|
|
202
|
+ int added_instruction = flush_and_init(file); // On Store tous les registre en mémoire et réinitialise les correspondances
|
|
203
|
+ add_instruction(RET, 0, 0, 0); // On traduit le RET
|
|
204
|
+ new_instruction(added_instruction + 1);}; // On déclare le nombre d'instruction ajoutées
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+// STOP Val -> STOP -> Val
|
|
215
|
+Instruction : tSTOP tNB {increment_time(); // On incrémente le temps, c'est a dire, une instruction de plus a été traduite (pour la politique LRU)
|
|
216
|
+ add_instruction(STOP, $2, 0, 0); // On traduit le STOP
|
|
217
|
+ new_instruction(1);}; // On déclare le nombre d'instruction ajoutées
|
147
|
218
|
|
148
|
219
|
%%
|
149
|
220
|
|