-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Generate CFG from linear IR blocks - Insert block labels for visualization - Override BasicBlock's compareTo for deterministic order - Render sample CFG in README
- Loading branch information
Showing
11 changed files
with
122 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 25 additions & 2 deletions
27
ep20/src/main/java/org/teachfx/antlr4/ep20/pass/cfg/CFGBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,34 @@ | ||
package org.teachfx.antlr4.ep20.pass.cfg; | ||
|
||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.teachfx.antlr4.ep20.ir.IRNode; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class CFGBuilder<I extends IRNode> { | ||
public CFGBuilder(BasicBlock<IRNode> startNode){ | ||
public class CFGBuilder { | ||
private CFG<IRNode> cfg; | ||
private List<BasicBlock<IRNode>> basicBlocks; | ||
private List<Pair<Integer,Integer>> edges; | ||
public CFGBuilder(List<LinearIRBlock> blockList){ | ||
basicBlocks =new ArrayList<>(); | ||
edges = new ArrayList<>(); | ||
for (var funcLabelBlock : blockList) { | ||
build(funcLabelBlock); | ||
} | ||
cfg = new CFG<>(basicBlocks, edges); | ||
} | ||
|
||
private void build(LinearIRBlock block){ | ||
basicBlocks.add(BasicBlock.buildFromLinearBlock(block)); | ||
for(var successor : block.getSuccessors()){ | ||
edges.add(Pair.of(block.getOrd(), successor.getOrd())); | ||
build(successor); | ||
} | ||
} | ||
|
||
public CFG<IRNode> getCFG() { | ||
return cfg; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters