diff --git a/src/main/java/dk/camelot64/kickc/asm/AsmFormat.java b/src/main/java/dk/camelot64/kickc/asm/AsmFormat.java index 2162270c8..d7073d0bb 100644 --- a/src/main/java/dk/camelot64/kickc/asm/AsmFormat.java +++ b/src/main/java/dk/camelot64/kickc/asm/AsmFormat.java @@ -58,8 +58,8 @@ public class AsmFormat { } else if(value instanceof ConstantSymbolPointer) { SymbolRef toSym = ((ConstantSymbolPointer) value).getToSymbol(); Symbol symbol = program.getScope().getSymbol(toSym); - if(symbol instanceof Variable) { - return getAsmParamName((Variable) symbol, codeScope); + if(symbol instanceof SymbolVariable) { + return getAsmParamName((SymbolVariable) symbol, codeScope); } else if(symbol instanceof Procedure) { return getAsmParamName((Procedure) symbol, codeScope); } else { diff --git a/src/main/java/dk/camelot64/kickc/model/CallingConventionStack.java b/src/main/java/dk/camelot64/kickc/model/CallingConventionStack.java index 67fb4546d..6da8069d5 100644 --- a/src/main/java/dk/camelot64/kickc/model/CallingConventionStack.java +++ b/src/main/java/dk/camelot64/kickc/model/CallingConventionStack.java @@ -36,7 +36,7 @@ public class CallingConventionStack { * @param parameter The parameter * @return The constant variable */ - public static ConstantRef getParameterOffsetConstant(Procedure procedure, Variable parameter) { + public static ConstantRef getParameterOffsetConstant(Procedure procedure, SymbolVariable parameter) { String paramOffsetConstantName = getParameterOffsetConstantName(parameter.getName()); ConstantVar paramOffsetConstant = procedure.getConstant(paramOffsetConstantName); if(paramOffsetConstant == null) { @@ -80,7 +80,7 @@ public class CallingConventionStack { */ public static long getParametersByteSize(Procedure procedure) { long byteSize = 0; - for(Variable procedureParameter : procedure.getParameters()) { + for(SymbolVariable procedureParameter : procedure.getParameters()) { byteSize += procedureParameter.getType().getSizeBytes(); } return byteSize; @@ -92,9 +92,9 @@ public class CallingConventionStack { * @param parameter The parameter to find offset for * @return The byte offset of the start of the member data */ - public static long getParameterByteOffset(Procedure procedure, Variable parameter) { + public static long getParameterByteOffset(Procedure procedure, SymbolVariable parameter) { long byteOffset = 0; - for(Variable procedureParameter : procedure.getParameters()) { + for(SymbolVariable procedureParameter : procedure.getParameters()) { if(parameter.equals(procedureParameter)) { break; } else { diff --git a/src/main/java/dk/camelot64/kickc/model/LiveRangeEquivalenceClass.java b/src/main/java/dk/camelot64/kickc/model/LiveRangeEquivalenceClass.java index 9c8f94fb0..8b1c8c66e 100644 --- a/src/main/java/dk/camelot64/kickc/model/LiveRangeEquivalenceClass.java +++ b/src/main/java/dk/camelot64/kickc/model/LiveRangeEquivalenceClass.java @@ -1,6 +1,6 @@ package dk.camelot64.kickc.model; -import dk.camelot64.kickc.model.symbols.Variable; +import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.values.VariableRef; import java.util.ArrayList; @@ -121,7 +121,7 @@ public class LiveRangeEquivalenceClass { /** * If all the variables in the equivalence class is versions of the same variable this method returns it. */ - public Variable getSingleVariableBase(Program program) { + public SymbolVariable getSingleVariableBase(Program program) { String fullNameUnversioned = null; for(VariableRef variable : variables) { if(fullNameUnversioned ==null) { @@ -142,7 +142,7 @@ public class LiveRangeEquivalenceClass { */ public boolean hasVolatile(Program program) { for(VariableRef varRef : variables) { - Variable variable = program.getScope().getVariable(varRef); + SymbolVariable variable = program.getScope().getVariable(varRef); if(variable.isVolatile()) { return true; } diff --git a/src/main/java/dk/camelot64/kickc/model/Program.java b/src/main/java/dk/camelot64/kickc/model/Program.java index af4015512..598eb5ad5 100644 --- a/src/main/java/dk/camelot64/kickc/model/Program.java +++ b/src/main/java/dk/camelot64/kickc/model/Program.java @@ -7,7 +7,7 @@ import dk.camelot64.kickc.model.statements.Statement; import dk.camelot64.kickc.model.statements.StatementInfos; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.values.LabelRef; -import dk.camelot64.kickc.model.values.VariableRef; +import dk.camelot64.kickc.model.values.SymbolVariableRef; import dk.camelot64.kickc.passes.calcs.*; import java.nio.file.Path; @@ -61,7 +61,7 @@ public class Program { /** The initial statement sequence generated by the parser. PASS 1 (STATIC) */ private StatementSequence statementSequence; /** Constants identified during pass 1. PASS 1 (STATIC) */ - private Collection earlyIdentifiedConstants; + private Collection earlyIdentifiedConstants; /** Variables modified inside procedures. PASS 1 (STATIC) */ private ProcedureModifiedVars procedureModifiedVars; /** Struct values unwound to individual variables. PASS 1 (STATIC) */ @@ -438,11 +438,11 @@ public class Program { this.registerPotentials = registerPotentials; } - public Collection getEarlyIdentifiedConstants() { + public Collection getEarlyIdentifiedConstants() { return earlyIdentifiedConstants; } - public void setEarlyIdentifiedConstants(Collection earlyIdentifiedConstants) { + public void setEarlyIdentifiedConstants(Collection earlyIdentifiedConstants) { this.earlyIdentifiedConstants = earlyIdentifiedConstants; } diff --git a/src/main/java/dk/camelot64/kickc/model/StructUnwinding.java b/src/main/java/dk/camelot64/kickc/model/StructUnwinding.java index fd2c4f910..cf4cb2ce0 100644 --- a/src/main/java/dk/camelot64/kickc/model/StructUnwinding.java +++ b/src/main/java/dk/camelot64/kickc/model/StructUnwinding.java @@ -1,7 +1,7 @@ package dk.camelot64.kickc.model; import dk.camelot64.kickc.model.values.LValue; -import dk.camelot64.kickc.model.values.SymbolRef; +import dk.camelot64.kickc.model.values.SymbolVariableRef; import dk.camelot64.kickc.model.values.VariableRef; import java.util.ArrayList; @@ -23,7 +23,7 @@ public class StructUnwinding { * @param ref The variable to look for * @return Information about the unwinding. Null if not unwound */ - public VariableUnwinding getVariableUnwinding(VariableRef ref) { + public VariableUnwinding getVariableUnwinding(SymbolVariableRef ref) { return structVariables.get(ref); } diff --git a/src/main/java/dk/camelot64/kickc/model/iterator/ProgramExpressionBinary.java b/src/main/java/dk/camelot64/kickc/model/iterator/ProgramExpressionBinary.java index cd8ff555f..006f80801 100644 --- a/src/main/java/dk/camelot64/kickc/model/iterator/ProgramExpressionBinary.java +++ b/src/main/java/dk/camelot64/kickc/model/iterator/ProgramExpressionBinary.java @@ -10,6 +10,7 @@ import dk.camelot64.kickc.model.statements.StatementConditionalJump; import dk.camelot64.kickc.model.statements.StatementPhiBlock; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.symbols.Scope; +import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.symbols.Variable; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypeInference; @@ -251,7 +252,7 @@ public interface ProgramExpressionBinary extends ProgramExpression { @Override public void addLeftCast(SymbolType toType, ListIterator stmtIt, ScopeRef currentScope, ProgramScope symbols) { if(assignment.getlValue() instanceof VariableRef) { - Variable variable = symbols.getVariable((VariableRef) assignment.getlValue()); + SymbolVariable variable = symbols.getVariable((VariableRef) assignment.getlValue()); if(variable.isInferredType()) variable.setTypeInferred(toType); else @@ -457,7 +458,7 @@ public interface ProgramExpressionBinary extends ProgramExpression { if(getPointerDereferenceIndexed().getIndex() instanceof ConstantValue) { getPointerDereferenceIndexed().setIndex(new ConstantCastValue(toType, (ConstantValue) getPointerDereferenceIndexed().getIndex())); } else if(getPointerDereferenceIndexed().getIndex() instanceof VariableRef) { - Variable variable = symbols.getVariable((VariableRef) getPointerDereferenceIndexed().getIndex()); + SymbolVariable variable = symbols.getVariable((VariableRef) getPointerDereferenceIndexed().getIndex()); if(variable.isInferredType()) variable.setTypeInferred(toType); else @@ -514,7 +515,7 @@ public interface ProgramExpressionBinary extends ProgramExpression { @Override public void addLeftCast(SymbolType toType, ListIterator stmtIt, ScopeRef currentScope, ProgramScope symbols) { - Variable variable = symbols.getVariable(phiVariable.getVariable()); + SymbolVariable variable = symbols.getVariable(phiVariable.getVariable()); if(variable.isInferredType()) variable.setTypeInferred(toType); else @@ -524,7 +525,7 @@ public interface ProgramExpressionBinary extends ProgramExpression { @Override public void addRightCast(SymbolType toType, ListIterator stmtIt, ScopeRef currentScope, ProgramScope symbols) { if(getRight() instanceof VariableRef) { - Variable variable = symbols.getVariable((VariableRef) getRight()); + SymbolVariable variable = symbols.getVariable((VariableRef) getRight()); if(variable.isInferredType()) variable.setTypeInferred(toType); } else if(getRight() instanceof ConstantValue) { diff --git a/src/main/java/dk/camelot64/kickc/model/iterator/ProgramExpressionIterator.java b/src/main/java/dk/camelot64/kickc/model/iterator/ProgramExpressionIterator.java index 14856b072..76018cc92 100644 --- a/src/main/java/dk/camelot64/kickc/model/iterator/ProgramExpressionIterator.java +++ b/src/main/java/dk/camelot64/kickc/model/iterator/ProgramExpressionIterator.java @@ -4,7 +4,7 @@ import dk.camelot64.kickc.model.ControlFlowBlock; import dk.camelot64.kickc.model.Program; import dk.camelot64.kickc.model.statements.*; import dk.camelot64.kickc.model.symbols.Procedure; -import dk.camelot64.kickc.model.symbols.Variable; +import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.values.*; import java.util.List; @@ -69,20 +69,20 @@ public class ProgramExpressionIterator { StatementCall call = (StatementCall) stmt; List paramValues = call.getParameters(); Procedure procedure = program.getScope().getProcedure(call.getProcedure()); - List paramDefs = procedure.getParameters(); + List paramDefs = procedure.getParameters(); if(paramValues != null && paramDefs.size() == paramValues.size()) { for(int i = 0; i < paramDefs.size(); i++) { - handler.execute(new ProgramExpressionBinary.ProgramExpressionBinaryCallParameter(paramDefs.get(i).getRef(), new ProgramValue.CallParameter(call, i)), stmt, stmtIt, block); + handler.execute(new ProgramExpressionBinary.ProgramExpressionBinaryCallParameter((VariableRef) paramDefs.get(i).getRef(), new ProgramValue.CallParameter(call, i)), stmt, stmtIt, block); } } } else if(stmt instanceof StatementCallPrepare) { StatementCallPrepare call = (StatementCallPrepare) stmt; List paramValues = call.getParameters(); Procedure procedure = program.getScope().getProcedure(call.getProcedure()); - List paramDefs = procedure.getParameters(); + List paramDefs = procedure.getParameters(); if(paramValues != null && paramDefs.size() == paramValues.size()) { for(int i = 0; i < paramDefs.size(); i++) { - handler.execute(new ProgramExpressionBinary.ProgramExpressionBinaryCallParameter(paramDefs.get(i).getRef(), new ProgramValue.CallPrepareParameter(call, i)), stmt, stmtIt, block); + handler.execute(new ProgramExpressionBinary.ProgramExpressionBinaryCallParameter((VariableRef) paramDefs.get(i).getRef(), new ProgramValue.CallPrepareParameter(call, i)), stmt, stmtIt, block); } } } diff --git a/src/main/java/dk/camelot64/kickc/model/symbols/Procedure.java b/src/main/java/dk/camelot64/kickc/model/symbols/Procedure.java index cd256cd54..cb17b544d 100644 --- a/src/main/java/dk/camelot64/kickc/model/symbols/Procedure.java +++ b/src/main/java/dk/camelot64/kickc/model/symbols/Procedure.java @@ -92,17 +92,17 @@ public class Procedure extends Scope { return returnType; } - public List getParameters() { - ArrayList parameters = new ArrayList<>(); + public List getParameters() { + ArrayList parameters = new ArrayList<>(); for(String name : parameterNames) { parameters.add(this.getVariable(name)); } return parameters; } - public void setParameters(List parameters) { + public void setParameters(List parameters) { this.parameterNames = new ArrayList<>(); - for(Variable parameter : parameters) { + for(SymbolVariable parameter : parameters) { add(parameter); parameterNames.add(parameter.getLocalName()); } @@ -215,7 +215,7 @@ public class Procedure extends Scope { res.append("("); boolean first = true; if(parameterNames != null) { - for(Variable parameter : getParameters()) { + for(SymbolVariable parameter : getParameters()) { if(!first) res.append(" , "); first = false; res.append(parameter.toString(program)); diff --git a/src/main/java/dk/camelot64/kickc/model/symbols/Scope.java b/src/main/java/dk/camelot64/kickc/model/symbols/Scope.java index 614a41a96..ebb9f8555 100644 --- a/src/main/java/dk/camelot64/kickc/model/symbols/Scope.java +++ b/src/main/java/dk/camelot64/kickc/model/symbols/Scope.java @@ -114,8 +114,8 @@ public abstract class Scope implements Symbol, Serializable { * @param unversioned The unversioned PHI-master variable * @return All versions of the variable */ - public Collection getVersions(Variable unversioned) { - LinkedHashSet versions = new LinkedHashSet<>(); + public Collection getVersions(SymbolVariable unversioned) { + LinkedHashSet versions = new LinkedHashSet<>(); for(Symbol symbol : symbols.values()) { if(symbol instanceof Variable) { if(((Variable) symbol).isStoragePhiVersion()) { @@ -163,11 +163,11 @@ public abstract class Scope implements Symbol, Serializable { return symbols.get(name); } - public Variable getVariable(String name) { - return (Variable) getSymbol(name); + public SymbolVariable getVariable(String name) { + return (SymbolVariable) getSymbol(name); } - public Variable getVariable(VariableRef variableRef) { + public SymbolVariable getVariable(SymbolVariableRef variableRef) { return getVariable(variableRef.getFullName()); } diff --git a/src/main/java/dk/camelot64/kickc/model/symbols/SymbolVariable.java b/src/main/java/dk/camelot64/kickc/model/symbols/SymbolVariable.java index 42740c24c..401cb1004 100644 --- a/src/main/java/dk/camelot64/kickc/model/symbols/SymbolVariable.java +++ b/src/main/java/dk/camelot64/kickc/model/symbols/SymbolVariable.java @@ -6,6 +6,7 @@ import dk.camelot64.kickc.model.Program; import dk.camelot64.kickc.model.Registers; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.values.ConstantValue; +import dk.camelot64.kickc.model.values.SymbolVariableRef; import java.util.ArrayList; import java.util.List; @@ -112,9 +113,10 @@ public abstract class SymbolVariable implements Symbol { setFullName(); if(isStoragePhiMaster()) this.nextPhiVersionNumber = 0; - } + public abstract SymbolVariableRef getRef(); + private void setFullName() { String scopeName = (scope == null) ? "" : scope.getFullName(); fullName = (scopeName.length() > 0) ? scopeName + "::" + name : name; @@ -138,7 +140,7 @@ public abstract class SymbolVariable implements Symbol { * * @return The original variable. Null if this is not a version. */ - public Variable getVersionOf() { + public SymbolVariable getVersionOf() { if(!isStoragePhiVersion()) throw new InternalError("Cannot get master for non-PHI version variable " + this.toString()); String name = getName(); diff --git a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java index fe5231b43..b9371fecb 100644 --- a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java +++ b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java @@ -16,7 +16,7 @@ public class SymbolTypeInference { public static SymbolType inferType(ProgramScope symbols, RValue rValue) { SymbolType type = null; if(rValue instanceof VariableRef) { - Variable variable = symbols.getVariable((VariableRef) rValue); + SymbolVariable variable = symbols.getVariable((VariableRef) rValue); type = variable.getType(); } else if(rValue instanceof ConstantRef) { ConstantVar constVar = symbols.getConstant((ConstantRef) rValue); @@ -107,7 +107,7 @@ public class SymbolTypeInference { if(structType instanceof SymbolTypeStruct) { String typeName = ((SymbolTypeStruct) structType).getStructTypeName(); StructDefinition structDefinition = symbols.getStructDefinition(typeName); - Variable structMember = structDefinition.getVariable(structMemberRef.getMemberName()); + SymbolVariable structMember = structDefinition.getVariable(structMemberRef.getMemberName()); return structMember.getType(); } else { throw new CompileError("Dot applied to non-struct "+ structMemberRef.getStruct().toString()); diff --git a/src/main/java/dk/camelot64/kickc/model/values/ConstantRef.java b/src/main/java/dk/camelot64/kickc/model/values/ConstantRef.java index 22a770142..9135ddbfd 100644 --- a/src/main/java/dk/camelot64/kickc/model/values/ConstantRef.java +++ b/src/main/java/dk/camelot64/kickc/model/values/ConstantRef.java @@ -2,6 +2,7 @@ package dk.camelot64.kickc.model.values; import dk.camelot64.kickc.model.symbols.ConstantVar; import dk.camelot64.kickc.model.symbols.ProgramScope; +import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.types.SymbolType; /** A reference to a named Constant (in the symbol table) */ @@ -13,7 +14,7 @@ public class ConstantRef extends SymbolVariableRef implements ConstantValue { @Override public SymbolType getType(ProgramScope scope) { - ConstantVar constant = scope.getConstant(this); + SymbolVariable constant = scope.getVariable(this); return constant.getType(); } diff --git a/src/main/java/dk/camelot64/kickc/model/values/SymbolVariableRef.java b/src/main/java/dk/camelot64/kickc/model/values/SymbolVariableRef.java index be26678a6..3dafc69ed 100644 --- a/src/main/java/dk/camelot64/kickc/model/values/SymbolVariableRef.java +++ b/src/main/java/dk/camelot64/kickc/model/values/SymbolVariableRef.java @@ -7,4 +7,5 @@ public abstract class SymbolVariableRef extends SymbolRef implements RValue { super(fullName); } + } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java index 62a524e8f..783863626 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java @@ -209,16 +209,16 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor parameterList = new ArrayList<>(); + List parameterList = new ArrayList<>(); if(ctx.parameterListDecl() != null) { - parameterList = (List) this.visit(ctx.parameterListDecl()); + parameterList = (List) this.visit(ctx.parameterListDecl()); } procedure.setParameters(parameterList); sequence.addStatement(new StatementProcedureBegin(procedure.getRef(), StatementSource.procedureBegin(ctx), Comment.NO_COMMENTS)); // Add parameter assignments if(Procedure.CallingConvension.STACK_CALL.equals(procedure.getCallingConvension())) { - for(Variable param : parameterList) { - sequence.addStatement(new StatementAssignment(param.getRef(), new ParamValue(param.getRef()), StatementSource.procedureEnd(ctx), Comment.NO_COMMENTS)); + for(SymbolVariable param : parameterList) { + sequence.addStatement(new StatementAssignment((LValue) param.getRef(), new ParamValue((VariableRef) param.getRef()), StatementSource.procedureEnd(ctx), Comment.NO_COMMENTS)); } } if(ctx.stmtSeq() != null) { @@ -1184,7 +1184,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor varDirectives = declVarDirectives; String varName = ctx.NAME().getText(); - Variable lValue; + SymbolVariable lValue; if(varType != null) { try { lValue = getCurrentScope().addVariablePhiMaster(varName, varType, defaultMemoryArea, currentDataSegment); @@ -1210,7 +1210,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor comments = ensureUnusedComments(getCommentsSymbol(stmtForCtx)); @@ -1221,7 +1221,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor declParameters = procedure.getParameters(); + List declParameters = procedure.getParameters(); List callParameters = call.getParameters(); if(callParameters.size()!=declParameters.size()) { throw new CompileError("Wrong number of parameters in call "+call.toString(getProgram(), false)+" expected "+procedure.toString(getProgram()), statement); } for(int i = 0; i < declParameters.size(); i++) { - Variable declParameter = declParameters.get(i); + SymbolVariable declParameter = declParameters.get(i); RValue callParameter = callParameters.get(i); SymbolType callParameterType = SymbolTypeInference.inferType(getScope(), callParameter); SymbolType declParameterType = declParameter.getType(); diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1AssertUsedVars.java b/src/main/java/dk/camelot64/kickc/passes/Pass1AssertUsedVars.java index 600bcbbf5..bc4e94721 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1AssertUsedVars.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1AssertUsedVars.java @@ -51,7 +51,7 @@ public class Pass1AssertUsedVars extends Pass1Base { * @param defined Variables already assigned a value at the point of the first execution of the block * @param visited Blocks already visited */ - public void assertUsedVars(ControlFlowBlock block, LabelRef predecessor, VariableReferenceInfos referenceInfos, Collection defined, Collection visited) { + public void assertUsedVars(ControlFlowBlock block, LabelRef predecessor, VariableReferenceInfos referenceInfos, Collection defined, Collection visited) { // If the block has a phi statement it is always examined (to not skip any of the predecessor checks) assertUsedVarsPhi(block, predecessor, referenceInfos, defined); // If we have already visited the block - skip it @@ -113,7 +113,7 @@ public class Pass1AssertUsedVars extends Pass1Base { * @param visited Blocks already visited */ - private void assertUsedVarsPhi(ControlFlowBlock block, LabelRef predecessor, VariableReferenceInfos referenceInfos, Collection defined) { + private void assertUsedVarsPhi(ControlFlowBlock block, LabelRef predecessor, VariableReferenceInfos referenceInfos, Collection defined) { if(predecessor != null && block.hasPhiBlock()) { StatementPhiBlock phiBlock = block.getPhiBlock(); ArrayList used = new ArrayList<>(); diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1EarlyConstantIdentification.java b/src/main/java/dk/camelot64/kickc/passes/Pass1EarlyConstantIdentification.java index 818d7c6e2..74c0e3a04 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1EarlyConstantIdentification.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1EarlyConstantIdentification.java @@ -11,6 +11,7 @@ import dk.camelot64.kickc.model.symbols.Scope; import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.symbols.Variable; import dk.camelot64.kickc.model.values.ConstantValue; +import dk.camelot64.kickc.model.values.SymbolVariableRef; import dk.camelot64.kickc.model.values.VariableRef; import java.util.ArrayList; @@ -26,7 +27,7 @@ public class Pass1EarlyConstantIdentification extends Pass1Base { @Override public boolean step() { - Collection earlyConstants = new ArrayList<>(); + Collection earlyConstants = new ArrayList<>(); for(Variable variable : getProgram().getScope().getAllVariables(true)) { VariableRef variableRef = variable.getRef(); if(!variable.isDeclaredConstant() && !variable.isVolatile() && !variableRef.isIntermediate()) { @@ -64,10 +65,10 @@ public class Pass1EarlyConstantIdentification extends Pass1Base { * @return true if the variable is a procedure parameter */ public boolean isParameter(VariableRef variableRef) { - Variable var = getScope().getVariable(variableRef); + SymbolVariable var = getScope().getVariable(variableRef); Scope varScope = var.getScope(); if(varScope instanceof Procedure) { - List parameters = ((Procedure) varScope).getParameters(); + List parameters = ((Procedure) varScope).getParameters(); if(parameters.contains(var)) return true; diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1FixLValuesLoHi.java b/src/main/java/dk/camelot64/kickc/passes/Pass1FixLValuesLoHi.java index 972bddd5d..879d942c7 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1FixLValuesLoHi.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1FixLValuesLoHi.java @@ -3,6 +3,7 @@ package dk.camelot64.kickc.passes; import dk.camelot64.kickc.model.*; import dk.camelot64.kickc.model.operators.Operator; import dk.camelot64.kickc.model.operators.Operators; +import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.values.LvalueIntermediate; import dk.camelot64.kickc.model.values.VariableRef; import dk.camelot64.kickc.model.statements.Statement; @@ -72,7 +73,7 @@ public class Pass1FixLValuesLoHi extends Pass1Base { StatementAssignment intermediateAssignment, Operator loHiOperator) { VariableRef loHiVar = (VariableRef) intermediateAssignment.getrValue2(); - Variable intermediateVar = programScope.getVariable(intermediate.getVariable()); + SymbolVariable intermediateVar = programScope.getVariable(intermediate.getVariable()); Scope currentScope = intermediateVar.getScope(); // Let assignment put value into a tmp Var Variable tmpVar = currentScope.addVariableIntermediate(); diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1GenerateSingleStaticAssignmentForm.java b/src/main/java/dk/camelot64/kickc/passes/Pass1GenerateSingleStaticAssignmentForm.java index 00c3d8e30..daca38e4b 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1GenerateSingleStaticAssignmentForm.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1GenerateSingleStaticAssignmentForm.java @@ -7,10 +7,7 @@ import dk.camelot64.kickc.model.Program; import dk.camelot64.kickc.model.iterator.ProgramValue; import dk.camelot64.kickc.model.iterator.ProgramValueIterator; import dk.camelot64.kickc.model.statements.*; -import dk.camelot64.kickc.model.symbols.Procedure; -import dk.camelot64.kickc.model.symbols.Scope; -import dk.camelot64.kickc.model.symbols.Symbol; -import dk.camelot64.kickc.model.symbols.Variable; +import dk.camelot64.kickc.model.symbols.*; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypeArray; import dk.camelot64.kickc.model.values.*; @@ -79,8 +76,8 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base { * @param source The statement source - usable for error messages */ private void versionAssignment(VariableRef lValueRef, ProgramValue programLValue, StatementSource source) { - Collection earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants(); - Variable assignedVar = getScope().getVariable(lValueRef); + Collection earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants(); + SymbolVariable assignedVar = getScope().getVariable(lValueRef); if(assignedVar.isStoragePhiMaster()) { if(assignedVar.isDeclaredConstant() || earlyIdentifiedConstants.contains(assignedVar.getRef())) throw new InternalError("Error! Constants can not be versioned ", source); @@ -95,16 +92,16 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base { private void versionAllUses() { for(ControlFlowBlock block : getGraph().getAllBlocks()) { // Newest version of variables in the block. - Map blockVersions = new LinkedHashMap<>(); + Map blockVersions = new LinkedHashMap<>(); // New phi functions introduced in the block to create versions of variables. - Map blockNewPhis = new LinkedHashMap<>(); + Map blockNewPhis = new LinkedHashMap<>(); ProgramValueIterator.execute(block, (programValue, currentStmt, stmtIt, currentBlock) -> { if(programValue instanceof ProgramValue.ProgramValueParamValue) { // Call parameter values should not be versioned return; } Value value = programValue.get(); - Variable version = findOrCreateVersion(value, blockVersions, blockNewPhis); + SymbolVariable version = findOrCreateVersion(value, blockVersions, blockNewPhis); if(version != null) { programValue.set(version.getRef()); } @@ -127,12 +124,12 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base { if(currentStmt instanceof StatementAssignment) { LValue lValue = ((StatementAssignment) currentStmt).getlValue(); if(lValue instanceof VariableRef) { - Variable assignedVar = Pass1GenerateSingleStaticAssignmentForm.this.getScope().getVariable((VariableRef) lValue); + SymbolVariable assignedVar = Pass1GenerateSingleStaticAssignmentForm.this.getScope().getVariable((VariableRef) lValue); SymbolType assignedVarType = assignedVar.getType(); if(assignedVarType instanceof SymbolTypeArray) { SymbolTypeArray assignedArrayType = (SymbolTypeArray) assignedVarType; RValue arraySize = assignedArrayType.getSize(); - Variable vrs = findOrCreateVersion(arraySize, blockVersions, blockNewPhis); + SymbolVariable vrs = findOrCreateVersion(arraySize, blockVersions, blockNewPhis); if(vrs != null) { assignedArrayType.setSize(vrs.getRef()); } @@ -141,15 +138,15 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base { } }); // Add new Phi functions to block - for(Variable symbol : blockNewPhis.keySet()) { - block.getPhiBlock().addPhiVariable(blockNewPhis.get(symbol).getRef()); + for(SymbolVariable symbol : blockNewPhis.keySet()) { + block.getPhiBlock().addPhiVariable((VariableRef) blockNewPhis.get(symbol).getRef()); } } } - private void updateBlockVersions(VariableRef lValue, Map blockVersions) { + private void updateBlockVersions(VariableRef lValue, Map blockVersions) { VariableRef lValueRef = lValue; - Variable variable = Pass1GenerateSingleStaticAssignmentForm.this.getScope().getVariable(lValueRef); + SymbolVariable variable = Pass1GenerateSingleStaticAssignmentForm.this.getScope().getVariable(lValueRef); if(variable.isStoragePhiVersion()) { blockVersions.put(variable.getVersionOf(), variable); } @@ -164,21 +161,21 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base { * @param blockNewPhis New versions to be created as phi-functions. Modified if a new phi-function needs to be created. * @return Null if the rValue does not need versioning. The versioned symbol to use if it does. */ - private Variable findOrCreateVersion( + private SymbolVariable findOrCreateVersion( Value rValue, - Map blockVersions, - Map blockNewPhis) { - Collection earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants(); - Variable version = null; + Map blockVersions, + Map blockNewPhis) { + Collection earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants(); + SymbolVariable version = null; if(rValue instanceof VariableRef) { - Variable rValueVar = getScope().getVariable((VariableRef) rValue); + SymbolVariable rValueVar = getScope().getVariable((VariableRef) rValue); if(rValueVar.isStoragePhiMaster()) { // rValue needs versioning - look for version in statements - Variable rSymbol = rValueVar; + SymbolVariable rSymbol = rValueVar; if(rSymbol.isDeclaredConstant() || earlyIdentifiedConstants.contains(rSymbol.getRef())) { // A constant - find the single created version Scope scope = rSymbol.getScope(); - Collection versions = scope.getVersions(rSymbol); + Collection versions = scope.getVersions(rSymbol); if(versions.size() != 1) { throw new CompileError("Error! Constants must have exactly one version " + rSymbol); } @@ -208,8 +205,8 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base { * false if new phis were added, meaning another iteration is needed. */ private boolean completePhiFunctions() { - Map> newPhis = new LinkedHashMap<>(); - Map> symbolMap = buildSymbolMap(); + Map> newPhis = new LinkedHashMap<>(); + Map> symbolMap = buildSymbolMap(); for(ControlFlowBlock block : getGraph().getAllBlocks()) { for(Statement statement : block.getStatements()) { @@ -218,19 +215,19 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base { for(StatementPhiBlock.PhiVariable phiVariable : phiBlock.getPhiVariables()) { if(phiVariable.isEmpty()) { VariableRef phiLValVarRef = phiVariable.getVariable(); - Variable versioned = getScope().getVariable(phiLValVarRef); - Variable unversioned = versioned.getVersionOf(); + SymbolVariable versioned = getScope().getVariable(phiLValVarRef); + SymbolVariable unversioned = versioned.getVersionOf(); List predecessors = getPhiPredecessors(block, getProgram()); for(ControlFlowBlock predecessor : predecessors) { LabelRef predecessorLabel = predecessor.getLabel(); - Map predecessorMap = symbolMap.get(predecessorLabel); - Variable previousSymbol = null; + Map predecessorMap = symbolMap.get(predecessorLabel); + SymbolVariable previousSymbol = null; if(predecessorMap != null) { previousSymbol = predecessorMap.get(unversioned); } if(previousSymbol == null) { // No previous symbol found in predecessor block. Look in new phi functions. - Map predecessorNewPhis = newPhis.get(predecessorLabel); + Map predecessorNewPhis = newPhis.get(predecessorLabel); if(predecessorNewPhis == null) { predecessorNewPhis = new LinkedHashMap<>(); newPhis.put(predecessorLabel, predecessorNewPhis); @@ -251,12 +248,12 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base { } // Ads new phi functions to blocks for(ControlFlowBlock block : getGraph().getAllBlocks()) { - Map blockNewPhis = newPhis.get(block.getLabel()); + Map blockNewPhis = newPhis.get(block.getLabel()); if(blockNewPhis != null) { - for(Variable symbol : blockNewPhis.keySet()) { + for(SymbolVariable symbol : blockNewPhis.keySet()) { StatementPhiBlock phiBlock = block.getPhiBlock(); - Variable variable = blockNewPhis.get(symbol); - phiBlock.addPhiVariable(variable.getRef()); + SymbolVariable variable = blockNewPhis.get(symbol); + phiBlock.addPhiVariable((VariableRef) variable.getRef()); } } } @@ -293,8 +290,8 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base { * Builds a map of all which versions each symbol has in each block. * Maps Control Flow Block Label -> ( Unversioned Symbol -> Versioned Symbol) for all relevant symbols. */ - private Map> buildSymbolMap() { - Map> symbolMap = new LinkedHashMap<>(); + private Map> buildSymbolMap() { + Map> symbolMap = new LinkedHashMap<>(); for(ControlFlowBlock block : getGraph().getAllBlocks()) { for(Statement statement : block.getStatements()) { if(statement instanceof StatementLValue) { @@ -311,14 +308,14 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base { return symbolMap; } - private void addSymbolToMap(LValue lValue, ControlFlowBlock block, Map> symbolMap) { + private void addSymbolToMap(LValue lValue, ControlFlowBlock block, Map> symbolMap) { if(lValue instanceof VariableRef) { - Variable lValueVar = getScope().getVariable((VariableRef) lValue); + SymbolVariable lValueVar = getScope().getVariable((VariableRef) lValue); if(lValueVar.isStoragePhiVersion()) { - Variable versioned = lValueVar; + SymbolVariable versioned = lValueVar; LabelRef label = block.getLabel(); - Variable unversioned = versioned.getVersionOf(); - Map blockMap = symbolMap.get(label); + SymbolVariable unversioned = versioned.getVersionOf(); + Map blockMap = symbolMap.get(label); if(blockMap == null) { blockMap = new LinkedHashMap<>(); symbolMap.put(label, blockMap); diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1PointerSizeofFix.java b/src/main/java/dk/camelot64/kickc/passes/Pass1PointerSizeofFix.java index 6bf25d1b8..b32c4d03f 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1PointerSizeofFix.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1PointerSizeofFix.java @@ -11,6 +11,7 @@ import dk.camelot64.kickc.model.statements.Statement; import dk.camelot64.kickc.model.statements.StatementAssignment; import dk.camelot64.kickc.model.symbols.StructDefinition; import dk.camelot64.kickc.model.symbols.Symbol; +import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.symbols.Variable; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypeInference; @@ -170,7 +171,7 @@ public class Pass1PointerSizeofFix extends Pass1Base { private SymbolTypePointer getPointerType(RValue pointer) { if(pointer instanceof VariableRef) { VariableRef varRef = (VariableRef) pointer; - Variable variable = getScope().getVariable(varRef); + SymbolVariable variable = getScope().getVariable(varRef); SymbolType type = variable.getType(); if(type instanceof SymbolTypePointer) { return (SymbolTypePointer) type; diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1ProcedureCallParameters.java b/src/main/java/dk/camelot64/kickc/passes/Pass1ProcedureCallParameters.java index 79bbc531b..bdebc4365 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1ProcedureCallParameters.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1ProcedureCallParameters.java @@ -59,21 +59,21 @@ public class Pass1ProcedureCallParameters extends ControlFlowGraphCopyVisitor { return copyCall; } - List parameterDecls = procedure.getParameters(); + List parameterDecls = procedure.getParameters(); List parameterValues = origCall.getParameters(); if(parameterDecls.size()!=parameterValues.size()) { throw new CompileError("Wrong number of parameters in call "+origCall.toString(program, false)+" expected "+procedure.toString(program), origCall); } for(int i = 0; i < parameterDecls.size(); i++) { - Variable parameterDecl = parameterDecls.get(i); + SymbolVariable parameterDecl = parameterDecls.get(i); RValue parameterValue = parameterValues.get(i); - addStatementToCurrentBlock(new StatementAssignment(parameterDecl.getRef(), parameterValue, origCall.getSource(), Comment.NO_COMMENTS)); + addStatementToCurrentBlock(new StatementAssignment((LValue) parameterDecl.getRef(), parameterValue, origCall.getSource(), Comment.NO_COMMENTS)); } String procedureName = origCall.getProcedureName(); - Variable procReturnVar = procedure.getVariable("return"); + SymbolVariable procReturnVar = procedure.getVariable("return"); LValue procReturnVarRef = null; if(procReturnVar != null) { - procReturnVarRef = procReturnVar.getRef(); + procReturnVarRef = (LValue) procReturnVar.getRef(); // Special handing of struct value returns if(procReturnVar.getType() instanceof SymbolTypeStruct) { StructUnwinding.VariableUnwinding returnVarUnwinding = program.getStructUnwinding().getVariableUnwinding((VariableRef) procReturnVarRef); @@ -108,7 +108,7 @@ public class Pass1ProcedureCallParameters extends ControlFlowGraphCopyVisitor { LValue lValue = origCall.getlValue(); if(lValue instanceof VariableRef) { VariableRef lValueRef = (VariableRef) lValue; - Variable lValueVar = getScope().getVariable(lValueRef); + SymbolVariable lValueVar = getScope().getVariable(lValueRef); lValueVar.getScope().remove(lValueVar); } } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1ProcedureInline.java b/src/main/java/dk/camelot64/kickc/passes/Pass1ProcedureInline.java index eaf59d483..3ea68397e 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1ProcedureInline.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1ProcedureInline.java @@ -110,9 +110,9 @@ public class Pass1ProcedureInline extends Pass1Base { blocksIt.add(restBlock); // Generate return assignment if(!procedure.getReturnType().equals(SymbolType.VOID)) { - Variable procReturnVar = procedure.getVariable("return"); + SymbolVariable procReturnVar = procedure.getVariable("return"); String inlinedReturnVarName = getInlineSymbolName(procedure, procReturnVar, serial); - Variable inlinedReturnVar = callScope.getVariable(inlinedReturnVarName); + SymbolVariable inlinedReturnVar = callScope.getVariable(inlinedReturnVarName); restBlock.addStatement(new StatementAssignment(call.getlValue(), inlinedReturnVar.getRef(), call.getSource(), Comment.NO_COMMENTS)); } else { // Remove the tmp var receiving the result @@ -246,10 +246,10 @@ public class Pass1ProcedureInline extends Pass1Base { Value rValue = programValue.get(); if(rValue instanceof VariableRef) { VariableRef procVarRef = (VariableRef) rValue; - Variable procVar = Pass1ProcedureInline.this.getScope().getVariable(procVarRef); + SymbolVariable procVar = Pass1ProcedureInline.this.getScope().getVariable(procVarRef); if(procVar.getScope().equals(procedure)) { String inlineSymbolName = Pass1ProcedureInline.this.getInlineSymbolName(procedure, procVar, serial); - Variable inlineVar = callScope.getVariable(inlineSymbolName); + SymbolVariable inlineVar = callScope.getVariable(inlineSymbolName); programValue.set(inlineVar.getRef()); } } else if(rValue instanceof PointerDereferenceSimple) { @@ -274,14 +274,14 @@ public class Pass1ProcedureInline extends Pass1Base { * @param serial The serial number (counted up for each inlined call to the same function within the called calling scope). */ private void inlineParameterAssignments(ListIterator statementsIt, StatementCall call, Procedure procedure, Scope callScope, int serial) { - List parameterDecls = procedure.getParameters(); + List parameterDecls = procedure.getParameters(); List parameterValues = call.getParameters(); for(int i = 0; i < parameterDecls.size(); i++) { - Variable parameterDecl = parameterDecls.get(i); + SymbolVariable parameterDecl = parameterDecls.get(i); String inlineParameterVarName = getInlineSymbolName(procedure, parameterDecl, serial); - Variable inlineParameterVar = callScope.getVariable(inlineParameterVarName); + SymbolVariable inlineParameterVar = callScope.getVariable(inlineParameterVarName); RValue parameterValue = parameterValues.get(i); - statementsIt.add(new StatementAssignment(inlineParameterVar.getRef(), parameterValue, call.getSource(), Comment.NO_COMMENTS)); + statementsIt.add(new StatementAssignment((VariableRef)inlineParameterVar.getRef(), parameterValue, call.getSource(), Comment.NO_COMMENTS)); } } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindStructValues.java b/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindStructValues.java index 09a12a6c1..fcf66f46f 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindStructValues.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindStructValues.java @@ -169,7 +169,7 @@ public class Pass1UnwindStructValues extends Pass1Base { for(Procedure procedure : getScope().getAllProcedures(true)) { ArrayList unwoundParameterNames = new ArrayList<>(); boolean procedureUnwound = false; - for(Variable parameter : procedure.getParameters()) { + for(SymbolVariable parameter : procedure.getParameters()) { if(parameter.getType() instanceof SymbolTypeStruct) { StructUnwinding structUnwinding = getProgram().getStructUnwinding(); StructUnwinding.VariableUnwinding parameterUnwinding = structUnwinding.getVariableUnwinding(parameter.getRef()); @@ -267,7 +267,7 @@ public class Pass1UnwindStructValues extends Pass1Base { for(String memberName : memberUnwinding.getMemberNames()) { VariableRef memberVarRef = (VariableRef) memberUnwinding.getMemberUnwinding(memberName); membersUnwound.add(memberVarRef); - Variable memberVar = getScope().getVariable(memberVarRef); + SymbolVariable memberVar = getScope().getVariable(memberVarRef); Statement initStmt = Pass0GenerateStatementSequence.createDefaultInitializationStatement(memberVarRef, memberVar.getType(), assignment.getSource(), Comment.NO_COMMENTS); stmtIt.add(initStmt); getLog().append("Adding struct value member variable default initializer " + initStmt.toString(getProgram(), false)); diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass2AliasElimination.java b/src/main/java/dk/camelot64/kickc/passes/Pass2AliasElimination.java index 071da25d9..043875b32 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass2AliasElimination.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass2AliasElimination.java @@ -4,6 +4,7 @@ import dk.camelot64.kickc.model.ControlFlowBlock; import dk.camelot64.kickc.model.Program; import dk.camelot64.kickc.model.statements.*; import dk.camelot64.kickc.model.symbols.ProgramScope; +import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.symbols.Variable; import dk.camelot64.kickc.model.values.*; @@ -92,7 +93,7 @@ public class Pass2AliasElimination extends Pass2SsaOptimization { boolean sameBaseVar = true; String unversionedFullName = null; for(VariableRef variableRef : aliasSet.getVars()) { - Variable variable = programScope.getVariable(variableRef); + SymbolVariable variable = programScope.getVariable(variableRef); if(variable.isVolatile() || variable.isStorageLoadStore()) { anyVolatile = true; } @@ -419,7 +420,7 @@ public class Pass2AliasElimination extends Pass2SsaOptimization { for(VariableRef var : vars) { String name; int score; - Variable variable = scope.getVariable(var); + SymbolVariable variable = scope.getVariable(var); if(variable.isDeclaredConstant() || variable.isStorageConstant()) { name = var.getFullNameUnversioned(); score = 100; diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass2ArrayInStructInlining.java b/src/main/java/dk/camelot64/kickc/passes/Pass2ArrayInStructInlining.java index a7a28f8b2..f4cd3b3ac 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass2ArrayInStructInlining.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass2ArrayInStructInlining.java @@ -4,6 +4,7 @@ import dk.camelot64.kickc.model.Program; import dk.camelot64.kickc.model.iterator.ProgramValue; import dk.camelot64.kickc.model.iterator.ProgramValueIterator; import dk.camelot64.kickc.model.symbols.ConstantVar; +import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.symbols.Variable; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypeArray; @@ -58,7 +59,7 @@ public class Pass2ArrayInStructInlining extends Pass2SsaOptimization { Value value = programValue.get(); if(programValue instanceof ProgramValue.ProgramValueConstantStructMember) { VariableRef memberRef = ((ProgramValue.ProgramValueConstantStructMember) programValue).getMemberRef(); - Variable structMemberVar = getScope().getVariable(memberRef); + SymbolVariable structMemberVar = getScope().getVariable(memberRef); if(structMemberVar.getType() instanceof SymbolTypeArray) { if(((SymbolTypeArray) structMemberVar.getType()).getSize() != null) { if(value instanceof ConstantValue) { diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass2AssertRValues.java b/src/main/java/dk/camelot64/kickc/passes/Pass2AssertRValues.java index 78c12aba7..5f318cae5 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass2AssertRValues.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass2AssertRValues.java @@ -30,7 +30,7 @@ public class Pass2AssertRValues extends Pass2SsaAssertion { } if(rValue instanceof VariableRef) { VariableRef variableRef = (VariableRef) rValue; - Variable variable = getScope().getVariable(variableRef); + SymbolVariable variable = getScope().getVariable(variableRef); if(variable.isStoragePhiMaster()) { throw new CompileError("No unversioned variable references allowed "+currentStmt.toString(getProgram(), false), currentStmt.getSource()); } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass2ConstantIdentification.java b/src/main/java/dk/camelot64/kickc/passes/Pass2ConstantIdentification.java index 47700d918..de9cb9c03 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass2ConstantIdentification.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass2ConstantIdentification.java @@ -12,10 +12,7 @@ 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.statements.StatementPhiBlock; -import dk.camelot64.kickc.model.symbols.ConstantVar; -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.symbols.*; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypeConversion; import dk.camelot64.kickc.model.types.SymbolTypeInference; @@ -44,7 +41,7 @@ public class Pass2ConstantIdentification extends Pass2SsaOptimization { // Update symbol table with the constant value Set constVars = new LinkedHashSet<>(constants.keySet()); for(VariableRef constRef : constVars) { - Variable variable = getProgram().getScope().getVariable(constRef); + SymbolVariable variable = getProgram().getScope().getVariable(constRef); ConstantVariableValue constVarVal = constants.get(constRef); Scope constScope = variable.getScope(); ConstantValue constVal = constVarVal.getConstantValue(); @@ -155,7 +152,7 @@ public class Pass2ConstantIdentification extends Pass2SsaOptimization { LValue lValue = assignment.getlValue(); if(lValue instanceof VariableRef) { VariableRef varRef = (VariableRef) lValue; - Variable var = getScope().getVariable(varRef); + SymbolVariable var = getScope().getVariable(varRef); if(var.isVolatile() || var.isDeclaredNotConstant() || var.isStorageLoadStore()) // Do not examine volatiles and non-versioned variables continue; @@ -171,7 +168,7 @@ public class Pass2ConstantIdentification extends Pass2SsaOptimization { StatementPhiBlock.PhiRValue phiRValue = phiVariable.getValues().get(0); if(getConstant(phiRValue.getrValue()) != null) { VariableRef varRef = phiVariable.getVariable(); - Variable var = getScope().getVariable(varRef); + SymbolVariable var = getScope().getVariable(varRef); if(var.isVolatile() || var.isDeclaredNotConstant() || var.isStorageLoadStore()) // Do not examine volatiles and non-versioned variables continue; diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass2DuplicateRValueIdentification.java b/src/main/java/dk/camelot64/kickc/passes/Pass2DuplicateRValueIdentification.java index 1a7e966ac..4eabd8347 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass2DuplicateRValueIdentification.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass2DuplicateRValueIdentification.java @@ -10,6 +10,7 @@ import dk.camelot64.kickc.model.operators.OperatorCast; import dk.camelot64.kickc.model.operators.Operators; import dk.camelot64.kickc.model.statements.Statement; import dk.camelot64.kickc.model.statements.StatementAssignment; +import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.symbols.Variable; import dk.camelot64.kickc.model.values.ConstantValue; import dk.camelot64.kickc.model.values.PointerDereference; @@ -94,7 +95,7 @@ public class Pass2DuplicateRValueIdentification extends Pass2SsaOptimization { if(programValue.get() instanceof PointerDereference) isVol.set(true); if(programValue.get() instanceof VariableRef) { - Variable variable = getScope().getVariable((VariableRef) programValue.get()); + SymbolVariable variable = getScope().getVariable((VariableRef) programValue.get()); if(variable.isVolatile()) isVol.set(true); } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass2EliminateUnusedBlocks.java b/src/main/java/dk/camelot64/kickc/passes/Pass2EliminateUnusedBlocks.java index 1318877a8..f31b4bc46 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass2EliminateUnusedBlocks.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass2EliminateUnusedBlocks.java @@ -7,10 +7,7 @@ import dk.camelot64.kickc.model.Program; import dk.camelot64.kickc.model.statements.Statement; import dk.camelot64.kickc.model.statements.StatementAssignment; import dk.camelot64.kickc.model.statements.StatementPhiBlock; -import dk.camelot64.kickc.model.symbols.Label; -import dk.camelot64.kickc.model.symbols.Procedure; -import dk.camelot64.kickc.model.symbols.Symbol; -import dk.camelot64.kickc.model.symbols.Variable; +import dk.camelot64.kickc.model.symbols.*; import dk.camelot64.kickc.model.values.*; import java.util.*; @@ -35,14 +32,14 @@ public class Pass2EliminateUnusedBlocks extends Pass2SsaOptimization { LValue lValue = assignment.getlValue(); if(lValue instanceof VariableRef) { getLog().append("Eliminating variable " + lValue.toString(getProgram()) + " from unused block " + block.getLabel()); - Variable variable = getScope().getVariable((VariableRef) lValue); + SymbolVariable variable = getScope().getVariable((VariableRef) lValue); variable.getScope().remove(variable); } } else if(stmt instanceof StatementPhiBlock) { for(StatementPhiBlock.PhiVariable phiVariable : ((StatementPhiBlock) stmt).getPhiVariables()) { VariableRef phiVar = phiVariable.getVariable(); getLog().append("Eliminating variable " + phiVar.toString(getProgram()) + " from unused block " + block.getLabel()); - Variable variable = getScope().getVariable(phiVar); + SymbolVariable variable = getScope().getVariable(phiVar); variable.getScope().remove(variable); } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass2LoopHeadConstantIdentification.java b/src/main/java/dk/camelot64/kickc/passes/Pass2LoopHeadConstantIdentification.java index d343ed7bf..101c0e5f3 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass2LoopHeadConstantIdentification.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass2LoopHeadConstantIdentification.java @@ -5,6 +5,7 @@ import dk.camelot64.kickc.model.iterator.ProgramValueIterator; import dk.camelot64.kickc.model.statements.Statement; import dk.camelot64.kickc.model.statements.StatementConditionalJump; import dk.camelot64.kickc.model.statements.StatementPhiBlock; +import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.symbols.Variable; import dk.camelot64.kickc.model.values.*; import dk.camelot64.kickc.passes.utils.Unroller; @@ -138,7 +139,7 @@ public class Pass2LoopHeadConstantIdentification extends Pass2SsaOptimization { isVol.set(true); } if(programValue.get() instanceof VariableRef) { - Variable variable = getScope().getVariable((VariableRef) programValue.get()); + SymbolVariable variable = getScope().getVariable((VariableRef) programValue.get()); if(variable.isVolatile()) isVol.set(true); } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass2NopCastInlining.java b/src/main/java/dk/camelot64/kickc/passes/Pass2NopCastInlining.java index 619ae841f..c49b60ad0 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass2NopCastInlining.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass2NopCastInlining.java @@ -4,6 +4,7 @@ import dk.camelot64.kickc.model.ControlFlowBlock; import dk.camelot64.kickc.model.Program; import dk.camelot64.kickc.model.statements.Statement; import dk.camelot64.kickc.model.statements.StatementAssignment; +import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.symbols.Variable; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypeInference; @@ -86,8 +87,8 @@ public class Pass2NopCastInlining extends Pass2SsaOptimization { // 3. Delete the cast variable delete.add((SymbolRef) castValue.getValue()); // Change the type of the assignment variable - Variable assignmentVar = getScope().getVariable((VariableRef) assignment.getlValue()); - Variable castVar = getScope().getVariable((VariableRef) castValue.getValue()); + SymbolVariable assignmentVar = getScope().getVariable((VariableRef) assignment.getlValue()); + SymbolVariable castVar = getScope().getVariable((VariableRef) castValue.getValue()); assignmentVar.setType(castVar.getType()); // Remove the assignment stmtIt.remove(); diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass3PhiLifting.java b/src/main/java/dk/camelot64/kickc/passes/Pass3PhiLifting.java index df0897185..44451b1d2 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass3PhiLifting.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass3PhiLifting.java @@ -48,10 +48,10 @@ public class Pass3PhiLifting { //VariableRef rValVarRef = (VariableRef) phiRValue.getrValue(); Variable newVar; if(phiVariable.getVariable().isVersion()) { - Variable lValVar = program.getScope().getVariable(phiVariable.getVariable()); + SymbolVariable lValVar = program.getScope().getVariable(phiVariable.getVariable()); newVar = lValVar.getVersionOf().createVersion(); } else { - Variable lValVar = program.getScope().getVariable(phiVariable.getVariable()); + SymbolVariable lValVar = program.getScope().getVariable(phiVariable.getVariable()); newVar = lValVar.getScope().addVariableIntermediate(); } Symbol phiLValue = programScope.getSymbol(phiVariable.getVariable()); diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass3PhiMemCoalesce.java b/src/main/java/dk/camelot64/kickc/passes/Pass3PhiMemCoalesce.java index f9eba27cd..297c727ef 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass3PhiMemCoalesce.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass3PhiMemCoalesce.java @@ -6,6 +6,7 @@ import dk.camelot64.kickc.model.LiveRangeEquivalenceClassSet; import dk.camelot64.kickc.model.Program; import dk.camelot64.kickc.model.statements.StatementAssignment; import dk.camelot64.kickc.model.statements.StatementPhiBlock; +import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.symbols.Variable; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.values.ConstantValue; @@ -73,8 +74,8 @@ public class Pass3PhiMemCoalesce extends Pass2SsaOptimization { VariableRef phiRVar = (VariableRef) phiRValue.getrValue(); LiveRangeEquivalenceClass rValEquivalenceClass = phiEquivalenceClasses.getOrCreateEquivalenceClass(phiRVar); if(!rValEquivalenceClass.equals(equivalenceClass)) { - Variable var = program.getScope().getVariable(variable); - Variable rVar = program.getScope().getVariable(phiRVar); + SymbolVariable var = program.getScope().getVariable(variable); + SymbolVariable rVar = program.getScope().getVariable(phiRVar); SymbolType varType = var.getType(); SymbolType rVarType = rVar.getType(); if(varType.getSizeBytes()==rVarType.getSizeBytes()) { diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass4CodeGeneration.java b/src/main/java/dk/camelot64/kickc/passes/Pass4CodeGeneration.java index 02889d6ad..0c6ca9626 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass4CodeGeneration.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass4CodeGeneration.java @@ -244,7 +244,7 @@ public class Pass4CodeGeneration { * @param procedureVariable The variable containing the function pointer * @param codeScopeRef The scope containing the code being generated. Used for adding scope to the name when needed (eg. line.x1 when referencing x1 variable inside line scope from outside line scope). */ - private void generateIndirectCall(AsmProgram asm, Variable procedureVariable, ScopeRef codeScopeRef) { + private void generateIndirectCall(AsmProgram asm, SymbolVariable procedureVariable, ScopeRef codeScopeRef) { String varAsmName = AsmFormat.getAsmParamName(procedureVariable, codeScopeRef); indirectCallAsmNames.add(varAsmName); asm.addInstruction("jsr", AsmAddressingMode.ABS, "bi_" + varAsmName, false); @@ -260,10 +260,10 @@ public class Pass4CodeGeneration { StringBuilder signature = new StringBuilder(); signature.append(" ").append(procedure.getLocalName()).append("("); int i = 0; - for(Variable parameter : procedure.getParameters()) { - List versions = new ArrayList<>(procedure.getVersions(parameter)); + for(SymbolVariable parameter : procedure.getParameters()) { + List versions = new ArrayList<>(procedure.getVersions(parameter)); if(versions.size() > 0) { - Variable param = versions.get(0); + SymbolVariable param = versions.get(0); Registers.Register allocation = param.getAllocation(); if(i++ > 0) signature.append(", "); signature.append(param.getType().getTypeName()).append(" "); @@ -575,7 +575,7 @@ public class Pass4CodeGeneration { ConstantStructValue structValue = (ConstantStructValue) value; for(VariableRef memberRef : structValue.getMembers()) { ConstantValue memberValue = structValue.getValue(memberRef); - Variable memberVariable = getScope().getVariable(memberRef); + SymbolVariable memberVariable = getScope().getVariable(memberRef); addChunkData(dataChunk, memberValue, memberVariable.getType(), scopeRef); } } else if(valueType instanceof SymbolTypeArray) { @@ -809,9 +809,9 @@ public class Pass4CodeGeneration { if(Procedure.CallingConvension.STACK_CALL.equals(procedure.getCallingConvension())) { // Push parameters to the stack List callParameters = call.getParameters(); - List procParameters = procedure.getParameters(); + List procParameters = procedure.getParameters(); for(int i = 0; i < procParameters.size(); i++) { - Variable procParameter = procParameters.get(i); + SymbolVariable procParameter = procParameters.get(i); RValue callParameter = callParameters.get(i); SymbolType parameterType = procParameter.getType(); AsmFragmentInstanceSpecFactory asmFragmentInstanceSpecFactory = new AsmFragmentInstanceSpecFactory(new StackPushValue(parameterType), callParameter, program, block.getScope()); @@ -928,16 +928,16 @@ public class Pass4CodeGeneration { asm.addInstruction("jsr", AsmAddressingMode.ABS, AsmFormat.getAsmConstant(program, (ConstantValue) pointer, 99, block.getScope()), false); supported = true; } else if(pointer instanceof VariableRef) { - Variable variable = getScope().getVariable((VariableRef) pointer); + SymbolVariable variable = getScope().getVariable((VariableRef) pointer); generateIndirectCall(asm, variable, block.getScope()); supported = true; } else if(pointer instanceof CastValue && ((CastValue) pointer).getValue() instanceof VariableRef) { - Variable variable = getScope().getVariable((VariableRef) ((CastValue) pointer).getValue()); + SymbolVariable variable = getScope().getVariable((VariableRef) ((CastValue) pointer).getValue()); generateIndirectCall(asm, variable, block.getScope()); supported = true; } } else if(procedure instanceof VariableRef) { - Variable procedureVariable = getScope().getVariable((VariableRef) procedure); + SymbolVariable procedureVariable = getScope().getVariable((VariableRef) procedure); SymbolType procedureVariableType = procedureVariable.getType(); if(procedureVariableType instanceof SymbolTypePointer) { if(((SymbolTypePointer) procedureVariableType).getElementType() instanceof SymbolTypeProcedure) { diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java b/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java index 369eb7536..6a59cdb94 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java @@ -2,6 +2,7 @@ package dk.camelot64.kickc.passes; import dk.camelot64.kickc.model.*; import dk.camelot64.kickc.model.symbols.Procedure; +import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.symbols.Variable; import dk.camelot64.kickc.model.values.ProcedureRef; import dk.camelot64.kickc.model.values.ScopeRef; @@ -109,7 +110,7 @@ public abstract class Pass4MemoryCoalesce extends Pass2Base { private static Collection getEquivalenceClassThreads(LiveRangeEquivalenceClass equivalenceClass, Program program, Collection threadHeads, CallGraph callGraph) { Collection threads = new ArrayList<>(); for(VariableRef varRef : equivalenceClass.getVariables()) { - Variable variable = program.getScope().getVariable(varRef); + SymbolVariable variable = program.getScope().getVariable(varRef); ScopeRef scopeRef = variable.getScope().getRef(); if(scopeRef.equals(ScopeRef.ROOT)) { ProcedureRef mainThreadHead = program.getScope().getProcedure(SymbolRef.MAIN_PROC_NAME).getRef(); @@ -183,8 +184,8 @@ public abstract class Pass4MemoryCoalesce extends Pass2Base { private static boolean canCoalesceVolatile(LiveRangeEquivalenceClass ec1, LiveRangeEquivalenceClass ec2, Program program) { // If any variable inside is volatile only allow coalesceing with itself if(ec1.hasVolatile(program) || ec2.hasVolatile(program)) { - Variable baseVar1 = ec1.getSingleVariableBase(program); - Variable baseVar2 = ec2.getSingleVariableBase(program); + SymbolVariable baseVar1 = ec1.getSingleVariableBase(program); + SymbolVariable baseVar2 = ec2.getSingleVariableBase(program); if(baseVar1 == null || baseVar2 == null) { // One of the equivalence classes have different base variables inside return false; diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass4RegisterUpliftPotentialInitialize.java b/src/main/java/dk/camelot64/kickc/passes/Pass4RegisterUpliftPotentialInitialize.java index 5feabb562..a38b7b8cc 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass4RegisterUpliftPotentialInitialize.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass4RegisterUpliftPotentialInitialize.java @@ -1,6 +1,7 @@ package dk.camelot64.kickc.passes; import dk.camelot64.kickc.model.*; +import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.symbols.Variable; import dk.camelot64.kickc.model.values.VariableRef; @@ -27,7 +28,7 @@ public class Pass4RegisterUpliftPotentialInitialize extends Pass2Base { Registers.Register declaredRegister = null; int bytes = -1; for(VariableRef varRef : equivalenceClass.getVariables()) { - Variable variable = getProgram().getScope().getVariable(varRef); + SymbolVariable variable = getProgram().getScope().getVariable(varRef); if(variable.getDeclaredRegister() != null) { if(declaredRegister != null && !declaredRegister.equals(variable.getDeclaredRegister())) { throw new CompileError("Equivalence class has variables with different declared registers \n" + @@ -77,7 +78,7 @@ public class Pass4RegisterUpliftPotentialInitialize extends Pass2Base { */ private boolean varVolatile(LiveRangeEquivalenceClass equivalenceClass) { for(VariableRef variableRef : equivalenceClass.getVariables()) { - Variable variable = getSymbols().getVariable(variableRef); + SymbolVariable variable = getSymbols().getVariable(variableRef); if(variable.isVolatile() || variable.isStorageLoadStore()) { return true; } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass4RegisterUpliftStatic.java b/src/main/java/dk/camelot64/kickc/passes/Pass4RegisterUpliftStatic.java index 5921d6c45..2ee3da59c 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass4RegisterUpliftStatic.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass4RegisterUpliftStatic.java @@ -1,6 +1,7 @@ package dk.camelot64.kickc.passes; import dk.camelot64.kickc.model.*; +import dk.camelot64.kickc.model.values.SymbolVariableRef; import dk.camelot64.kickc.model.values.VariableRef; import dk.camelot64.kickc.model.symbols.ProgramScope; @@ -113,18 +114,18 @@ public class Pass4RegisterUpliftStatic extends Pass2Base { private void setRegister(RegisterCombination combination, String varFullName, Registers.Register register) { LiveRangeEquivalenceClassSet equivalenceClassSet = getProgram().getLiveRangeEquivalenceClassSet(); ProgramScope scope = getProgram().getScope(); - VariableRef variableRef = scope.getVariable(varFullName).getRef(); - LiveRangeEquivalenceClass equivalenceClass = equivalenceClassSet.getEquivalenceClass(variableRef); + SymbolVariableRef variableRef = scope.getVariable(varFullName).getRef(); + LiveRangeEquivalenceClass equivalenceClass = equivalenceClassSet.getEquivalenceClass((VariableRef) variableRef); combination.setRegister(equivalenceClass, register); } private void collapseEquivalenceClasses(String varFullName1, String varFullName2) { LiveRangeEquivalenceClassSet equivalenceClassSet = getProgram().getLiveRangeEquivalenceClassSet(); ProgramScope scope = getProgram().getScope(); - VariableRef variableRef1 = scope.getVariable(varFullName1).getRef(); - LiveRangeEquivalenceClass equivalenceClass1 = equivalenceClassSet.getEquivalenceClass(variableRef1); - VariableRef variableRef2 = scope.getVariable(varFullName2).getRef(); - LiveRangeEquivalenceClass equivalenceClass2 = equivalenceClassSet.getEquivalenceClass(variableRef2); + SymbolVariableRef variableRef1 = scope.getVariable(varFullName1).getRef(); + LiveRangeEquivalenceClass equivalenceClass1 = equivalenceClassSet.getEquivalenceClass((VariableRef) variableRef1); + SymbolVariableRef variableRef2 = scope.getVariable(varFullName2).getRef(); + LiveRangeEquivalenceClass equivalenceClass2 = equivalenceClassSet.getEquivalenceClass((VariableRef) variableRef2); if(!equivalenceClass1.equals(equivalenceClass2)) { equivalenceClassSet.consolidate(equivalenceClass1, equivalenceClass2); } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass4RegistersFinalize.java b/src/main/java/dk/camelot64/kickc/passes/Pass4RegistersFinalize.java index f2602118e..0f6e23606 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass4RegistersFinalize.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass4RegistersFinalize.java @@ -52,7 +52,7 @@ public class Pass4RegistersFinalize extends Pass2Base { LiveRangeEquivalenceClassSet liveRangeEquivalenceClassSet = getProgram().getLiveRangeEquivalenceClassSet(); for(LiveRangeEquivalenceClass equivalenceClass : liveRangeEquivalenceClassSet.getEquivalenceClasses()) { for(VariableRef variableRef : equivalenceClass.getVariables()) { - Variable variable = getProgram().getScope().getVariable(variableRef); + SymbolVariable variable = getProgram().getScope().getVariable(variableRef); Registers.Register declaredRegister = variable.getDeclaredRegister(); //TODO: Handle register/memory/storage strategy differently! Registers.Register register = declaredRegister; if(declaredRegister !=null) { diff --git a/src/main/java/dk/camelot64/kickc/passes/PassNAssertConstantModification.java b/src/main/java/dk/camelot64/kickc/passes/PassNAssertConstantModification.java index 319c38a9e..d89567de4 100644 --- a/src/main/java/dk/camelot64/kickc/passes/PassNAssertConstantModification.java +++ b/src/main/java/dk/camelot64/kickc/passes/PassNAssertConstantModification.java @@ -5,8 +5,10 @@ import dk.camelot64.kickc.model.ControlFlowBlock; import dk.camelot64.kickc.model.Program; import dk.camelot64.kickc.model.statements.Statement; import dk.camelot64.kickc.model.statements.StatementLValue; +import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.symbols.Variable; import dk.camelot64.kickc.model.values.LValue; +import dk.camelot64.kickc.model.values.SymbolVariableRef; import dk.camelot64.kickc.model.values.VariableRef; import java.util.Collection; @@ -24,7 +26,7 @@ public class PassNAssertConstantModification extends Pass2SsaOptimization { @Override public boolean step() { - Collection earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants(); + Collection earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants(); Set assigned = new HashSet<>(); for(ControlFlowBlock block : getGraph().getAllBlocks()) { for(Statement statement : block.getStatements()) { @@ -32,7 +34,7 @@ public class PassNAssertConstantModification extends Pass2SsaOptimization { LValue lValue = ((StatementLValue) statement).getlValue(); if(lValue instanceof VariableRef) { VariableRef variableRef = (VariableRef) lValue; - Variable variable = getScope().getVariable(variableRef); + SymbolVariable variable = getScope().getVariable(variableRef); if(variable.isStorageConstant() || earlyIdentifiedConstants.contains(variableRef)) { if(assigned.contains(variableRef)) { throw new CompileError("Error! Constants can not be modified", statement.getSource()); diff --git a/src/main/java/dk/camelot64/kickc/passes/PassNCallingConventionStack.java b/src/main/java/dk/camelot64/kickc/passes/PassNCallingConventionStack.java index f765570a8..986ef93d6 100644 --- a/src/main/java/dk/camelot64/kickc/passes/PassNCallingConventionStack.java +++ b/src/main/java/dk/camelot64/kickc/passes/PassNCallingConventionStack.java @@ -24,14 +24,14 @@ public class PassNCallingConventionStack extends Pass2SsaOptimization { @Override public boolean step() { // Offset-constants for all stack-call parameters - Map offsetConstants = new HashMap<>(); + Map offsetConstants = new HashMap<>(); // Introduce STACK_OFFSET constants boolean createStackBase = false; for(Procedure procedure : getScope().getAllProcedures(true)) { if(Procedure.CallingConvension.STACK_CALL.equals(procedure.getCallingConvension())) { // Introduce the parameter offsets - for(Variable parameter : procedure.getParameters()) { + for(SymbolVariable parameter : procedure.getParameters()) { ConstantRef parameterOffsetConstant = CallingConventionStack.getParameterOffsetConstant(procedure, parameter); offsetConstants.put(parameter.getRef(), parameterOffsetConstant); createStackBase = true; diff --git a/src/main/java/dk/camelot64/kickc/passes/PassNEliminateUnusedVars.java b/src/main/java/dk/camelot64/kickc/passes/PassNEliminateUnusedVars.java index 09d89bbe9..f3c439926 100644 --- a/src/main/java/dk/camelot64/kickc/passes/PassNEliminateUnusedVars.java +++ b/src/main/java/dk/camelot64/kickc/passes/PassNEliminateUnusedVars.java @@ -4,10 +4,7 @@ import dk.camelot64.kickc.model.ControlFlowBlock; import dk.camelot64.kickc.model.Program; import dk.camelot64.kickc.model.VariableReferenceInfos; import dk.camelot64.kickc.model.statements.*; -import dk.camelot64.kickc.model.symbols.ConstantVar; -import dk.camelot64.kickc.model.symbols.EnumDefinition; -import dk.camelot64.kickc.model.symbols.Procedure; -import dk.camelot64.kickc.model.symbols.Variable; +import dk.camelot64.kickc.model.symbols.*; import dk.camelot64.kickc.model.types.SymbolTypeStruct; import dk.camelot64.kickc.model.values.LValue; import dk.camelot64.kickc.model.values.StructUnwoundPlaceholder; @@ -42,7 +39,7 @@ public class PassNEliminateUnusedVars extends Pass2SsaOptimization { StatementAssignment assignment = (StatementAssignment) statement; LValue lValue = assignment.getlValue(); if(lValue instanceof VariableRef && referenceInfos.isUnused((VariableRef) lValue)) { - Variable variable = getScope().getVariable((VariableRef) lValue); + SymbolVariable variable = getScope().getVariable((VariableRef) lValue); boolean eliminate = false; if(variable == null) { // Already deleted @@ -74,7 +71,7 @@ public class PassNEliminateUnusedVars extends Pass2SsaOptimization { StatementCall call = (StatementCall) statement; LValue lValue = call.getlValue(); if(lValue instanceof VariableRef && referenceInfos.isUnused((VariableRef) lValue)) { - Variable variable = getScope().getVariable((VariableRef) lValue); + SymbolVariable variable = getScope().getVariable((VariableRef) lValue); if(!variable.isVolatile()) { if(pass2 || getLog().isVerbosePass1CreateSsa()) { getLog().append("Eliminating unused variable - keeping the call " + lValue.toString(getProgram())); @@ -90,7 +87,7 @@ public class PassNEliminateUnusedVars extends Pass2SsaOptimization { StatementCallFinalize call = (StatementCallFinalize) statement; LValue lValue = call.getlValue(); if(lValue instanceof VariableRef && referenceInfos.isUnused((VariableRef) lValue)) { - Variable variable = getScope().getVariable((VariableRef) lValue); + SymbolVariable variable = getScope().getVariable((VariableRef) lValue); if(!variable.isVolatile()) { if(pass2 || getLog().isVerbosePass1CreateSsa()) { getLog().append("Eliminating unused variable - keeping the call " + lValue.toString(getProgram())); @@ -106,7 +103,7 @@ public class PassNEliminateUnusedVars extends Pass2SsaOptimization { StatementCallPointer call = (StatementCallPointer) statement; LValue lValue = call.getlValue(); if(lValue instanceof VariableRef && referenceInfos.isUnused((VariableRef) lValue)) { - Variable variable = getScope().getVariable((VariableRef) lValue); + SymbolVariable variable = getScope().getVariable((VariableRef) lValue); if(!variable.isVolatile()) { if(pass2 || getLog().isVerbosePass1CreateSsa()) { getLog().append("Eliminating unused variable - keeping the call " + lValue.toString(getProgram())); @@ -125,7 +122,7 @@ public class PassNEliminateUnusedVars extends Pass2SsaOptimization { StatementPhiBlock.PhiVariable phiVariable = phiVarIt.next(); VariableRef variableRef = phiVariable.getVariable(); if(referenceInfos.isUnused(variableRef)) { - Variable variable = getScope().getVariable(variableRef); + SymbolVariable variable = getScope().getVariable(variableRef); if(!variable.isVolatile()) { if(pass2 || getLog().isVerbosePass1CreateSsa()) { getLog().append("Eliminating unused variable - keeping the phi block " + variableRef.toString(getProgram())); @@ -170,7 +167,7 @@ public class PassNEliminateUnusedVars extends Pass2SsaOptimization { * @param variable The variable * @return true if this is the return variable for a function */ - private boolean isReturnValue(Variable variable) { + private boolean isReturnValue(SymbolVariable variable) { if(variable == null) return false; return variable.getScope() instanceof Procedure && variable.getLocalName().equals("return"); } diff --git a/src/main/java/dk/camelot64/kickc/passes/PassNTypeInference.java b/src/main/java/dk/camelot64/kickc/passes/PassNTypeInference.java index 571b0e2fe..4ca99ad2f 100644 --- a/src/main/java/dk/camelot64/kickc/passes/PassNTypeInference.java +++ b/src/main/java/dk/camelot64/kickc/passes/PassNTypeInference.java @@ -62,7 +62,7 @@ public class PassNTypeInference extends Pass2SsaOptimization { ProgramScope programScope = program.getScope(); LValue lValue = call.getlValue(); if(lValue instanceof VariableRef) { - Variable symbol = programScope.getVariable((VariableRef) lValue); + SymbolVariable symbol = programScope.getVariable((VariableRef) lValue); if(SymbolType.VAR.equals(symbol.getType()) || SymbolType.NUMBER.equals(symbol.getType())|| SymbolType.UNUMBER.equals(symbol.getType())|| SymbolType.SNUMBER.equals(symbol.getType())) { Procedure procedure = programScope.getProcedure(call.getProcedure()); SymbolType type = procedure.getReturnType(); @@ -75,7 +75,7 @@ public class PassNTypeInference extends Pass2SsaOptimization { ProgramScope programScope = program.getScope(); LValue lValue = call.getlValue(); if(lValue instanceof VariableRef) { - Variable symbol = programScope.getVariable((VariableRef) lValue); + SymbolVariable symbol = programScope.getVariable((VariableRef) lValue); if(SymbolType.VAR.equals(symbol.getType()) || SymbolType.NUMBER.equals(symbol.getType())|| SymbolType.UNUMBER.equals(symbol.getType())|| SymbolType.SNUMBER.equals(symbol.getType())) { Procedure procedure = programScope.getProcedure(call.getProcedure()); SymbolType type = procedure.getReturnType(); @@ -88,7 +88,7 @@ public class PassNTypeInference extends Pass2SsaOptimization { ProgramScope programScope = program.getScope(); LValue lValue = call.getlValue(); if(lValue instanceof VariableRef) { - Variable symbol = programScope.getVariable((VariableRef) lValue); + SymbolVariable symbol = programScope.getVariable((VariableRef) lValue); if(SymbolType.VAR.equals(symbol.getType()) || SymbolType.NUMBER.equals(symbol.getType())|| SymbolType.UNUMBER.equals(symbol.getType())|| SymbolType.SNUMBER.equals(symbol.getType())) { SymbolType procedureType = SymbolTypeInference.inferType(programScope, call.getProcedure()); if(procedureType instanceof SymbolTypeProcedure) { @@ -101,7 +101,7 @@ public class PassNTypeInference extends Pass2SsaOptimization { private static void updateInferedTypePhiVariable(Program program, StatementPhiBlock.PhiVariable phiVariable) { ProgramScope programScope = program.getScope(); - Variable symbol = programScope.getVariable(phiVariable.getVariable()); + SymbolVariable symbol = programScope.getVariable(phiVariable.getVariable()); if(SymbolType.VAR.equals(symbol.getType()) || SymbolType.NUMBER.equals(symbol.getType())|| SymbolType.UNUMBER.equals(symbol.getType())|| SymbolType.SNUMBER.equals(symbol.getType())) { SymbolType type = null; for(StatementPhiBlock.PhiRValue phiRValue : phiVariable.getValues()) { @@ -129,7 +129,7 @@ public class PassNTypeInference extends Pass2SsaOptimization { ProgramScope programScope = program.getScope(); LValue lValue = assignment.getlValue(); if(lValue instanceof VariableRef) { - Variable symbol = programScope.getVariable((VariableRef) lValue); + SymbolVariable symbol = programScope.getVariable((VariableRef) lValue); if(SymbolType.VAR.equals(symbol.getType()) || SymbolType.NUMBER.equals(symbol.getType())|| SymbolType.UNUMBER.equals(symbol.getType()) || SymbolType.SNUMBER.equals(symbol.getType())) { SymbolType type = SymbolTypeInference.inferType(programScope, new AssignmentRValue(assignment)); setInferedType(program, assignment, symbol, type); @@ -147,7 +147,7 @@ public class PassNTypeInference extends Pass2SsaOptimization { } } - private static void setInferedType(Program program, Statement statement, Variable symbol, SymbolType type) { + private static void setInferedType(Program program, Statement statement, SymbolVariable symbol, SymbolType type) { if(!SymbolType.VAR.equals(symbol.getType()) && !type.equals(symbol.getType())) { program.getLog().append("Inferred type updated to " + type + " in " + statement.toString(program, false)); } diff --git a/src/main/java/dk/camelot64/kickc/passes/calcs/PassNCalcLiveRangesEffective.java b/src/main/java/dk/camelot64/kickc/passes/calcs/PassNCalcLiveRangesEffective.java index 2b9458391..9d68e2ebe 100644 --- a/src/main/java/dk/camelot64/kickc/passes/calcs/PassNCalcLiveRangesEffective.java +++ b/src/main/java/dk/camelot64/kickc/passes/calcs/PassNCalcLiveRangesEffective.java @@ -6,7 +6,7 @@ import dk.camelot64.kickc.model.statements.StatementAssignment; import dk.camelot64.kickc.model.statements.StatementPhiBlock; import dk.camelot64.kickc.model.symbols.Procedure; import dk.camelot64.kickc.model.symbols.Scope; -import dk.camelot64.kickc.model.symbols.Variable; +import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.values.*; import dk.camelot64.kickc.passes.Pass2AliasElimination; import dk.camelot64.kickc.passes.Pass2ConstantIdentification; @@ -153,7 +153,7 @@ public class PassNCalcLiveRangesEffective extends PassNCalcBase copyDefinedVars(BlockSet unrollBlocks, Program program) { Map definedToNewVar = new LinkedHashMap<>(); for(VariableRef definedVarRef : getVarsDefinedIn(unrollBlocks, program)) { - Variable definedVar = program.getScope().getVariable(definedVarRef); + SymbolVariable definedVar = program.getScope().getVariable(definedVarRef); Variable newVar; if(definedVarRef.isIntermediate()) { newVar = definedVar.getScope().addVariableIntermediate();