mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-09-08 17:54:40 +00:00
Added another block assertion
This commit is contained in:
parent
878059da13
commit
16d4ab93f0
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user