mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-04-08 14:37:40 +00:00
Added pass 2 assertion that no unversioned or fwddref variable refs exist.
This commit is contained in:
parent
4640b31043
commit
eb2ff934c7
@ -170,6 +170,7 @@ public class Compiler {
|
||||
assertions.add(new Pass2AssertNoProcs(program));
|
||||
assertions.add(new Pass2AssertNoLabels(program));
|
||||
assertions.add(new Pass2AssertSingleAssignment(program));
|
||||
assertions.add(new Pass2AssertRValues(program));
|
||||
for(Pass2SsaAssertion assertion : assertions) {
|
||||
assertion.check();
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package dk.camelot64.kickc.passes;
|
||||
|
||||
import dk.camelot64.kickc.model.CompileError;
|
||||
import dk.camelot64.kickc.model.ControlFlowBlock;
|
||||
import dk.camelot64.kickc.model.ControlFlowGraphBaseVisitor;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.model.statements.StatementCall;
|
||||
import dk.camelot64.kickc.model.values.ForwardVariableRef;
|
||||
import dk.camelot64.kickc.model.values.RValue;
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
|
||||
import java.util.ListIterator;
|
||||
|
||||
/** Asserts that the program does not contain any RValues that are forward-reference or unversioned */
|
||||
public class Pass2AssertRValues extends Pass2SsaAssertion {
|
||||
|
||||
public Pass2AssertRValues(Program program) {
|
||||
super(program);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void check() throws AssertionFailed {
|
||||
ValueReplacer.executeAll(getGraph(), (replaceable, currentStmt, stmtIt, currentBlock) -> {
|
||||
RValue rValue = replaceable.get();
|
||||
if(rValue instanceof ForwardVariableRef) {
|
||||
throw new CompileError("No forward references allowed "+currentStmt.toString(getProgram(), false));
|
||||
}
|
||||
if(rValue instanceof VariableRef) {
|
||||
VariableRef variableRef = (VariableRef) rValue;
|
||||
if(!variableRef.isIntermediate() && !variableRef.isVersion()) {
|
||||
throw new CompileError("No unversioned variable references allowed "+currentStmt.toString(getProgram(), false));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user