diff --git a/src/dk/camelot64/kickc/icl/ControlFlowBlock.java b/src/dk/camelot64/kickc/icl/ControlFlowBlock.java index 2862e0fca..39a4f23ed 100644 --- a/src/dk/camelot64/kickc/icl/ControlFlowBlock.java +++ b/src/dk/camelot64/kickc/icl/ControlFlowBlock.java @@ -62,7 +62,7 @@ public class ControlFlowBlock { } public void addPhiStatement(VariableVersion newVersion) { - statements.add(0, new StatementPhi(new VariableRef(newVersion))); + statements.add(0, new StatementPhi(newVersion.getRef())); } public String getAsTypedString(ControlFlowGraph graph, ProgramScope scope) { diff --git a/src/dk/camelot64/kickc/icl/StatementAssignment.java b/src/dk/camelot64/kickc/icl/StatementAssignment.java index 24858483b..eba847f28 100644 --- a/src/dk/camelot64/kickc/icl/StatementAssignment.java +++ b/src/dk/camelot64/kickc/icl/StatementAssignment.java @@ -29,11 +29,11 @@ public class StatementAssignment implements StatementLValue { } public StatementAssignment(Variable lValue, Variable rValue2) { - this(new VariableRef(lValue), new VariableRef(rValue2)); + this(lValue.getRef(), rValue2.getRef()); } public StatementAssignment(Variable lValue, RValue rValue2) { - this(new VariableRef(lValue), rValue2); + this(lValue.getRef(), rValue2); } @JsonCreator diff --git a/src/dk/camelot64/kickc/icl/Variable.java b/src/dk/camelot64/kickc/icl/Variable.java index 482ca2b78..aa15c0e82 100644 --- a/src/dk/camelot64/kickc/icl/Variable.java +++ b/src/dk/camelot64/kickc/icl/Variable.java @@ -134,4 +134,8 @@ public abstract class Variable implements Symbol { return getTypedName(); } + @JsonIgnore + public VariableRef getRef() { + return new VariableRef(this); + } } diff --git a/src/dk/camelot64/kickc/passes/Pass1GenerateSingleStaticAssignmentForm.java b/src/dk/camelot64/kickc/passes/Pass1GenerateSingleStaticAssignmentForm.java index e43a09ad0..1dccb206e 100644 --- a/src/dk/camelot64/kickc/passes/Pass1GenerateSingleStaticAssignmentForm.java +++ b/src/dk/camelot64/kickc/passes/Pass1GenerateSingleStaticAssignmentForm.java @@ -49,7 +49,7 @@ public class Pass1GenerateSingleStaticAssignmentForm { // Assignment to a non-versioned non-intermediary variable VariableUnversioned assignedSymbol = (VariableUnversioned) assignedVar; VariableVersion version = assignedSymbol.createVersion(); - statementLValue.setlValue(new VariableRef(version)); + statementLValue.setlValue(version.getRef()); } } } @@ -72,7 +72,7 @@ public class Pass1GenerateSingleStaticAssignmentForm { { VariableVersion version = findOrCreateVersion(statementReturn.getValue(), blockVersions, blockNewPhis); if (version != null) { - statementReturn.setValue(new VariableRef(version)); + statementReturn.setValue(version.getRef()); } } @@ -82,13 +82,13 @@ public class Pass1GenerateSingleStaticAssignmentForm { { VariableVersion version = findOrCreateVersion(assignment.getrValue1(), blockVersions, blockNewPhis); if (version != null) { - assignment.setrValue1(new VariableRef(version)); + assignment.setrValue1(version.getRef()); } } { VariableVersion version = findOrCreateVersion(assignment.getrValue2(), blockVersions, blockNewPhis); if (version != null) { - assignment.setrValue2(new VariableRef(version)); + assignment.setrValue2(version.getRef()); } } // Update map of versions encountered in the block @@ -105,19 +105,19 @@ public class Pass1GenerateSingleStaticAssignmentForm { RValue pointer = deref.getPointer(); VariableVersion version = findOrCreateVersion(pointer, blockVersions, blockNewPhis); if (version != null) { - deref.setPointer(new VariableRef(version)); + deref.setPointer(version.getRef()); } } else if(lValue instanceof PointerDereferenceIndexed) { PointerDereferenceIndexed deref = (PointerDereferenceIndexed) lValue; RValue pointer = deref.getPointer(); VariableVersion version = findOrCreateVersion(pointer, blockVersions, blockNewPhis); if (version != null) { - deref.setPointer(new VariableRef(version)); + deref.setPointer(version.getRef()); } RValue index = deref.getIndex(); VariableVersion iVersion = findOrCreateVersion(index, blockVersions, blockNewPhis); if (iVersion != null) { - deref.setIndex(new VariableRef(iVersion)); + deref.setIndex(iVersion.getRef()); } } } @@ -201,7 +201,7 @@ public class Pass1GenerateSingleStaticAssignmentForm { predecessorNewPhis.put(unversioned, previousSymbol); } } - phi.addPreviousVersion(predecessorLabel, new VariableRef(previousSymbol)); + phi.addPreviousVersion(predecessorLabel, previousSymbol.getRef()); } } } diff --git a/src/dk/camelot64/kickc/passes/Pass1GenerateStatementSequence.java b/src/dk/camelot64/kickc/passes/Pass1GenerateStatementSequence.java index 2e926948d..44efe2ad2 100644 --- a/src/dk/camelot64/kickc/passes/Pass1GenerateStatementSequence.java +++ b/src/dk/camelot64/kickc/passes/Pass1GenerateStatementSequence.java @@ -177,7 +177,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor { sequence.addStatement(new StatementAssignment(returnVar, returnVar)); } VariableRef returnVarRef = null; - if(returnVar!=null) {new VariableRef(returnVar); } + if(returnVar!=null) {returnVarRef = returnVar.getRef();} sequence.addStatement(new StatementReturn(returnVarRef)); scopeStack.pop(); sequence.addStatement(new StatementProcedureEnd(procedure.getRef())); @@ -249,7 +249,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor { @Override public LValue visitLvalueName(KickCParser.LvalueNameContext ctx) { Variable variable = getCurrentSymbols().getVariable(ctx.NAME().getText()); - return new VariableRef(variable); + return variable.getRef(); } @Override @@ -322,8 +322,9 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor { parameters = new ArrayList<>(); } VariableIntermediate tmpVar = getCurrentSymbols().addVariableIntermediate(); - sequence.addStatement(new StatementCall(new VariableRef(tmpVar), ctx.NAME().getText(), parameters)); - return tmpVar; + VariableRef tmpVarRef = tmpVar.getRef(); + sequence.addStatement(new StatementCall(tmpVarRef, ctx.NAME().getText(), parameters)); + return tmpVarRef; } @Override @@ -342,7 +343,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor { RValue index = (RValue) visit(ctx.expr(1)); Operator operator = new Operator("*idx"); VariableIntermediate tmpVar = getCurrentSymbols().addVariableIntermediate(); - VariableRef tmpVarRef = new VariableRef(tmpVar); + VariableRef tmpVarRef = tmpVar.getRef(); Statement stmt = new StatementAssignment(tmpVarRef, array, operator, index); sequence.addStatement(stmt); return tmpVarRef; @@ -376,7 +377,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor { String op = ((TerminalNode) ctx.getChild(1)).getSymbol().getText(); Operator operator = new Operator(op); VariableIntermediate tmpVar = getCurrentSymbols().addVariableIntermediate(); - VariableRef tmpVarRef = new VariableRef(tmpVar); + VariableRef tmpVarRef = tmpVar.getRef(); Statement stmt = new StatementAssignment(tmpVarRef, left, operator, right); sequence.addStatement(stmt); return tmpVarRef; @@ -388,7 +389,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor { String op = ((TerminalNode) ctx.getChild(0)).getSymbol().getText(); Operator operator = new Operator(op); VariableIntermediate tmpVar = getCurrentSymbols().addVariableIntermediate(); - VariableRef tmpVarRef = new VariableRef(tmpVar); + VariableRef tmpVarRef = tmpVar.getRef(); Statement stmt = new StatementAssignment(tmpVarRef, operator, child); sequence.addStatement(stmt); return tmpVarRef; @@ -414,7 +415,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor { @Override public RValue visitExprId(KickCParser.ExprIdContext ctx) { Variable variable = getCurrentSymbols().getVariable(ctx.NAME().getText()); - return new VariableRef(variable); + return variable.getRef(); } public StatementSequence getSequence() { diff --git a/src/dk/camelot64/kickc/passes/Pass1ProcedureCallParameters.java b/src/dk/camelot64/kickc/passes/Pass1ProcedureCallParameters.java index 959c05347..593a1aa1f 100644 --- a/src/dk/camelot64/kickc/passes/Pass1ProcedureCallParameters.java +++ b/src/dk/camelot64/kickc/passes/Pass1ProcedureCallParameters.java @@ -31,13 +31,13 @@ public class Pass1ProcedureCallParameters extends ControlFlowGraphCopyVisitor { for (int i = 0; i < parameterDecls.size(); i++) { Variable parameterDecl = parameterDecls.get(i); RValue parameterValue = parameterValues.get(i); - addStatementToCurrentBlock(new StatementAssignment(new VariableRef(parameterDecl), parameterValue)); + addStatementToCurrentBlock(new StatementAssignment(parameterDecl.getRef(), parameterValue)); } String procedureName = origCall.getProcedureName(); Variable procReturnVar = procedure.getVariable("return"); VariableRef procReturnVarRef = null; if (procReturnVar != null) { - procReturnVarRef = new VariableRef(procReturnVar); + procReturnVarRef = procReturnVar.getRef(); } StatementCall copyCall = new StatementCall(procReturnVarRef, procedureName, null); copyCall.setParametersByAssignment(true);