1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-17 16:31:34 +00:00

master commit

This commit is contained in:
jespergravgaard 2019-09-29 10:43:42 +02:00
parent e5e57aa714
commit bf01ce2f50
5 changed files with 49 additions and 29 deletions

View File

@ -21,7 +21,7 @@ public class Variable extends SymbolVariable {
/** true if the variable is intermediate. */ /** true if the variable is intermediate. */
private boolean isIntermediate; 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; private boolean isPhiMaster;
/** The number of the next version (only used for PHI masters)*/ /** The number of the next version (only used for PHI masters)*/
@ -72,16 +72,24 @@ public class Variable extends SymbolVariable {
this.allocation = allocation; this.allocation = allocation;
} }
public boolean isConstant() {
return StorageStrategy.CONSTANT.equals(getStorageStrategy());
}
public boolean isPhiMaster() { public boolean isPhiMaster() {
return StorageStrategy.PHI_MASTER.equals(getStorageStrategy());
}
public boolean isPhiMaster2() {
/* /*
if(isPhiMaster) { if(isPhiMaster) {
if(!StorageStrategy.PHI_MASTER.equals(getStorageStrategy())) { if(!StorageStrategy.PHI_MASTER.equals(getStorageStrategy())) {
System.out.println("PHI master mismatch!"); System.out.println("PHI master mismatch!");
}; }
} }
return StorageStrategy.PHI_MASTER.equals(getStorageStrategy()); */
*/
return isPhiMaster; return isPhiMaster;
//return StorageStrategy.PHI_MASTER.equals(getStorageStrategy());
} }
public boolean isPhiVersion() { public boolean isPhiVersion() {

View File

@ -76,7 +76,7 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base {
private void versionAssignment(VariableRef lValueRef, ProgramValue programLValue, StatementSource source) { private void versionAssignment(VariableRef lValueRef, ProgramValue programLValue, StatementSource source) {
Collection<VariableRef> earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants(); Collection<VariableRef> earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants();
Variable assignedVar = getScope().getVariable(lValueRef); Variable assignedVar = getScope().getVariable(lValueRef);
if(assignedVar.isPhiMaster()) { if(assignedVar.isPhiMaster2()) {
// Assignment to a non-versioned non-intermediary variable // Assignment to a non-versioned non-intermediary variable
Variable assignedSymbol = assignedVar; Variable assignedSymbol = assignedVar;
Variable version; Variable version;
@ -177,7 +177,7 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base {
Variable version = null; Variable version = null;
if(rValue instanceof VariableRef) { if(rValue instanceof VariableRef) {
Variable rValueVar = getScope().getVariable((VariableRef) rValue); Variable rValueVar = getScope().getVariable((VariableRef) rValue);
if(rValueVar.isPhiMaster()) { if(rValueVar.isPhiMaster2()) {
// rValue needs versioning - look for version in statements // rValue needs versioning - look for version in statements
Variable rSymbol = rValueVar; Variable rSymbol = rValueVar;
if(rSymbol.isDeclaredConstant() || earlyIdentifiedConstants.contains(rSymbol.getRef())) { if(rSymbol.isDeclaredConstant() || earlyIdentifiedConstants.contains(rSymbol.getRef())) {

View File

@ -4,7 +4,10 @@ import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.Program; import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.iterator.ProgramValueIterator; import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
import dk.camelot64.kickc.model.symbols.*; 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.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -35,12 +38,12 @@ public class Pass1UnwindBlockScopes extends Pass1Base {
Value value = programValue.get(); Value value = programValue.get();
if(value instanceof VariableRef) { if(value instanceof VariableRef) {
SymbolRef unwound = unwoundSymbols.get(value); SymbolRef unwound = unwoundSymbols.get(value);
if(unwound!=null) { if(unwound != null) {
programValue.set(unwound); programValue.set(unwound);
} }
} else if(value instanceof LabelRef) { } else if(value instanceof LabelRef) {
SymbolRef unwound = unwoundSymbols.get(value); SymbolRef unwound = unwoundSymbols.get(value);
if(unwound!=null) { if(unwound != null) {
programValue.set(unwound); programValue.set(unwound);
} }
} }
@ -51,6 +54,7 @@ public class Pass1UnwindBlockScopes extends Pass1Base {
/** /**
* Unwind symbols inside a single block scope (recursively) * Unwind symbols inside a single block scope (recursively)
*
* @param subScope The block scope * @param subScope The block scope
* @param procedure The containing procedure * @param procedure The containing procedure
* @param unwoundSymbols All unwound symbols * @param unwoundSymbols All unwound symbols
@ -62,30 +66,35 @@ public class Pass1UnwindBlockScopes extends Pass1Base {
if(symbol.getRef().isIntermediate()) { if(symbol.getRef().isIntermediate()) {
Label unwound = procedure.addLabelIntermediate(); Label unwound = procedure.addLabelIntermediate();
unwoundSymbols.put(symbol.getRef(), unwound.getRef()); unwoundSymbols.put(symbol.getRef(), unwound.getRef());
} else { } else {
String name = findLocalName(procedure, symbol); String name = findLocalName(procedure, symbol);
Label unwound = procedure.addLabel(name); Label unwound = procedure.addLabel(name);
unwoundSymbols.put(symbol.getRef(), unwound.getRef()); unwoundSymbols.put(symbol.getRef(), unwound.getRef());
} }
} else if(symbol instanceof Variable && ((Variable) symbol).isPhiMaster()) { } else if(symbol instanceof Variable) {
String name = findLocalName(procedure, symbol); Variable variable = (Variable) symbol;
Variable var = (Variable) symbol; if(variable.isPhiMaster() || variable.isConstant()) {
Variable unwound = procedure.addVariablePhiMaster(name, symbol.getType(), var.getDataSegment()); String name = findLocalName(procedure, symbol);
unwound.setDeclaredAlignment(var.getDeclaredAlignment()); Variable var = (Variable) symbol;
unwound.setDeclaredConstant(var.isDeclaredConstant()); Variable unwound = procedure.addVariablePhiMaster(name, symbol.getType(), var.getDataSegment());
unwound.setDeclaredVolatile(var.isDeclaredVolatile()); unwound.setDeclaredAlignment(var.getDeclaredAlignment());
unwound.setInferedVolatile(var.isInferedVolatile()); unwound.setDeclaredConstant(var.isDeclaredConstant());
unwound.setDeclaredRegister((var.getDeclaredRegister())); unwound.setDeclaredVolatile(var.isDeclaredVolatile());
unwound.setDeclaredExport(var.isDeclaredExport()); unwound.setInferedVolatile(var.isInferedVolatile());
unwoundSymbols.put(symbol.getRef(), unwound.getRef()); unwound.setDeclaredRegister((var.getDeclaredRegister()));
} else if(symbol instanceof Variable && ((Variable) symbol).isIntermediate()) { unwound.setDeclaredExport(var.isDeclaredExport());
Variable unwound = procedure.addVariableIntermediate(); unwoundSymbols.put(symbol.getRef(), unwound.getRef());
unwoundSymbols.put(symbol.getRef(), unwound.getRef()); } else if(variable.isIntermediate()) {
} else if(symbol instanceof BlockScope) { 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! // Recurse!
unwindSubScope((Scope) symbol, procedure, unwoundSymbols); unwindSubScope((Scope) symbol, procedure, unwoundSymbols);
} else { } 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. * Find a suitable name for the symbol in the surrounding procedure.
* Avoids clashes with other symbols already in the procedure * Avoids clashes with other symbols already in the procedure
*
* @param procedure The procedure * @param procedure The procedure
* @param symbol The symbol to find a good ,ocal name for * @param symbol The symbol to find a good ,ocal name for
* @return An unused local name * @return An unused local name
@ -101,8 +111,8 @@ public class Pass1UnwindBlockScopes extends Pass1Base {
private String findLocalName(Procedure procedure, Symbol symbol) { private String findLocalName(Procedure procedure, Symbol symbol) {
String name = symbol.getLocalName(); String name = symbol.getLocalName();
int idx = 0; int idx = 0;
while(procedure.getLocalSymbol(name)!=null) { while(procedure.getLocalSymbol(name) != null) {
name = symbol.getLocalName()+(++idx); name = symbol.getLocalName() + (++idx);
} }
return name; return name;
} }

View File

@ -43,7 +43,7 @@ public class Pass2AssertSymbols extends Pass2SsaAssertion {
Collection<Symbol> tableSymbols = getScope().getAllSymbols(true); Collection<Symbol> tableSymbols = getScope().getAllSymbols(true);
for(Symbol tableSymbol : tableSymbols) { 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 ConstantVar) continue;
if(tableSymbol instanceof StructDefinition) continue; if(tableSymbol instanceof StructDefinition) continue;
if(tableSymbol instanceof EnumDefinition) continue; if(tableSymbol instanceof EnumDefinition) continue;