1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-04-08 14:37:40 +00:00

Moved many usages from Variable to SymbolVariable.

This commit is contained in:
jespergravgaard 2019-11-01 08:08:34 +01:00
parent e35f1b1530
commit 5b1e3ec153
45 changed files with 197 additions and 189 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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;
}

View File

@ -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<VariableRef> earlyIdentifiedConstants;
private Collection<SymbolVariableRef> 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<VariableRef> getEarlyIdentifiedConstants() {
public Collection<SymbolVariableRef> getEarlyIdentifiedConstants() {
return earlyIdentifiedConstants;
}
public void setEarlyIdentifiedConstants(Collection<VariableRef> earlyIdentifiedConstants) {
public void setEarlyIdentifiedConstants(Collection<SymbolVariableRef> earlyIdentifiedConstants) {
this.earlyIdentifiedConstants = earlyIdentifiedConstants;
}

View File

@ -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);
}

View File

@ -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<Statement> 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<Statement> 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<Statement> 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) {

View File

@ -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<RValue> paramValues = call.getParameters();
Procedure procedure = program.getScope().getProcedure(call.getProcedure());
List<Variable> paramDefs = procedure.getParameters();
List<SymbolVariable> 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<RValue> paramValues = call.getParameters();
Procedure procedure = program.getScope().getProcedure(call.getProcedure());
List<Variable> paramDefs = procedure.getParameters();
List<SymbolVariable> 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);
}
}
}

View File

@ -92,17 +92,17 @@ public class Procedure extends Scope {
return returnType;
}
public List<Variable> getParameters() {
ArrayList<Variable> parameters = new ArrayList<>();
public List<SymbolVariable> getParameters() {
ArrayList<SymbolVariable> parameters = new ArrayList<>();
for(String name : parameterNames) {
parameters.add(this.getVariable(name));
}
return parameters;
}
public void setParameters(List<Variable> parameters) {
public void setParameters(List<SymbolVariable> 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));

View File

@ -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<Variable> getVersions(Variable unversioned) {
LinkedHashSet<Variable> versions = new LinkedHashSet<>();
public Collection<SymbolVariable> getVersions(SymbolVariable unversioned) {
LinkedHashSet<SymbolVariable> 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());
}

View File

@ -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();

View File

@ -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());

View File

@ -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();
}

View File

@ -7,4 +7,5 @@ public abstract class SymbolVariableRef extends SymbolRef implements RValue {
super(fullName);
}
}

View File

