From 47d6ea3f9acebbdd172da8f808dafdfd0175dc4c Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Sun, 25 Jul 2021 22:30:22 +0200 Subject: [PATCH] Working in classic structs. #197 --- .../java/dk/camelot64/kickc/Compiler.java | 1 + .../kickc/passes/Pass1CallPhiParameters.java | 26 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/dk/camelot64/kickc/Compiler.java b/src/main/java/dk/camelot64/kickc/Compiler.java index cf9c32b24..754b511b5 100644 --- a/src/main/java/dk/camelot64/kickc/Compiler.java +++ b/src/main/java/dk/camelot64/kickc/Compiler.java @@ -553,6 +553,7 @@ public class Compiler { private void pass3Analysis() { if(program.getTargetPlatform().getVariableBuilderConfig().isStructModelClassic()) { + new Pass1UnwindStructValues(program).execute(); new PassNStructUnwoundPlaceholderRemoval(program).execute(); } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1CallPhiParameters.java b/src/main/java/dk/camelot64/kickc/passes/Pass1CallPhiParameters.java index 9b9fa3bac..22fb6bb2f 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1CallPhiParameters.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1CallPhiParameters.java @@ -2,7 +2,10 @@ package dk.camelot64.kickc.passes; import dk.camelot64.kickc.model.*; import dk.camelot64.kickc.model.statements.*; -import dk.camelot64.kickc.model.symbols.*; +import dk.camelot64.kickc.model.symbols.Procedure; +import dk.camelot64.kickc.model.symbols.ProgramScope; +import dk.camelot64.kickc.model.symbols.Scope; +import dk.camelot64.kickc.model.symbols.Variable; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypeStruct; import dk.camelot64.kickc.model.values.*; @@ -117,18 +120,21 @@ public class Pass1CallPhiParameters { LValue procReturnVarRef = null; if(procReturnVar != null) { procReturnVarRef = (LValue) procReturnVar.getRef(); + + // Special handing of struct value returns - if(procReturnVar.getType() instanceof SymbolTypeStruct) { - StructVariableMemberUnwinding.VariableUnwinding returnVarUnwinding = program.getStructVariableMemberUnwinding().getVariableUnwinding((VariableRef) procReturnVarRef); - if(returnVarUnwinding != null) { - ArrayList unwoundReturnVars = new ArrayList<>(); - for(String memberName : returnVarUnwinding.getMemberNames()) { - final SymbolVariableRef memberUnwound = returnVarUnwinding.getMemberUnwound(memberName); - unwoundReturnVars.add(memberUnwound); + if(!program.getTargetPlatform().getVariableBuilderConfig().isStructModelClassic()) + if(procReturnVar.getType() instanceof SymbolTypeStruct) { + StructVariableMemberUnwinding.VariableUnwinding returnVarUnwinding = program.getStructVariableMemberUnwinding().getVariableUnwinding((VariableRef) procReturnVarRef); + if(returnVarUnwinding != null) { + ArrayList unwoundReturnVars = new ArrayList<>(); + for(String memberName : returnVarUnwinding.getMemberNames()) { + final SymbolVariableRef memberUnwound = returnVarUnwinding.getMemberUnwound(memberName); + unwoundReturnVars.add(memberUnwound); + } + procReturnVarRef = new ValueList(unwoundReturnVars); } - procReturnVarRef = new ValueList(unwoundReturnVars); } - } } // Save original LValue and update the LValue final LValue origCallLValue = call.getlValue();