blob: a93601db73b2974569b75bf41947a3cd92c0de74 (
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
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
|
package spiglet.spiglet2kanga;
import java.util.HashSet;
import java.util.Vector;
public class SpgExpr extends SpgSym {
public enum ExpType { CALL, ALLOC, BinOp, Simple };
/*
* CALL Simp (Tmp Tmp ...)
* HALLOCATE Simp
* BinOP Tmp Simp
* Simp := Tmp | Int | Label
*/
public ExpType type;
public String op;
public SpgTemp oprand;
public SpgSimpExpr se;
public Vector<SpgTemp> callParams;
public SpgExpr(ExpType t) {
type = t;
callParams = new Vector<SpgTemp>();
}
public void addCallParam(SpgTemp t) {
if (type!=ExpType.CALL) {
System.err.println("Error adding parameter, should be a CALL expression.");
return;
}
callParams.addElement(t);
}
public String toString() {
String str;
switch (type) {
case ALLOC:
return "ALLOC " + se.toString();
case BinOp:
return op + " " + oprand.toString() + " " + se.toString();
case CALL:
str = "CALL " + se.toString();
for (int i=0; i<callParams.size(); i++) {
str += " " + callParams.elementAt(i).toString();
}
return str;
case Simple:
return ((SpgSimpExpr)this).toString();
default:
return null;
}
}
public HashSet<SpgTemp> getTmpUsed() {
HashSet<SpgTemp> s = new HashSet<SpgTemp>();
HashSet<SpgTemp> stmp;
switch (type) {
case ALLOC:
return se.getTmpUsed();
case BinOp:
s.add(oprand);
stmp = se.getTmpUsed();
if (stmp!=null) {
s.addAll(se.getTmpUsed());
}
return s;
case CALL:
stmp = se.getTmpUsed();
if (stmp!=null) {
s.addAll(se.getTmpUsed());
}
s.addAll(callParams);
return s;
case Simple:
System.err.println("Should not be here...");
return ((SpgSimpExpr)this).getTmpUsed();
default:
return null;
}
}
}
|