mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-04 18:05:50 +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 pass3IdentifyAliveRanges = new Pass3IdentifyAliveRanges(program, log);
|
||||||
pass3IdentifyAliveRanges.findLiveRanges();
|
pass3IdentifyAliveRanges.findLiveRanges();
|
||||||
|
|
||||||
|
|
||||||
log.append("CONTROL FLOW GRAPH - LIVE RANGES");
|
log.append("CONTROL FLOW GRAPH - LIVE RANGES");
|
||||||
log.append(program.getGraph().toString(program.getScope()));
|
log.append(program.getGraph().toString(program.getScope()));
|
||||||
pass2AssertSSA(program, log);
|
pass2AssertSSA(program, log);
|
||||||
|
@ -2,6 +2,8 @@ package dk.camelot64.kickc.passes;
|
|||||||
|
|
||||||
import dk.camelot64.kickc.icl.*;
|
import dk.camelot64.kickc.icl.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/** Assert that all referenced blocks exist in the program */
|
/** Assert that all referenced blocks exist in the program */
|
||||||
public class Pass2AssertBlocks extends Pass2SsaAssertion {
|
public class Pass2AssertBlocks extends Pass2SsaAssertion {
|
||||||
|
|
||||||
@ -11,16 +13,32 @@ public class Pass2AssertBlocks extends Pass2SsaAssertion {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void check() throws AssertionFailed {
|
public void check() throws AssertionFailed {
|
||||||
ControlFlowGraphBaseVisitor<Void> blockReferenceFinder = new BlockReferenceChecker(getGraph());
|
BlockReferenceChecker blockReferenceFinder = new BlockReferenceChecker(getGraph());
|
||||||
blockReferenceFinder.visitGraph(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 static class BlockReferenceChecker extends ControlFlowGraphBaseVisitor<Void> {
|
||||||
|
|
||||||
private ControlFlowGraph graph;
|
private ControlFlowGraph graph;
|
||||||
|
|
||||||
|
Set<LabelRef> seenBlocks;
|
||||||
|
|
||||||
public BlockReferenceChecker(ControlFlowGraph graph) {
|
public BlockReferenceChecker(ControlFlowGraph graph) {
|
||||||
this.graph = graph;
|
this.graph = graph;
|
||||||
|
this.seenBlocks = new HashSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<LabelRef> getSeenBlocks() {
|
||||||
|
return seenBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertBlock(LabelRef blockLabel) throws AssertionFailed {
|
private void assertBlock(LabelRef blockLabel) throws AssertionFailed {
|
||||||
@ -30,6 +48,7 @@ public class Pass2AssertBlocks extends Pass2SsaAssertion {
|
|||||||
if (blockLabel.getFullName().equals("@RETURN")) {
|
if (blockLabel.getFullName().equals("@RETURN")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
seenBlocks.add(blockLabel);
|
||||||
ControlFlowBlock block = graph.getBlock(blockLabel);
|
ControlFlowBlock block = graph.getBlock(blockLabel);
|
||||||
if (block == null) {
|
if (block == null) {
|
||||||
throw new AssertionFailed("Compilation Process Error! Block referenced, but not found in program. " + blockLabel);
|
throw new AssertionFailed("Compilation Process Error! Block referenced, but not found in program. " + blockLabel);
|
||||||
|
Loading…
Reference in New Issue
Block a user