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

Renamed to Variable.

This commit is contained in:
jespergravgaard 2019-11-01 20:46:10 +01:00
parent fd307776ae
commit c7d5be3962
84 changed files with 557 additions and 527 deletions

View File

@ -22,7 +22,7 @@ public class AsmFormat {
*/
public static String getAsmConstant(Program program, ConstantValue value, int precedence, ScopeRef codeScope) {
if(value instanceof ConstantRef) {
SymbolVariable constantVar = program.getScope().getConstant((ConstantRef) value);
Variable constantVar = program.getScope().getConstant((ConstantRef) value);
String asmName = constantVar.getAsmName() == null ? constantVar.getLocalName() : constantVar.getAsmName();
return getAsmParamName(constantVar.getScope().getRef(), asmName, codeScope);
} else if(value instanceof ConstantInteger) {
@ -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 SymbolVariable) {
return getAsmParamName((SymbolVariable) symbol, codeScope);
if(symbol instanceof Variable) {
return getAsmParamName((Variable) symbol, codeScope);
} else if(symbol instanceof Procedure) {
return getAsmParamName((Procedure) symbol, codeScope);
} else {
@ -308,7 +308,7 @@ public class AsmFormat {
* @param boundVar The variable
* @return The ASM parameter to use in the ASM code
*/
public static String getAsmParamName(SymbolVariable boundVar, ScopeRef codeScopeRef) {
public static String getAsmParamName(Variable boundVar, ScopeRef codeScopeRef) {
ScopeRef varScopeRef = boundVar.getScope().getRef();
String asmName = boundVar.getAsmName() == null ? boundVar.getLocalName() : boundVar.getAsmName();
return getAsmParamName(varScopeRef, asmName, codeScopeRef);

View File

@ -7,7 +7,7 @@ import dk.camelot64.kickc.model.InternalError;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.Registers;
import dk.camelot64.kickc.model.symbols.Label;
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.*;
import dk.camelot64.kickc.parser.KickCParser;
@ -75,8 +75,8 @@ public class AsmFragmentInstance {
if(boundValue == null) {
throw new RuntimeException("Binding '" + name + "' not found in fragment " + this.name);
}
if(boundValue instanceof SymbolVariable && ((SymbolVariable) boundValue).isVariable()) {
SymbolVariable boundVar = (SymbolVariable) boundValue;
if(boundValue instanceof Variable && ((Variable) boundValue).isVariable()) {
Variable boundVar = (Variable) boundValue;
Registers.Register register = boundVar.getAllocation();
if(register != null && register instanceof Registers.RegisterZpMem) {
return new AsmParameter(AsmFormat.getAsmParamName(boundVar, codeScopeRef), true);
@ -85,8 +85,8 @@ public class AsmFragmentInstance {
} else {
throw new RuntimeException("Register Type not implemented " + register);
}
} else if(boundValue instanceof SymbolVariable && ((SymbolVariable) boundValue).isConstant()) {
SymbolVariable constantVar = (SymbolVariable) boundValue;
} else if(boundValue instanceof Variable && ((Variable) boundValue).isConstant()) {
Variable constantVar = (Variable) boundValue;
String constantValueAsm = AsmFormat.getAsmConstant(program, constantVar.getConstantRef(), 99, codeScopeRef);
boolean constantValueZp = SymbolType.BYTE.equals(constantVar.getType());
if(!constantValueZp) {
@ -126,7 +126,7 @@ public class AsmFragmentInstance {
// ignore
}
if(boundConst instanceof ConstantRef) {
SymbolVariable reffedConstant = program.getScope().getConstant((ConstantRef) boundConst);
Variable reffedConstant = program.getScope().getConstant((ConstantRef) boundConst);
return isConstantValueZp(reffedConstant.getConstantValue());
}
if(boundConst instanceof ConstantCastValue) {

View File

@ -103,7 +103,7 @@ public class AsmFragmentInstanceSpecFactory {
throw new AsmFragmentInstance.AluNotApplicableException("Error! ALU register only allowed as rValue2. " + assignment);
}
VariableRef assignmentRValue2 = (VariableRef) assignment.getrValue2();
SymbolVariable assignmentRValue2Var = program.getSymbolInfos().getVariable(assignmentRValue2);
Variable assignmentRValue2Var = program.getSymbolInfos().getVariable(assignmentRValue2);
Registers.Register rVal2Register = assignmentRValue2Var.getAllocation();
if(!rVal2Register.getType().equals(Registers.RegisterType.REG_ALU)) {
@ -335,7 +335,7 @@ public class AsmFragmentInstanceSpecFactory {
return bindValue.toString();
}
} else if(value instanceof VariableRef) {
SymbolVariable variable = program.getSymbolInfos().getVariable((VariableRef) value);
Variable variable = program.getSymbolInfos().getVariable((VariableRef) value);
if(castType == null) {
castType = variable.getType();
}
@ -452,8 +452,8 @@ public class AsmFragmentInstanceSpecFactory {
String zpNameIdx = null;
for(String boundName : bindings.keySet()) {
Value boundValue = bindings.get(boundName);
if(boundValue instanceof SymbolVariable && ((SymbolVariable) boundValue).isVariable()) {
SymbolVariable boundVariable = (SymbolVariable) boundValue;
if(boundValue instanceof Variable && ((Variable) boundValue).isVariable()) {
Variable boundVariable = (Variable) boundValue;
Registers.Register boundRegister = boundVariable.getAllocation();
if(boundRegister != null && Registers.RegisterType.ZP_MEM.equals(boundRegister.getType())) {
Registers.RegisterZpMem boundRegisterZp = (Registers.RegisterZpMem) boundRegister;
@ -474,8 +474,8 @@ public class AsmFragmentInstanceSpecFactory {
String memNameIdx = null;
for(String boundName : bindings.keySet()) {
Value boundValue = bindings.get(boundName);
if(boundValue instanceof SymbolVariable && ((SymbolVariable) boundValue).isVariable()) {
SymbolVariable boundVariable = (SymbolVariable) boundValue;
if(boundValue instanceof Variable && ((Variable) boundValue).isVariable()) {
Variable boundVariable = (Variable) boundValue;
Registers.Register boundRegister = boundVariable.getAllocation();
if(boundRegister instanceof Registers.RegisterMainMem) {
if(boundRegister.equals(register)) {
@ -506,7 +506,7 @@ public class AsmFragmentInstanceSpecFactory {
// If the constant is already bound - reuse the index
for(String boundName : bindings.keySet()) {
Value boundValue = bindings.get(boundName);
if(boundValue instanceof ConstantValue || (boundValue instanceof SymbolVariable && ((SymbolVariable) boundValue).isConstant())) {
if(boundValue instanceof ConstantValue || (boundValue instanceof Variable && ((Variable) boundValue).isConstant())) {
if(boundValue.equals(constant)) {
return "c" + boundName.substring(boundName.length() - 1);
}

View File

@ -7,7 +7,7 @@ import dk.camelot64.kickc.model.Registers;
import dk.camelot64.kickc.model.statements.StatementSource;
import dk.camelot64.kickc.model.symbols.Label;
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.types.SymbolType;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ScopeRef;
@ -79,12 +79,12 @@ public class AsmFragmentTemplate {
ProgramScope scope = new ProgramScope();
LinkedHashMap<String, Value> bindings = new LinkedHashMap<>();
{
SymbolVariable v1 = new SymbolVariable( false, "z1", scope, SymbolType.BYTE, SymbolVariable.StorageStrategy.PHI_VERSION, SymbolVariable.MemoryArea.ZEROPAGE_MEMORY, null);
SymbolVariable v2 = new SymbolVariable( false, "z2", scope, SymbolType.BYTE, SymbolVariable.StorageStrategy.PHI_VERSION, SymbolVariable.MemoryArea.ZEROPAGE_MEMORY, null);
SymbolVariable v3 = new SymbolVariable( false, "z3", scope, SymbolType.BYTE, SymbolVariable.StorageStrategy.PHI_VERSION, SymbolVariable.MemoryArea.ZEROPAGE_MEMORY, null);
SymbolVariable v4 = new SymbolVariable( false, "z4", scope, SymbolType.BYTE, SymbolVariable.StorageStrategy.PHI_VERSION, SymbolVariable.MemoryArea.ZEROPAGE_MEMORY, null);
SymbolVariable v5 = new SymbolVariable( false, "z5", scope, SymbolType.BYTE, SymbolVariable.StorageStrategy.PHI_VERSION, SymbolVariable.MemoryArea.ZEROPAGE_MEMORY, null);
SymbolVariable v6 = new SymbolVariable( false, "z6", scope, SymbolType.BYTE, SymbolVariable.StorageStrategy.PHI_VERSION, SymbolVariable.MemoryArea.ZEROPAGE_MEMORY, null);
Variable v1 = new Variable( "z1", scope, SymbolType.BYTE, Variable.StorageStrategy.PHI_VERSION, Variable.MemoryArea.ZEROPAGE_MEMORY, null);
Variable v2 = new Variable( "z2", scope, SymbolType.BYTE, Variable.StorageStrategy.PHI_VERSION, Variable.MemoryArea.ZEROPAGE_MEMORY, null);
Variable v3 = new Variable( "z3", scope, SymbolType.BYTE, Variable.StorageStrategy.PHI_VERSION, Variable.MemoryArea.ZEROPAGE_MEMORY, null);
Variable v4 = new Variable( "z4", scope, SymbolType.BYTE, Variable.StorageStrategy.PHI_VERSION, Variable.MemoryArea.ZEROPAGE_MEMORY, null);
Variable v5 = new Variable( "z5", scope, SymbolType.BYTE, Variable.StorageStrategy.PHI_VERSION, Variable.MemoryArea.ZEROPAGE_MEMORY, null);
Variable v6 = new Variable( "z6", scope, SymbolType.BYTE, Variable.StorageStrategy.PHI_VERSION, Variable.MemoryArea.ZEROPAGE_MEMORY, null);
v1.setAllocation(new Registers.RegisterZpMem(2, 1));
v2.setAllocation(new Registers.RegisterZpMem(4, 1));
v3.setAllocation(new Registers.RegisterZpMem(6, 1));
@ -99,12 +99,12 @@ public class AsmFragmentTemplate {
if(signature.contains("z6")) bindings.put("z6", v6);
}
{
SymbolVariable v1 = new SymbolVariable( false, "m1", scope, SymbolType.BYTE, SymbolVariable.StorageStrategy.LOAD_STORE, SymbolVariable.MemoryArea.MAIN_MEMORY, null);
SymbolVariable v2 = new SymbolVariable( false, "m2", scope, SymbolType.BYTE, SymbolVariable.StorageStrategy.LOAD_STORE, SymbolVariable.MemoryArea.MAIN_MEMORY, null);
SymbolVariable v3 = new SymbolVariable( false, "m3", scope, SymbolType.BYTE, SymbolVariable.StorageStrategy.LOAD_STORE, SymbolVariable.MemoryArea.MAIN_MEMORY, null);
SymbolVariable v4 = new SymbolVariable( false, "m4", scope, SymbolType.BYTE, SymbolVariable.StorageStrategy.LOAD_STORE, SymbolVariable.MemoryArea.MAIN_MEMORY, null);
SymbolVariable v5 = new SymbolVariable( false, "m5", scope, SymbolType.BYTE, SymbolVariable.StorageStrategy.LOAD_STORE, SymbolVariable.MemoryArea.MAIN_MEMORY, null);
SymbolVariable v6 = new SymbolVariable( false, "m6", scope, SymbolType.BYTE, SymbolVariable.StorageStrategy.LOAD_STORE, SymbolVariable.MemoryArea.MAIN_MEMORY, null);
Variable v1 = new Variable( "m1", scope, SymbolType.BYTE, Variable.StorageStrategy.LOAD_STORE, Variable.MemoryArea.MAIN_MEMORY, null);
Variable v2 = new Variable( "m2", scope, SymbolType.BYTE, Variable.StorageStrategy.LOAD_STORE, Variable.MemoryArea.MAIN_MEMORY, null);
Variable v3 = new Variable( "m3", scope, SymbolType.BYTE, Variable.StorageStrategy.LOAD_STORE, Variable.MemoryArea.MAIN_MEMORY, null);
Variable v4 = new Variable( "m4", scope, SymbolType.BYTE, Variable.StorageStrategy.LOAD_STORE, Variable.MemoryArea.MAIN_MEMORY, null);
Variable v5 = new Variable( "m5", scope, SymbolType.BYTE, Variable.StorageStrategy.LOAD_STORE, Variable.MemoryArea.MAIN_MEMORY, null);
Variable v6 = new Variable( "m6", scope, SymbolType.BYTE, Variable.StorageStrategy.LOAD_STORE, Variable.MemoryArea.MAIN_MEMORY, null);
v1.setAllocation(new Registers.RegisterMainMem(v1.getVariableRef(), 1, null));
v2.setAllocation(new Registers.RegisterMainMem(v2.getVariableRef(), 1, null));
v3.setAllocation(new Registers.RegisterMainMem(v3.getVariableRef(), 1, null));

View File

@ -19,11 +19,11 @@ public class CallingConventionStack {
*/
public static ConstantRef getReturnOffsetConstant(Procedure procedure) {
String returnOffsetConstantName = "OFFSET_STACK_RETURN";
SymbolVariable returnOffsetConstant = procedure.getConstant(returnOffsetConstantName);
Variable returnOffsetConstant = procedure.getConstant(returnOffsetConstantName);
if(returnOffsetConstant == null) {
// Constant not found - create it
long returnByteOffset = getReturnByteOffset(procedure);
returnOffsetConstant = new SymbolVariable(returnOffsetConstantName, procedure, SymbolType.BYTE, Scope.SEGMENT_DATA_DEFAULT, new ConstantInteger(returnByteOffset & 0xff, SymbolType.BYTE));
returnOffsetConstant = new Variable(returnOffsetConstantName, procedure, SymbolType.BYTE, Scope.SEGMENT_DATA_DEFAULT, new ConstantInteger(returnByteOffset & 0xff, SymbolType.BYTE));
procedure.add(returnOffsetConstant);
}
return returnOffsetConstant.getConstantRef();
@ -36,13 +36,13 @@ public class CallingConventionStack {
* @param parameter The parameter
* @return The constant variable
*/
public static ConstantRef getParameterOffsetConstant(Procedure procedure, SymbolVariable parameter) {
public static ConstantRef getParameterOffsetConstant(Procedure procedure, Variable parameter) {
String paramOffsetConstantName = getParameterOffsetConstantName(parameter.getName());
SymbolVariable paramOffsetConstant = procedure.getConstant(paramOffsetConstantName);
Variable paramOffsetConstant = procedure.getConstant(paramOffsetConstantName);
if(paramOffsetConstant == null) {
// Constant not found - create it
long paramByteOffset = getParameterByteOffset(procedure, parameter);
paramOffsetConstant = new SymbolVariable(paramOffsetConstantName, procedure, SymbolType.BYTE, Scope.SEGMENT_DATA_DEFAULT, new ConstantInteger(paramByteOffset & 0xff, SymbolType.BYTE));
paramOffsetConstant = new Variable(paramOffsetConstantName, procedure, SymbolType.BYTE, Scope.SEGMENT_DATA_DEFAULT, new ConstantInteger(paramByteOffset & 0xff, SymbolType.BYTE));
procedure.add(paramOffsetConstant);
}
return paramOffsetConstant.getConstantRef();
@ -80,7 +80,7 @@ public class CallingConventionStack {
*/
public static long getParametersByteSize(Procedure procedure) {
long byteSize = 0;
for(SymbolVariable procedureParameter : procedure.getParameters()) {
for(Variable 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, SymbolVariable parameter) {
public static long getParameterByteOffset(Procedure procedure, Variable parameter) {
long byteOffset = 0;
for(SymbolVariable procedureParameter : procedure.getParameters()) {
for(Variable procedureParameter : procedure.getParameters()) {
if(parameter.equals(procedureParameter)) {
break;
} else {
@ -123,7 +123,7 @@ public class CallingConventionStack {
*/
public static ConstantRef getStackBaseConstant(ProgramScope programScope) {
long STACK_BASE_ADDRESS = 0x103L;
SymbolVariable stackBase = new SymbolVariable("STACK_BASE", programScope, SymbolType.WORD, Scope.SEGMENT_DATA_DEFAULT, new ConstantInteger(STACK_BASE_ADDRESS, SymbolType.WORD));
Variable stackBase = new Variable("STACK_BASE", programScope, SymbolType.WORD, Scope.SEGMENT_DATA_DEFAULT, new ConstantInteger(STACK_BASE_ADDRESS, SymbolType.WORD));
programScope.add(stackBase);
return stackBase.getConstantRef();
}

View File

@ -1,7 +1,7 @@
package 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 java.util.List;
@ -13,9 +13,9 @@ public interface Directive {
class Const implements Directive {
/** The const declaration. */
SymbolVariable.ConstantDeclaration constantDeclaration;
Variable.ConstantDeclaration constantDeclaration;
public Const(SymbolVariable.ConstantDeclaration constantDeclaration) {
public Const(Variable.ConstantDeclaration constantDeclaration) {
this.constantDeclaration = constantDeclaration;
}
@ -105,12 +105,12 @@ public interface Directive {
class MemoryArea implements Directive {
/** The memory area. */
SymbolVariable.MemoryArea memoryArea;
Variable.MemoryArea memoryArea;
/** Optional hard-coded address to use for storing the variable. */
public Long address;
public MemoryArea(SymbolVariable.MemoryArea memoryArea, Long address) {
public MemoryArea(Variable.MemoryArea memoryArea, Long address) {
this.memoryArea = memoryArea;
this.address = address;
}

View File

@ -31,7 +31,7 @@ public class DirectiveParserContext {
public enum DirectiveScope {
GLOBAL, LOCAL, PARAMETER, MEMBER;
public static DirectiveScope getFor(SymbolVariable lValue, boolean isParameter) {
public static DirectiveScope getFor(Variable lValue, boolean isParameter) {
if(isParameter) {
return PARAMETER;
}
@ -130,22 +130,22 @@ public class DirectiveParserContext {
this.statementDirectives = null;
// Setup default directives
this.defaultDirectives = Arrays.asList(
new Directive.MemoryArea(SymbolVariable.MemoryArea.ZEROPAGE_MEMORY, null),
new Directive.MemoryArea(Variable.MemoryArea.ZEROPAGE_MEMORY, null),
new Directive.FormSsa(true),
new Directive.Const(SymbolVariable.ConstantDeclaration.MAYBE_CONST)
new Directive.Const(Variable.ConstantDeclaration.MAYBE_CONST)
);
this.registerImpliesDirectives = new ArrayList<>();
this.typeDirectives = new HashMap<>();
this.typeDirectives.put(DirectiveType.ARRAY, Arrays.asList(
new Directive.Const(SymbolVariable.ConstantDeclaration.CONST),
new Directive.MemoryArea(SymbolVariable.MemoryArea.MAIN_MEMORY, null)
new Directive.Const(Variable.ConstantDeclaration.CONST),
new Directive.MemoryArea(Variable.MemoryArea.MAIN_MEMORY, null)
));
this.typeDirectives.put(DirectiveType.POINTER, Arrays.asList(
new Directive.MemoryArea(SymbolVariable.MemoryArea.ZEROPAGE_MEMORY, null)
new Directive.MemoryArea(Variable.MemoryArea.ZEROPAGE_MEMORY, null)
));
this.scopeDirectives = new HashMap<>();
//this.scopeDirectives.put(DirectiveScope.GLOBAL, Arrays.asList(
// new Directive.MemoryArea(SymbolVariable.MemoryArea.MAIN_MEMORY, null),
// new Directive.MemoryArea(Variable.MemoryArea.MAIN_MEMORY, null),
// new Directive.FormSsa(false)
//));
this.scopeTypeDirectives = new HashMap<>();
@ -159,26 +159,26 @@ public class DirectiveParserContext {
* @param source The source line.
* @return
*/
public void applyDirectives(SymbolVariable lValue, boolean isParameter, List<Directive> sourceDirectives, StatementSource source) {
public void applyDirectives(Variable lValue, boolean isParameter, List<Directive> sourceDirectives, StatementSource source) {
DirectiveType directiveType = DirectiveType.getFor(lValue.getType());
DirectiveScope directiveScope = DirectiveScope.getFor(lValue, isParameter);
Directive.FormSsa ssaDirective = findDirective(Directive.FormSsa.class, sourceDirectives, directiveScope, directiveType);
if(ssaDirective != null) {
if(ssaDirective.ssa) {
lValue.setStorageStrategy(SymbolVariable.StorageStrategy.PHI_MASTER);
lValue.setStorageStrategy(Variable.StorageStrategy.PHI_MASTER);
} else {
lValue.setStorageStrategy(SymbolVariable.StorageStrategy.LOAD_STORE);
lValue.setStorageStrategy(Variable.StorageStrategy.LOAD_STORE);
}
}
Directive.Const constDirective = findDirective(Directive.Const.class, sourceDirectives, directiveScope, directiveType);
if(constDirective != null) {
lValue.setConstantDeclaration(constDirective.constantDeclaration);
if(SymbolVariable.ConstantDeclaration.CONST.equals(constDirective.constantDeclaration)) {
lValue.setStorageStrategy(SymbolVariable.StorageStrategy.CONSTANT);
if(Variable.ConstantDeclaration.CONST.equals(constDirective.constantDeclaration)) {
lValue.setStorageStrategy(Variable.StorageStrategy.CONSTANT);
if(!(lValue.getType() instanceof SymbolTypePointer))
lValue.setMemoryArea(SymbolVariable.MemoryArea.MAIN_MEMORY);
lValue.setMemoryArea(Variable.MemoryArea.MAIN_MEMORY);
}
}
@ -206,7 +206,7 @@ public class DirectiveParserContext {
if(memoryAreaDirective != null) {
lValue.setMemoryArea(memoryAreaDirective.memoryArea);
if(memoryAreaDirective.address != null) {
if(SymbolVariable.MemoryArea.ZEROPAGE_MEMORY.equals(memoryAreaDirective.memoryArea)) {
if(Variable.MemoryArea.ZEROPAGE_MEMORY.equals(memoryAreaDirective.memoryArea)) {
Registers.Register register = new Registers.RegisterZpMem(memoryAreaDirective.address.intValue(), -1, true);
lValue.setDeclaredRegister(register);
} else {
@ -220,7 +220,7 @@ public class DirectiveParserContext {
if(registerDirective != null) {
if(registerDirective.isRegister) {
lValue.setDeclaredAsRegister(true);
lValue.setStorageStrategy(SymbolVariable.StorageStrategy.PHI_MASTER);
lValue.setStorageStrategy(Variable.StorageStrategy.PHI_MASTER);
if(registerDirective.name != null) {
// Ignore register directive without parameter (all variables are placed on ZP and attempted register uplift anyways)
Registers.Register register = Registers.getRegister(registerDirective.name);
@ -231,7 +231,7 @@ public class DirectiveParserContext {
}
} else {
lValue.setDeclaredNotRegister(true);
lValue.setStorageStrategy(SymbolVariable.StorageStrategy.LOAD_STORE);
lValue.setStorageStrategy(Variable.StorageStrategy.LOAD_STORE);
}
}

View File

@ -1,6 +1,6 @@
package 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;
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 SymbolVariable getSingleVariableBase(Program program) {
public Variable 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) {
SymbolVariable variable = program.getScope().getVariable(varRef);
Variable variable = program.getScope().getVariable(varRef);
if(variable.isVolatile()) {
return true;
}

View File

@ -1,6 +1,6 @@
package 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;
import java.util.ArrayList;
@ -107,7 +107,7 @@ public class LiveRangeEquivalenceClassSet {
for(LiveRangeEquivalenceClass equivalenceClass : getEquivalenceClasses()) {
Registers.Register register = equivalenceClass.getRegister();
for(VariableRef variable : equivalenceClass.getVariables()) {
SymbolVariable var = program.getSymbolInfos().getVariable(variable);
Variable var = program.getSymbolInfos().getVariable(variable);
var.setAllocation(register);
}
}

View File

@ -2,7 +2,7 @@ package dk.camelot64.kickc.model;
import dk.camelot64.kickc.model.statements.Statement;
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.RValue;
import dk.camelot64.kickc.model.values.VariableRef;
@ -187,8 +187,8 @@ public class PhiTransitions {
PhiTransition.PhiAssignment assignment = assignments.get(i);
PhiTransition.PhiAssignment otherAssignment = otherAssignments.get(i);
if(assignment.getVariable() != null && otherAssignment.getVariable() != null) {
SymbolVariable var = program.getSymbolInfos().getVariable(assignment.getVariable());
SymbolVariable otherVar = program.getSymbolInfos().getVariable(otherAssignment.getVariable());
Variable var = program.getSymbolInfos().getVariable(assignment.getVariable());
Variable otherVar = program.getSymbolInfos().getVariable(otherAssignment.getVariable());
if(!var.getAllocation().equals(otherVar.getAllocation())) {
return false;
}
@ -196,8 +196,8 @@ public class PhiTransitions {
return false;
}
if(assignment.getrValue() instanceof VariableRef && otherAssignment.getrValue() instanceof VariableRef) {
SymbolVariable var = program.getSymbolInfos().getVariable((VariableRef) assignment.getrValue());
SymbolVariable otherVar = program.getSymbolInfos().getVariable((VariableRef) otherAssignment.getrValue());
Variable var = program.getSymbolInfos().getVariable((VariableRef) assignment.getrValue());
Variable otherVar = program.getSymbolInfos().getVariable((VariableRef) otherAssignment.getrValue());
if(!var.getAllocation().equals(otherVar.getAllocation())) {
return false;
}

View File

@ -1,6 +1,6 @@
package 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;
import java.util.LinkedHashMap;
@ -28,7 +28,7 @@ public class RegisterCombination {
for(LiveRangeEquivalenceClass equivalenceClass : allocation.keySet()) {
Registers.Register register = allocation.get(equivalenceClass);
for(VariableRef variable : equivalenceClass.getVariables()) {
SymbolVariable var = program.getSymbolInfos().getVariable(variable);
Variable var = program.getSymbolInfos().getVariable(variable);
var.setAllocation(register);
}
}

View File

@ -1,7 +1,7 @@
package dk.camelot64.kickc.model;
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.values.SymbolRef;
import dk.camelot64.kickc.model.values.VariableRef;
@ -20,8 +20,8 @@ public class SymbolInfos {
return symbols.get(ref);
}
public SymbolVariable getVariable(VariableRef ref) {
return (SymbolVariable) getSymbol(ref);
public Variable getVariable(VariableRef ref) {
return (Variable) getSymbol(ref);
}
}

View File

@ -10,7 +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;
import dk.camelot64.kickc.model.values.*;
@ -118,7 +118,7 @@ public interface ProgramExpressionBinary extends ProgramExpression {
assignment.setrValue1(new ConstantCastValue(toType, (ConstantValue) assignment.getrValue1()));
} else {
Scope blockScope = symbols.getScope(currentScope);
SymbolVariable tmpVar = blockScope.addVariableIntermediate();
Variable tmpVar = blockScope.addVariableIntermediate();
tmpVar.setTypeInferred(toType);
StatementAssignment newAssignment = new StatementAssignment((LValue) tmpVar.getRef(), Operators.getCastUnary(toType), assignment.getrValue1(), assignment.getSource(), Comment.NO_COMMENTS);
assignment.setrValue1(tmpVar.getRef());
@ -134,7 +134,7 @@ public interface ProgramExpressionBinary extends ProgramExpression {
assignment.setrValue2(new ConstantCastValue(toType, (ConstantValue) assignment.getrValue2()));
} else {
Scope blockScope = symbols.getScope(currentScope);
SymbolVariable tmpVar = blockScope.addVariableIntermediate();
Variable tmpVar = blockScope.addVariableIntermediate();
tmpVar.setTypeInferred(toType);
StatementAssignment newAssignment = new StatementAssignment((LValue) tmpVar.getRef(), Operators.getCastUnary(toType), assignment.getrValue2(), assignment.getSource(), Comment.NO_COMMENTS);
assignment.setrValue2(tmpVar.getRef());
@ -251,14 +251,14 @@ public interface ProgramExpressionBinary extends ProgramExpression {
@Override
public void addLeftCast(SymbolType toType, ListIterator<Statement> stmtIt, ScopeRef currentScope, ProgramScope symbols) {
if(assignment.getlValue() instanceof VariableRef) {
SymbolVariable variable = symbols.getVariable((VariableRef) assignment.getlValue());
Variable variable = symbols.getVariable((VariableRef) assignment.getlValue());
if(variable.isInferredType())
variable.setTypeInferred(toType);
else
throw new InternalError("Cannot cast declared type!" + variable.toString());
} else {
Scope blockScope = symbols.getScope(currentScope);
SymbolVariable tmpVar = blockScope.addVariableIntermediate();
Variable tmpVar = blockScope.addVariableIntermediate();
SymbolType rightType = SymbolTypeInference.inferType(symbols, getRight());
tmpVar.setTypeInferred(rightType);
StatementAssignment newAssignment = new StatementAssignment(assignment.getlValue(), Operators.getCastUnary(toType), tmpVar.getRef(), assignment.getSource(), Comment.NO_COMMENTS);
@ -273,7 +273,7 @@ public interface ProgramExpressionBinary extends ProgramExpression {
assignment.setOperator(Operators.getCastUnary(toType));
} else {
Scope blockScope = symbols.getScope(currentScope);
SymbolVariable tmpVar = blockScope.addVariableIntermediate();
Variable tmpVar = blockScope.addVariableIntermediate();
SymbolType rightType = SymbolTypeInference.inferType(symbols, getRight());
tmpVar.setTypeInferred(rightType);
StatementAssignment newAssignment = new StatementAssignment(assignment.getlValue(), Operators.getCastUnary(toType), tmpVar.getRef(), assignment.getSource(), Comment.NO_COMMENTS);
@ -457,7 +457,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) {
SymbolVariable variable = symbols.getVariable((VariableRef) getPointerDereferenceIndexed().getIndex());
Variable variable = symbols.getVariable((VariableRef) getPointerDereferenceIndexed().getIndex());
if(variable.isInferredType())
variable.setTypeInferred(toType);
else
@ -514,7 +514,7 @@ public interface ProgramExpressionBinary extends ProgramExpression {
@Override
public void addLeftCast(SymbolType toType, ListIterator<Statement> stmtIt, ScopeRef currentScope, ProgramScope symbols) {
SymbolVariable variable = symbols.getVariable(phiVariable.getVariable());
Variable variable = symbols.getVariable(phiVariable.getVariable());
if(variable.isInferredType())
variable.setTypeInferred(toType);
else
@ -524,7 +524,7 @@ public interface ProgramExpressionBinary extends ProgramExpression {
@Override
public void addRightCast(SymbolType toType, ListIterator<Statement> stmtIt, ScopeRef currentScope, ProgramScope symbols) {
if(getRight() instanceof VariableRef) {
SymbolVariable variable = symbols.getVariable((VariableRef) getRight());
Variable 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.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.values.*;
import java.util.List;
@ -69,7 +69,7 @@ public class ProgramExpressionIterator {
StatementCall call = (StatementCall) stmt;
List<RValue> paramValues = call.getParameters();
Procedure procedure = program.getScope().getProcedure(call.getProcedure());
List<SymbolVariable> paramDefs = procedure.getParameters();
List<Variable> paramDefs = procedure.getParameters();
if(paramValues != null && paramDefs.size() == paramValues.size()) {
for(int i = 0; i < paramDefs.size(); i++) {
handler.execute(new ProgramExpressionBinary.ProgramExpressionBinaryCallParameter((VariableRef) paramDefs.get(i).getRef(), new ProgramValue.CallParameter(call, i)), stmt, stmtIt, block);
@ -79,7 +79,7 @@ public class ProgramExpressionIterator {
StatementCallPrepare call = (StatementCallPrepare) stmt;
List<RValue> paramValues = call.getParameters();
Procedure procedure = program.getScope().getProcedure(call.getProcedure());
List<SymbolVariable> paramDefs = procedure.getParameters();
List<Variable> paramDefs = procedure.getParameters();
if(paramValues != null && paramDefs.size() == paramValues.size()) {
for(int i = 0; i < paramDefs.size(); i++) {
handler.execute(new ProgramExpressionBinary.ProgramExpressionBinaryCallParameter((VariableRef) paramDefs.get(i).getRef(), new ProgramValue.CallPrepareParameter(call, i)), stmt, stmtIt, block);

View File

@ -2,7 +2,7 @@ package dk.camelot64.kickc.model.iterator;
import dk.camelot64.kickc.model.ControlFlowBlock;
import dk.camelot64.kickc.model.statements.*;
import dk.camelot64.kickc.model.symbols.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.types.SymbolTypeArray;
import dk.camelot64.kickc.model.values.*;
@ -630,9 +630,9 @@ public interface ProgramValue {
}
class ProgramValueConstantVar implements ProgramValue {
private final SymbolVariable constantVar;
private final Variable constantVar;
ProgramValueConstantVar(SymbolVariable constantVar) {
ProgramValueConstantVar(Variable constantVar) {
this.constantVar = constantVar;
}

View File

@ -35,23 +35,23 @@ public class ProgramValueIterator {
* @param handler The handler to execute
*/
public static void execute(ProgramScope programScope, ProgramValueHandler handler) {
for(SymbolVariable symbolVariable : programScope.getAllSymbolVariables(true)) {
execute(symbolVariable, handler);
for(Variable variable : programScope.getAllSymbolVariables(true)) {
execute(variable, handler);
}
}
/**
* Execute a programValueHandler on all values in a variable symbol (variable or constant).
*
* @param symbolVariable The symbol variable
* @param variable The symbol variable
* @param programValueHandler The programValueHandler to execute
*/
public static void execute(SymbolVariable symbolVariable, ProgramValueHandler programValueHandler) {
if(symbolVariable.getType() instanceof SymbolTypeArray) {
execute(new ProgramValue.ProgramValueTypeArraySize((SymbolTypeArray) symbolVariable.getType()), programValueHandler, null, null, null);
public static void execute(Variable variable, ProgramValueHandler programValueHandler) {
if(variable.getType() instanceof SymbolTypeArray) {
execute(new ProgramValue.ProgramValueTypeArraySize((SymbolTypeArray) variable.getType()), programValueHandler, null, null, null);
}
if(symbolVariable.isConstant()) {
execute(new ProgramValue.ProgramValueConstantVar(symbolVariable), programValueHandler, null, null, null);
if(variable.isConstant()) {
execute(new ProgramValue.ProgramValueConstantVar(variable), programValueHandler, null, null, null);
}
}
@ -250,7 +250,7 @@ public class ProgramValueIterator {
subValues.add(new ProgramValue.ProgramValueStackIdxValue((StackIdxValue) value));
} else if(value == null ||
value instanceof SymbolVariableRef ||
value instanceof SymbolVariable ||
value instanceof Variable ||
value instanceof ProcedureRef ||
value instanceof ConstantLiteral ||
value instanceof StructZero ||

View File

@ -1,9 +1,8 @@
package dk.camelot64.kickc.model.operators;
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.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypePointer;
import dk.camelot64.kickc.model.values.ConstantInteger;
@ -39,11 +38,11 @@ public class OperatorSizeOf extends OperatorUnary {
*/
public static ConstantRef getSizeOfConstantVar(ProgramScope programScope, SymbolType type) {
String typeConstName = getSizeofConstantName(type);
SymbolVariable typeSizeConstant = programScope.getConstant(typeConstName);
Variable typeSizeConstant = programScope.getConstant(typeConstName);
if(typeSizeConstant == null) {
// Constant not found - create it
long typeSize = type.getSizeBytes();
typeSizeConstant = new SymbolVariable(typeConstName, programScope, SymbolType.BYTE, Scope.SEGMENT_DATA_DEFAULT, new ConstantInteger(typeSize&0xff, SymbolType.BYTE));
typeSizeConstant = new Variable(typeConstName, programScope, SymbolType.BYTE, Scope.SEGMENT_DATA_DEFAULT, new ConstantInteger(typeSize&0xff, SymbolType.BYTE));
programScope.add(typeSizeConstant);
}
return typeSizeConstant.getConstantRef();

View File

@ -1,10 +1,12 @@
package dk.camelot64.kickc.model.operators;
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.SymbolVariable;
import dk.camelot64.kickc.model.types.*;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypeNamed;
import dk.camelot64.kickc.model.types.SymbolTypePointer;
import dk.camelot64.kickc.model.types.SymbolTypeProcedure;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
import dk.camelot64.kickc.model.values.ConstantRef;
@ -41,11 +43,11 @@ public class OperatorTypeId extends OperatorUnary {
*/
public static ConstantRef getTypeIdConstantVar(ProgramScope programScope, SymbolType type) {
String typeConstName = "TYPEID_" + getTypeIdConstantName(type);
SymbolVariable typeIdConstant = programScope.getConstant(typeConstName);
Variable typeIdConstant = programScope.getConstant(typeConstName);
if(typeIdConstant == null) {
// Constant not found - create it
long typeSize = getTypeId(type);
typeIdConstant = new SymbolVariable(typeConstName, programScope, SymbolType.BYTE, Scope.SEGMENT_DATA_DEFAULT, new ConstantInteger(typeSize));
typeIdConstant = new Variable(typeConstName, programScope, SymbolType.BYTE, Scope.SEGMENT_DATA_DEFAULT, new ConstantInteger(typeSize));
programScope.add(typeIdConstant);
}
return typeIdConstant.getConstantRef();

View File

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

View File

@ -100,13 +100,13 @@ public abstract class Scope implements Symbol, Serializable {
symbols.remove(symbol.getLocalName());
}
public SymbolVariable addVariablePhiMaster(String name, SymbolType type, SymbolVariable.MemoryArea memoryArea, String dataSegment) {
return add(new SymbolVariable( false, name, this, type, SymbolVariable.StorageStrategy.PHI_MASTER, memoryArea, dataSegment));
public Variable addVariablePhiMaster(String name, SymbolType type, Variable.MemoryArea memoryArea, String dataSegment) {
return add(new Variable( name, this, type, Variable.StorageStrategy.PHI_MASTER, memoryArea, dataSegment));
}
public SymbolVariable addVariableIntermediate() {
public Variable addVariableIntermediate() {
String name = allocateIntermediateVariableName();
return add(new SymbolVariable( false, name, this, SymbolType.VAR, SymbolVariable.StorageStrategy.INTERMEDIATE, SymbolVariable.MemoryArea.ZEROPAGE_MEMORY, getSegmentData()));
return add(new Variable( name, this, SymbolType.VAR, Variable.StorageStrategy.INTERMEDIATE, Variable.MemoryArea.ZEROPAGE_MEMORY, getSegmentData()));
}
/**
@ -115,11 +115,11 @@ public abstract class Scope implements Symbol, Serializable {
* @param unversioned The unversioned PHI-master variable
* @return All versions of the variable
*/
public Collection<SymbolVariable> getVersions(SymbolVariable unversioned) {
LinkedHashSet<SymbolVariable> versions = new LinkedHashSet<>();
public Collection<Variable> getVersions(Variable unversioned) {
LinkedHashSet<Variable> versions = new LinkedHashSet<>();
for(Symbol symbol : symbols.values()) {
if(symbol instanceof SymbolVariable) {
SymbolVariable variable = (SymbolVariable) symbol;
if(symbol instanceof Variable) {
Variable variable = (Variable) symbol;
if(variable.isVariable() && variable.isStoragePhiVersion() && variable.getVersionOf().equals(unversioned)) {
versions.add(variable);
}
@ -163,31 +163,31 @@ public abstract class Scope implements Symbol, Serializable {
return symbols.get(name);
}
public SymbolVariable getVariable(String name) {
SymbolVariable symbol = (SymbolVariable) getSymbol(name);
public Variable getVariable(String name) {
Variable symbol = (Variable) getSymbol(name);
if(symbol!=null && !symbol.isVariable()) throw new InternalError("Symbol is not a variable! "+symbol.toString());
return symbol;
}
public SymbolVariable getVariable(SymbolVariableRef variableRef) {
public Variable getVariable(SymbolVariableRef variableRef) {
return getVariable(variableRef.getFullName());
}
public SymbolVariable getConstant(String name) {
SymbolVariable symbol = (SymbolVariable) getSymbol(name);
public Variable getConstant(String name) {
Variable symbol = (Variable) getSymbol(name);
if(symbol!=null && !symbol.isConstant()) throw new InternalError("Symbol is not a constant! "+symbol.toString());
return symbol;
}
public SymbolVariable getConstant(ConstantRef constantRef) {
public Variable getConstant(ConstantRef constantRef) {
return getConstant(constantRef.getFullName());
}
public Collection<SymbolVariable> getAllSymbolVariables(boolean includeSubScopes) {
Collection<SymbolVariable> vars = new ArrayList<>();
public Collection<Variable> getAllSymbolVariables(boolean includeSubScopes) {
Collection<Variable> vars = new ArrayList<>();
for(Symbol symbol : symbols.values()) {
if(symbol instanceof SymbolVariable) {
vars.add((SymbolVariable) symbol);
if(symbol instanceof Variable) {
vars.add((Variable) symbol);
}
if(includeSubScopes && symbol instanceof Scope) {
Scope subScope = (Scope) symbol;
@ -197,20 +197,20 @@ public abstract class Scope implements Symbol, Serializable {
return vars;
}
public Collection<SymbolVariable> getAllVariables(boolean includeSubScopes) {
Collection<SymbolVariable> symbolVariables = getAllSymbolVariables(includeSubScopes);
Collection<SymbolVariable> vars = new ArrayList<>();
symbolVariables.stream().
filter(SymbolVariable::isVariable).
public Collection<Variable> getAllVariables(boolean includeSubScopes) {
Collection<Variable> variables = getAllSymbolVariables(includeSubScopes);
Collection<Variable> vars = new ArrayList<>();
variables.stream().
filter(Variable::isVariable).
forEach(vars::add);
return vars;
}
public Collection<SymbolVariable> getAllConstants(boolean includeSubScopes) {
Collection<SymbolVariable> symbolVariables = getAllSymbolVariables(includeSubScopes);
Collection<SymbolVariable> vars = new ArrayList<>();
symbolVariables.stream().
filter(SymbolVariable::isConstant).
public Collection<Variable> getAllConstants(boolean includeSubScopes) {
Collection<Variable> variables = getAllSymbolVariables(includeSubScopes);
Collection<Variable> vars = new ArrayList<>();
variables.stream().
filter(Variable::isConstant).
forEach(vars::add);
return vars;
}
@ -343,8 +343,8 @@ public abstract class Scope implements Symbol, Serializable {
if(symbol instanceof Scope) {
// Always output scopes
res.append(((Scope) symbol).toString(program, onlyVars));
} else if(symbol instanceof SymbolVariable) {
SymbolVariable symVar = (SymbolVariable) symbol;
} else if(symbol instanceof Variable) {
Variable symVar = (Variable) symbol;
if(!onlyVars || symVar.isVariable()) {
// Output if not instructed to only output variables - or if it is a variable
res.append(symbol.toString(program));

View File

@ -23,8 +23,8 @@ public class StructDefinition extends Scope {
* @param name The name of the member
* @return The member variable
*/
public SymbolVariable getMember(String name) {
for(SymbolVariable member : getAllVariables(false)) {
public Variable getMember(String name) {
for(Variable member : getAllVariables(false)) {
if(member.getLocalName().equals(name)) {
return member;
}
@ -37,9 +37,9 @@ public class StructDefinition extends Scope {
* @param member The member to find offset for
* @return The byte offset of the start of the member data
*/
public long getMemberByteOffset(SymbolVariable member, ProgramScope programScope) {
public long getMemberByteOffset(Variable member, ProgramScope programScope) {
long byteOffset=0;
for(SymbolVariable structMember : getAllVariables(false)) {
for(Variable structMember : getAllVariables(false)) {
if(structMember.equals(member)) {
break;
} else {

View File

@ -13,8 +13,8 @@ import dk.camelot64.kickc.model.values.VariableRef;
import java.util.ArrayList;
import java.util.List;
/** Abstract Variable or a Constant Variable */
public class SymbolVariable implements Symbol {
/** A Variable symbol (can either be a runtime variable or a compile-time constant)*/
public class Variable implements Symbol {
/** The name of the variable. */
private String name;
@ -31,7 +31,7 @@ public class SymbolVariable implements Symbol {
/** A short name used for the variable in ASM code. If possible variable names of variables are shortened in ASM code. This is possible, when several versions of the var use the same register. */
private String asmName;
/** True of the variable is a compile-time constant (previously ConstantVar*/
/** True of the variable is a compile-time constant (previously ConstantVar */
private boolean isConstant;
/** Specifies whether the symbol is declared to be constant, never constant or maybe constant. */
@ -105,35 +105,64 @@ public class SymbolVariable implements Symbol {
/** If the variable is assigned to a specific "register", this contains the register. If null the variable has no allocation (yet). Constants are never assigned to registers. */
private Registers.Register allocation;
public SymbolVariable(boolean isConstant, String name, Scope scope, SymbolType type, StorageStrategy storageStrategy, MemoryArea memoryArea, String dataSegment) {
this.isConstant = isConstant;
/**
* Create a compile-time constant variable
* @param name The name
* @param scope The scope
* @param type The type
* @param dataSegment The data segment (in main memory)
* @param value The constant value
*/
public Variable(String name, Scope scope, SymbolType type, String dataSegment, ConstantValue value) {
this.isConstant = true;
this.name = name;
this.scope = scope;
this.type = type;
this.dataSegment = dataSegment;
this.storageStrategy = StorageStrategy.CONSTANT;
this.memoryArea = MemoryArea.MAIN_MEMORY;
this.constantDeclaration = ConstantDeclaration.MAYBE_CONST;
this.constantValue = value;
this.inferredType = false;
this.comments = new ArrayList<>();
setFullName();
}
/**
* Create a runtime variable
* @param name The name
* @param scope The scope
* @param type The type
* @param storageStrategy The storage strategy (PHI-master/PHI-version/Intermediate/load store/constant)
* @param memoryArea The memory area (zeropage/main memory)
* @param dataSegment The data segment (in main memory)
*/
public Variable(String name, Scope scope, SymbolType type, StorageStrategy storageStrategy, MemoryArea memoryArea, String dataSegment) {
this.isConstant = false;
this.name = name;
this.scope = scope;
this.type = type;
this.dataSegment = dataSegment;
this.storageStrategy = storageStrategy;
this.memoryArea = memoryArea;
this.constantDeclaration = ConstantDeclaration.MAYBE_CONST;
setFullName();
if(isStoragePhiMaster())
if(StorageStrategy.PHI_MASTER.equals(storageStrategy))
this.nextPhiVersionNumber = 0;
this.inferredType = false;
this.comments = new ArrayList<>();
setFullName();
}
public SymbolVariable(String name, Scope scope, SymbolType type, String dataSegment, ConstantValue value) {
this(true, name, scope, type, StorageStrategy.CONSTANT, MemoryArea.MAIN_MEMORY, dataSegment);
setConstantValue(value);
}
/**
* Create a version of a PHI master variable
*
* @param phiMaster The PHI master variable.
* @param version The version number
*/
public SymbolVariable(SymbolVariable phiMaster, int version) {
this(false, phiMaster.getName() + "#" + version, phiMaster.getScope(), phiMaster.getType(), StorageStrategy.PHI_VERSION, phiMaster.getMemoryArea(), phiMaster.getDataSegment());
/**
* Create a version of a PHI master variable
*
* @param phiMaster The PHI master variable.
* @param version The version number
*/
public Variable(Variable phiMaster, int version) {
this(phiMaster.getName() + "#" + version, phiMaster.getScope(), phiMaster.getType(), StorageStrategy.PHI_VERSION, phiMaster.getMemoryArea(), phiMaster.getDataSegment());
this.setDeclaredAlignment(phiMaster.getDeclaredAlignment());
this.setDeclaredAsRegister(phiMaster.isDeclaredAsRegister());
this.setDeclaredNotRegister(phiMaster.isDeclaredAsNotRegister());
@ -148,6 +177,7 @@ public class SymbolVariable implements Symbol {
/**
* True if the variable is a compile time constant. (Previously this was ConstantVar)
*
* @return True if the variable is a compile time constant.
*/
public boolean isConstant() {
@ -156,6 +186,7 @@ public class SymbolVariable implements Symbol {
/**
* True if the variable is a not compile time constant. (Previously this was Variable)
*
* @return True if the variable is not a compile-time constant
*/
public boolean isVariable() {
@ -187,10 +218,10 @@ public class SymbolVariable implements Symbol {
*
* @return The new version of the PHI master
*/
public SymbolVariable createVersion() {
public Variable createVersion() {
if(!isStoragePhiMaster())
throw new InternalError("Cannot version non-PHI variable " + this.toString());
SymbolVariable version = new SymbolVariable(this, nextPhiVersionNumber++);
Variable version = new Variable(this, nextPhiVersionNumber++);
getScope().add(version);
return version;
}
@ -200,7 +231,7 @@ public class SymbolVariable implements Symbol {
*
* @return The original variable. Null if this is not a version.
*/
public SymbolVariable getVersionOf() {
public Variable getVersionOf() {
if(!isStoragePhiVersion())
throw new InternalError("Cannot get master for non-PHI version variable " + this.toString());
String name = getName();
@ -434,7 +465,7 @@ public class SymbolVariable implements Symbol {
.append("(")
.append((constantValue != null) ? "const " : "")
.append(getType().getTypeName())
.append((constantValue==null&&inferredType) ? "~" : "")
.append((constantValue == null && inferredType) ? "~" : "")
.append(") ")
.append(getFullName()).toString();
}
@ -448,7 +479,7 @@ public class SymbolVariable implements Symbol {
return false;
}
SymbolVariable variable = (SymbolVariable) o;
Variable variable = (Variable) o;
if(name != null ? !name.equals(variable.name) : variable.name != null) {
return false;
}

View File

@ -16,10 +16,10 @@ public class SymbolTypeInference {
public static SymbolType inferType(ProgramScope symbols, RValue rValue) {
SymbolType type = null;
if(rValue instanceof VariableRef) {
SymbolVariable variable = symbols.getVariable((VariableRef) rValue);
Variable variable = symbols.getVariable((VariableRef) rValue);
type = variable.getType();
} else if(rValue instanceof ConstantRef) {
SymbolVariable constVar = symbols.getConstant((ConstantRef) rValue);
Variable constVar = symbols.getConstant((ConstantRef) rValue);
type = constVar.getType();
} else if(rValue instanceof Symbol) {
Symbol rSymbol = (Symbol) rValue;
@ -107,7 +107,7 @@ public class SymbolTypeInference {
if(structType instanceof SymbolTypeStruct) {
String typeName = ((SymbolTypeStruct) structType).getStructTypeName();
StructDefinition structDefinition = symbols.getStructDefinition(typeName);
SymbolVariable structMember = structDefinition.getVariable(structMemberRef.getMemberName());
Variable structMember = structDefinition.getVariable(structMemberRef.getMemberName());
return structMember.getType();
} else {
throw new CompileError("Dot applied to non-struct "+ structMemberRef.getStruct().toString());

View File

@ -2,7 +2,7 @@ package dk.camelot64.kickc.model.types;
import dk.camelot64.kickc.model.symbols.ProgramScope;
import dk.camelot64.kickc.model.symbols.StructDefinition;
import dk.camelot64.kickc.model.symbols.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
import dk.camelot64.kickc.model.values.ConstantValue;
@ -53,7 +53,7 @@ public class SymbolTypeStruct implements SymbolType {
*/
public int calculateSizeBytes(StructDefinition structDefinition, ProgramScope programScope) {
int sizeBytes = 0;
for(SymbolVariable member : structDefinition.getAllVariables(false)) {
for(Variable member : structDefinition.getAllVariables(false)) {
SymbolType memberType = member.getType();
int memberSize = getMemberSizeBytes(memberType, programScope);
sizeBytes += memberSize;

View File

@ -2,13 +2,13 @@ package dk.camelot64.kickc.model.values;
import dk.camelot64.kickc.model.InternalError;
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.types.SymbolType;
/** A reference to a named Constant (in the symbol table) */
public class ConstantRef extends SymbolVariableRef implements ConstantValue {
public ConstantRef(SymbolVariable constantVar) {
public ConstantRef(Variable constantVar) {
super(constantVar.getFullName());
if(!constantVar.isConstant())
throw new InternalError("VariableRef not allowed for non-constant "+constantVar.toString());
@ -16,13 +16,13 @@ public class ConstantRef extends SymbolVariableRef implements ConstantValue {
@Override
public SymbolType getType(ProgramScope scope) {
SymbolVariable constant = scope.getConstant(this);
Variable constant = scope.getConstant(this);
return constant.getType();
}
@Override
public ConstantLiteral calculateLiteral(ProgramScope scope) {
SymbolVariable constantVar = scope.getConstant(this);
Variable constantVar = scope.getConstant(this);
ConstantValue constantVarValue = constantVar.getConstantValue();
return constantVarValue.calculateLiteral(scope);
}

View File

@ -5,7 +5,7 @@ import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.Registers;
import dk.camelot64.kickc.model.symbols.ProgramScope;
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.SymbolTypePointer;
@ -39,8 +39,8 @@ public class ConstantSymbolPointer implements ConstantValue {
public ConstantLiteral calculateLiteral(ProgramScope scope) {
// If the symbol has been allocated we can calculate a literal value!
Symbol symbol = scope.getSymbol(toSymbol);
if(symbol instanceof SymbolVariable) {
SymbolVariable variable = (SymbolVariable) symbol;
if(symbol instanceof Variable) {
Variable variable = (Variable) symbol;
if(variable.isVariable()) {
Registers.Register allocation = variable.getAllocation();
if(allocation != null && Registers.RegisterType.ZP_MEM.equals(allocation.getType())) {

View File

@ -1,7 +1,7 @@
package dk.camelot64.kickc.model.values;
import dk.camelot64.kickc.model.InternalError;
import dk.camelot64.kickc.model.symbols.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
/** A reference to a variable from the symbol table */
public class VariableRef extends SymbolVariableRef implements RValue, LValue {
@ -10,7 +10,7 @@ public class VariableRef extends SymbolVariableRef implements RValue, LValue {
super(fullName);
}
public VariableRef(SymbolVariable variable) {
public VariableRef(Variable variable) {
this(variable.getFullName());
if(!variable.isVariable())
throw new InternalError("VariableRef not allowed for non-variable "+variable.toString());

View File

@ -3,7 +3,7 @@ package dk.camelot64.kickc.model.values;
import dk.camelot64.kickc.model.InternalError;
import dk.camelot64.kickc.model.symbols.ProgramScope;
import dk.camelot64.kickc.model.symbols.StructDefinition;
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.SymbolTypeIntegerFixed;
import dk.camelot64.kickc.model.types.SymbolTypePointer;
@ -21,7 +21,7 @@ public class ZeroConstantValues {
SymbolTypeStruct typeStruct = (SymbolTypeStruct) type;
LinkedHashMap<SymbolVariableRef, ConstantValue> zeroValues = new LinkedHashMap<>();
StructDefinition structDefinition = typeStruct.getStructDefinition(programScope);
for(SymbolVariable memberVar : structDefinition.getAllVariables(false)) {
for(Variable memberVar : structDefinition.getAllVariables(false)) {
zeroValues.put(memberVar.getRef(), zeroValue(memberVar.getType(), programScope));
}
return new ConstantStructValue(typeStruct, zeroValues);

View File

@ -44,7 +44,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
/** Used to build the scopes of the source file. */
private Stack<Scope> scopeStack;
/** The memory area used by default for variables. */
private SymbolVariable.MemoryArea defaultMemoryArea;
private Variable.MemoryArea defaultMemoryArea;
/** Context used for adding directives to variables. */
private DirectiveParserContext directiveContext;
@ -54,7 +54,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
this.program = program;
this.sequence = program.getStatementSequence();
this.scopeStack = new Stack<>();
this.defaultMemoryArea = SymbolVariable.MemoryArea.ZEROPAGE_MEMORY;
this.defaultMemoryArea = Variable.MemoryArea.ZEROPAGE_MEMORY;
this.directiveContext = new DirectiveParserContext();
scopeStack.push(program.getScope());
}
@ -205,19 +205,19 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
procedure.setComments(ensureUnusedComments(getCommentsSymbol(ctx)));
scopeStack.push(procedure);
Label procExit = procedure.addLabel(SymbolRef.PROCEXIT_BLOCK_NAME);
SymbolVariable returnVar = null;
Variable returnVar = null;
if(!SymbolType.VOID.equals(type)) {
returnVar = procedure.addVariablePhiMaster("return", type, defaultMemoryArea, procedure.getSegmentData());
}
List<SymbolVariable> parameterList = new ArrayList<>();
List<Variable> parameterList = new ArrayList<>();
if(ctx.parameterListDecl() != null) {
parameterList = (List<SymbolVariable>) this.visit(ctx.parameterListDecl());
parameterList = (List<Variable>) 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(SymbolVariable param : parameterList) {
for(Variable param : parameterList) {
sequence.addStatement(new StatementAssignment((LValue) param.getRef(), new ParamValue((VariableRef) param.getRef()), StatementSource.procedureEnd(ctx), Comment.NO_COMMENTS));
}
}
@ -241,8 +241,8 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
@Override
public List<SymbolVariable> visitParameterListDecl(KickCParser.ParameterListDeclContext ctx) {
ArrayList<SymbolVariable> parameterDecls = new ArrayList<>();
public List<Variable> visitParameterListDecl(KickCParser.ParameterListDeclContext ctx) {
ArrayList<Variable> parameterDecls = new ArrayList<>();
for(KickCParser.ParameterDeclContext parameterDeclCtx : ctx.parameterDecl()) {
Object parameterDecl = this.visit(parameterDeclCtx);
if(parameterDecl.equals(SymbolType.VOID)) {
@ -252,8 +252,8 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
} else {
throw new CompileError("Illegal void parameter.", new StatementSource(ctx));
}
} else if(parameterDecl instanceof SymbolVariable) {
parameterDecls.add((SymbolVariable) parameterDecl);
} else if(parameterDecl instanceof Variable) {
parameterDecls.add((Variable) parameterDecl);
} else {
throw new CompileError("Unknown parameter " + ctx.getText(), new StatementSource(ctx));
}
@ -266,7 +266,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
this.visitDeclTypes(ctx.declTypes());
SymbolType type = declVarType;
List<Directive> directives = declVarDirectives;
SymbolVariable param = new SymbolVariable( false, ctx.NAME().getText(), getCurrentScope(), type, SymbolVariable.StorageStrategy.PHI_MASTER, defaultMemoryArea, currentDataSegment);
Variable param = new Variable( ctx.NAME().getText(), getCurrentScope(), type, Variable.StorageStrategy.PHI_MASTER, defaultMemoryArea, currentDataSegment);
// Add directives
addDirectives(param, true, directives, new StatementSource(ctx));
exitDeclTypes();
@ -557,7 +557,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
@Override
public Object visitDeclVariableInitExpr(KickCParser.DeclVariableInitExprContext ctx) {
String varName = ctx.NAME().getText();
SymbolVariable lValue = visitDeclVariableInit(varName, ctx);
Variable lValue = visitDeclVariableInit(varName, ctx);
SymbolType type = declVarType;
List<Comment> comments = declVarComments;
KickCParser.ExprContext initializer = ctx.expr();
@ -582,7 +582,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
@Override
public Object visitDeclVariableInitKasm(KickCParser.DeclVariableInitKasmContext ctx) {
String varName = ctx.NAME().getText();
SymbolVariable lValue = visitDeclVariableInit(varName, ctx);
Variable lValue = visitDeclVariableInit(varName, ctx);
SymbolType type = this.declVarType;
List<Comment> comments = this.declVarComments;
if(!(type instanceof SymbolTypeArray)) {
@ -611,12 +611,12 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
return null;
}
private SymbolVariable visitDeclVariableInit(String varName, KickCParser.DeclVariableInitContext ctx) {
private Variable visitDeclVariableInit(String varName, KickCParser.DeclVariableInitContext ctx) {
List<Directive> directives = declVarDirectives;
SymbolType type = declVarType;
List<Comment> comments = declVarComments;
SymbolVariable lValue;
Variable lValue;
try {
lValue = getCurrentScope().addVariablePhiMaster(varName, type, defaultMemoryArea, currentDataSegment);
} catch(CompileError e) {
@ -626,9 +626,9 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
addDirectives(lValue, false, directives, new StatementSource(ctx));
// Array / String variables are implicitly constant
if(type instanceof SymbolTypeArray || type.equals(SymbolType.STRING)) {
lValue.setConstantDeclaration(SymbolVariable.ConstantDeclaration.CONST);
lValue.setStorageStrategy(SymbolVariable.StorageStrategy.CONSTANT);
lValue.setMemoryArea(SymbolVariable.MemoryArea.MAIN_MEMORY);
lValue.setConstantDeclaration(Variable.ConstantDeclaration.CONST);
lValue.setStorageStrategy(Variable.StorageStrategy.CONSTANT);
lValue.setMemoryArea(Variable.MemoryArea.MAIN_MEMORY);
}
if(lValue.isDeclaredConstant()) {
// Add comments to constant
@ -682,7 +682,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
* @param isParameter True if the lValue is a parameter
* @param directives The directives to add
*/
private void addDirectives(SymbolVariable lValue, boolean isParameter, List<Directive> directives, StatementSource source) {
private void addDirectives(Variable lValue, boolean isParameter, List<Directive> directives, StatementSource source) {
directiveContext.applyDirectives(lValue, isParameter, directives, source);
}
@ -742,17 +742,17 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
@Override
public Directive visitDirectiveConst(KickCParser.DirectiveConstContext ctx) {
return new Directive.Const(SymbolVariable.ConstantDeclaration.CONST);
return new Directive.Const(Variable.ConstantDeclaration.CONST);
}
@Override
public Object visitDirectiveNotConst(KickCParser.DirectiveNotConstContext ctx) {
return new Directive.Const(SymbolVariable.ConstantDeclaration.NOT_CONST);
return new Directive.Const(Variable.ConstantDeclaration.NOT_CONST);
}
@Override
public Object visitDirectiveMaybeConst(KickCParser.DirectiveMaybeConstContext ctx) {
return new Directive.Const(SymbolVariable.ConstantDeclaration.MAYBE_CONST);
return new Directive.Const(Variable.ConstantDeclaration.MAYBE_CONST);
}
@Override
@ -796,12 +796,12 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
@Override
public Object visitDirectiveMemoryAreaZp(KickCParser.DirectiveMemoryAreaZpContext ctx) {
return new Directive.MemoryArea(SymbolVariable.MemoryArea.ZEROPAGE_MEMORY, null);
return new Directive.MemoryArea(Variable.MemoryArea.ZEROPAGE_MEMORY, null);
}
@Override
public Object visitDirectiveMemoryAreaMain(KickCParser.DirectiveMemoryAreaMainContext ctx) {
return new Directive.MemoryArea(SymbolVariable.MemoryArea.MAIN_MEMORY, null);
return new Directive.MemoryArea(Variable.MemoryArea.MAIN_MEMORY, null);
}
@Override
@ -809,7 +809,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
try {
ConstantInteger memoryAddress = NumberParser.parseIntegerLiteral(ctx.NUMBER().getText());
Long address = memoryAddress.getInteger();
SymbolVariable.MemoryArea memoryArea = (address < 0x100) ? SymbolVariable.MemoryArea.ZEROPAGE_MEMORY : SymbolVariable.MemoryArea.MAIN_MEMORY;
Variable.MemoryArea memoryArea = (address < 0x100) ? Variable.MemoryArea.ZEROPAGE_MEMORY : Variable.MemoryArea.MAIN_MEMORY;
return new Directive.MemoryArea(memoryArea, address);
} catch(NumberFormatException e) {
throw new CompileError(e.getMessage(), new StatementSource(ctx));
@ -877,7 +877,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
RValue exprVal = (RValue) this.visit(ctx.commaExpr());
if(notConsumed(exprVal)) {
// Make a tmpVar to create the statement
SymbolVariable tmpVar = getCurrentScope().addVariableIntermediate();
Variable tmpVar = getCurrentScope().addVariableIntermediate();
List<Comment> comments = ensureUnusedComments(getCommentsSymbol(ctx));
RValue rVal = exprVal;
if(exprVal instanceof LValue) {
@ -1184,7 +1184,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
SymbolType varType = declVarType;
List<Directive> varDirectives = declVarDirectives;
String varName = ctx.NAME().getText();
SymbolVariable lValue;
Variable lValue;
if(varType != null) {
try {
lValue = getCurrentScope().addVariablePhiMaster(varName, varType, defaultMemoryArea, currentDataSegment);
@ -1225,7 +1225,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
sequence.addStatement(stmtNxt);
// Add condition i!=last+1 or i!=last-1
RValue beyondLastVal = new RangeComparison(rangeFirstValue, rangeLastValue, lValue.getType());
SymbolVariable tmpVar = getCurrentScope().addVariableIntermediate();
Variable tmpVar = getCurrentScope().addVariableIntermediate();
SymbolVariableRef tmpVarRef = tmpVar.getRef();
Statement stmtTmpVar = new StatementAssignment((LValue) tmpVarRef, lValue.getRef(), Operators.NEQ, beyondLastVal, statementSource, Comment.NO_COMMENTS);
sequence.addStatement(stmtTmpVar);
@ -1411,7 +1411,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
if(exprCtx != null) {
PrePostModifierHandler.addPreModifiers(this, exprCtx, new StatementSource(ctx));
rValue = (RValue) this.visit(exprCtx);
SymbolVariable returnVar = procedure.getVariable("return");
Variable 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));
}
@ -1420,7 +1420,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
return null;
}
private void addInitialAssignment(KickCParser.ExprContext initializer, SymbolVariable lValue, List<Comment> comments, StatementSource statementSource) {
private void addInitialAssignment(KickCParser.ExprContext initializer, Variable lValue, List<Comment> comments, StatementSource statementSource) {
PrePostModifierHandler.addPreModifiers(this, initializer, statementSource);
RValue rValue = (RValue) visit(initializer);
Statement stmt = new StatementAssignment((LValue) lValue.getRef(), rValue, statementSource, ensureUnusedComments(comments));
@ -1499,8 +1499,8 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
// Copy all members to upper-level scope
Scope parentScope = getCurrentScope();
while(parentScope instanceof StructDefinition) parentScope = parentScope.getScope();
for(SymbolVariable member : enumDefinition.getAllConstants(false)) {
parentScope.add(new SymbolVariable(member.getLocalName(), parentScope, SymbolType.BYTE, currentDataSegment, member.getConstantValue()));
for(Variable member : enumDefinition.getAllConstants(false)) {
parentScope.add(new Variable(member.getLocalName(), parentScope, SymbolType.BYTE, currentDataSegment, member.getConstantValue()));
}
return SymbolType.BYTE;
} catch(CompileError e) {
@ -1520,11 +1520,11 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
enumValue = (ConstantValue) exprVal;
} else {
// No specific value - find previous value
List<SymbolVariable> values = new ArrayList<>(currentEnum.getAllConstants(false));
List<Variable> values = new ArrayList<>(currentEnum.getAllConstants(false));
if(values.isEmpty()) {
enumValue = new ConstantInteger(0L, SymbolType.BYTE);
} else {
SymbolVariable prevEnumMember = values.get(values.size() - 1);
Variable prevEnumMember = values.get(values.size() - 1);
ConstantValue prevValue = prevEnumMember.getConstantValue();
if(prevValue instanceof ConstantInteger) {
enumValue = new ConstantInteger(((ConstantInteger) prevValue).getInteger() + 1, SymbolType.BYTE);
@ -1534,7 +1534,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
}
}
}
currentEnum.add(new SymbolVariable(memberName, getCurrentScope(), SymbolType.BYTE, currentDataSegment, enumValue));
currentEnum.add(new Variable(memberName, getCurrentScope(), SymbolType.BYTE, currentDataSegment, enumValue));
return null;
}
@ -1556,7 +1556,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
@Override
public Object visitTypeNamedRef(KickCParser.TypeNamedRefContext ctx) {
Scope typeDefScope = program.getScope().getTypeDefScope();
SymbolVariable typeDefVariable = typeDefScope.getVariable(ctx.getText());
Variable typeDefVariable = typeDefScope.getVariable(ctx.getText());
if(typeDefVariable != null) {
return typeDefVariable.getType();
}
@ -1771,7 +1771,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
RValue child = (RValue) this.visit(ctx.expr());
SymbolType castType = (SymbolType) this.visit(ctx.typeDecl());
Operator operator = Operators.getCastUnary(castType);
SymbolVariable tmpVar = getCurrentScope().addVariableIntermediate();
Variable tmpVar = getCurrentScope().addVariableIntermediate();
SymbolVariableRef tmpVarRef = tmpVar.getRef();
Statement stmt = new StatementAssignment((LValue) tmpVarRef, operator, child, new StatementSource(ctx), ensureUnusedComments(getCommentsSymbol(ctx)));
sequence.addStatement(stmt);
@ -1788,7 +1788,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
} else {
// sizeof(expression) - add a unary expression to be resolved later
RValue child = (RValue) this.visit(ctx.expr());
SymbolVariable tmpVar = getCurrentScope().addVariableIntermediate();
Variable tmpVar = getCurrentScope().addVariableIntermediate();
SymbolVariableRef tmpVarRef = tmpVar.getRef();
Statement stmt = new StatementAssignment((LValue) tmpVarRef, Operators.SIZEOF, child, new StatementSource(ctx), ensureUnusedComments(getCommentsSymbol(ctx)));
sequence.addStatement(stmt);
@ -1806,7 +1806,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
} else {
// typeid(expression) - add a unary expression to be resolved later
RValue child = (RValue) this.visit(ctx.expr());
SymbolVariable tmpVar = getCurrentScope().addVariableIntermediate();
Variable tmpVar = getCurrentScope().addVariableIntermediate();
SymbolVariableRef tmpVarRef = tmpVar.getRef();
Statement stmt = new StatementAssignment((LValue) tmpVarRef, Operators.TYPEID, child, new StatementSource(ctx), ensureUnusedComments(getCommentsSymbol(ctx)));
sequence.addStatement(stmt);
@ -1824,7 +1824,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
} else {
parameters = new ArrayList<>();
}
SymbolVariable tmpVar = getCurrentScope().addVariableIntermediate();
Variable tmpVar = getCurrentScope().addVariableIntermediate();
SymbolVariableRef tmpVarRef = tmpVar.getRef();
String procedureName;
@ -1953,7 +1953,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
if(left instanceof ConstantValue && right instanceof ConstantValue) {
return new ConstantBinary((ConstantValue) left, (OperatorBinary) operator, (ConstantValue) right);
} else {
SymbolVariable tmpVar = getCurrentScope().addVariableIntermediate();
Variable tmpVar = getCurrentScope().addVariableIntermediate();
SymbolVariableRef tmpVarRef = tmpVar.getRef();
Statement stmt = new StatementAssignment((LValue) tmpVarRef, left, operator, right, new StatementSource(ctx), ensureUnusedComments(getCommentsSymbol(ctx)));
sequence.addStatement(stmt);
@ -1982,7 +1982,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
} else if(child instanceof ConstantValue) {
return new ConstantUnary((OperatorUnary) operator, (ConstantValue) child);
} else {
SymbolVariable tmpVar = getCurrentScope().addVariableIntermediate();
Variable tmpVar = getCurrentScope().addVariableIntermediate();
SymbolVariableRef tmpVarRef = tmpVar.getRef();
Statement stmt = new StatementAssignment((LValue) tmpVarRef, operator, child, new StatementSource(ctx), ensureUnusedComments(getCommentsSymbol(ctx)));
sequence.addStatement(stmt);
@ -2052,8 +2052,8 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
@Override
public RValue visitExprId(KickCParser.ExprIdContext ctx) {
Symbol symbol = getCurrentScope().getSymbol(ctx.NAME().getText());
if(symbol instanceof SymbolVariable) {
SymbolVariable variable = (SymbolVariable) symbol;
if(symbol instanceof Variable) {
Variable variable = (Variable) symbol;
return variable.getRef();
} else if(symbol instanceof Procedure) {
Procedure procedure = (Procedure) symbol;

View File

@ -6,7 +6,7 @@ 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.Symbol;
import dk.camelot64.kickc.model.symbols.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.values.RValue;
import dk.camelot64.kickc.model.values.SymbolVariableRef;
@ -29,8 +29,8 @@ public class Pass1AddressOfVolatile extends Pass2SsaOptimization {
RValue rValue = assignment.getrValue2();
if(rValue instanceof SymbolVariableRef) {
Symbol toSymbol = getScope().getSymbol((SymbolVariableRef) rValue);
if(toSymbol instanceof SymbolVariable) {
((SymbolVariable) toSymbol).setInferedVolatile(true);
if(toSymbol instanceof Variable) {
((Variable) toSymbol).setInferedVolatile(true);
getLog().append("Setting inferred volatile on symbol affected by address-of "+statement.toString(getProgram(), false));
}
}

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.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
/**
* 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(SymbolVariable parameter : procedure.getParameters()) {
for(Variable 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.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
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<SymbolVariable> declParameters = procedure.getParameters();
List<Variable> 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++) {
SymbolVariable declParameter = declParameters.get(i);
Variable declParameter = declParameters.get(i);
RValue callParameter = callParameters.get(i);
SymbolType callParameterType = SymbolTypeInference.inferType(getScope(), callParameter);
SymbolType declParameterType = declParameter.getType();

View File

@ -8,10 +8,9 @@ import dk.camelot64.kickc.model.statements.StatementAssignment;
import dk.camelot64.kickc.model.statements.StatementLValue;
import dk.camelot64.kickc.model.symbols.Procedure;
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;
import java.util.Collection;
@ -27,7 +26,7 @@ public class Pass1EarlyConstantIdentification extends Pass1Base {
@Override
public boolean step() {
Collection<SymbolVariableRef> earlyConstants = new ArrayList<>();
for(SymbolVariable variable : getProgram().getScope().getAllVariables(true)) {
for(Variable variable : getProgram().getScope().getAllVariables(true)) {
SymbolVariableRef variableRef = variable.getRef();
if(!variable.isDeclaredConstant() && !variable.isVolatile() && !variableRef.isIntermediate()) {
if(variable.isDeclaredNotConstant())
@ -42,11 +41,11 @@ public class Pass1EarlyConstantIdentification extends Pass1Base {
if(assign.getrValue1() == null && assign.getOperator() == null && assign.getrValue2() instanceof ConstantValue) {
getLog().append("Identified constant variable " + variable.toString(getProgram()));
earlyConstants.add(variableRef);
variable.setStorageStrategy(SymbolVariable.StorageStrategy.CONSTANT);
variable.setStorageStrategy(Variable.StorageStrategy.CONSTANT);
} else if(assign.getrValue1() == null && assign.getOperator() instanceof OperatorCastPtr && assign.getrValue2() instanceof ConstantValue) {
getLog().append("Identified constant variable " + variable.toString(getProgram()));
earlyConstants.add(variableRef);
variable.setStorageStrategy(SymbolVariable.StorageStrategy.CONSTANT);
variable.setStorageStrategy(Variable.StorageStrategy.CONSTANT);
}
}
}
@ -64,10 +63,10 @@ public class Pass1EarlyConstantIdentification extends Pass1Base {
* @return true if the variable is a procedure parameter
*/
public boolean isParameter(SymbolVariableRef variableRef) {
SymbolVariable var = getScope().getVariable(variableRef);
Variable var = getScope().getVariable(variableRef);
Scope varScope = var.getScope();
if(varScope instanceof Procedure) {
List<SymbolVariable> parameters = ((Procedure) varScope).getParameters();
List<Variable> parameters = ((Procedure) varScope).getParameters();
if(parameters.contains(var))
return true;
@ -81,7 +80,7 @@ public class Pass1EarlyConstantIdentification extends Pass1Base {
* @param variable The variable
* @return all assignments
*/
private Collection<StatementLValue> getAssignments(SymbolVariable variable) {
private Collection<StatementLValue> getAssignments(Variable variable) {
Collection<StatementLValue> assignments = new ArrayList<>();
for(ControlFlowBlock block : getGraph().getAllBlocks()) {
for(Statement statement : block.getStatements()) {

View File

@ -1,16 +1,15 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.model.*;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
import dk.camelot64.kickc.model.statements.StatementCallPrepare;
import dk.camelot64.kickc.model.symbols.SymbolVariable;
import dk.camelot64.kickc.model.values.ConstantString;
import dk.camelot64.kickc.model.values.RValue;
import dk.camelot64.kickc.model.statements.StatementCall;
import dk.camelot64.kickc.model.symbols.ConstantVar;
import dk.camelot64.kickc.model.statements.StatementCallPrepare;
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.types.SymbolType;
import dk.camelot64.kickc.model.values.ConstantString;
import dk.camelot64.kickc.model.values.RValue;
import dk.camelot64.kickc.model.values.Value;
import java.util.List;
@ -56,14 +55,14 @@ public class Pass1ExtractInlineStrings extends Pass1Base {
Scope blockScope = Pass1ExtractInlineStrings.this.getProgram().getScope().getScope(currentBlock.getScope());
Value value = programValue.get();
if(value instanceof ConstantString) {
SymbolVariable strConst = Pass1ExtractInlineStrings.this.createStringConstantVar(blockScope, (ConstantString) programValue.get(), nameHint);
Variable strConst = Pass1ExtractInlineStrings.this.createStringConstantVar(blockScope, (ConstantString) programValue.get(), nameHint);
programValue.set(strConst.getRef());
}
});
return false;
}
private SymbolVariable createStringConstantVar(Scope blockScope, ConstantString constantString, String nameHint) {
private Variable createStringConstantVar(Scope blockScope, ConstantString constantString, String nameHint) {
String name;
if(nameHint == null) {
name = blockScope.allocateIntermediateVariableName();
@ -74,7 +73,7 @@ public class Pass1ExtractInlineStrings extends Pass1Base {
name = nameHint + nameHintIdx++;
}
}
SymbolVariable strConst = new SymbolVariable(name, blockScope, SymbolType.STRING, blockScope.getSegmentData(), constantString);
Variable strConst = new Variable(name, blockScope, SymbolType.STRING, blockScope.getSegmentData(), constantString);
blockScope.add(strConst);
if(getLog().isVerbosePass1CreateSsa()) {
getLog().append("Creating constant string variable for inline " + strConst.toString(getProgram()) + " \"" + constantString.getValue() + "\"");

View File

@ -9,7 +9,7 @@ import dk.camelot64.kickc.model.statements.StatementAssignment;
import dk.camelot64.kickc.model.statements.StatementLValue;
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.values.LValue;
import dk.camelot64.kickc.model.values.LvalueIntermediate;
import dk.camelot64.kickc.model.values.SymbolVariableRef;
@ -75,10 +75,10 @@ public class Pass1FixLValuesLoHi extends Pass1Base {
StatementAssignment intermediateAssignment,
Operator loHiOperator) {
VariableRef loHiVar = (VariableRef) intermediateAssignment.getrValue2();
SymbolVariable intermediateVar = programScope.getVariable(intermediate.getVariable());
Variable intermediateVar = programScope.getVariable(intermediate.getVariable());
Scope currentScope = intermediateVar.getScope();
// Let assignment put value into a tmp Var
SymbolVariable tmpVar = currentScope.addVariableIntermediate();
Variable tmpVar = currentScope.addVariableIntermediate();
SymbolVariableRef tmpVarRef = tmpVar.getRef();
statementLValue.setlValue((LValue) tmpVarRef);
PassNTypeInference.updateInferedTypeLValue(getProgram(), statementLValue);

View File

@ -77,11 +77,11 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base {
*/
private void versionAssignment(VariableRef lValueRef, ProgramValue programLValue, StatementSource source) {
Collection<SymbolVariableRef> earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants();
SymbolVariable assignedVar = getScope().getVariable(lValueRef);
Variable assignedVar = getScope().getVariable(lValueRef);
if(assignedVar.isStoragePhiMaster()) {
if(assignedVar.isDeclaredConstant() || earlyIdentifiedConstants.contains(assignedVar.getRef()))
throw new InternalError("Error! Constants can not be versioned ", source);
SymbolVariable version = assignedVar.createVersion();
Variable version = assignedVar.createVersion();
programLValue.set(version.getRef());
}
}
@ -92,16 +92,16 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base {
private void versionAllUses() {
for(ControlFlowBlock block : getGraph().getAllBlocks()) {
// Newest version of variables in the block.
Map<SymbolVariable, SymbolVariable> blockVersions = new LinkedHashMap<>();
Map<Variable, Variable> blockVersions = new LinkedHashMap<>();
// New phi functions introduced in the block to create versions of variables.
Map<SymbolVariable, SymbolVariable> blockNewPhis = new LinkedHashMap<>();
Map<Variable, Variable> 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();
SymbolVariable version = findOrCreateVersion(value, blockVersions, blockNewPhis);
Variable version = findOrCreateVersion(value, blockVersions, blockNewPhis);
if(version != null) {
programValue.set(version.getRef());
}
@ -124,12 +124,12 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base {
if(currentStmt instanceof StatementAssignment) {
LValue lValue = ((StatementAssignment) currentStmt).getlValue();
if(lValue instanceof VariableRef) {
SymbolVariable assignedVar = Pass1GenerateSingleStaticAssignmentForm.this.getScope().getVariable((VariableRef) lValue);
Variable assignedVar = Pass1GenerateSingleStaticAssignmentForm.this.getScope().getVariable((VariableRef) lValue);
SymbolType assignedVarType = assignedVar.getType();
if(assignedVarType instanceof SymbolTypeArray) {
SymbolTypeArray assignedArrayType = (SymbolTypeArray) assignedVarType;
RValue arraySize = assignedArrayType.getSize();
SymbolVariable vrs = findOrCreateVersion(arraySize, blockVersions, blockNewPhis);
Variable vrs = findOrCreateVersion(arraySize, blockVersions, blockNewPhis);
if(vrs != null) {
assignedArrayType.setSize(vrs.getRef());
}
@ -138,15 +138,15 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base {
}
});
// Add new Phi functions to block
for(SymbolVariable symbol : blockNewPhis.keySet()) {
for(Variable symbol : blockNewPhis.keySet()) {
block.getPhiBlock().addPhiVariable((VariableRef) blockNewPhis.get(symbol).getRef());
}
}
}
private void updateBlockVersions(VariableRef lValue, Map<SymbolVariable, SymbolVariable> blockVersions) {
private void updateBlockVersions(VariableRef lValue, Map<Variable, Variable> blockVersions) {
VariableRef lValueRef = lValue;
SymbolVariable variable = Pass1GenerateSingleStaticAssignmentForm.this.getScope().getVariable(lValueRef);
Variable variable = Pass1GenerateSingleStaticAssignmentForm.this.getScope().getVariable(lValueRef);
if(variable.isStoragePhiVersion()) {
blockVersions.put(variable.getVersionOf(), variable);
}
@ -161,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 SymbolVariable findOrCreateVersion(
private Variable findOrCreateVersion(
Value rValue,
Map<SymbolVariable, SymbolVariable> blockVersions,
Map<SymbolVariable, SymbolVariable> blockNewPhis) {
Map<Variable, Variable> blockVersions,
Map<Variable, Variable> blockNewPhis) {
Collection<SymbolVariableRef> earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants();
SymbolVariable version = null;
Variable version = null;
if(rValue instanceof VariableRef) {
SymbolVariable rValueVar = getScope().getVariable((VariableRef) rValue);
Variable rValueVar = getScope().getVariable((VariableRef) rValue);
if(rValueVar.isStoragePhiMaster()) {
// rValue needs versioning - look for version in statements
SymbolVariable rSymbol = rValueVar;
Variable rSymbol = rValueVar;
if(rSymbol.isDeclaredConstant() || earlyIdentifiedConstants.contains(rSymbol.getRef())) {
// A constant - find the single created version
Scope scope = rSymbol.getScope();
Collection<SymbolVariable> versions = scope.getVersions(rSymbol);
Collection<Variable> versions = scope.getVersions(rSymbol);
if(versions.size() != 1) {
throw new CompileError("Error! Constants must have exactly one version " + rSymbol);
}
@ -205,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<SymbolVariable, SymbolVariable>> newPhis = new LinkedHashMap<>();
Map<LabelRef, Map<SymbolVariable, SymbolVariable>> symbolMap = buildSymbolMap();
Map<LabelRef, Map<Variable, Variable>> newPhis = new LinkedHashMap<>();
Map<LabelRef, Map<Variable, Variable>> symbolMap = buildSymbolMap();
for(ControlFlowBlock block : getGraph().getAllBlocks()) {
for(Statement statement : block.getStatements()) {
@ -215,19 +215,19 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base {
for(StatementPhiBlock.PhiVariable phiVariable : phiBlock.getPhiVariables()) {
if(phiVariable.isEmpty()) {
VariableRef phiLValVarRef = phiVariable.getVariable();
SymbolVariable versioned = getScope().getVariable(phiLValVarRef);
SymbolVariable unversioned = versioned.getVersionOf();
Variable versioned = getScope().getVariable(phiLValVarRef);
Variable unversioned = versioned.getVersionOf();
List<ControlFlowBlock> predecessors = getPhiPredecessors(block, getProgram());
for(ControlFlowBlock predecessor : predecessors) {
LabelRef predecessorLabel = predecessor.getLabel();
Map<SymbolVariable, SymbolVariable> predecessorMap = symbolMap.get(predecessorLabel);
SymbolVariable previousSymbol = null;
Map<Variable, Variable> predecessorMap = symbolMap.get(predecessorLabel);
Variable 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<SymbolVariable, SymbolVariable> predecessorNewPhis = newPhis.get(predecessorLabel);
Map<Variable, Variable> predecessorNewPhis = newPhis.get(predecessorLabel);
if(predecessorNewPhis == null) {
predecessorNewPhis = new LinkedHashMap<>();
newPhis.put(predecessorLabel, predecessorNewPhis);
@ -248,11 +248,11 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base {
}
// Ads new phi functions to blocks
for(ControlFlowBlock block : getGraph().getAllBlocks()) {
Map<SymbolVariable, SymbolVariable> blockNewPhis = newPhis.get(block.getLabel());
Map<Variable, Variable> blockNewPhis = newPhis.get(block.getLabel());
if(blockNewPhis != null) {
for(SymbolVariable symbol : blockNewPhis.keySet()) {
for(Variable symbol : blockNewPhis.keySet()) {
StatementPhiBlock phiBlock = block.getPhiBlock();
SymbolVariable variable = blockNewPhis.get(symbol);
Variable variable = blockNewPhis.get(symbol);
phiBlock.addPhiVariable((VariableRef) variable.getRef());
}
}
@ -290,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<SymbolVariable, SymbolVariable>> buildSymbolMap() {
Map<LabelRef, Map<SymbolVariable, SymbolVariable>> symbolMap = new LinkedHashMap<>();
private Map<LabelRef, Map<Variable, Variable>> buildSymbolMap() {
Map<LabelRef, Map<Variable, Variable>> symbolMap = new LinkedHashMap<>();
for(ControlFlowBlock block : getGraph().getAllBlocks()) {
for(Statement statement : block.getStatements()) {
if(statement instanceof StatementLValue) {
@ -308,14 +308,14 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base {
return symbolMap;
}
private void addSymbolToMap(LValue lValue, ControlFlowBlock block, Map<LabelRef, Map<SymbolVariable, SymbolVariable>> symbolMap) {
private void addSymbolToMap(LValue lValue, ControlFlowBlock block, Map<LabelRef, Map<Variable, Variable>> symbolMap) {
if(lValue instanceof VariableRef) {
SymbolVariable lValueVar = getScope().getVariable((VariableRef) lValue);
Variable lValueVar = getScope().getVariable((VariableRef) lValue);
if(lValueVar.isStoragePhiVersion()) {
SymbolVariable versioned = lValueVar;
Variable versioned = lValueVar;
LabelRef label = block.getLabel();
SymbolVariable unversioned = versioned.getVersionOf();
Map<SymbolVariable, SymbolVariable> blockMap = symbolMap.get(label);
Variable unversioned = versioned.getVersionOf();
Map<Variable, Variable> blockMap = symbolMap.get(label);
if(blockMap == null) {
blockMap = new LinkedHashMap<>();
symbolMap.put(label, blockMap);

View File

@ -11,7 +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;
import dk.camelot64.kickc.model.types.SymbolTypePointer;
@ -60,7 +60,7 @@ public class Pass1PointerSizeofFix extends Pass1Base {
getLog().append("Fixing pointer array-indexing " + deref.toString(getProgram()));
SymbolVariableRef idx2VarRef = handled.getOrDefault(currentStmt, new LinkedHashMap<>()).get(deref.getIndex());
if(idx2VarRef == null) {
SymbolVariable idx2Var = getScope().getScope(currentBlock.getScope()).addVariableIntermediate();
Variable idx2Var = getScope().getScope(currentBlock.getScope()).addVariableIntermediate();
idx2Var.setTypeInferred(SymbolTypeInference.inferType(getScope(), deref.getIndex()));
ConstantRef sizeOfTargetType = OperatorSizeOf.getSizeOfConstantVar(getProgram().getScope(), pointerType.getElementType());
StatementAssignment idx2 = new StatementAssignment((LValue) idx2Var.getRef(), deref.getIndex(), Operators.MULTIPLY, sizeOfTargetType, currentStmt.getSource(), Comment.NO_COMMENTS);
@ -103,7 +103,7 @@ public class Pass1PointerSizeofFix extends Pass1Base {
isPointerPlusConst = false;
getLog().append("Fixing pointer addition " + assignment.toString(getProgram(), false));
LValue lValue = assignment.getlValue();
SymbolVariable tmpVar = getScope().getScope(block.getScope()).addVariableIntermediate();
Variable tmpVar = getScope().getScope(block.getScope()).addVariableIntermediate();
tmpVar.setTypeInferred(SymbolTypeInference.inferType(getScope(), assignment.getlValue()));
assignment.setlValue((LValue) tmpVar.getRef());
ConstantRef sizeOfTargetType = OperatorSizeOf.getSizeOfConstantVar(getProgram().getScope(), pointerType.getElementType());
@ -115,7 +115,7 @@ public class Pass1PointerSizeofFix extends Pass1Base {
// Binary operation on a non-byte pointer - sizeof()-handling is probably needed!
// Adding to a pointer - multiply by sizeof()
getLog().append("Fixing pointer addition " + assignment.toString(getProgram(), false));
SymbolVariable tmpVar = getScope().getScope(block.getScope()).addVariableIntermediate();
Variable tmpVar = getScope().getScope(block.getScope()).addVariableIntermediate();
tmpVar.setTypeInferred(SymbolTypeInference.inferType(getScope(), assignment.getrValue2()));
stmtIt.remove();
ConstantRef sizeOfTargetType = OperatorSizeOf.getSizeOfConstantVar(getProgram().getScope(), pointerType.getElementType());
@ -170,7 +170,7 @@ public class Pass1PointerSizeofFix extends Pass1Base {
private SymbolTypePointer getPointerType(RValue pointer) {
if(pointer instanceof VariableRef) {
VariableRef varRef = (VariableRef) pointer;
SymbolVariable variable = getScope().getVariable(varRef);
Variable variable = getScope().getVariable(varRef);
SymbolType type = variable.getType();
if(type instanceof SymbolTypePointer) {
return (SymbolTypePointer) type;
@ -181,7 +181,7 @@ public class Pass1PointerSizeofFix extends Pass1Base {
SymbolType structType = SymbolTypeInference.inferType(getScope(), struct);
if(structType instanceof SymbolTypeStruct) {
StructDefinition structDefinition = ((SymbolTypeStruct) structType).getStructDefinition(getScope());
SymbolVariable memberVariable = structDefinition.getMember(structMemberRef.getMemberName());
Variable memberVariable = structDefinition.getMember(structMemberRef.getMemberName());
SymbolType memberType = memberVariable.getType();
if(memberType instanceof SymbolTypePointer) {
return (SymbolTypePointer) memberType;

View File

@ -59,18 +59,18 @@ public class Pass1ProcedureCallParameters extends ControlFlowGraphCopyVisitor {
return copyCall;
}
List<SymbolVariable> parameterDecls = procedure.getParameters();
List<Variable> 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++) {
SymbolVariable parameterDecl = parameterDecls.get(i);
Variable parameterDecl = parameterDecls.get(i);
RValue parameterValue = parameterValues.get(i);
addStatementToCurrentBlock(new StatementAssignment((LValue) parameterDecl.getRef(), parameterValue, origCall.getSource(), Comment.NO_COMMENTS));
}
String procedureName = origCall.getProcedureName();
SymbolVariable procReturnVar = procedure.getVariable("return");
Variable procReturnVar = procedure.getVariable("return");
LValue procReturnVarRef = null;
if(procReturnVar != null) {
procReturnVarRef = (LValue) procReturnVar.getRef();
@ -108,7 +108,7 @@ public class Pass1ProcedureCallParameters extends ControlFlowGraphCopyVisitor {
LValue lValue = origCall.getlValue();
if(lValue instanceof VariableRef) {
VariableRef lValueRef = (VariableRef) lValue;
SymbolVariable lValueVar = getScope().getVariable(lValueRef);
Variable 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)) {
SymbolVariable procReturnVar = procedure.getVariable("return");
Variable procReturnVar = procedure.getVariable("return");
String inlinedReturnVarName = getInlineSymbolName(procedure, procReturnVar, serial);
SymbolVariable inlinedReturnVar = callScope.getVariable(inlinedReturnVarName);
Variable 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;
SymbolVariable procVar = Pass1ProcedureInline.this.getScope().getVariable(procVarRef);
Variable procVar = Pass1ProcedureInline.this.getScope().getVariable(procVarRef);
if(procVar.getScope().equals(procedure)) {
String inlineSymbolName = Pass1ProcedureInline.this.getInlineSymbolName(procedure, procVar, serial);
SymbolVariable inlineVar = callScope.getVariable(inlineSymbolName);
Variable inlineVar = callScope.getVariable(inlineSymbolName);
programValue.set(inlineVar.getRef());
}
} else if(rValue instanceof PointerDereferenceSimple) {
@ -274,12 +274,12 @@ 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<SymbolVariable> parameterDecls = procedure.getParameters();
List<Variable> parameterDecls = procedure.getParameters();
List<RValue> parameterValues = call.getParameters();
for(int i = 0; i < parameterDecls.size(); i++) {
SymbolVariable parameterDecl = parameterDecls.get(i);
Variable parameterDecl = parameterDecls.get(i);
String inlineParameterVarName = getInlineSymbolName(procedure, parameterDecl, serial);
SymbolVariable inlineParameterVar = callScope.getVariable(inlineParameterVarName);
Variable inlineParameterVar = callScope.getVariable(inlineParameterVarName);
RValue parameterValue = parameterValues.get(i);
statementsIt.add(new StatementAssignment((VariableRef)inlineParameterVar.getRef(), parameterValue, call.getSource(), Comment.NO_COMMENTS));
}
@ -297,10 +297,10 @@ public class Pass1ProcedureInline extends Pass1Base {
callScope.addLabel(procedure.getLocalName() + serial);
// And copy all procedure symbols
for(Symbol procSymbol : procedure.getAllSymbols()) {
if(procSymbol instanceof SymbolVariable) {
SymbolVariable procVar = (SymbolVariable) procSymbol;
if(procSymbol instanceof Variable) {
Variable procVar = (Variable) procSymbol;
String inlineVarName = getInlineSymbolName(procedure, procSymbol, serial);
SymbolVariable inlineVar = callScope.addVariablePhiMaster(inlineVarName, procSymbol.getType(), procVar.getMemoryArea(), procVar.getDataSegment());
Variable inlineVar = callScope.addVariablePhiMaster(inlineVarName, procSymbol.getType(), procVar.getMemoryArea(), procVar.getDataSegment());
inlineVar.setInferredType(procVar.isInferredType());
inlineVar.setDeclaredAlignment(procVar.getDeclaredAlignment());
inlineVar.setConstantDeclaration(procVar.getConstantDeclaration());

View File

@ -2,7 +2,7 @@ package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.symbols.StructDefinition;
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.SymbolTypePointer;
import dk.camelot64.kickc.model.types.SymbolTypeStruct;
@ -21,7 +21,7 @@ public class Pass1StructTypeSizeFix extends Pass2SsaOptimization {
@Override
public boolean step() {
AtomicBoolean modified = new AtomicBoolean(false);
for(SymbolVariable variable : getScope().getAllVariables(true)) {
for(Variable variable : getScope().getAllVariables(true)) {
modified.set(fixStructSize(variable.getType()));
}
return modified.get();

View File

@ -71,12 +71,12 @@ public class Pass1UnwindBlockScopes extends Pass1Base {
Label unwound = procedure.addLabel(name);
unwoundSymbols.put(symbol.getRef(), unwound.getRef());
}
} else if(symbol instanceof SymbolVariable) {
SymbolVariable variable = (SymbolVariable) symbol;
} else if(symbol instanceof Variable) {
Variable variable = (Variable) symbol;
if(variable.isStoragePhiMaster() || variable.isStorageConstant()) {
String name = findLocalName(procedure, symbol);
SymbolVariable var = (SymbolVariable) symbol;
SymbolVariable unwound = procedure.addVariablePhiMaster(name, symbol.getType(), var.getMemoryArea(), var.getDataSegment());
Variable var = (Variable) symbol;
Variable unwound = procedure.addVariablePhiMaster(name, symbol.getType(), var.getMemoryArea(), var.getDataSegment());
unwound.setDeclaredAlignment(var.getDeclaredAlignment());
unwound.setConstantDeclaration(var.getConstantDeclaration());
unwound.setDeclaredVolatile(var.isDeclaredVolatile());
@ -87,7 +87,7 @@ public class Pass1UnwindBlockScopes extends Pass1Base {
unwound.setStorageStrategy(var.getStorageStrategy());
unwound.setMemoryArea(var.getMemoryArea());
} else if(variable.isStorageIntermediate()) {
SymbolVariable unwound = procedure.addVariableIntermediate();
Variable unwound = procedure.addVariableIntermediate();
unwound.setStorageStrategy(variable.getStorageStrategy());
unwound.setMemoryArea(variable.getMemoryArea());
unwoundSymbols.put(symbol.getRef(), unwound.getRef());

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(SymbolVariable parameter : procedure.getParameters()) {
for(Variable parameter : procedure.getParameters()) {
if(parameter.getType() instanceof SymbolTypeStruct) {
StructUnwinding structUnwinding = getProgram().getStructUnwinding();
StructUnwinding.VariableUnwinding parameterUnwinding = structUnwinding.getVariableUnwinding(parameter.getRef());
@ -199,7 +199,7 @@ public class Pass1UnwindStructValues extends Pass1Base {
private boolean unwindStructVariables() {
boolean modified = false;
// Iterate through all scopes generating member-variables for each struct
for(SymbolVariable variable : getScope().getAllVariables(true)) {
for(Variable variable : getScope().getAllVariables(true)) {
if(variable.getType() instanceof SymbolTypeStruct) {
StructUnwinding structUnwinding = getProgram().getStructUnwinding();
if(structUnwinding.getVariableUnwinding(variable.getRef()) == null) {
@ -209,14 +209,14 @@ public class Pass1UnwindStructValues extends Pass1Base {
// Not inside another struct
StructDefinition structDefinition = ((SymbolTypeStruct) variable.getType()).getStructDefinition(getProgram().getScope());
StructUnwinding.VariableUnwinding variableUnwinding = structUnwinding.createVariableUnwinding(variable.getRef());
for(SymbolVariable member : structDefinition.getAllVariables(false)) {
SymbolVariable memberVariable;
for(Variable member : structDefinition.getAllVariables(false)) {
Variable memberVariable;
if(variable.getRef().isIntermediate()) {
memberVariable = scope.add(new SymbolVariable( false, variable.getLocalName() + "_" + member.getLocalName(), scope, member.getType(), SymbolVariable.StorageStrategy.INTERMEDIATE, variable.getMemoryArea(), variable.getDataSegment()));
memberVariable = scope.add(new Variable( variable.getLocalName() + "_" + member.getLocalName(), scope, member.getType(), Variable.StorageStrategy.INTERMEDIATE, variable.getMemoryArea(), variable.getDataSegment()));
} else {
if(member.getType() instanceof SymbolTypePointer) {
// Always put pointers in ZP memory area
memberVariable = scope.addVariablePhiMaster(variable.getLocalName() + "_" + member.getLocalName(), member.getType(), SymbolVariable.MemoryArea.ZEROPAGE_MEMORY, variable.getDataSegment());
memberVariable = scope.addVariablePhiMaster(variable.getLocalName() + "_" + member.getLocalName(), member.getType(), Variable.MemoryArea.ZEROPAGE_MEMORY, variable.getDataSegment());
} else {
memberVariable = scope.addVariablePhiMaster(variable.getLocalName() + "_" + member.getLocalName(), member.getType(), member.getMemoryArea(), variable.getDataSegment());
}
@ -227,7 +227,7 @@ public class Pass1UnwindStructValues extends Pass1Base {
memberVariable.setDeclaredExport(variable.isDeclaredExport());
memberVariable.setStorageStrategy(variable.getStorageStrategy());
if(memberVariable.getType() instanceof SymbolTypePointer) {
memberVariable.setMemoryArea(SymbolVariable.MemoryArea.ZEROPAGE_MEMORY);
memberVariable.setMemoryArea(Variable.MemoryArea.ZEROPAGE_MEMORY);
} else {
memberVariable.setMemoryArea(variable.getMemoryArea());
}
@ -267,7 +267,7 @@ public class Pass1UnwindStructValues extends Pass1Base {
for(String memberName : memberUnwinding.getMemberNames()) {
VariableRef memberVarRef = (VariableRef) memberUnwinding.getMemberUnwinding(memberName);
membersUnwound.add(memberVarRef);
SymbolVariable memberVar = getScope().getVariable(memberVarRef);
Variable 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));
@ -405,9 +405,9 @@ public class Pass1UnwindStructValues extends Pass1Base {
@Override
public List<String> getMemberNames() {
Collection<SymbolVariable> structMemberVars = structDefinition.getAllVariables(false);
Collection<Variable> structMemberVars = structDefinition.getAllVariables(false);
ArrayList<String> memberNames = new ArrayList<>();
for(SymbolVariable structMemberVar : structMemberVars) {
for(Variable structMemberVar : structMemberVars) {
memberNames.add(structMemberVar.getLocalName());
}
return memberNames;
@ -416,9 +416,9 @@ public class Pass1UnwindStructValues extends Pass1Base {
@Override
public LValue getMemberUnwinding(String memberName) {
ConstantRef memberOffsetConstant = PassNStructPointerRewriting.getMemberOffsetConstant(getScope(), structDefinition, memberName);
SymbolVariable member = structDefinition.getMember(memberName);
Variable member = structDefinition.getMember(memberName);
Scope scope = getScope().getScope(currentBlock.getScope());
SymbolVariable memberAddress = scope.addVariableIntermediate();
Variable memberAddress = scope.addVariableIntermediate();
memberAddress.setType(new SymbolTypePointer(member.getType()));
CastValue structTypedPointer = new CastValue(new SymbolTypePointer(member.getType()), pointerDeref.getPointer());
// Add statement $1 = ptr_struct + OFFSET_STRUCT_NAME_MEMBER
@ -446,9 +446,9 @@ public class Pass1UnwindStructValues extends Pass1Base {
@Override
public List<String> getMemberNames() {
Collection<SymbolVariable> structMemberVars = structDefinition.getAllVariables(false);
Collection<Variable> structMemberVars = structDefinition.getAllVariables(false);
ArrayList<String> memberNames = new ArrayList<>();
for(SymbolVariable structMemberVar : structMemberVars) {
for(Variable structMemberVar : structMemberVars) {
memberNames.add(structMemberVar.getLocalName());
}
return memberNames;
@ -457,9 +457,9 @@ public class Pass1UnwindStructValues extends Pass1Base {
@Override
public LValue getMemberUnwinding(String memberName) {
ConstantRef memberOffsetConstant = PassNStructPointerRewriting.getMemberOffsetConstant(getScope(), structDefinition, memberName);
SymbolVariable member = structDefinition.getMember(memberName);
Variable member = structDefinition.getMember(memberName);
Scope scope = getScope().getScope(currentBlock.getScope());
SymbolVariable memberAddress = scope.addVariableIntermediate();
Variable memberAddress = scope.addVariableIntermediate();
memberAddress.setType(new SymbolTypePointer(member.getType()));
CastValue structTypedPointer = new CastValue(new SymbolTypePointer(member.getType()), pointerDeref.getPointer());
// Add statement $1 = ptr_struct + OFFSET_STRUCT_NAME_MEMBER

View File

@ -6,7 +6,7 @@ import dk.camelot64.kickc.model.StructUnwinding;
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.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.types.SymbolTypeStruct;
import dk.camelot64.kickc.model.values.RValue;
import dk.camelot64.kickc.model.values.StructUnwoundPlaceholder;
@ -38,12 +38,12 @@ public class Pass1UnwindStructVersions extends Pass1Base {
StructUnwoundPlaceholder placeholder = (StructUnwoundPlaceholder) assignment.getrValue2();
SymbolTypeStruct typeStruct = placeholder.getTypeStruct();
StructDefinition structDefinition = typeStruct.getStructDefinition(getProgram().getScope());
Collection<SymbolVariable> members = structDefinition.getAllVariables(false);
Iterator<SymbolVariable> memberDefIt = members.iterator();
Collection<Variable> members = structDefinition.getAllVariables(false);
Iterator<Variable> memberDefIt = members.iterator();
List<RValue> unwoundMembers = placeholder.getUnwoundMembers();
Iterator<RValue> memberUnwoundIt = unwoundMembers.iterator();
while(memberDefIt.hasNext()) {
SymbolVariable memberVar = memberDefIt.next();
Variable memberVar = memberDefIt.next();
RValue memberVal = memberUnwoundIt.next();
versionedUnwinding.setMemberUnwinding(memberVar.getLocalName(), (VariableRef) memberVal);
}

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.ProgramScope;
import dk.camelot64.kickc.model.symbols.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.values.*;
import java.util.*;
@ -92,7 +92,7 @@ public class Pass2AliasElimination extends Pass2SsaOptimization {
boolean sameBaseVar = true;
String unversionedFullName = null;
for(VariableRef variableRef : aliasSet.getVars()) {
SymbolVariable variable = programScope.getVariable(variableRef);
Variable variable = programScope.getVariable(variableRef);
if(variable.isVolatile() || variable.isStorageLoadStore()) {
anyVolatile = true;
}
@ -419,7 +419,7 @@ public class Pass2AliasElimination extends Pass2SsaOptimization {
for(VariableRef var : vars) {
String name;
int score;
SymbolVariable variable = scope.getVariable(var);
Variable variable = scope.getVariable(var);
if(variable.isDeclaredConstant() || variable.isStorageConstant()) {
name = var.getFullNameUnversioned();
score = 100;

View File

@ -3,7 +3,7 @@ package dk.camelot64.kickc.passes;
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.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypeArray;
import dk.camelot64.kickc.model.values.ConstantRef;
@ -57,14 +57,14 @@ public class Pass2ArrayInStructInlining extends Pass2SsaOptimization {
Value value = programValue.get();
if(programValue instanceof ProgramValue.ProgramValueConstantStructMember) {
SymbolVariableRef memberRef = ((ProgramValue.ProgramValueConstantStructMember) programValue).getMemberRef();
SymbolVariable structMemberVar = getScope().getVariable(memberRef);
Variable structMemberVar = getScope().getVariable(memberRef);
if(structMemberVar.getType() instanceof SymbolTypeArray) {
if(((SymbolTypeArray) structMemberVar.getType()).getSize() != null) {
if(value instanceof ConstantValue) {
ConstantValue constantValue = (ConstantValue) value;
if(constantValue.getType(getProgram().getScope()).equals(SymbolType.STRING)) {
if(constantValue instanceof ConstantRef) {
SymbolVariable constantStringVar = getScope().getConstant((ConstantRef) constantValue);
Variable constantStringVar = getScope().getConstant((ConstantRef) constantValue);
inline.put((ConstantRef) constantValue, constantStringVar.getConstantValue());
}
}

View File

@ -4,7 +4,7 @@ import dk.camelot64.kickc.model.CompileError;
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.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.values.ForwardVariableRef;
import dk.camelot64.kickc.model.values.Value;
import dk.camelot64.kickc.model.values.VariableRef;
@ -29,7 +29,7 @@ public class Pass2AssertRValues extends Pass2SsaAssertion {
}
if(rValue instanceof VariableRef) {
VariableRef variableRef = (VariableRef) rValue;
SymbolVariable variable = getScope().getVariable(variableRef);
Variable variable = getScope().getVariable(variableRef);
if(variable.isStoragePhiMaster()) {
throw new CompileError("No unversioned variable references allowed "+currentStmt.toString(getProgram(), false), currentStmt.getSource());
}

View File

@ -43,10 +43,10 @@ public class Pass2AssertSymbols extends Pass2SsaAssertion {
Collection<Symbol> tableSymbols = getScope().getAllSymbols(true);
for(Symbol tableSymbol : tableSymbols) {
if(tableSymbol instanceof SymbolVariable && ((SymbolVariable) tableSymbol).isStoragePhiMaster()) continue;
if(tableSymbol instanceof SymbolVariable && ((SymbolVariable) tableSymbol).isStorageConstant()) continue;
if(tableSymbol instanceof SymbolVariable && ((SymbolVariable) tableSymbol).isStorageLoadStore()) continue;
if(tableSymbol instanceof SymbolVariable && (((SymbolVariable) tableSymbol).isConstant()) ) continue;
if(tableSymbol instanceof Variable && ((Variable) tableSymbol).isStoragePhiMaster()) continue;
if(tableSymbol instanceof Variable && ((Variable) tableSymbol).isStorageConstant()) continue;
if(tableSymbol instanceof Variable && ((Variable) tableSymbol).isStorageLoadStore()) continue;
if(tableSymbol instanceof Variable && (((Variable) tableSymbol).isConstant()) ) continue;
if(tableSymbol instanceof StructDefinition) continue;
if(tableSymbol instanceof EnumDefinition) continue;
if(tableSymbol instanceof TypeDefsScope) continue;

View File

@ -5,7 +5,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.statements.StatementCallPointer;
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.SymbolTypePointer;
import dk.camelot64.kickc.model.types.SymbolTypeProcedure;
@ -38,7 +38,7 @@ public class Pass2ConstantCallPointerIdentification extends Pass2SsaOptimization
optimized = true;
}
} else if(procedure instanceof ConstantRef) {
SymbolVariable procedureVariable = getScope().getConstant((ConstantRef) procedure);
Variable procedureVariable = getScope().getConstant((ConstantRef) procedure);
SymbolType procedureVariableType = procedureVariable.getType();
if(procedureVariableType instanceof SymbolTypePointer) {
if(((SymbolTypePointer) procedureVariableType).getElementType() instanceof SymbolTypeProcedure) {
@ -82,7 +82,7 @@ public class Pass2ConstantCallPointerIdentification extends Pass2SsaOptimization
*/
private ProcedureRef findConstProcedure(RValue procedurePointer) {
if(procedurePointer instanceof ConstantRef) {
SymbolVariable constant = getScope().getConstant((ConstantRef) procedurePointer);
Variable constant = getScope().getConstant((ConstantRef) procedurePointer);
return findConstProcedure(constant.getConstantValue());
} else if(procedurePointer instanceof ConstantSymbolPointer) {
ConstantSymbolPointer pointer = (ConstantSymbolPointer) procedurePointer;

View File

@ -41,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) {
SymbolVariable variable = getProgram().getScope().getVariable(constRef);
Variable variable = getProgram().getScope().getVariable(constRef);
ConstantVariableValue constVarVal = constants.get(constRef);
Scope constScope = variable.getScope();
ConstantValue constVal = constVarVal.getConstantValue();
@ -69,7 +69,7 @@ public class Pass2ConstantIdentification extends Pass2SsaOptimization {
);
}
SymbolVariable constantVar = new SymbolVariable(
Variable constantVar = new Variable(
variable.getName(),
constScope,
variableType,
@ -151,7 +151,7 @@ public class Pass2ConstantIdentification extends Pass2SsaOptimization {
LValue lValue = assignment.getlValue();
if(lValue instanceof VariableRef) {
VariableRef varRef = (VariableRef) lValue;
SymbolVariable var = getScope().getVariable(varRef);
Variable var = getScope().getVariable(varRef);
if(var.isVolatile() || var.isDeclaredNotConstant() || var.isStorageLoadStore())
// Do not examine volatiles and non-versioned variables
continue;
@ -167,7 +167,7 @@ public class Pass2ConstantIdentification extends Pass2SsaOptimization {
StatementPhiBlock.PhiRValue phiRValue = phiVariable.getValues().get(0);
if(getConstant(phiRValue.getrValue()) != null) {
VariableRef varRef = phiVariable.getVariable();
SymbolVariable var = getScope().getVariable(varRef);
Variable var = getScope().getVariable(varRef);
if(var.isVolatile() || var.isDeclaredNotConstant() || var.isStorageLoadStore())
// Do not examine volatiles and non-versioned variables
continue;
@ -181,7 +181,7 @@ public class Pass2ConstantIdentification extends Pass2SsaOptimization {
}
// Look for constants among non-versioned variables
for(SymbolVariable variable : getScope().getAllVariables(true)) {
for(Variable variable : getScope().getAllVariables(true)) {
if(variable.isVolatile() || variable.isDeclaredNotConstant() || !variable.isStorageLoadStore())
// Do not examine volatiles, non-constants or versioned variables
continue;
@ -216,8 +216,8 @@ public class Pass2ConstantIdentification extends Pass2SsaOptimization {
public static ConstantValue getConstant(RValue rValue) {
if(rValue instanceof ConstantValue) {
return (ConstantValue) rValue;
} else if(rValue instanceof SymbolVariable && ((SymbolVariable) rValue).isConstant()) {
SymbolVariable constantVar = (SymbolVariable) rValue;
} else if(rValue instanceof Variable && ((Variable) rValue).isConstant()) {
Variable constantVar = (Variable) rValue;
return constantVar.getConstantRef();
} else if(rValue instanceof CastValue) {
CastValue castValue = (CastValue) rValue;

View File

@ -6,7 +6,7 @@ import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
import dk.camelot64.kickc.model.statements.Statement;
import dk.camelot64.kickc.model.symbols.StructDefinition;
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;
import dk.camelot64.kickc.model.types.SymbolTypeConversion;
@ -86,7 +86,7 @@ public class Pass2ConstantInitializerValueLists extends Pass2SsaOptimization {
// Check that type of constant values match the struct member types
SymbolTypeStruct declaredStructType = (SymbolTypeStruct) declaredType;
StructDefinition structDefinition = declaredStructType.getStructDefinition(getScope());
Collection<SymbolVariable> memberDefs = structDefinition.getAllVariables(false);
Collection<Variable> memberDefs = structDefinition.getAllVariables(false);
if(memberDefs.size()!=constantValues.size()) {
throw new CompileError(
"Struct initializer has wrong size ("+valueList.getList().size()+"), " +
@ -94,10 +94,10 @@ public class Pass2ConstantInitializerValueLists extends Pass2SsaOptimization {
" Struct initializer: "+valueList.toString(getProgram()),
currentStmt);
}
Iterator<SymbolVariable> memberDefIt = memberDefs.iterator();
Iterator<Variable> memberDefIt = memberDefs.iterator();
LinkedHashMap<SymbolVariableRef, ConstantValue> memberValues = new LinkedHashMap<>();
for(int i = 0; i < constantValues.size(); i++) {
SymbolVariable memberDef = memberDefIt.next();
Variable memberDef = memberDefIt.next();
SymbolType declaredElementType = memberDef.getType();
ConstantValue memberValue = constantValues.get(i);
SymbolType elmType = memberValue.getType(getScope());

View File

@ -89,8 +89,8 @@ public class Pass2ConstantInlining extends Pass2SsaOptimization {
*/
private Map<ConstantRef, ConstantValue> findUnnamedConstants() {
Map<ConstantRef, ConstantValue> unnamed = new HashMap<>();
Collection<SymbolVariable> allConstants = getProgram().getScope().getAllConstants(true);
for(SymbolVariable constant : allConstants) {
Collection<Variable> allConstants = getProgram().getScope().getAllConstants(true);
for(Variable constant : allConstants) {
if(constant.getRef().isIntermediate()) {
if(!(constant.getType().equals(SymbolType.STRING)) && !(constant.getConstantValue() instanceof ConstantArray)) {
unnamed.put(constant.getConstantRef(), constant.getConstantValue());
@ -108,8 +108,8 @@ public class Pass2ConstantInlining extends Pass2SsaOptimization {
private Map<ConstantRef, ConstantValue> findAliasConstants() {
Map<ConstantRef, ConstantValue> aliases = new HashMap<>();
ProgramScope programScope = getProgram().getScope();
Collection<SymbolVariable> allConstants = programScope.getAllConstants(true);
for(SymbolVariable constant : allConstants) {
Collection<Variable> allConstants = programScope.getAllConstants(true);
for(Variable constant : allConstants) {
ConstantValue constantValue = constant.getConstantValue();
if(constantValue instanceof ConstantRef) {
if(((ConstantRef) constantValue).isIntermediate()) {
@ -134,8 +134,8 @@ public class Pass2ConstantInlining extends Pass2SsaOptimization {
private Map<ConstantRef, ConstantValue> findConstVarVersions() {
Map<ConstantRef, ConstantValue> aliases = new HashMap<>();
Collection<SymbolVariable> allConstants = getProgram().getScope().getAllConstants(true);
for(SymbolVariable constant : allConstants) {
Collection<Variable> allConstants = getProgram().getScope().getAllConstants(true);
for(Variable constant : allConstants) {
if(constant.getRef().isVersion()) {
// Constant is a version - find the other versions
String baseName = constant.getRef().getFullNameUnversioned();
@ -143,12 +143,12 @@ public class Pass2ConstantInlining extends Pass2SsaOptimization {
for(Symbol symbol : scopeSymbols) {
if(symbol.getRef().isVersion() && symbol.getRef().getFullNameUnversioned().equals(baseName)) {
ConstantValue value = constant.getConstantValue();
if(symbol instanceof SymbolVariable && ((SymbolVariable) symbol).isVariable()) {
if(symbol instanceof Variable && ((Variable) symbol).isVariable()) {
aliases.put(constant.getConstantRef(), value);
getLog().append("Inlining constant with var siblings " + constant);
break;
} else if(symbol instanceof SymbolVariable && ((SymbolVariable) symbol).isConstant()) {
ConstantValue otherValue = ((SymbolVariable) symbol).getConstantValue();
} else if(symbol instanceof Variable && ((Variable) symbol).isConstant()) {
ConstantValue otherValue = ((Variable) symbol).getConstantValue();
if(!otherValue.equals(value) && !(value instanceof ConstantString) && !(value instanceof ConstantArray) && !(otherValue instanceof ConstantRef)) {
aliases.put(constant.getConstantRef(), value);
getLog().append("Inlining constant with different constant siblings " + constant);

View File

@ -1,16 +1,18 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.model.Program;
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.symbols.Variable;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.values.ConstantRef;
import dk.camelot64.kickc.model.values.ConstantString;
import dk.camelot64.kickc.model.values.ConstantValue;
import dk.camelot64.kickc.model.values.ScopeRef;
import java.util.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* Compiler Pass finding and consolidating identical constant strings
@ -31,18 +33,18 @@ public class Pass2ConstantStringConsolidation extends Pass2SsaOptimization {
public boolean step() {
boolean modified = false;
// Build a map with all constant strings
Map<ConstantString, List<SymbolVariable>> constantStringMap = new LinkedHashMap<>();
for(SymbolVariable constVar : getScope().getAllConstants(true)) {
Map<ConstantString, List<Variable>> constantStringMap = new LinkedHashMap<>();
for(Variable constVar : getScope().getAllConstants(true)) {
ConstantValue constVal = constVar.getConstantValue();
if(constVal instanceof ConstantString) {
ConstantString constString = (ConstantString) constVal;
List<SymbolVariable> constantVars = constantStringMap.computeIfAbsent(constString, k -> new ArrayList<>());
List<Variable> constantVars = constantStringMap.computeIfAbsent(constString, k -> new ArrayList<>());
constantVars.add(constVar);
}
}
// Handle all constant strings with duplicate definitions
for(ConstantString constantString : constantStringMap.keySet()) {
List<SymbolVariable> constantVars = constantStringMap.get(constantString);
List<Variable> constantVars = constantStringMap.get(constantString);
if(constantVars.size() > 1) {
// Found duplicate constant strings
modified |= handleDuplicateConstantString(constantVars, constantString);
@ -58,14 +60,14 @@ public class Pass2ConstantStringConsolidation extends Pass2SsaOptimization {
* @param constantVars The constant strings with identical values
* @return true if any optimization was performed
*/
private boolean handleDuplicateConstantString(List<SymbolVariable> constantVars, ConstantString constString) {
private boolean handleDuplicateConstantString(List<Variable> constantVars, ConstantString constString) {
boolean modified = false;
// Look for a constant in the root scope - or check if they are all in the same scope
SymbolVariable rootConstant = null;
Variable rootConstant = null;
boolean isCommonScope = true;
ScopeRef commonScope = null;
String segmentData = null;
for(SymbolVariable constantVar : constantVars) {
for(Variable constantVar : constantVars) {
ScopeRef constScope = constantVar.getScope().getRef();
segmentData = constantVar.getDataSegment();
if(constScope.equals(ScopeRef.ROOT)) {
@ -90,13 +92,13 @@ public class Pass2ConstantStringConsolidation extends Pass2SsaOptimization {
// Create a new root - and roll around again
ProgramScope rootScope = getScope();
String localName = getRootName(constantVars);
SymbolVariable newRootConstant = new SymbolVariable(localName, rootScope, SymbolType.STRING, segmentData, constString);
Variable newRootConstant = new Variable(localName, rootScope, SymbolType.STRING, segmentData, constString);
rootScope.add(newRootConstant);
rootConstant = newRootConstant;
}
}
// Modify all other constants to be references to the root constant
for(SymbolVariable constantVar : constantVars) {
for(Variable constantVar : constantVars) {
if(!constantVar.equals(rootConstant)) {
constantVar.setConstantValue(new ConstantRef(rootConstant));
modified = true;
@ -109,10 +111,10 @@ public class Pass2ConstantStringConsolidation extends Pass2SsaOptimization {
return modified;
}
private String getRootName(List<SymbolVariable> constantVars) {
private String getRootName(List<Variable> constantVars) {
String constName = null;
// Try all variables with non-intermediate names
for(SymbolVariable constantVar : constantVars) {
for(Variable constantVar : constantVars) {
if(!constantVar.getRef().isIntermediate()) {
String candidateName = constantVar.getLocalName();
if(getScope().getSymbol(candidateName) == null) {

View File

@ -6,7 +6,7 @@ import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
import dk.camelot64.kickc.model.operators.Operators;
import dk.camelot64.kickc.model.statements.StatementAssignment;
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;
import dk.camelot64.kickc.model.values.*;
@ -32,7 +32,7 @@ public class Pass2DeInlineWordDerefIdx extends Pass2SsaOptimization {
// Index is multiple bytes - de-inline it
getLog().append("De-inlining pointer[w] to *(pointer+w) "+currentStmt.toString(getProgram(), false));
Scope currentScope = getScope().getScope(currentBlock.getScope());
SymbolVariable tmpVar = currentScope.addVariableIntermediate();
Variable tmpVar = currentScope.addVariableIntermediate();
stmtIt.previous();
StatementAssignment tmpVarAssignment = new StatementAssignment((LValue) tmpVar.getRef(), dereferenceIndexed.getPointer(), Operators.PLUS, indexValue, currentStmt.getSource(), Comment.NO_COMMENTS);
stmtIt.add(tmpVarAssignment);

View File

@ -10,7 +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;
import dk.camelot64.kickc.model.values.RValue;
@ -96,7 +96,7 @@ public class Pass2DuplicateRValueIdentification extends Pass2SsaOptimization {
if(programValue.get() instanceof PointerDereference)
isVol.set(true);
if(programValue.get() instanceof VariableRef) {
SymbolVariable variable = getScope().getVariable((VariableRef) programValue.get());
Variable variable = getScope().getVariable((VariableRef) programValue.get());
if(variable.isVolatile())
isVol.set(true);
}

View File

@ -32,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());
SymbolVariable variable = getScope().getVariable((VariableRef) lValue);
Variable 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());
SymbolVariable variable = getScope().getVariable(phiVar);
Variable variable = getScope().getVariable(phiVar);
variable.getScope().remove(variable);
}

View File

@ -10,7 +10,7 @@ import dk.camelot64.kickc.model.operators.*;
import dk.camelot64.kickc.model.statements.Statement;
import dk.camelot64.kickc.model.statements.StatementAssignment;
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.SymbolTypeArray;
import dk.camelot64.kickc.model.types.SymbolTypePointer;
@ -83,7 +83,7 @@ public class Pass2FixInlineConstructors extends Pass2SsaOptimization {
public void addLiteralWordConstructor(OperatorBinary constructOperator, SymbolType constructType, SymbolType subType, ProgramExpression programExpression, List<RValue> listValues, Statement currentStmt, ListIterator<Statement> stmtIt, ControlFlowBlock currentBlock) {
// Convert list to a word constructor in a new tmp variable
Scope currentScope = Pass2FixInlineConstructors.this.getScope().getScope(currentBlock.getScope());
SymbolVariable tmpVar = currentScope.addVariableIntermediate();
Variable tmpVar = currentScope.addVariableIntermediate();
//tmpVar.setTypeInferred(constructType);
// Move backward - to insert before the current statement
stmtIt.previous();

View File

@ -2,11 +2,9 @@ package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.model.ControlFlowBlock;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.Registers;
import dk.camelot64.kickc.model.statements.Statement;
import dk.camelot64.kickc.model.statements.StatementPhiBlock;
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.values.RValue;
import dk.camelot64.kickc.model.values.SymbolVariableRef;
import dk.camelot64.kickc.model.values.VariableRef;
@ -39,7 +37,7 @@ public class Pass2IdenticalPhiElimination extends Pass2SsaOptimization {
boolean identical = true;
for(StatementPhiBlock.PhiRValue phiRValue : phiVariable.getValues()) {
if(phiRValue.getrValue() instanceof SymbolVariableRef) {
SymbolVariable symbolVar = (SymbolVariable) getScope().getSymbol((SymbolVariableRef) phiRValue.getrValue());
Variable symbolVar = (Variable) getScope().getSymbol((SymbolVariableRef) phiRValue.getrValue());
if(symbolVar.getDeclaredRegister() != null) { //TODO: Handle register/memory/storage strategy differently!
// Do not collapse PHI's for variables with declared registers (this prevents procedure parameters from being turned into constants)
identical = false;

View File

@ -5,7 +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.ConstantValue;
import dk.camelot64.kickc.model.values.LabelRef;
import dk.camelot64.kickc.model.values.PointerDereference;
@ -141,7 +141,7 @@ public class Pass2LoopHeadConstantIdentification extends Pass2SsaOptimization {
isVol.set(true);
}
if(programValue.get() instanceof VariableRef) {
SymbolVariable variable = getScope().getVariable((VariableRef) programValue.get());
Variable variable = getScope().getVariable((VariableRef) programValue.get());
if(variable.isVolatile())
isVol.set(true);
}

View File

@ -8,7 +8,7 @@ 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.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;
import dk.camelot64.kickc.model.values.*;
@ -71,12 +71,12 @@ public class Pass2MultiplyToShiftRewriting extends Pass2SsaOptimization {
long powVal = 1L <<pow2;
if(remains>=powVal) {
// First add shifts
SymbolVariable varShift = scope.addVariableIntermediate();
Variable varShift = scope.addVariableIntermediate();
varShift.setType(resultType);
stmtIt.add(new StatementAssignment((LValue) varShift.getRef(), building, Operators.SHIFT_LEFT, new ConstantInteger(shiftCount, SymbolType.BYTE), assignment.getSource(), Comment.NO_COMMENTS));
shiftCount = 0;
// Then add rvalue1
SymbolVariable varAdd = scope.addVariableIntermediate();
Variable varAdd = scope.addVariableIntermediate();
varAdd.setType(resultType);
stmtIt.add(new StatementAssignment((LValue) varAdd.getRef(), varShift.getRef(), Operators.PLUS, assignment.getrValue1(), assignment.getSource(), Comment.NO_COMMENTS));
building = varAdd.getRef();
@ -90,7 +90,7 @@ public class Pass2MultiplyToShiftRewriting extends Pass2SsaOptimization {
}
// add remaining shifts
if(shiftCount>0) {
SymbolVariable varShift = scope.addVariableIntermediate();
Variable varShift = scope.addVariableIntermediate();
varShift.setType(resultType);
stmtIt.add(new StatementAssignment((LValue) varShift.getRef(), building, Operators.SHIFT_LEFT, new ConstantInteger(shiftCount, SymbolType.BYTE), assignment.getSource(), Comment.NO_COMMENTS));
building = varShift.getRef();

View File

@ -4,7 +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;
import dk.camelot64.kickc.model.types.SymbolTypePointer;
@ -86,8 +86,8 @@ public class Pass2NopCastInlining extends Pass2SsaOptimization {
// 3. Delete the cast variable
delete.add((SymbolRef) castValue.getValue());
// Change the type of the assignment variable
SymbolVariable assignmentVar = getScope().getVariable((VariableRef) assignment.getlValue());
SymbolVariable castVar = getScope().getVariable((VariableRef) castValue.getValue());
Variable assignmentVar = getScope().getVariable((VariableRef) assignment.getlValue());
Variable castVar = getScope().getVariable((VariableRef) castValue.getValue());
assignmentVar.setType(castVar.getType());
// Remove the assignment
stmtIt.remove();

View File

@ -2,7 +2,7 @@ package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.Program;
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;
import dk.camelot64.kickc.model.values.*;
@ -20,8 +20,8 @@ public class Pass3AssertArrayLengths extends Pass2SsaAssertion {
@Override
public void check() throws AssertionFailed {
Collection<SymbolVariable> allConstants = getScope().getAllConstants(true);
for(SymbolVariable constantVar : allConstants) {
Collection<Variable> allConstants = getScope().getAllConstants(true);
for(Variable constantVar : allConstants) {
SymbolType constantType = constantVar.getType();
if(constantType instanceof SymbolTypeArray) {
RValue declaredSize = ((SymbolTypeArray) constantType).getSize();

View File

@ -47,12 +47,12 @@ public class Pass3PhiLifting {
LabelRef predecessorRef = phiRValue.getPredecessor();
ControlFlowBlock predecessorBlock = graph.getBlock(predecessorRef);
//VariableRef rValVarRef = (VariableRef) phiRValue.getrValue();
SymbolVariable newVar;
Variable newVar;
if(phiVariable.getVariable().isVersion()) {
SymbolVariable lValVar = program.getScope().getVariable(phiVariable.getVariable());
Variable lValVar = program.getScope().getVariable(phiVariable.getVariable());
newVar = lValVar.getVersionOf().createVersion();
} else {
SymbolVariable lValVar = program.getScope().getVariable(phiVariable.getVariable());
Variable lValVar = program.getScope().getVariable(phiVariable.getVariable());
newVar = lValVar.getScope().addVariableIntermediate();
}
Symbol phiLValue = programScope.getSymbol(phiVariable.getVariable());

View File

@ -6,7 +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;
import dk.camelot64.kickc.model.values.VariableRef;
@ -73,8 +73,8 @@ public class Pass3PhiMemCoalesce extends Pass2SsaOptimization {
VariableRef phiRVar = (VariableRef) phiRValue.getrValue();
LiveRangeEquivalenceClass rValEquivalenceClass = phiEquivalenceClasses.getOrCreateEquivalenceClass(phiRVar);
if(!rValEquivalenceClass.equals(equivalenceClass)) {
SymbolVariable var = program.getScope().getVariable(variable);
SymbolVariable rVar = program.getScope().getVariable(phiRVar);
Variable var = program.getScope().getVariable(variable);
Variable rVar = program.getScope().getVariable(phiRVar);
SymbolType varType = var.getType();
SymbolType rVarType = rVar.getType();
if(varType.getSizeBytes()==rVarType.getSizeBytes()) {

View File

@ -5,7 +5,7 @@ import dk.camelot64.kickc.asm.AsmClobber;
import dk.camelot64.kickc.asm.AsmProgram;
import dk.camelot64.kickc.model.*;
import dk.camelot64.kickc.model.statements.Statement;
import dk.camelot64.kickc.model.symbols.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.values.LabelRef;
import dk.camelot64.kickc.model.values.RValue;
import dk.camelot64.kickc.model.values.VariableRef;
@ -100,7 +100,7 @@ public class Pass4AssertNoCpuClobber extends Pass2Base {
// Non-assigned alive variables must not be clobbered
for(VariableRef aliveVar : aliveVars) {
SymbolVariable variable = getProgram().getSymbolInfos().getVariable(aliveVar);
Variable variable = getProgram().getSymbolInfos().getVariable(aliveVar);
Registers.Register aliveVarRegister = variable.getAllocation();
if(aliveVarRegister.isMem()) {
// No need to check a zp-register - here we are only interested in CPU registers

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.Registers;
import dk.camelot64.kickc.model.symbols.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
import java.util.Collection;
@ -18,8 +18,8 @@ public class Pass4AssertZeropageAllocation extends Pass2Base {
* Check that all variables fit onto zeropage
*/
public void check() {
Collection<SymbolVariable> allVariables = getSymbols().getAllVariables(true);
for(SymbolVariable variable : allVariables) {
Collection<Variable> allVariables = getSymbols().getAllVariables(true);
for(Variable variable : allVariables) {
Registers.Register allocation = variable.getAllocation();
if(allocation != null && Registers.RegisterType.ZP_MEM.equals(allocation.getType())) {
int zp = ((Registers.RegisterZpMem) allocation).getZp();

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, SymbolVariable procedureVariable, ScopeRef codeScopeRef) {
private void generateIndirectCall(AsmProgram asm, Variable 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(SymbolVariable parameter : procedure.getParameters()) {
List<SymbolVariable> versions = new ArrayList<>(procedure.getVersions(parameter));
for(Variable parameter : procedure.getParameters()) {
List<Variable> versions = new ArrayList<>(procedure.getVersions(parameter));
if(versions.size() > 0) {
SymbolVariable param = versions.get(0);
Variable param = versions.get(0);
Registers.Register allocation = param.getAllocation();
if(i++ > 0) signature.append(", ");
signature.append(param.getType().getTypeName()).append(" ");
@ -299,7 +299,7 @@ public class Pass4CodeGeneration {
}
}
private boolean hasData(SymbolVariable constantVar) {
private boolean hasData(Variable constantVar) {
ConstantValue constantValue = constantVar.getConstantValue();
if(constantValue instanceof ConstantArray) {
return true;
@ -325,7 +325,7 @@ public class Pass4CodeGeneration {
* @param constantVar The constant to examine
* @return true if a .label should be used in the generated ASM
*/
private boolean useLabelForConst(ScopeRef scopeRef, SymbolVariable constantVar) {
private boolean useLabelForConst(ScopeRef scopeRef, Variable constantVar) {
boolean useLabel = false;
Collection<Integer> constRefStatements = program.getVariableReferenceInfos().getConstRefStatements(constantVar.getConstantRef());
if(constRefStatements != null) {
@ -368,7 +368,7 @@ public class Pass4CodeGeneration {
Collection<SymbolVariableRef> symbolRefConsts = program.getVariableReferenceInfos().getSymbolRefConsts(constantVar.getConstantRef());
if(symbolRefConsts != null) {
for(SymbolVariableRef symbolRefConst : symbolRefConsts) {
SymbolVariable symbolRefVar = (SymbolVariable) program.getScope().getSymbol(symbolRefConst);
Variable symbolRefVar = (Variable) program.getScope().getSymbol(symbolRefConst);
if(!symbolRefVar.getScope().getRef().equals(scopeRef)) {
// Used in constant in another scope - generate label
useLabel = true;
@ -389,10 +389,10 @@ public class Pass4CodeGeneration {
private void addConstantsAndLabels(AsmProgram asm, ScopeRef scopeRef) {
Scope scope = program.getScope().getScope(scopeRef);
Set<String> added = new LinkedHashSet<>();
Collection<SymbolVariable> scopeConstants = scope.getAllConstants(false);
Collection<Variable> scopeConstants = scope.getAllConstants(false);
// Add all constants without data
for(SymbolVariable constantVar : scopeConstants) {
for(Variable constantVar : scopeConstants) {
if(!hasData(constantVar)) {
String asmName = constantVar.getAsmName() == null ? constantVar.getLocalName() : constantVar.getAsmName();
if(asmName != null && !added.contains(asmName)) {
@ -424,8 +424,8 @@ public class Pass4CodeGeneration {
}
// Add labels for memory variables without data
Collection<SymbolVariable> scopeVars = scope.getAllVariables(false);
for(SymbolVariable scopeVar : scopeVars) {
Collection<Variable> scopeVars = scope.getAllVariables(false);
for(Variable scopeVar : scopeVars) {
Registers.Register register = scopeVar.getAllocation();
if(register != null) {
if(Registers.RegisterType.ZP_MEM.equals(register.getType())) {
@ -462,10 +462,10 @@ public class Pass4CodeGeneration {
*/
private void addData(AsmProgram asm, ScopeRef scopeRef) {
Scope scope = program.getScope().getScope(scopeRef);
Collection<SymbolVariable> scopeConstants = scope.getAllConstants(false);
Collection<Variable> scopeConstants = scope.getAllConstants(false);
Set<String> added = new LinkedHashSet<>();
// Add all constants arrays incl. strings with data
for(SymbolVariable constantVar : scopeConstants) {
for(Variable constantVar : scopeConstants) {
if(hasData(constantVar)) {
// Skip if already added
String asmName = constantVar.getAsmName() == null ? constantVar.getLocalName() : constantVar.getAsmName();
@ -494,8 +494,8 @@ public class Pass4CodeGeneration {
}
}
// Add all memory variables
Collection<SymbolVariable> scopeVariables = scope.getAllVariables(false);
for(SymbolVariable variable : scopeVariables) {
Collection<Variable> scopeVariables = scope.getAllVariables(false);
for(Variable variable : scopeVariables) {
if(variable.isMemoryAreaMain()) {
// Skip PHI masters
if(variable.isStoragePhiMaster())
@ -575,7 +575,7 @@ public class Pass4CodeGeneration {
ConstantStructValue structValue = (ConstantStructValue) value;
for(SymbolVariableRef memberRef : structValue.getMembers()) {
ConstantValue memberValue = structValue.getValue(memberRef);
SymbolVariable memberVariable = getScope().getVariable(memberRef);
Variable 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<SymbolVariable> procParameters = procedure.getParameters();
List<Variable> procParameters = procedure.getParameters();
for(int i = 0; i < procParameters.size(); i++) {
SymbolVariable procParameter = procParameters.get(i);
Variable 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) {
SymbolVariable variable = getScope().getVariable((VariableRef) pointer);
Variable variable = getScope().getVariable((VariableRef) pointer);
generateIndirectCall(asm, variable, block.getScope());
supported = true;
} else if(pointer instanceof CastValue && ((CastValue) pointer).getValue() instanceof VariableRef) {
SymbolVariable variable = getScope().getVariable((VariableRef) ((CastValue) pointer).getValue());
Variable variable = getScope().getVariable((VariableRef) ((CastValue) pointer).getValue());
generateIndirectCall(asm, variable, block.getScope());
supported = true;
}
} else if(procedure instanceof VariableRef) {
SymbolVariable procedureVariable = getScope().getVariable((VariableRef) procedure);
Variable procedureVariable = getScope().getVariable((VariableRef) procedure);
SymbolType procedureVariableType = procedureVariable.getType();
if(procedureVariableType instanceof SymbolTypePointer) {
if(((SymbolTypePointer) procedureVariableType).getElementType() instanceof SymbolTypeProcedure) {
@ -946,7 +946,7 @@ public class Pass4CodeGeneration {
}
}
} else if(procedure instanceof ConstantRef) {
SymbolVariable procedureVariable = getScope().getConstant((ConstantRef) procedure);
Variable procedureVariable = getScope().getConstant((ConstantRef) procedure);
SymbolType procedureVariableType = procedureVariable.getType();
if(procedureVariableType instanceof SymbolTypePointer) {
if(((SymbolTypePointer) procedureVariableType).getElementType() instanceof SymbolTypeProcedure) {

View File

@ -4,7 +4,7 @@ import dk.camelot64.kickc.model.*;
import dk.camelot64.kickc.model.statements.StatementAssignment;
import dk.camelot64.kickc.model.statements.StatementCall;
import dk.camelot64.kickc.model.statements.StatementCallFinalize;
import dk.camelot64.kickc.model.symbols.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.values.VariableRef;
import java.util.ArrayList;
@ -32,10 +32,10 @@ public class Pass4LiveRangeEquivalenceClassesFinalize extends Pass2Base {
// Add all versions of volatile variables to the same equivalence class
for(SymbolVariable variable : getSymbols().getAllVariables(true)) {
for(Variable variable : getSymbols().getAllVariables(true)) {
if(variable.isStoragePhiVersion() && variable.isVolatile()) {
// Found a volatile non-versioned variable
for(SymbolVariable otherVariable : variable.getScope().getAllVariables(false)) {
for(Variable otherVariable : variable.getScope().getAllVariables(false)) {
if(otherVariable.isStoragePhiVersion()) {
if((otherVariable).getVersionOf().equals((variable).getVersionOf())) {
// They share the same main variable
@ -115,8 +115,8 @@ public class Pass4LiveRangeEquivalenceClassesFinalize extends Pass2Base {
for(VariableRef preference : preferences) {
LiveRangeEquivalenceClass preferenceEquivalenceClass = liveRangeEquivalenceClassSet.getEquivalenceClass(preference);
if(preferenceEquivalenceClass != null) {
SymbolVariable potentialVariable = getProgram().getSymbolInfos().getVariable(preference);
SymbolVariable lValVariable = getProgram().getSymbolInfos().getVariable(lValVar);
Variable potentialVariable = getProgram().getSymbolInfos().getVariable(preference);
Variable lValVariable = getProgram().getSymbolInfos().getVariable(lValVar);
if(lValVariable.getType().equals(potentialVariable.getType())) {
if(!lValLiveRange.overlaps(preferenceEquivalenceClass.getLiveRange())) {
chosen = preferenceEquivalenceClass;

View File

@ -2,7 +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;
import dk.camelot64.kickc.model.values.SymbolRef;
@ -109,7 +109,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()) {
SymbolVariable variable = program.getScope().getVariable(varRef);
Variable 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 +183,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)) {
SymbolVariable baseVar1 = ec1.getSingleVariableBase(program);
SymbolVariable baseVar2 = ec2.getSingleVariableBase(program);
Variable baseVar1 = ec1.getSingleVariableBase(program);
Variable baseVar2 = ec2.getSingleVariableBase(program);
if(baseVar1 == null || baseVar2 == null) {
// One of the equivalence classes have different base variables inside
return false;

View File

@ -6,7 +6,7 @@ import dk.camelot64.kickc.fragment.AsmFragmentInstance;
import dk.camelot64.kickc.fragment.AsmFragmentTemplateSynthesizer;
import dk.camelot64.kickc.model.*;
import dk.camelot64.kickc.model.statements.Statement;
import dk.camelot64.kickc.model.symbols.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.values.ScopeRef;
import dk.camelot64.kickc.model.values.VariableRef;
@ -204,7 +204,7 @@ public class Pass4RegisterUpliftCombinations extends Pass2Base {
Collection<VariableRef> alive = aliveCombinations.getEffectiveAliveAtStmt(callPath);
Pass2AliasElimination.Aliases callPathAliases = aliveCombinations.getEffectiveAliasesAtStmt(callPath);
for(VariableRef varRef : alive) {
SymbolVariable var = program.getSymbolInfos().getVariable(varRef);
Variable var = program.getSymbolInfos().getVariable(varRef);
Registers.Register allocation = var.getAllocation();
LiveRangeEquivalenceClass allocationClass = usedRegisters.get(allocation);
if(allocationClass != null && !allocationClass.contains(varRef)) {

View File

@ -1,7 +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;
import java.util.ArrayList;
@ -27,7 +27,7 @@ public class Pass4RegisterUpliftPotentialInitialize extends Pass2Base {
Registers.Register declaredRegister = null;
int bytes = -1;
for(VariableRef varRef : equivalenceClass.getVariables()) {
SymbolVariable variable = getProgram().getScope().getVariable(varRef);
Variable 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 +77,7 @@ public class Pass4RegisterUpliftPotentialInitialize extends Pass2Base {
*/
private boolean varVolatile(LiveRangeEquivalenceClass equivalenceClass) {
for(VariableRef variableRef : equivalenceClass.getVariables()) {
SymbolVariable variable = getSymbols().getVariable(variableRef);
Variable variable = getSymbols().getVariable(variableRef);
if(variable.isVolatile() || variable.isStorageLoadStore()) {
return true;
}

View File

@ -36,7 +36,7 @@ public class Pass4RegistersFinalize extends Pass2Base {
}
}
// Add all ZP's declared hardcoded register for a live variable
for(SymbolVariable variable : getSymbols().getAllVariables(true)) {
for(Variable variable : getSymbols().getAllVariables(true)) {
if(variable.getDeclaredRegister() instanceof Registers.RegisterZpMem) {
int zp = ((Registers.RegisterZpMem) variable.getDeclaredRegister()).getZp();
int sizeBytes = variable.getType().getSizeBytes();
@ -52,7 +52,7 @@ public class Pass4RegistersFinalize extends Pass2Base {
LiveRangeEquivalenceClassSet liveRangeEquivalenceClassSet = getProgram().getLiveRangeEquivalenceClassSet();
for(LiveRangeEquivalenceClass equivalenceClass : liveRangeEquivalenceClassSet.getEquivalenceClasses()) {
for(VariableRef variableRef : equivalenceClass.getVariables()) {
SymbolVariable variable = getProgram().getScope().getVariable(variableRef);
Variable variable = getProgram().getScope().getVariable(variableRef);
Registers.Register declaredRegister = variable.getDeclaredRegister(); //TODO: Handle register/memory/storage strategy differently!
Registers.Register register = declaredRegister;
if(declaredRegister !=null) {
@ -95,27 +95,27 @@ public class Pass4RegistersFinalize extends Pass2Base {
allScopes.add(getProgram().getScope());
for(Scope scope : allScopes) {
// Create initial short names
for(SymbolVariable variable : scope.getAllVariables(false)) {
for(Variable variable : scope.getAllVariables(false)) {
if(variable.getAllocation() != null && variable.getAllocation().isMem()) {
variable.setAsmName(variable.getLocalName());
} else {
variable.setAsmName(null);
}
}
for(SymbolVariable constantVar : scope.getAllConstants(false)) {
for(Variable constantVar : scope.getAllConstants(false)) {
constantVar.setAsmName(constantVar.getLocalName());
}
// Maps short name to the allocated register.
Map<String, Registers.Register> shortNames = new LinkedHashMap<>();
// Shorten variable and constant names
for(SymbolVariable variable : scope.getAllVariables(false)) {
for(Variable variable : scope.getAllVariables(false)) {
Registers.Register allocation = variable.getAllocation();
if(allocation != null && allocation.isMem()) {
shortenAsmName(shortNames, variable, allocation);
}
}
for(SymbolVariable constantVar : scope.getAllConstants(false)) {
for(Variable constantVar : scope.getAllConstants(false)) {
Registers.Register allocation = new Registers.RegisterConstant(constantVar.getConstantValue());
shortenAsmName(shortNames, constantVar, allocation);
}
@ -129,7 +129,7 @@ public class Pass4RegistersFinalize extends Pass2Base {
* @param variable The variable to shorten the name for
* @param allocation The register allocation for the variable
*/
private void shortenAsmName(Map<String, Registers.Register> shortNames, SymbolVariable variable, Registers.Register allocation) {
private void shortenAsmName(Map<String, Registers.Register> shortNames, Variable variable, Registers.Register allocation) {
String asmName = variable.getAsmName();
String prefix = asmName;
if(asmName.contains("#")) {
@ -170,7 +170,7 @@ public class Pass4RegistersFinalize extends Pass2Base {
if(reallocate) {
String before = register == null ? null : register.toString();
VariableRef variableRef = equivalenceClass.getVariables().get(0);
SymbolVariable variable = getProgram().getSymbolInfos().getVariable(variableRef);
Variable variable = getProgram().getSymbolInfos().getVariable(variableRef);
if(variable.isMemoryAreaMain()) {
register = new Registers.RegisterMainMem(variableRef, variable.getType().getSizeBytes(), null);
} else {
@ -217,7 +217,7 @@ public class Pass4RegistersFinalize extends Pass2Base {
* The register type created uses one or more zero page locations based on the variable type
* @return The new zeropage register
*/
private Registers.Register allocateNewRegisterZp(SymbolVariable variable) {
private Registers.Register allocateNewRegisterZp(Variable variable) {
SymbolType varType = variable.getType();
if(SymbolType.BYTE.equals(varType)) {
return new Registers.RegisterZpMem(allocateZp(1), 1);

View File

@ -10,7 +10,7 @@ import dk.camelot64.kickc.model.statements.Statement;
import dk.camelot64.kickc.model.statements.StatementAssignment;
import dk.camelot64.kickc.model.statements.StatementConditionalJump;
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;
import dk.camelot64.kickc.model.types.SymbolTypePointer;
@ -41,7 +41,7 @@ public class PassNAddBooleanCasts extends Pass2SsaOptimization {
if(SymbolType.isInteger(type) || type instanceof SymbolTypePointer) {
// Found integer condition - add boolean cast
getLog().append("Warning! Adding boolean cast to non-boolean condition "+rValue2.toString(getProgram()));
SymbolVariable tmpVar = addBooleanCast(rValue2, type, currentStmt, stmtIt, currentBlock);
Variable tmpVar = addBooleanCast(rValue2, type, currentStmt, stmtIt, currentBlock);
conditionalJump.setrValue2(tmpVar.getRef());
}
}
@ -59,7 +59,7 @@ public class PassNAddBooleanCasts extends Pass2SsaOptimization {
unaryExpression.setOperand(new ConstantBinary(new ConstantInteger(0L, SymbolType.NUMBER), Operators.NEQ, (ConstantValue) operand));
} else {
SymbolType type = SymbolTypeInference.inferType(getScope(), operand);
SymbolVariable tmpVar = addBooleanCast(operand, type, currentStmt, stmtIt, currentBlock);
Variable tmpVar = addBooleanCast(operand, type, currentStmt, stmtIt, currentBlock);
unaryExpression.setOperand(tmpVar.getRef());
}
}
@ -68,10 +68,10 @@ public class PassNAddBooleanCasts extends Pass2SsaOptimization {
return false;
}
public SymbolVariable addBooleanCast(RValue rValue, SymbolType rValueType, Statement currentStmt, ListIterator<Statement> stmtIt, ControlFlowBlock currentBlock) {
public Variable addBooleanCast(RValue rValue, SymbolType rValueType, Statement currentStmt, ListIterator<Statement> stmtIt, ControlFlowBlock currentBlock) {
Scope currentScope = getScope().getScope(currentBlock.getScope());
stmtIt.previous();
SymbolVariable tmpVar = currentScope.addVariableIntermediate();
Variable tmpVar = currentScope.addVariableIntermediate();
tmpVar.setTypeInferred(SymbolType.BOOLEAN);
// Go straight to xxx!=0 instead of casting to bool
ConstantValue nullValue;

View File

@ -9,7 +9,7 @@ import dk.camelot64.kickc.model.iterator.ProgramValue;
import dk.camelot64.kickc.model.operators.Operators;
import dk.camelot64.kickc.model.statements.Statement;
import dk.camelot64.kickc.model.symbols.StructDefinition;
import dk.camelot64.kickc.model.symbols.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.types.*;
import dk.camelot64.kickc.model.values.*;
@ -74,7 +74,7 @@ public class PassNAddInitializerValueListTypeCasts extends Pass2SsaOptimization
SymbolTypeStruct declaredStructType = (SymbolTypeStruct) declaredType;
// Recursively cast all sub-elements
StructDefinition structDefinition = declaredStructType.getStructDefinition(getScope());
Collection<SymbolVariable> memberDefinitions = structDefinition.getAllVariables(false);
Collection<Variable> memberDefinitions = structDefinition.getAllVariables(false);
int size = memberDefinitions.size();
if(size!=valueList.getList().size()) {
throw new CompileError(
@ -83,9 +83,9 @@ public class PassNAddInitializerValueListTypeCasts extends Pass2SsaOptimization
" Struct initializer: "+valueList.toString(getProgram()),
currentStmt);
}
Iterator<SymbolVariable> memberDefIt = memberDefinitions.iterator();
Iterator<Variable> memberDefIt = memberDefinitions.iterator();
for(int i = 0; i < size; i++) {
SymbolVariable memberDef = memberDefIt.next();
Variable memberDef = memberDefIt.next();
exprModified |= addValueCasts(memberDef.getType(), new ProgramValue.ProgramValueListElement(valueList, i), currentStmt);
}
// Add a cast to the value list itself

View File

@ -5,7 +5,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.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;
@ -33,7 +33,7 @@ public class PassNAssertConstantModification extends Pass2SsaOptimization {
LValue lValue = ((StatementLValue) statement).getlValue();
if(lValue instanceof VariableRef) {
VariableRef variableRef = (VariableRef) lValue;
SymbolVariable variable = getScope().getVariable(variableRef);
Variable 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

@ -4,7 +4,7 @@ import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
import dk.camelot64.kickc.model.symbols.StructDefinition;
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;
import dk.camelot64.kickc.model.types.SymbolTypeStruct;
@ -28,7 +28,7 @@ public class PassNAssertStructMembers extends Pass2SsaOptimization {
if(type instanceof SymbolTypeStruct) {
SymbolTypeStruct structType = (SymbolTypeStruct) type;
StructDefinition structDefinition = structType.getStructDefinition(getScope());
SymbolVariable member = structDefinition.getMember(structMemberRef.getMemberName());
Variable member = structDefinition.getMember(structMemberRef.getMemberName());
if(member==null) {
throw new CompileError("Unknown struct member "+structMemberRef.getMemberName()+" in struct "+structType.getTypeName(), currentStmt);
}

View File

@ -31,7 +31,7 @@ public class PassNCallingConventionStack extends Pass2SsaOptimization {
for(Procedure procedure : getScope().getAllProcedures(true)) {
if(Procedure.CallingConvension.STACK_CALL.equals(procedure.getCallingConvension())) {
// Introduce the parameter offsets
for(SymbolVariable parameter : procedure.getParameters()) {
for(Variable parameter : procedure.getParameters()) {
ConstantRef parameterOffsetConstant = CallingConventionStack.getParameterOffsetConstant(procedure, parameter);
offsetConstants.put(parameter.getRef(), parameterOffsetConstant);
createStackBase = true;

View File

@ -39,7 +39,7 @@ public class PassNEliminateUnusedVars extends Pass2SsaOptimization {
StatementAssignment assignment = (StatementAssignment) statement;
LValue lValue = assignment.getlValue();
if(lValue instanceof VariableRef && referenceInfos.isUnused((VariableRef) lValue)) {
SymbolVariable variable = getScope().getVariable((VariableRef) lValue);
Variable variable = getScope().getVariable((VariableRef) lValue);
boolean eliminate = false;
if(variable == null) {
// Already deleted
@ -71,7 +71,7 @@ public class PassNEliminateUnusedVars extends Pass2SsaOptimization {
StatementCall call = (StatementCall) statement;
LValue lValue = call.getlValue();
if(lValue instanceof VariableRef && referenceInfos.isUnused((VariableRef) lValue)) {
SymbolVariable variable = getScope().getVariable((VariableRef) lValue);
Variable variable = getScope().getVariable((VariableRef) lValue);
if(!variable.isVolatile()) {
if(pass2 || getLog().isVerbosePass1CreateSsa()) {
getLog().append("Eliminating unused variable - keeping the call " + lValue.toString(getProgram()));
@ -87,7 +87,7 @@ public class PassNEliminateUnusedVars extends Pass2SsaOptimization {
StatementCallFinalize call = (StatementCallFinalize) statement;
LValue lValue = call.getlValue();
if(lValue instanceof VariableRef && referenceInfos.isUnused((VariableRef) lValue)) {
SymbolVariable variable = getScope().getVariable((VariableRef) lValue);
Variable variable = getScope().getVariable((VariableRef) lValue);
if(!variable.isVolatile()) {
if(pass2 || getLog().isVerbosePass1CreateSsa()) {
getLog().append("Eliminating unused variable - keeping the call " + lValue.toString(getProgram()));
@ -103,7 +103,7 @@ public class PassNEliminateUnusedVars extends Pass2SsaOptimization {
StatementCallPointer call = (StatementCallPointer) statement;
LValue lValue = call.getlValue();
if(lValue instanceof VariableRef && referenceInfos.isUnused((VariableRef) lValue)) {
SymbolVariable variable = getScope().getVariable((VariableRef) lValue);
Variable variable = getScope().getVariable((VariableRef) lValue);
if(!variable.isVolatile()) {
if(pass2 || getLog().isVerbosePass1CreateSsa()) {
getLog().append("Eliminating unused variable - keeping the call " + lValue.toString(getProgram()));
@ -122,7 +122,7 @@ public class PassNEliminateUnusedVars extends Pass2SsaOptimization {
StatementPhiBlock.PhiVariable phiVariable = phiVarIt.next();
VariableRef variableRef = phiVariable.getVariable();
if(referenceInfos.isUnused(variableRef)) {
SymbolVariable variable = getScope().getVariable(variableRef);
Variable variable = getScope().getVariable(variableRef);
if(!variable.isVolatile()) {
if(pass2 || getLog().isVerbosePass1CreateSsa()) {
getLog().append("Eliminating unused variable - keeping the phi block " + variableRef.toString(getProgram()));
@ -139,8 +139,8 @@ public class PassNEliminateUnusedVars extends Pass2SsaOptimization {
}
}
Collection<SymbolVariable> allConstants = getScope().getAllConstants(true);
for(SymbolVariable constant : allConstants) {
Collection<Variable> allConstants = getScope().getAllConstants(true);
for(Variable constant : allConstants) {
if(!(constant.getScope() instanceof EnumDefinition)) {
if(referenceInfos.isUnused(constant.getRef())) {
if(constant.isDeclaredExport()) {
@ -167,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(SymbolVariable variable) {
private boolean isReturnValue(Variable variable) {
if(variable == null) return false;
return variable.getScope() instanceof Procedure && variable.getLocalName().equals("return");
}

View File

@ -3,7 +3,7 @@ package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.model.InternalError;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
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.SymbolTypeConversion;
import dk.camelot64.kickc.model.values.ConstantCastValue;
@ -45,7 +45,7 @@ public class PassNFinalizeNumberTypeConversions extends Pass2SsaOptimization {
if(SymbolType.UNUMBER.equals(toType)) {
if(constantCastValue.getValue() instanceof ConstantRef) {
ConstantRef constRef = (ConstantRef) constantCastValue.getValue();
SymbolVariable constant = getScope().getConstant(constRef);
Variable constant = getScope().getConstant(constRef);
if(constant.isInferredType())
constant.setTypeInferred(toType);
else
@ -60,7 +60,7 @@ public class PassNFinalizeNumberTypeConversions extends Pass2SsaOptimization {
} else if(SymbolType.SNUMBER.equals(toType)) {
if(constantCastValue.getValue() instanceof ConstantRef) {
ConstantRef constRef = (ConstantRef) constantCastValue.getValue();
SymbolVariable constant = getScope().getConstant(constRef);
Variable constant = getScope().getConstant(constRef);
if(constant.isInferredType())
constant.setTypeInferred(toType);
else

View File

@ -10,7 +10,7 @@ import dk.camelot64.kickc.model.operators.OperatorSizeOf;
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.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypeArray;
import dk.camelot64.kickc.model.types.SymbolTypePointer;
@ -38,7 +38,7 @@ public class PassNSizeOfSimplification extends Pass2SsaOptimization {
if(Operators.SIZEOF.equals(assignment.getOperator())) {
if(assignment.getrValue2() instanceof SymbolVariableRef) {
SymbolVariableRef symbolRef = (SymbolVariableRef) assignment.getrValue2();
SymbolVariable symbolVar = (SymbolVariable) getScope().getSymbol(symbolRef);
Variable symbolVar = (Variable) getScope().getSymbol(symbolRef);
SymbolType symbolType = symbolVar.getType();
if(!(symbolType instanceof SymbolTypeArray)) {
getLog().append("Resolving sizeof() " + assignment.toString(getProgram(), false));
@ -69,7 +69,7 @@ public class PassNSizeOfSimplification extends Pass2SsaOptimization {
public void resolveConstantSizeOf(AtomicBoolean modified, ProgramValue programValue, ConstantUnary unary, ConstantValue operand) {
if(operand instanceof ConstantRef) {
SymbolVariable constant = getScope().getConstant((ConstantRef) operand);
Variable constant = getScope().getConstant((ConstantRef) operand);
SymbolType symbolType = constant.getType();
if(symbolType instanceof SymbolTypeArray) {
SymbolTypeArray arrayType = (SymbolTypeArray) symbolType;

View File

@ -44,7 +44,7 @@ public class PassNStructPointerRewriting extends Pass2SsaOptimization {
CastValue structTypedPointer = new CastValue(memberType, structPointer);
// Create temporary variable to hold pointer to member ($1)
Scope scope = getScope().getScope(currentBlock.getScope());
SymbolVariable memberAddress1 = scope.addVariableIntermediate();
Variable memberAddress1 = scope.addVariableIntermediate();
memberAddress1.setType(memberType);
// Add statement $1 = ptr_struct + OFFSET_STRUCT_NAME_MEMBER
stmtIt.previous();
@ -57,7 +57,7 @@ public class PassNStructPointerRewriting extends Pass2SsaOptimization {
CastValue structTypedPointer = new CastValue(new SymbolTypePointer(memberType), structPointer);
// Create temporary variable to hold pointer to member ($1)
Scope scope = getScope().getScope(currentBlock.getScope());
SymbolVariable memberAddress = scope.addVariableIntermediate();
Variable memberAddress = scope.addVariableIntermediate();
memberAddress.setType(new SymbolTypePointer(memberType));
// Add statement $1 = ptr_struct + OFFSET_STRUCT_NAME_MEMBER
stmtIt.previous();
@ -83,9 +83,9 @@ public class PassNStructPointerRewriting extends Pass2SsaOptimization {
CastValue structTypedPointer = new CastValue(memberType, structPointer);
// Create temporary variable to hold pointer to member ($1)
Scope scope = getScope().getScope(currentBlock.getScope());
SymbolVariable memberAddress1 = scope.addVariableIntermediate();
Variable memberAddress1 = scope.addVariableIntermediate();
memberAddress1.setType(memberType);
SymbolVariable memberAddress2 = scope.addVariableIntermediate();
Variable memberAddress2 = scope.addVariableIntermediate();
memberAddress2.setType(memberType);
// Add statement $1 = ptr_struct + OFFSET_STRUCT_NAME_MEMBER
stmtIt.previous();
@ -100,7 +100,7 @@ public class PassNStructPointerRewriting extends Pass2SsaOptimization {
CastValue structTypedPointer = new CastValue(new SymbolTypePointer(memberType), structPointer);
// Create temporary variable to hold pointer to member ($1)
Scope scope = getScope().getScope(currentBlock.getScope());
SymbolVariable memberAddress = scope.addVariableIntermediate();
Variable memberAddress = scope.addVariableIntermediate();
memberAddress.setType(new SymbolTypePointer(memberType));
// Add statement $1 = ptr_struct + OFFSET_STRUCT_NAME_MEMBER
stmtIt.previous();
@ -126,12 +126,12 @@ public class PassNStructPointerRewriting extends Pass2SsaOptimization {
*/
public static ConstantRef getMemberOffsetConstant(ProgramScope programScope, StructDefinition structDefinition, String memberName) {
String typeConstName = getMemberOffsetConstantName(structDefinition, memberName);
SymbolVariable memberOffsetConstant = programScope.getConstant(typeConstName);
Variable memberOffsetConstant = programScope.getConstant(typeConstName);
if(memberOffsetConstant == null) {
// Constant not found - create it
SymbolVariable memberDef = structDefinition.getMember(memberName);
Variable memberDef = structDefinition.getMember(memberName);
long memberByteOffset = structDefinition.getMemberByteOffset(memberDef, programScope);
memberOffsetConstant = new SymbolVariable(typeConstName, programScope, SymbolType.BYTE, Scope.SEGMENT_DATA_DEFAULT, new ConstantInteger(memberByteOffset & 0xff, SymbolType.BYTE));
memberOffsetConstant = new Variable(typeConstName, programScope, SymbolType.BYTE, Scope.SEGMENT_DATA_DEFAULT, new ConstantInteger(memberByteOffset & 0xff, SymbolType.BYTE));
programScope.add(memberOffsetConstant);
}
return memberOffsetConstant.getConstantRef();

View File

@ -6,7 +6,7 @@ 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.ProgramScope;
import dk.camelot64.kickc.model.symbols.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.types.*;
import dk.camelot64.kickc.model.values.AssignmentRValue;
import dk.camelot64.kickc.model.values.LValue;
@ -61,7 +61,7 @@ public class PassNTypeInference extends Pass2SsaOptimization {
ProgramScope programScope = program.getScope();
LValue lValue = call.getlValue();
if(lValue instanceof VariableRef) {
SymbolVariable symbol = programScope.getVariable((VariableRef) lValue);
Variable 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();
@ -74,7 +74,7 @@ public class PassNTypeInference extends Pass2SsaOptimization {
ProgramScope programScope = program.getScope();
LValue lValue = call.getlValue();
if(lValue instanceof VariableRef) {
SymbolVariable symbol = programScope.getVariable((VariableRef) lValue);
Variable 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();
@ -87,7 +87,7 @@ public class PassNTypeInference extends Pass2SsaOptimization {
ProgramScope programScope = program.getScope();
LValue lValue = call.getlValue();
if(lValue instanceof VariableRef) {
SymbolVariable symbol = programScope.getVariable((VariableRef) lValue);
Variable 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) {
@ -100,7 +100,7 @@ public class PassNTypeInference extends Pass2SsaOptimization {
private static void updateInferedTypePhiVariable(Program program, StatementPhiBlock.PhiVariable phiVariable) {
ProgramScope programScope = program.getScope();
SymbolVariable symbol = programScope.getVariable(phiVariable.getVariable());
Variable 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()) {
@ -128,25 +128,25 @@ public class PassNTypeInference extends Pass2SsaOptimization {
ProgramScope programScope = program.getScope();
LValue lValue = assignment.getlValue();
if(lValue instanceof VariableRef) {
SymbolVariable symbol = programScope.getVariable((VariableRef) lValue);
Variable 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);
// If the type is an array or a string the symbol is constant
if(symbol.getType() instanceof SymbolTypeArray) {
symbol.setConstantDeclaration(SymbolVariable.ConstantDeclaration.CONST);
symbol.setStorageStrategy(SymbolVariable.StorageStrategy.CONSTANT);
symbol.setMemoryArea(SymbolVariable.MemoryArea.MAIN_MEMORY);
symbol.setConstantDeclaration(Variable.ConstantDeclaration.CONST);
symbol.setStorageStrategy(Variable.StorageStrategy.CONSTANT);
symbol.setMemoryArea(Variable.MemoryArea.MAIN_MEMORY);
} else if(SymbolType.STRING.equals(symbol.getType())) {
symbol.setConstantDeclaration(SymbolVariable.ConstantDeclaration.CONST);
symbol.setStorageStrategy(SymbolVariable.StorageStrategy.CONSTANT);
symbol.setMemoryArea(SymbolVariable.MemoryArea.MAIN_MEMORY);
symbol.setConstantDeclaration(Variable.ConstantDeclaration.CONST);
symbol.setStorageStrategy(Variable.StorageStrategy.CONSTANT);
symbol.setMemoryArea(Variable.MemoryArea.MAIN_MEMORY);
}
}
}
}
private static void setInferedType(Program program, Statement statement, SymbolVariable symbol, SymbolType type) {
private static void setInferedType(Program program, Statement statement, Variable 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.SymbolVariable;
import dk.camelot64.kickc.model.symbols.Variable;
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) {
SymbolVariable lValueVar = getProgram().getScope().getVariable((VariableRef) lValue);
Variable 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

@ -8,7 +8,7 @@ import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
import dk.camelot64.kickc.model.statements.Statement;
import dk.camelot64.kickc.model.statements.StatementLValue;
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 java.util.*;
@ -74,8 +74,8 @@ public class PassNCalcVariableReferenceInfos extends PassNCalcBase<VariableRefer
blockSuccessors.put(blockLabel, successorClosure);
}
// Gather symbols in the symbol table referencing other variables/constants
Collection<SymbolVariable> allSymbolVariables = getProgram().getScope().getAllSymbolVariables(true);
for(SymbolVariable referencingVar : allSymbolVariables) {
Collection<Variable> allVariables = getProgram().getScope().getAllSymbolVariables(true);
for(Variable referencingVar : allVariables) {
ProgramValueIterator.execute(referencingVar,
(programValue, currentStmt, stmtIt, currentBlock) -> {
Value rValue = programValue.get();

View File

@ -6,7 +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;
import dk.camelot64.kickc.passes.calcs.PassNCalcVariableReferenceInfos;
@ -170,7 +170,7 @@ public class Unroller {
* @return The new version
*/
private SymbolVariableRef createNewVersion(SymbolVariableRef origVarRef) {
SymbolVariable origVar = program.getScope().getVariable(origVarRef);
Variable origVar = program.getScope().getVariable(origVarRef);
Scope scope = origVar.getScope();
SymbolVariableRef newVarRef;
if(origVarRef.isIntermediate()) {
@ -226,8 +226,8 @@ public class Unroller {
private static Map<SymbolVariableRef, SymbolVariableRef> copyDefinedVars(BlockSet unrollBlocks, Program program) {
Map<SymbolVariableRef, SymbolVariableRef> definedToNewVar = new LinkedHashMap<>();
for(VariableRef definedVarRef : getVarsDefinedIn(unrollBlocks, program)) {
SymbolVariable definedVar = program.getScope().getVariable(definedVarRef);
SymbolVariable newVar;
Variable definedVar = program.getScope().getVariable(definedVarRef);
Variable newVar;
if(definedVarRef.isIntermediate()) {
newVar = definedVar.getScope().addVariableIntermediate();
newVar.setType(definedVar.getType());