@ -209,16 +209,16 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
if(!SymbolType.VOID.equals(type)) {
returnVar = procedure.addVariablePhiMaster("return", type, defaultMemoryArea, procedure.getSegmentData());
}
List<Variable> parameterList = new ArrayList<>();
List<SymbolVariable> parameterList = new ArrayList<>();
if(ctx.parameterListDecl() != null) {
parameterList = (List<Variable>) this.visit(ctx.parameterListDecl());
parameterList = (List<SymbolVariable>) 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<Objec
SymbolType varType = declVarType;
List<Directive> 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<Objec
if(rangeFirstValue instanceof ConstantInteger) ((ConstantInteger) rangeFirstValue).setType(varType);
if(rangeLastValue instanceof ConstantInteger) ((ConstantInteger) rangeLastValue).setType(varType);
}
Statement stmtInit = new StatementAssignment(lValue.getRef(), rangeFirstValue, statementSource, Comment.NO_COMMENTS);
Statement stmtInit = new StatementAssignment((LValue) lValue.getRef(), rangeFirstValue, statementSource, Comment.NO_COMMENTS);
sequence.addStatement(stmtInit);
// Add label
List<Comment> comments = ensureUnusedComments(getCommentsSymbol(stmtForCtx));
@ -1221,7 +1221,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
addLoopBody(stmtForCtx.stmt());
addLoopContinueLabel(loopStack.peek(), ctx);
// Add increment
Statement stmtNxt = new StatementAssignment(lValue.getRef(), lValue.getRef(), Operators.PLUS, new RangeNext(rangeFirstValue, rangeLastValue), statementSource, Comment.NO_COMMENTS);
Statement stmtNxt = new StatementAssignment((LValue) lValue.getRef(), lValue.getRef(), Operators.PLUS, new RangeNext(rangeFirstValue, rangeLastValue), statementSource, Comment.NO_COMMENTS);
sequence.addStatement(stmtNxt);
// Add condition i!=last+1 or i!=last-1
RValue beyondLastVal = new RangeComparison(rangeFirstValue, rangeLastValue, lValue.getType());
@ -1411,8 +1411,8 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
if(exprCtx != null) {
PrePostModifierHandler.addPreModifiers(this, exprCtx, new StatementSource(ctx));
rValue = (RValue) this.visit(exprCtx);
Variable returnVar = procedure.getVariable("return");
sequence.addStatement(new StatementAssignment(returnVar.getRef(), rValue, new StatementSource(ctx), ensureUnusedComments(getCommentsSymbol(ctx))));
SymbolVariable returnVar = procedure.getVariable("return");
sequence.addStatement(new StatementAssignment((LValue) returnVar.getRef(), rValue, new StatementSource(ctx), ensureUnusedComments(getCommentsSymbol(ctx))));
PrePostModifierHandler.addPostModifiers(this, exprCtx, new StatementSource(ctx));
}
Label returnLabel = procedure.getLabel(SymbolRef.PROCEXIT_BLOCK_NAME);
@ -1556,7 +1556,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
@Override
public Object visitTypeNamedRef(KickCParser.TypeNamedRefContext ctx) {
Scope typeDefScope = program.getScope().getTypeDefScope();
Variable typeDefVariable = typeDefScope.getVariable(ctx.getText());
SymbolVariable typeDefVariable = typeDefScope.getVariable(ctx.getText());
if(typeDefVariable != null) {
return typeDefVariable.getType();
}

View File

@ -3,7 +3,7 @@ package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.symbols.Procedure;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.symbols.SymbolVariable;
/**
* Check that no parameters are declared const
@ -17,7 +17,7 @@ public class Pass1AssertNoConstParams extends Pass1Base {
@Override
public boolean step() {
for(Procedure procedure : getScope().getAllProcedures(true)) {
for(Variable parameter : procedure.getParameters()) {
for(SymbolVariable parameter : procedure.getParameters()) {
if(parameter.isDeclaredConstant()) {
throw new CompileError("Error! Const parameters not supported "+parameter.getName()+" in "+ procedure.getFullName()+"()");
}

View File

@ -6,7 +6,7 @@ import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.statements.Statement;
import dk.camelot64.kickc.model.statements.StatementCall;
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.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypeConversion;
import dk.camelot64.kickc.model.types.SymbolTypeInference;
@ -30,13 +30,13 @@ public class Pass1AssertProcedureCallParameters extends Pass1Base {
if(statement instanceof StatementCall) {
StatementCall call = (StatementCall) statement;
Procedure procedure = getScope().getProcedure(call.getProcedure());
List<Variable> declParameters = procedure.getParameters();
List<SymbolVariable> declParameters = procedure.getParameters();
List<RValue> 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();

View File

@ -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<VariableRef> defined, Collection<LabelRef> visited) {
public void assertUsedVars(ControlFlowBlock block, LabelRef predecessor, VariableReferenceInfos referenceInfos, Collection<SymbolVariableRef> defined, Collection<LabelRef> 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<VariableRef> defined) {
private void assertUsedVarsPhi(ControlFlowBlock block, LabelRef predecessor, VariableReferenceInfos referenceInfos, Collection<SymbolVariableRef> defined) {
if(predecessor != null && block.hasPhiBlock()) {
StatementPhiBlock phiBlock = block.getPhiBlock();
ArrayList<SymbolVariableRef> used = new ArrayList<>();

View File

@ -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<VariableRef> earlyConstants = new ArrayList<>();
Collection<SymbolVariableRef> 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<Variable> parameters = ((Procedure) varScope).getParameters();
List<SymbolVariable> parameters = ((Procedure) varScope).getParameters();
if(parameters.contains(var))
return true;

View File

@ -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();

View File

@ -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<VariableRef> earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants();
Variable assignedVar = getScope().getVariable(lValueRef);
Collection<SymbolVariableRef> 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<Variable, Variable> blockVersions = new LinkedHashMap<>();
Map<SymbolVariable, SymbolVariable> blockVersions = new LinkedHashMap<>();
// New phi functions introduced in the block to create versions of variables.
Map<Variable, Variable> blockNewPhis = new LinkedHashMap<>();
Map<SymbolVariable, SymbolVariable> 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<Variable, Variable> blockVersions) {
private void updateBlockVersions(VariableRef lValue, Map<SymbolVariable, SymbolVariable> 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<Variable, Variable> blockVersions,
Map<Variable, Variable> blockNewPhis) {
Collection<VariableRef> earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants();
Variable version = null;
Map<SymbolVariable, SymbolVariable> blockVersions,
Map<SymbolVariable, SymbolVariable> blockNewPhis) {
Collection<SymbolVariableRef> 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<Variable> versions = scope.getVersions(rSymbol);
Collection<SymbolVariable> 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<LabelRef, Map<Variable, Variable>> newPhis = new LinkedHashMap<>();
Map<LabelRef, Map<Variable, Variable>> symbolMap = buildSymbolMap();
Map<LabelRef, Map<SymbolVariable, SymbolVariable>> newPhis = new LinkedHashMap<>();
Map<LabelRef, Map<SymbolVariable, SymbolVariable>> 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<ControlFlowBlock> predecessors = getPhiPredecessors(block, getProgram());
for(ControlFlowBlock predecessor : predecessors) {
LabelRef predecessorLabel = predecessor.getLabel();
Map<Variable, Variable> predecessorMap = symbolMap.get(predecessorLabel);
Variable previousSymbol = null;
Map<SymbolVariable, SymbolVariable> 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<Variable, Variable> predecessorNewPhis = newPhis.get(predecessorLabel);
Map<SymbolVariable, SymbolVariable> 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<Variable, Variable> blockNewPhis = newPhis.get(block.getLabel());
Map<SymbolVariable, SymbolVariable> 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<LabelRef, Map<Variable, Variable>> buildSymbolMap() {
Map<LabelRef, Map<Variable, Variable>> symbolMap = new LinkedHashMap<>();
private Map<LabelRef, Map<SymbolVariable, SymbolVariable>> buildSymbolMap() {
Map<LabelRef, Map<SymbolVariable, SymbolVariable>> 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<LabelRef, Map<Variable, Variable>> symbolMap) {
private void addSymbolToMap(LValue lValue, ControlFlowBlock block, Map<LabelRef, Map<SymbolVariable, SymbolVariable>> 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<Variable, Variable> blockMap = symbolMap.get(label);
SymbolVariable unversioned = versioned.getVersionOf();
Map<SymbolVariable, SymbolVariable> blockMap = symbolMap.get(label);
if(blockMap == null) {
blockMap = new LinkedHashMap<>();
symbolMap.put(label, blockMap);

View File

@ -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;

View File

@ -59,21 +59,21 @@ public class Pass1ProcedureCallParameters extends ControlFlowGraphCopyVisitor {
return copyCall;
}
List<Variable> parameterDecls = procedure.getParameters();
List<SymbolVariable> parameterDecls = procedure.getParameters();
List<RValue> 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);
}
}

View File

@ -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<Statement> statementsIt, StatementCall call, Procedure procedure, Scope callScope, int serial) {
List<Variable> parameterDecls = procedure.getParameters();
List<SymbolVariable> parameterDecls = procedure.getParameters();
List<RValue> 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));
}
}

View File

@ -169,7 +169,7 @@ public class Pass1UnwindStructValues extends Pass1Base {
for(Procedure procedure : getScope().getAllProcedures(true)) {
ArrayList<String> 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));

View File

@ -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;

View File

@ -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) {

View File

@ -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());
}

View File

@ -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<VariableRef> 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;

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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();

View File

@ -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());

View File

@ -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()) {

View File

@ -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<Variable> versions = new ArrayList<>(procedure.getVersions(parameter));
for(SymbolVariable parameter : procedure.getParameters()) {
List<SymbolVariable> 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<RValue> callParameters = call.getParameters();
List<Variable> procParameters = procedure.getParameters();
List<SymbolVariable> 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) {

View File

@ -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<ScopeRef> getEquivalenceClassThreads(LiveRangeEquivalenceClass equivalenceClass, Program program, Collection<ScopeRef> threadHeads, CallGraph callGraph) {
Collection<ScopeRef> 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;

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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) {

View File

@ -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<VariableRef> earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants();
Collection<SymbolVariableRef> earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants();
Set<VariableRef> 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());

View File

@ -24,14 +24,14 @@ public class PassNCallingConventionStack extends Pass2SsaOptimization {
@Override
public boolean step() {
// Offset-constants for all stack-call parameters
Map<VariableRef, ConstantRef> offsetConstants = new HashMap<>();
Map<SymbolVariableRef, ConstantRef> 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;

View File

@ -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");
}

View File

@ -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));
}

View File

@ -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<LiveRangeVariabl
StatementAssignment assignment = (StatementAssignment) statement;
LValue lValue = assignment.getlValue();
if(lValue instanceof VariableRef) {
Variable lValueVar = getProgram().getScope().getVariable((VariableRef) lValue);
SymbolVariable lValueVar = getProgram().getScope().getVariable((VariableRef) lValue);
if(lValueVar.getScope().equals(procedure)) {
// Assigning into the procedure scope
if(assignment.getrValue1() == null && assignment.getOperator() == null && assignment.getrValue2() instanceof VariableRef) {

View File

@ -6,6 +6,7 @@ import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
import dk.camelot64.kickc.model.statements.*;
import dk.camelot64.kickc.model.symbols.Label;
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.*;
import dk.camelot64.kickc.passes.Pass1GenerateSingleStaticAssignmentForm;
@ -170,7 +171,7 @@ public class Unroller {
* @return The new version
*/
private VariableRef createNewVersion(VariableRef origVarRef) {
Variable origVar = program.getScope().getVariable(origVarRef);
SymbolVariable origVar = program.getScope().getVariable(origVarRef);
Scope scope = origVar.getScope();
VariableRef newVarRef;
if(origVarRef.isIntermediate()) {
@ -226,7 +227,7 @@ public class Unroller {
private static Map<VariableRef, VariableRef> copyDefinedVars(BlockSet unrollBlocks, Program program) {
Map<VariableRef, VariableRef> 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();