-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathNode.java
More file actions
133 lines (109 loc) · 3.12 KB
/
Copy pathNode.java
File metadata and controls
133 lines (109 loc) · 3.12 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package regalloc.graph;
import IR.Quadruple;
import java.util.Hashtable;
import java.util.ArrayList;
import java.util.List;
import java.util.BitSet;
import symboltable.Variable;
public class Node {
Quadruple instr;
int num;
List<String> jumpToLabel;
List<Node> next;
boolean jumpToFunction;
boolean exitFunction;
boolean isMove;
public Node (Quadruple IR, int n){
instr = IR;
num=n;
jumpToLabel = new ArrayList<String>();
next = new ArrayList<Node>();
jumpToFunction = false;
exitFunction= false;
isMove = false;
}
//
public void addJumpTo(String name){
jumpToLabel.add(name);
}
public void setJumpToFunction(){
jumpToFunction = true;
}
public boolean getJumpToFunction(){
return jumpToFunction;
}
public void setExitFunction(){
exitFunction = true;
}
public boolean getExitFunction(){
return exitFunction;
}
//can be a label or the next instruction
public List<String> nextLabel(){
return jumpToLabel;
}
public void addNext(Node n){
if(n!=null){
next.add(n);
}
}
public List<Node> nextNode(){
return next;
}
public void setNextNull() {
next.clear();
}
public Quadruple getInstr(){
return instr;
}
public int getNum(){
return num;
}
public void setMove(){
isMove = true;
}
public boolean getMove(){
return isMove;
}
public BitSet calculateDef(List<Variable> listVar) {
BitSet bitDef = new BitSet(listVar.size());
if (instr.getResult() != null) {
if ((instr.getResult()) instanceof Variable) {
for (int i = 0; i < listVar.size(); i++) {
if (listVar.get(i).getName().equals(((Variable) instr.getResult()).getName())) {
bitDef.set(i);
}
}
}
}
return bitDef;
}
public BitSet calculateUse(List<Variable> listVar) {
BitSet bitUse = new BitSet(listVar.size());
if (instr.getArg1() != null) {
if ((instr.getArg1()) instanceof Variable) {
Variable arg1 = (Variable) instr.getArg1();
if (!arg1.getType().equals("constant")) {
for (int i = 0; i < listVar.size(); i++) {
if ( arg1.getName().equals(listVar.get(i).getName())) {
bitUse.set(i);
}
}
}
}
}
if (instr.getArg2() != null) {
if ((instr.getArg2()) instanceof Variable) {
Variable arg2 = (Variable) instr.getArg2();
if (!arg2.getType().equals("constant")) {
for (int i = 0; i < listVar.size(); i++) {
if ( arg2.getName().equals(listVar.get(i).getName())) {
bitUse.set(i);
}
}
}
}
}
return bitUse;
}
}