Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Feature/dead code improve #1770

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Prev Previous commit
Next Next commit
Merge branch 'feature/cfg' into feature/dead-code-improve
EvilBeaver committed Aug 29, 2021
commit 862a1ee674a0b2f8d79e1c1e89092dee3ccf7bcd
Original file line number Diff line number Diff line change
@@ -38,6 +38,20 @@ public class CfgBuildingParseTreeVisitor extends BSLParserBaseVisitor<ParseTree>
private Map<String, LabelVertex> jumpLabels;

private boolean produceLoopIterationsEnabled = true;
private boolean producePreprocessorConditionsEnabled = true;
private boolean adjacentDeadCodeEnabled = false;

public void produceLoopIterations(boolean enable) {
produceLoopIterationsEnabled = enable;
}

public void producePreprocessorConditions(boolean enable) {
producePreprocessorConditionsEnabled = enable;
}

public void determineAdjacentDeadCode(boolean enabled) {
adjacentDeadCodeEnabled = enabled;
}

public ControlFlowGraph buildGraph(BSLParser.CodeBlockContext block) {

@@ -69,10 +83,6 @@ public ControlFlowGraph buildGraph(BSLParser.CodeBlockContext block) {
return graph;
}

public void produceLoopIterations(boolean flag) {
produceLoopIterationsEnabled = flag;
}

@Override
public ParseTree visitCallStatement(BSLParser.CallStatementContext ctx) {
blocks.addStatement(ctx);
@@ -528,8 +538,9 @@ private void buildLoopSubgraph(BSLParser.CodeBlockContext ctx, LoopVertex loopSt

graph.addEdge(loopStart, body.begin(), CfgEdgeType.TRUE_BRANCH);
graph.addEdge(loopStart, blocks.getCurrentBlock().end(), CfgEdgeType.FALSE_BRANCH);
if (produceLoopIterationsEnabled)
if (produceLoopIterationsEnabled) {
graph.addEdge(body.end(), loopStart, CfgEdgeType.LOOP_ITERATION);
}
}

private void connectGraphTail(StatementsBlockWriter.StatementsBlockRecord currentBlock, CfgVertex vertex) {
You are viewing a condensed version of this merge commit. You can view the full changes here.