Skip to content

Commit f78d828

Browse files
committed
Fix the problem in the CFG
1 parent 3c1172b commit f78d828

2 files changed

Lines changed: 19 additions & 17 deletions

File tree

‎MiniJavaCompiler.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ public static void main(String[] args)
115115
CodeGenerator gen = new CodeGenerator(IRList, labels, fileName);
116116
gen.generateMIPS();
117117

118-
//System.out.println("\n Testing Graph");
119-
//AssemFlowGraph asmFG = new AssemFlowGraph(IRList,labels);
120-
//asmFG.buildCFG();
121-
//asmFG.printGraph();
118+
System.out.println("\n Testing Graph");
119+
AssemFlowGraph asmFG = new AssemFlowGraph(IRList,labels);
120+
asmFG.buildCFG();
121+
asmFG.printGraph();
122122

123123
//Link runtime.asm file
124124
Linker linker = new Linker("linker/runtime.asm", fileName);

‎regalloc/flowgraph/AssemFlowGraph.java‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ public Node buildCFG(){
3131
//if is not the last node
3232
if(i != graph.size()-2){
3333
Node aux = graph.get(i+1);
34-
System.out.println(i);
35-
if(aux==null){
36-
System.out.println("null");
37-
}
3834
n.addNext(aux);
3935
}
4036
}
@@ -48,7 +44,7 @@ public Node buildCFG(){
4844
}
4945
else{
5046
int numLabel = labelNode.get(strAux.get(j));
51-
n.addNext(graph.get(numLabel));
47+
n.addNext(graph.get(numLabel));
5248
}
5349

5450
}
@@ -72,6 +68,10 @@ public void buildNodes(){
7268
//save label and its number
7369
labelNode.put(l.getName(), i);
7470
}
71+
//the label can be in one line but actually represents the next one
72+
else{
73+
labelNode.put(l.getName(),i+1);
74+
}
7575
}
7676

7777
}
@@ -89,7 +89,7 @@ public void buildNodes(){
8989
}
9090
graph.add(n);
9191
}
92-
System.out.println("Graph without flow:");
92+
System.out.println("\nGraph without flow:");
9393
printGraph();
9494
System.out.println();
9595
}
@@ -98,17 +98,19 @@ public void printGraph(){
9898
for (int i = 0; i < graph.size(); i++) {
9999

100100
Node n = graph.get(i);
101-
System.out.print(i+" ");
102-
System.out.println(n.getInstr().toString());
103-
/*List<Node> listN = n.nextNode();
104-
if(listN!=null){
105-
System.out.println("Nexts:");
101+
System.out.print(n.getNum()+ " ");
102+
System.out.println(n.getInstr().toString());
103+
List<Node> listN = n.nextNode();
104+
if(listN.size()!=0){
105+
106+
System.out.println("Nexts:");
106107
for (int j = 0; j < listN.size(); j++) {
107-
System.out.println(listN.get(i).getInstr().toString());
108+
System.out.print(listN.get(j).getNum()+ " ");
109+
System.out.println(listN.get(j).getInstr().toString());
108110

109111
}
110112
}
111-
*/
113+
112114

113115
}
114116

0 commit comments

Comments
 (0)