@@ -14,7 +14,7 @@ public class CompiledFunction {
1414
1515 public BasicBlock entry ;
1616 public BasicBlock exit ;
17- private int bid = 0 ;
17+ private int BID = 0 ;
1818 public BasicBlock currentBlock ;
1919 private BasicBlock currentBreakTarget ;
2020 private BasicBlock currentContinueTarget ;
@@ -41,7 +41,7 @@ public CompiledFunction(Symbol.FunctionTypeSymbol functionSymbol) {
4141 this .functionType = (Type .TypeFunction ) functionSymbol .type ;
4242 this .registerPool = new RegisterPool ();
4343 setVirtualRegisters (funcDecl .scope );
44- this .bid = 0 ;
44+ this .BID = 0 ;
4545 this .entry = this .currentBlock = createBlock ();
4646 this .exit = createBlock ();
4747 this .currentBreakTarget = null ;
@@ -55,7 +55,7 @@ public CompiledFunction(Symbol.FunctionTypeSymbol functionSymbol) {
5555 public CompiledFunction (Type .TypeFunction functionType ) {
5656 this .functionType = (Type .TypeFunction ) functionType ;
5757 this .registerPool = new RegisterPool ();
58- this .bid = 0 ;
58+ this .BID = 0 ;
5959 this .entry = this .currentBlock = createBlock ();
6060 this .exit = createBlock ();
6161 this .currentBreakTarget = null ;
@@ -99,11 +99,11 @@ private void setVirtualRegisters(Scope scope) {
9999 }
100100
101101 public BasicBlock createBlock () {
102- return new BasicBlock (bid ++);
102+ return new BasicBlock (BID ++);
103103 }
104104
105105 private BasicBlock createLoopHead () {
106- return new BasicBlock (bid ++, true );
106+ return new BasicBlock (BID ++, true );
107107 }
108108
109109 private void compileBlock (AST .BlockStmt block ) {
@@ -574,4 +574,19 @@ public void livenessAnalysis() {
574574 public List <BasicBlock > getBlocks () {
575575 return BBHelper .findAllBlocks (entry );
576576 }
577+
578+ public StringBuilder toDot (StringBuilder sb , boolean verbose ) {
579+ sb .append ("digraph CompiledFunction {\n " );
580+ List <BasicBlock > blocks = getBlocks ();
581+ for (BasicBlock block : blocks ) {
582+ sb .append ("L" ).append (block .bid ).append (" [shape=none, margin=0, label=<" );
583+ block .toDot (sb , verbose );
584+ sb .append (">];\n " );
585+ for (BasicBlock s : block .successors ) {
586+ sb .append ("L" ).append (block .bid ).append (" -> " ).append ("L" ).append (s .bid ).append ("\n " );
587+ }
588+ }
589+ sb .append ("}\n " );
590+ return sb ;
591+ }
577592}
0 commit comments