From bf01ce2f50cf87aebbdc22d27fa0e881a6410f31 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Sun, 29 Sep 2019 10:43:42 +0200 Subject: [PATCH] master commit --- ...=pbuc2_derefidx_(pbuc3_derefidx_vbuxx).asm | 2 + .../kickc/model/symbols/Variable.java | 16 ++++-- ...ss1GenerateSingleStaticAssignmentForm.java | 4 +- .../kickc/passes/Pass1UnwindBlockScopes.java | 54 +++++++++++-------- .../kickc/passes/Pass2AssertSymbols.java | 2 +- 5 files changed, 49 insertions(+), 29 deletions(-) create mode 100644 src/main/fragment/mos6502-common/_deref_(pptc1_derefidx_vbuyy)=pbuc2_derefidx_(pbuc3_derefidx_vbuxx).asm diff --git a/src/main/fragment/mos6502-common/_deref_(pptc1_derefidx_vbuyy)=pbuc2_derefidx_(pbuc3_derefidx_vbuxx).asm b/src/main/fragment/mos6502-common/_deref_(pptc1_derefidx_vbuyy)=pbuc2_derefidx_(pbuc3_derefidx_vbuxx).asm new file mode 100644 index 000000000..6a846a14e --- /dev/null +++ b/src/main/fragment/mos6502-common/_deref_(pptc1_derefidx_vbuyy)=pbuc2_derefidx_(pbuc3_derefidx_vbuxx).asm @@ -0,0 +1,2 @@ +lda {c3},y +TOTOTOTOTO \ No newline at end of file diff --git a/src/main/java/dk/camelot64/kickc/model/symbols/Variable.java b/src/main/java/dk/camelot64/kickc/model/symbols/Variable.java index 26210d73e..caf1054b7 100644 --- a/src/main/java/dk/camelot64/kickc/model/symbols/Variable.java +++ b/src/main/java/dk/camelot64/kickc/model/symbols/Variable.java @@ -21,7 +21,7 @@ public class Variable extends SymbolVariable { /** true if the variable is intermediate. */ private boolean isIntermediate; - /* true if the variable is a PHI master variable that is turned into versions. (the variable has storage strategy PHI)*/ + /** true if the variable is a PHI master variable that is turned into versions. (the variable has storage strategy PHI)*/ private boolean isPhiMaster; /** The number of the next version (only used for PHI masters)*/ @@ -72,16 +72,24 @@ public class Variable extends SymbolVariable { this.allocation = allocation; } + public boolean isConstant() { + return StorageStrategy.CONSTANT.equals(getStorageStrategy()); + } + public boolean isPhiMaster() { + return StorageStrategy.PHI_MASTER.equals(getStorageStrategy()); + } + + public boolean isPhiMaster2() { /* if(isPhiMaster) { if(!StorageStrategy.PHI_MASTER.equals(getStorageStrategy())) { System.out.println("PHI master mismatch!"); - }; + } } - return StorageStrategy.PHI_MASTER.equals(getStorageStrategy()); - */ + */ return isPhiMaster; + //return StorageStrategy.PHI_MASTER.equals(getStorageStrategy()); } public boolean isPhiVersion() { diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1GenerateSingleStaticAssignmentForm.java b/src/main/java/dk/camelot64/kickc/passes/Pass1GenerateSingleStaticAssignmentForm.java index 3a0aa16fc..0301f0005 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1GenerateSingleStaticAssignmentForm.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1GenerateSingleStaticAssignmentForm.java @@ -76,7 +76,7 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base { private void versionAssignment(VariableRef lValueRef, ProgramValue programLValue, StatementSource source) { Collection earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants(); Variable assignedVar = getScope().getVariable(lValueRef); - if(assignedVar.isPhiMaster()) { + if(assignedVar.isPhiMaster2()) { // Assignment to a non-versioned non-intermediary variable Variable assignedSymbol = assignedVar; Variable version; @@ -177,7 +177,7 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base { Variable version = null; if(rValue instanceof VariableRef) { Variable rValueVar = getScope().getVariable((VariableRef) rValue); - if(rValueVar.isPhiMaster()) { + if(rValueVar.isPhiMaster2()) { // rValue needs versioning - look for version in statements Variable rSymbol = rValueVar; if(rSymbol.isDeclaredConstant() || earlyIdentifiedConstants.contains(rSymbol.getRef())) { diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindBlockScopes.java b/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindBlockScopes.java index fdda58242..f9aaa5941 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindBlockScopes.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindBlockScopes.java @@ -4,7 +4,10 @@ import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.Program; import dk.camelot64.kickc.model.iterator.ProgramValueIterator; import dk.camelot64.kickc.model.symbols.*; -import dk.camelot64.kickc.model.values.*; +import dk.camelot64.kickc.model.values.LabelRef; +import dk.camelot64.kickc.model.values.SymbolRef; +import dk.camelot64.kickc.model.values.Value; +import dk.camelot64.kickc.model.values.VariableRef; import java.util.ArrayList; import java.util.Collection; @@ -35,12 +38,12 @@ public class Pass1UnwindBlockScopes extends Pass1Base { Value value = programValue.get(); if(value instanceof VariableRef) { SymbolRef unwound = unwoundSymbols.get(value); - if(unwound!=null) { + if(unwound != null) { programValue.set(unwound); } } else if(value instanceof LabelRef) { SymbolRef unwound = unwoundSymbols.get(value); - if(unwound!=null) { + if(unwound != null) { programValue.set(unwound); } } @@ -51,6 +54,7 @@ public class Pass1UnwindBlockScopes extends Pass1Base { /** * Unwind symbols inside a single block scope (recursively) + * * @param subScope The block scope * @param procedure The containing procedure * @param unwoundSymbols All unwound symbols @@ -62,30 +66,35 @@ public class Pass1UnwindBlockScopes extends Pass1Base { if(symbol.getRef().isIntermediate()) { Label unwound = procedure.addLabelIntermediate(); unwoundSymbols.put(symbol.getRef(), unwound.getRef()); - } else { + } else { String name = findLocalName(procedure, symbol); Label unwound = procedure.addLabel(name); unwoundSymbols.put(symbol.getRef(), unwound.getRef()); } - } else if(symbol instanceof Variable && ((Variable) symbol).isPhiMaster()) { - String name = findLocalName(procedure, symbol); - Variable var = (Variable) symbol; - Variable unwound = procedure.addVariablePhiMaster(name, symbol.getType(), var.getDataSegment()); - unwound.setDeclaredAlignment(var.getDeclaredAlignment()); - unwound.setDeclaredConstant(var.isDeclaredConstant()); - unwound.setDeclaredVolatile(var.isDeclaredVolatile()); - unwound.setInferedVolatile(var.isInferedVolatile()); - unwound.setDeclaredRegister((var.getDeclaredRegister())); - unwound.setDeclaredExport(var.isDeclaredExport()); - unwoundSymbols.put(symbol.getRef(), unwound.getRef()); - } else if(symbol instanceof Variable && ((Variable) symbol).isIntermediate()) { - Variable unwound = procedure.addVariableIntermediate(); - unwoundSymbols.put(symbol.getRef(), unwound.getRef()); - } else if(symbol instanceof BlockScope) { + } else if(symbol instanceof Variable) { + Variable variable = (Variable) symbol; + if(variable.isPhiMaster() || variable.isConstant()) { + String name = findLocalName(procedure, symbol); + Variable var = (Variable) symbol; + Variable unwound = procedure.addVariablePhiMaster(name, symbol.getType(), var.getDataSegment()); + unwound.setDeclaredAlignment(var.getDeclaredAlignment()); + unwound.setDeclaredConstant(var.isDeclaredConstant()); + unwound.setDeclaredVolatile(var.isDeclaredVolatile()); + unwound.setInferedVolatile(var.isInferedVolatile()); + unwound.setDeclaredRegister((var.getDeclaredRegister())); + unwound.setDeclaredExport(var.isDeclaredExport()); + unwoundSymbols.put(symbol.getRef(), unwound.getRef()); + } else if(variable.isIntermediate()) { + Variable unwound = procedure.addVariableIntermediate(); + unwoundSymbols.put(symbol.getRef(), unwound.getRef()); + } else { + throw new CompileError("ERROR! Unexpected symbol encountered in block scope " + symbol.toString(getProgram())); + } + } else if(symbol instanceof BlockScope) { // Recurse! unwindSubScope((Scope) symbol, procedure, unwoundSymbols); } else { - throw new CompileError("ERROR! Unexpected symbol encountered in block scope "+symbol.toString(getProgram())); + throw new CompileError("ERROR! Unexpected symbol encountered in block scope " + symbol.toString(getProgram())); } } } @@ -94,6 +103,7 @@ public class Pass1UnwindBlockScopes extends Pass1Base { /** * Find a suitable name for the symbol in the surrounding procedure. * Avoids clashes with other symbols already in the procedure + * * @param procedure The procedure * @param symbol The symbol to find a good ,ocal name for * @return An unused local name @@ -101,8 +111,8 @@ public class Pass1UnwindBlockScopes extends Pass1Base { private String findLocalName(Procedure procedure, Symbol symbol) { String name = symbol.getLocalName(); int idx = 0; - while(procedure.getLocalSymbol(name)!=null) { - name = symbol.getLocalName()+(++idx); + while(procedure.getLocalSymbol(name) != null) { + name = symbol.getLocalName() + (++idx); } return name; } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass2AssertSymbols.java b/src/main/java/dk/camelot64/kickc/passes/Pass2AssertSymbols.java index d16fd639a..6aad99207 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass2AssertSymbols.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass2AssertSymbols.java @@ -43,7 +43,7 @@ public class Pass2AssertSymbols extends Pass2SsaAssertion { Collection tableSymbols = getScope().getAllSymbols(true); for(Symbol tableSymbol : tableSymbols) { - if(tableSymbol instanceof Variable && ((Variable) tableSymbol).isPhiMaster()) continue; + if(tableSymbol instanceof Variable && ((Variable) tableSymbol).isPhiMaster2()) continue; if(tableSymbol instanceof ConstantVar) continue; if(tableSymbol instanceof StructDefinition) continue; if(tableSymbol instanceof EnumDefinition) continue;