diff --git a/src/dk/camelot64/kickc/Compiler.java b/src/dk/camelot64/kickc/Compiler.java index d2110243c..31dca207c 100644 --- a/src/dk/camelot64/kickc/Compiler.java +++ b/src/dk/camelot64/kickc/Compiler.java @@ -112,6 +112,7 @@ public class Compiler { Pass3IdentifyAliveRanges pass3IdentifyAliveRanges = new Pass3IdentifyAliveRanges(program, log); pass3IdentifyAliveRanges.findLiveRanges(); + log.append("CONTROL FLOW GRAPH - LIVE RANGES"); log.append(program.getGraph().toString(program.getScope())); pass2AssertSSA(program, log); diff --git a/src/dk/camelot64/kickc/passes/Pass2AssertBlocks.java b/src/dk/camelot64/kickc/passes/Pass2AssertBlocks.java index 55a57dbb7..c7a3ce414 100644 --- a/src/dk/camelot64/kickc/passes/Pass2AssertBlocks.java +++ b/src/dk/camelot64/kickc/passes/Pass2AssertBlocks.java @@ -2,6 +2,8 @@ package dk.camelot64.kickc.passes; import dk.camelot64.kickc.icl.*; +import java.util.*; + /** Assert that all referenced blocks exist in the program */ public class Pass2AssertBlocks extends Pass2SsaAssertion { @@ -11,16 +13,32 @@ public class Pass2AssertBlocks extends Pass2SsaAssertion { @Override public void check() throws AssertionFailed { - ControlFlowGraphBaseVisitor blockReferenceFinder = new BlockReferenceChecker(getGraph()); + BlockReferenceChecker blockReferenceFinder = new BlockReferenceChecker(getGraph()); blockReferenceFinder.visitGraph(getGraph()); + + Set seenBlocks = blockReferenceFinder.getSeenBlocks(); + Collection allBlocks = getGraph().getAllBlocks(); + for (LabelRef seenBlock : seenBlocks) { + ControlFlowBlock block = getGraph().getBlock(seenBlock); + if(!allBlocks.contains(block)) { + throw new AssertionFailed("Compilation Process Error! A block in the program is not contained in the allBocks list (probably a block sequence problem). " + seenBlock); + } + } } private static class BlockReferenceChecker extends ControlFlowGraphBaseVisitor { private ControlFlowGraph graph; + Set seenBlocks; + public BlockReferenceChecker(ControlFlowGraph graph) { this.graph = graph; + this.seenBlocks = new HashSet<>(); + } + + public Set getSeenBlocks() { + return seenBlocks; } private void assertBlock(LabelRef blockLabel) throws AssertionFailed { @@ -30,6 +48,7 @@ public class Pass2AssertBlocks extends Pass2SsaAssertion { if (blockLabel.getFullName().equals("@RETURN")) { return; } + seenBlocks.add(blockLabel); ControlFlowBlock block = graph.getBlock(blockLabel); if (block == null) { throw new AssertionFailed("Compilation Process Error! Block referenced, but not found in program. " + blockLabel);