1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-08-02 09:29:35 +00:00

Added another block assertion

This commit is contained in:
jespergravgaard 2017-07-26 17:01:01 +02:00
parent 878059da13
commit 16d4ab93f0
2 changed files with 21 additions and 1 deletions

View File

@ -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);

View File

@ -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<Void> blockReferenceFinder = new BlockReferenceChecker(getGraph());
BlockReferenceChecker blockReferenceFinder = new BlockReferenceChecker(getGraph());
blockReferenceFinder.visitGraph(getGraph());
Set<LabelRef> seenBlocks = blockReferenceFinder.getSeenBlocks();
Collection<ControlFlowBlock> 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<Void> {
private ControlFlowGraph graph;
Set<LabelRef> seenBlocks;
public BlockReferenceChecker(ControlFlowGraph graph) {
this.graph = graph;
this.seenBlocks = new HashSet<>();
}
public Set<LabelRef> 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);