blob: 41f2c9c567f0f6a1549e1e38e148b80722f3e902 (
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
|
package cfg;
import misc.*;
import cs132.vapor.ast.*;
import java.util.*;
public class CFGNode {
private Node instruction;
private ArrayList<CFGNode> sources;
private ArrayList<CFGNode> dests;
public Set<String> defs;
public Set<String> reaching;
public Set<String> liveness;
public CFGNode(Node instruction) {
this.instruction = instruction;
this.sources = new ArrayList<>();
this.dests = new ArrayList<>();
this.defs = new HashSet<>();
this.reaching = new HashSet<>();
this.liveness = new HashSet<>();
}
@Override public String toString() {
return String.format("L%d",
this.instruction.sourcePos.line);
}
/**
* For if we only have a line
* number. (VBranch issues)
*/
public boolean equals(Object other) {
return (other instanceof CFGNode &&
(((CFGNode) other).instruction ==
this.instruction)) ||
(other instanceof Node &&
(((Node) other).sourcePos ==
this.instruction.sourcePos)) ||
(other instanceof Integer &&
(((Integer) other)
.equals(this.instruction.sourcePos.line)));
}
protected void addSource(CFGNode node) {
this.sources.add(node);
}
protected void addDest(CFGNode node) {
this.dests.add(node);
}
public Node getInstruction() {
return this.instruction;
}
public List<CFGNode> getSources() {
return Collections.unmodifiableList(this.sources);
}
public List<CFGNode> getDests() {
return Collections.unmodifiableList(this.dests);
}
public Set<String> getReaching() {
return Collections.unmodifiableSet(this.reaching);
}
public Set<String> getLiveness() {
return Collections.unmodifiableSet(this.liveness);
}
public Set<String> getDefinitions() {
return Collections.unmodifiableSet(this.defs);
}
}
|