1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-14 23:04:57 +00:00

Added more asserts

This commit is contained in:
jespergravgaard 2017-07-26 16:09:47 +02:00
parent d7e0a638f2
commit 878059da13
5 changed files with 124 additions and 0 deletions

View File

@ -148,6 +148,10 @@ public class Compiler {
List<Pass2SsaAssertion> assertions = new ArrayList<>(); List<Pass2SsaAssertion> assertions = new ArrayList<>();
assertions.add(new Pass2AssertSymbols(program)); assertions.add(new Pass2AssertSymbols(program));
assertions.add(new Pass2AssertBlocks(program)); assertions.add(new Pass2AssertBlocks(program));
assertions.add(new Pass2AssertNoCallParameters(program));
assertions.add(new Pass2AssertNoCallLvalues(program));
assertions.add(new Pass2AssertNoProcs(program));
assertions.add(new Pass2AssertNoLabels(program));
for (Pass2SsaAssertion assertion : assertions) { for (Pass2SsaAssertion assertion : assertions) {
assertion.check(); assertion.check();
} }

View File

@ -0,0 +1,33 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.icl.ControlFlowGraphBaseVisitor;
import dk.camelot64.kickc.icl.Program;
import dk.camelot64.kickc.icl.RValue;
import dk.camelot64.kickc.icl.StatementCall;
import java.util.List;
/** Asserts that the program does not contain calls with lValues */
public class Pass2AssertNoCallLvalues extends Pass2SsaAssertion {
public Pass2AssertNoCallLvalues(Program program) {
super(program);
}
@Override
public void check() throws AssertionFailed {
ControlFlowGraphBaseVisitor<Void> checkCalls = new ControlFlowGraphBaseVisitor<Void>() {
@Override
public Void visitCall(StatementCall callLValue) {
if(callLValue.getlValue()!=null) {
throw new AssertionFailed("No call lValue allowed! "+callLValue);
}
return null;
}
};
checkCalls.visitGraph(getGraph());
}
}

View File

@ -0,0 +1,32 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.icl.*;
import java.util.HashSet;
import java.util.List;
/** Asserts that the program does not contain calls with parameters */
public class Pass2AssertNoCallParameters extends Pass2SsaAssertion {
public Pass2AssertNoCallParameters(Program program) {
super(program);
}
@Override
public void check() throws AssertionFailed {
ControlFlowGraphBaseVisitor<Void> checkCalls = new ControlFlowGraphBaseVisitor<Void>() {
@Override
public Void visitCall(StatementCall callLValue) {
List<RValue> parameters = callLValue.getParameters();
if(parameters!=null && parameters.size()>0) {
throw new AssertionFailed("No call parameters allowed! "+callLValue);
}
return null;
}
};
checkCalls.visitGraph(getGraph());
}
}

View File

@ -0,0 +1,25 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.icl.*;
/** Asserts that the graph contains no label statements */
public class Pass2AssertNoLabels extends Pass2SsaAssertion {
public Pass2AssertNoLabels(Program program) {
super(program);
}
@Override
public void check() throws AssertionFailed {
ControlFlowGraphBaseVisitor<Void> checkCalls = new ControlFlowGraphBaseVisitor<Void>() {
@Override
public Void visitJumpTarget(StatementLabel jumpTarget) {
throw new AssertionFailed("No label statements allowed! "+jumpTarget);
}
};
checkCalls.visitGraph(getGraph());
}
}

View File

@ -0,0 +1,30 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.icl.*;
/** Asserts that the graph contains no proc/endproc statements */
public class Pass2AssertNoProcs extends Pass2SsaAssertion {
public Pass2AssertNoProcs(Program program) {
super(program);
}
@Override
public void check() throws AssertionFailed {
ControlFlowGraphBaseVisitor<Void> checkCalls = new ControlFlowGraphBaseVisitor<Void>() {
@Override
public Void visitProcedureBegin(StatementProcedureBegin statement) {
throw new AssertionFailed("No proc statements allowed! "+statement);
}
@Override
public Void visitProcedureEnd(StatementProcedureEnd statement) {
throw new AssertionFailed("No proc statements allowed! "+statement);
}
};
checkCalls.visitGraph(getGraph());
}
}