-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYVM.java
214 lines (168 loc) · 4.33 KB
/
YVM.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.Stack;
//import com.modeliosoft.modelio.javadesigner.annotations.objid;
public class YVM {
private PrintWriter p; // objet pour écrire dans un fichier
public Yaka yaka;
private TabIdent tab;
//stocke la numérotation des "faire" et des "si"
private Stack<Integer> etiquetteFaire;
private int nbEtiquette;
private Stack<Integer> etiquetteSi;
private int nbEtiqSi;
//contructeur qui prend en param le nom du fichier dans lequel écrire les instrucions YVM
public YVM(String fileName, TabIdent tab){
try {
this.p = new PrintWriter(new FileOutputStream(fileName));
}catch (FileNotFoundException e) {
System.out.println("erreur: ouverture du fichier " + fileName);
}
this.tab = tab;
this.etiquetteFaire = new Stack<Integer>();
this.nbEtiquette = 0;
this.etiquetteSi = new Stack<Integer>();
this.nbEtiqSi = 0;
}
//entete et queue
public void entete(){
p.println("entete");
}
public void ouvrePrinc(){
p.println("ouvrePrinc " + (this.tab.getIterateurVariable()+2)*-1);
}
public void queue(){
p.println("queue");
p.close();
}
//instructions arithmétiques
public void iadd() {
p.println("iadd");
}
public void isub() {
p.println("isub");
}
public void imul() {
p.println("imul");
}
public void idiv() {
p.println("idiv");
}
public void inot() {
p.println("inot");
}
public void ineg() {
p.println("ineg");
}
public void ior() {
p.println("ior");
}
public void iand() {
p.println("iand");
}
//instructions de comparaisons
public void iinf() {
p.println("iinf");
}
public void isup() {
p.println("isup");
}
public void iinfegal() {
p.println("iinfegal");
}
public void isupegal() {
p.println("isupegal");
}
public void iegal() {
p.println("iegal");
}
public void idiff() {
p.println("idiff");
}
//instructions de stockage et de chargement
public void iload(int i) {
p.println("iload " + i);
}
public void istore(int i) {
p.println("istore " + i);
}
public void ecrireMain(){
p.println("main:");
}
public void iconst(int i) {
p.println("iconst " + i);
}
//instructions de contrôle de flot
public void ifeq(String eti) {
p.println("ifeq " + eti);
}
public void goTo(String eti) {
p.println("goto " + eti);
}
//instructions de pile
public void ouvrePrinc(int i) {
p.println("ouvrePrinc" + i);
}
//entrées sorties
public void ecrireEnt(){
p.println("ecrireEnt");
}
public void ecrireChaine(String s){
p.println("ecrireChaine " + s);
}
public void ecrireBool(){
p.println("ecrireBool");
}
public void lireEnt(int offset){
p.println("lireEnt " + offset);
}
public void aLaLigne(){
p.println("aLaLigne");
}
//itération
public void tantQue(){
this.nbEtiquette++;
this.etiquetteFaire.push(this.nbEtiquette);
p.println("FAIRE" + this.etiquetteFaire.peek() + ":");
}
public void faire(){
p.println("iffaux FAIT" + this.etiquetteFaire.peek());
}
public void fait(){
p.println("goto FAIRE" + this.etiquetteFaire.peek());
p.println("FAIT" + this.etiquetteFaire.pop() + ":");
}
public void si(){
this.nbEtiqSi++;
this.etiquetteSi.push(this.nbEtiqSi);
}
public void alors(){
p.println("iffaux SINON" + this.etiquetteSi.peek());
}
public void sinon(){
p.println("goto FSI" + this.etiquetteSi.peek());
p.println("SINON" + this.etiquetteSi.peek() + ":");
}
public void fsi(){
p.println("FSI" + this.etiquetteSi.pop() + ":");
}
public void ouvreBloc(){
p.println("ouvbloc " + (this.tab.getIterateurVariable()+2)*-1);
}
public void ecrireFonction(String s){
p.println(s+":");
}
public void fermeBloc(){
p.println("fermebloc " + (this.tab.getIterateurParametre()-4));
}
public void ireturn(int i){
p.println("ireturn " + i);
}
public void reserveRetour(){
p.println("reserveRetour");
}
public void call(String n){
p.println("call " + n);
}
}