mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-02-21 22:29:07 +00:00
Added assert securing that phi predecessors are direct predecessors.
This commit is contained in:
parent
c64713c913
commit
e43a2e2c61
@ -222,7 +222,7 @@ public class Compiler {
|
|||||||
assertions.add(new Pass2AssertNoLabels(program));
|
assertions.add(new Pass2AssertNoLabels(program));
|
||||||
assertions.add(new Pass2AssertSingleAssignment(program));
|
assertions.add(new Pass2AssertSingleAssignment(program));
|
||||||
assertions.add(new Pass2AssertRValues(program));
|
assertions.add(new Pass2AssertRValues(program));
|
||||||
//assertions.add(new Pass2AssertPhiPredecessors(program));
|
assertions.add(new Pass2AssertPhiPredecessors(program));
|
||||||
for(Pass2SsaAssertion assertion : assertions) {
|
for(Pass2SsaAssertion assertion : assertions) {
|
||||||
assertion.check();
|
assertion.check();
|
||||||
}
|
}
|
||||||
|
@ -197,7 +197,7 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base {
|
|||||||
VariableRef phiLValVarRef = phiVariable.getVariable();
|
VariableRef phiLValVarRef = phiVariable.getVariable();
|
||||||
VariableVersion versioned = (VariableVersion) getScope().getVariable(phiLValVarRef);
|
VariableVersion versioned = (VariableVersion) getScope().getVariable(phiLValVarRef);
|
||||||
VariableUnversioned unversioned = versioned.getVersionOf();
|
VariableUnversioned unversioned = versioned.getVersionOf();
|
||||||
List<ControlFlowBlock> predecessors = getPredecessors(block);
|
List<ControlFlowBlock> predecessors = getPhiPredecessors(block, getProgram());
|
||||||
for(ControlFlowBlock predecessor : predecessors) {
|
for(ControlFlowBlock predecessor : predecessors) {
|
||||||
LabelRef predecessorLabel = predecessor.getLabel();
|
LabelRef predecessorLabel = predecessor.getLabel();
|
||||||
Map<VariableUnversioned, VariableVersion> predecessorMap = symbolMap.get(predecessorLabel);
|
Map<VariableUnversioned, VariableVersion> predecessorMap = symbolMap.get(predecessorLabel);
|
||||||
@ -245,15 +245,15 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base {
|
|||||||
* @param block The block to examine
|
* @param block The block to examine
|
||||||
* @return All predecessor blocks
|
* @return All predecessor blocks
|
||||||
*/
|
*/
|
||||||
private List<ControlFlowBlock> getPredecessors(ControlFlowBlock block) {
|
public static List<ControlFlowBlock> getPhiPredecessors(ControlFlowBlock block, Program program) {
|
||||||
List<ControlFlowBlock> predecessors = getGraph().getPredecessors(block);
|
List<ControlFlowBlock> predecessors = program.getGraph().getPredecessors(block);
|
||||||
Symbol symbol = getScope().getSymbol(block.getLabel());
|
Symbol symbol = program.getScope().getSymbol(block.getLabel());
|
||||||
if(symbol instanceof Procedure) {
|
if(symbol instanceof Procedure) {
|
||||||
Procedure procedure = (Procedure) symbol;
|
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
|
// Find all root-level predecessors to the main block
|
||||||
ControlFlowBlock mainBlock = getGraph().getBlock(new LabelRef(SymbolRef.MAIN_PROC_NAME));
|
ControlFlowBlock mainBlock = program.getGraph().getBlock(new LabelRef(SymbolRef.MAIN_PROC_NAME));
|
||||||
List<ControlFlowBlock> mainPredecessors = getGraph().getPredecessors(mainBlock);
|
List<ControlFlowBlock> mainPredecessors = program.getGraph().getPredecessors(mainBlock);
|
||||||
for(ControlFlowBlock mainPredecessor : mainPredecessors) {
|
for(ControlFlowBlock mainPredecessor : mainPredecessors) {
|
||||||
if(mainPredecessor.getScope().equals(ScopeRef.ROOT)) {
|
if(mainPredecessor.getScope().equals(ScopeRef.ROOT)) {
|
||||||
predecessors.add(mainPredecessor);
|
predecessors.add(mainPredecessor);
|
||||||
|
@ -21,8 +21,9 @@ public class Pass2AssertPhiPredecessors extends Pass2SsaAssertion {
|
|||||||
for(ControlFlowBlock block : getGraph().getAllBlocks()) {
|
for(ControlFlowBlock block : getGraph().getAllBlocks()) {
|
||||||
if(block.hasPhiBlock()) {
|
if(block.hasPhiBlock()) {
|
||||||
StatementPhiBlock phiBlock = block.getPhiBlock();
|
StatementPhiBlock phiBlock = block.getPhiBlock();
|
||||||
|
List<ControlFlowBlock> phiPredecessors = Pass1GenerateSingleStaticAssignmentForm.getPhiPredecessors(block, getProgram());
|
||||||
List<LabelRef> predecessors =
|
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.PhiVariable phiVariable : phiBlock.getPhiVariables()) {
|
||||||
for(StatementPhiBlock.PhiRValue phiRValue : phiVariable.getValues()) {
|
for(StatementPhiBlock.PhiRValue phiRValue : phiVariable.getValues()) {
|
||||||
if(!predecessors.contains(phiRValue.getPredecessor())) {
|
if(!predecessors.contains(phiRValue.getPredecessor())) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user