1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-02-20 15:29:10 +00:00

Added assert securing that phi predecessors are direct predecessors.

This commit is contained in:
jespergravgaard 2019-04-27 08:04:44 +02:00
parent c64713c913
commit e43a2e2c61
3 changed files with 10 additions and 9 deletions

View File

@ -222,7 +222,7 @@ public class Compiler {
assertions.add(new Pass2AssertNoLabels(program));
assertions.add(new Pass2AssertSingleAssignment(program));
assertions.add(new Pass2AssertRValues(program));
//assertions.add(new Pass2AssertPhiPredecessors(program));
assertions.add(new Pass2AssertPhiPredecessors(program));
for(Pass2SsaAssertion assertion : assertions) {
assertion.check();
}

View File

@ -197,7 +197,7 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base {
VariableRef phiLValVarRef = phiVariable.getVariable();
VariableVersion versioned = (VariableVersion) getScope().getVariable(phiLValVarRef);
VariableUnversioned unversioned = versioned.getVersionOf();
List<ControlFlowBlock> predecessors = getPredecessors(block);
List<ControlFlowBlock> predecessors = getPhiPredecessors(block, getProgram());
for(ControlFlowBlock predecessor : predecessors) {
LabelRef predecessorLabel = predecessor.getLabel();
Map<VariableUnversioned, VariableVersion> predecessorMap = symbolMap.get(predecessorLabel);
@ -245,15 +245,15 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base {
* @param block The block to examine
* @return All predecessor blocks
*/
private List<ControlFlowBlock> getPredecessors(ControlFlowBlock block) {
List<ControlFlowBlock> predecessors = getGraph().getPredecessors(block);
Symbol symbol = getScope().getSymbol(block.getLabel());
public static List<ControlFlowBlock> getPhiPredecessors(ControlFlowBlock block, Program program) {
List<ControlFlowBlock> predecessors = program.getGraph().getPredecessors(block);
Symbol symbol = program.getScope().getSymbol(block.getLabel());
if(symbol instanceof Procedure) {
Procedure procedure = (Procedure) symbol;
if(procedure.getInterruptType()!=null || Pass2ConstantIdentification.isAddressOfUsed(procedure.getRef(), getProgram())) {
if(procedure.getInterruptType()!=null || Pass2ConstantIdentification.isAddressOfUsed(procedure.getRef(), program)) {
// Find all root-level predecessors to the main block
ControlFlowBlock mainBlock = getGraph().getBlock(new LabelRef(SymbolRef.MAIN_PROC_NAME));
List<ControlFlowBlock> mainPredecessors = getGraph().getPredecessors(mainBlock);
ControlFlowBlock mainBlock = program.getGraph().getBlock(new LabelRef(SymbolRef.MAIN_PROC_NAME));
List<ControlFlowBlock> mainPredecessors = program.getGraph().getPredecessors(mainBlock);
for(ControlFlowBlock mainPredecessor : mainPredecessors) {
if(mainPredecessor.getScope().equals(ScopeRef.ROOT)) {
predecessors.add(mainPredecessor);

View File

@ -21,8 +21,9 @@ public class Pass2AssertPhiPredecessors extends Pass2SsaAssertion {
for(ControlFlowBlock block : getGraph().getAllBlocks()) {
if(block.hasPhiBlock()) {
StatementPhiBlock phiBlock = block.getPhiBlock();
List<ControlFlowBlock> phiPredecessors = Pass1GenerateSingleStaticAssignmentForm.getPhiPredecessors(block, getProgram());
List<LabelRef> predecessors =
getGraph().getPredecessors(block).stream().map(ControlFlowBlock::getLabel).collect(Collectors.toList());
phiPredecessors.stream().map(ControlFlowBlock::getLabel).collect(Collectors.toList());
for(StatementPhiBlock.PhiVariable phiVariable : phiBlock.getPhiVariables()) {
for(StatementPhiBlock.PhiRValue phiRValue : phiVariable.getValues()) {
if(!predecessors.contains(phiRValue.getPredecessor())) {