blob: aefcd28c803657564051cf72b1aef14e49bd39aa (
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
85
86
87
88
89
90
91
92
93
94
|
package vaporize.library;
import misc.*;
import cs132.vapor.ast.*;
import java.util.ArrayList;
import java.util.HashSet;
class CFGNode {
private Node instruction;
private ArrayList<CFGNode> sources;
private ArrayList<CFGNode> dests;
private HashSet<String> reaching;
private ArrayList<String> liveness;
private int line;
protected CFGNode(Node instruction) {
this.instruction = instruction;
this.sources = new ArrayList<>();
this.dests = new ArrayList<>();
this.reaching = new HashSet<>();
this.line = this.instruction.sourcePos.line;
}
public String toString() {
return this.instruction.toString();
}
/**
* For if we only have a line
* number. (VBranch issues)
*/
// FIXME
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);
}
protected void addReaching(String add) {
MinimalLogger.info(String.format("Def %s at %s",
add,
this.line));
this.reaching.add(add);
}
protected void addLive(String add) {
MinimalLogger.info(String.format("Use %s at %s",
add,
this.line));
this.liveness.add(add);
}
protected Node getInstruction() {
return this.instruction;
}
protected ArrayList<CFGNode> getSources() {
return this.sources;
}
protected ArrayList<CFGNode> getDests() {
return this.dests;
}
protected HashSet<String> getReaching() {
return this.reaching;
}
protected HashSet<String> getLiveness() {
return this.liveness;
}
protected int getLine() {
return this.line;
}
}
|