blob: 61403d8be18b3f14d3f9b62d418e911fd7af0d71 (
plain)
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
|
package codegen;
public class Label {
private static String funDef = "";
private static int labelCounter = 0;
private static int globalVarNum = 0;
private static int functionLabelCounter = 0;
private static int varDefCount = 0;
public static void addFunDef(String s) {
funDef += s;
}
public static String getFunDef() {
return funDef;
}
public static void addGlobalVar() {
globalVarNum++;
}
public static int getGlobalVarNum() {
return globalVarNum;
}
/**
* Create a new basic label. Use this method to define labels for if, while and
* for statemests.
*/
public static String newBasic(String base) {
return base + (labelCounter++);
}
/**
* Create a new label for a function definition.
*/
public static String newFun(String base) {
return base + (functionLabelCounter++);
}
public static String newVar() {
return "tmp" + (varDefCount++);
}
}
|