From 9403fe34c83c5532e39154ec58b32963a8caa2af Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Fri, 15 Nov 2019 08:53:09 +0100 Subject: [PATCH] Working on catching all declared constants in parse 0. Added hacky handing of phi master. --- .../passes/PassNStructAddressOfRewriting.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/dk/camelot64/kickc/passes/PassNStructAddressOfRewriting.java b/src/main/java/dk/camelot64/kickc/passes/PassNStructAddressOfRewriting.java index 0b1cd8b16..d77c7a168 100644 --- a/src/main/java/dk/camelot64/kickc/passes/PassNStructAddressOfRewriting.java +++ b/src/main/java/dk/camelot64/kickc/passes/PassNStructAddressOfRewriting.java @@ -8,10 +8,12 @@ import dk.camelot64.kickc.model.statements.Statement; import dk.camelot64.kickc.model.statements.StatementAssignment; import dk.camelot64.kickc.model.statements.StatementLValue; import dk.camelot64.kickc.model.symbols.Symbol; +import dk.camelot64.kickc.model.symbols.Variable; import dk.camelot64.kickc.model.types.SymbolTypePointer; import dk.camelot64.kickc.model.types.SymbolTypeStruct; import dk.camelot64.kickc.model.values.*; +import java.util.Collection; import java.util.concurrent.atomic.AtomicBoolean; /** @@ -70,7 +72,18 @@ public class PassNStructAddressOfRewriting extends Pass2SsaOptimization { } private RValue rewriteStructAddressOf(VariableRef toSymbol) { - StatementLValue toSymbolAssignment = getGraph().getAssignment(toSymbol); + Variable variable = getScope().getVariable(toSymbol); + // Hacky way to handle PHI-masters + if(variable.isKindPhiMaster()) { + Collection versions = variable.getScope().getVersions(variable); + for(Variable version : versions) { + if(variable.isVariable()) + variable = version; + break; + } + } + + StatementLValue toSymbolAssignment = getGraph().getAssignment(variable.getVariableRef()); if(toSymbolAssignment instanceof StatementAssignment) { StatementAssignment assignment = (StatementAssignment) toSymbolAssignment; if(assignment.getrValue2() instanceof StructUnwoundPlaceholder) {