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
|
package vaporize;
import cs132.vapor.ast.*;
import st.*;
import misc.*;
import java.util.*;
public class SpillEverywhere extends VInstr.VisitorPR<String, String, RuntimeException> {
private VaporProgram vp;
private Kettle kettle;
public SpillEverywhere(VaporProgram vp, ArrayList<String> vapor) {
this.vp = vp;
this.kettle = new Kettle(vapor);
for (VFunction f : this.vp.functions) {
MinimalLogger.severe("Num : " + Arrays.toString(f.vars));
this.kettle.replaceFunctionDeclare(f, 0, 0, 3); // use three registers for "spill everywhere"
for (VInstr s : f.body) {
s.accept("", this);
}
}
MinimalLogger.info(kettle.dump());
}
public String visit(String p, VMemRead n) throws RuntimeException {
MinimalLogger.info(String.format("->%s (%s:%s)",
n.getClass().getSimpleName(),
this.kettle.get(n).trim(),
n.sourcePos.toString()));
return null;
}
public String visit(String p, VMemWrite n) throws RuntimeException {
MinimalLogger.info(String.format("->%s (%s:%s)",
n.getClass().getSimpleName(),
this.kettle.get(n).trim(),
n.sourcePos.toString()));
return null;
}
public String visit(String p, VAssign n) throws RuntimeException {
MinimalLogger.info(String.format("->%s (%s:%s)",
n.getClass().getSimpleName(),
this.kettle.get(n).trim(),
n.sourcePos.toString()));
return null;
}
public String visit(String p, VBranch n) throws RuntimeException {
MinimalLogger.info(String.format("->%s (%s:%s)",
n.getClass().getSimpleName(),
this.kettle.get(n).trim(),
n.sourcePos.toString()));
return null;
}
public String visit(String p, VGoto n) throws RuntimeException {
MinimalLogger.info(String.format("->%s (%s:%s)",
n.getClass().getSimpleName(),
this.kettle.get(n).trim(),
n.sourcePos.toString()));
return null;
}
public String visit(String p, VCall n) throws RuntimeException {
MinimalLogger.info(String.format("->%s (%s:%s)",
n.getClass().getSimpleName(),
this.kettle.get(n).trim(),
n.sourcePos.toString()));
return null;
}
public String visit(String p, VBuiltIn n) throws RuntimeException {
MinimalLogger.info(String.format("->%s (%s:%s)",
n.op.name,
this.kettle.get(n).trim(),
n.sourcePos.toString()));
return null;
}
public String visit(String p, VReturn n) throws RuntimeException {
MinimalLogger.info(String.format("->%s (%s:%s)",
n.getClass().getSimpleName(),
this.kettle.get(n).trim(),
n.sourcePos.toString()));
return null;
}
}
|