From dd2b23bc33d2befddbe7f0594c4d90fbd71b1dae Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Fri, 27 Sep 2019 22:31:46 +0200 Subject: [PATCH] Eliminated VariableIntermediate. --- .../iterator/ProgramExpressionBinary.java | 9 ++++---- .../model/iterator/ProgramValueIterator.java | 2 +- .../camelot64/kickc/model/symbols/Scope.java | 4 ++-- .../kickc/model/symbols/Variable.java | 22 +++++++++++++++---- .../model/symbols/VariableIntermediate.java | 20 ----------------- .../model/symbols/VariableUnversioned.java | 7 +----- .../kickc/model/symbols/VariableVersion.java | 17 ++------------ .../Pass0GenerateStatementSequence.java | 16 +++++++------- .../kickc/passes/Pass1FixLValuesLoHi.java | 3 +-- .../kickc/passes/Pass1PointerSizeofFix.java | 7 +++--- .../kickc/passes/Pass1UnwindBlockScopes.java | 4 ++-- .../kickc/passes/Pass1UnwindStructValues.java | 6 ++--- .../passes/Pass2DeInlineWordDerefIdx.java | 4 ++-- .../passes/Pass2FixInlineConstructors.java | 4 ++-- .../passes/Pass2MultiplyToShiftRewriting.java | 8 +++---- .../kickc/passes/PassNAddBooleanCasts.java | 10 ++++----- .../passes/PassNStructPointerRewriting.java | 10 ++++----- 17 files changed, 63 insertions(+), 90 deletions(-) delete mode 100644 src/main/java/dk/camelot64/kickc/model/symbols/VariableIntermediate.java diff --git a/src/main/java/dk/camelot64/kickc/model/iterator/ProgramExpressionBinary.java b/src/main/java/dk/camelot64/kickc/model/iterator/ProgramExpressionBinary.java index 2aba31210..cd8ff555f 100644 --- a/src/main/java/dk/camelot64/kickc/model/iterator/ProgramExpressionBinary.java +++ b/src/main/java/dk/camelot64/kickc/model/iterator/ProgramExpressionBinary.java @@ -11,7 +11,6 @@ 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.Variable; -import dk.camelot64.kickc.model.symbols.VariableIntermediate; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypeInference; import dk.camelot64.kickc.model.values.*; @@ -119,7 +118,7 @@ public interface ProgramExpressionBinary extends ProgramExpression { assignment.setrValue1(new ConstantCastValue(toType, (ConstantValue) assignment.getrValue1())); } else { Scope blockScope = symbols.getScope(currentScope); - VariableIntermediate tmpVar = blockScope.addVariableIntermediate(); + Variable tmpVar = blockScope.addVariableIntermediate(); tmpVar.setTypeInferred(toType); StatementAssignment newAssignment = new StatementAssignment(tmpVar.getRef(), Operators.getCastUnary(toType), assignment.getrValue1(), assignment.getSource(), Comment.NO_COMMENTS); assignment.setrValue1(tmpVar.getRef()); @@ -135,7 +134,7 @@ public interface ProgramExpressionBinary extends ProgramExpression { assignment.setrValue2(new ConstantCastValue(toType, (ConstantValue) assignment.getrValue2())); } else { Scope blockScope = symbols.getScope(currentScope); - VariableIntermediate tmpVar = blockScope.addVariableIntermediate(); + Variable tmpVar = blockScope.addVariableIntermediate(); tmpVar.setTypeInferred(toType); StatementAssignment newAssignment = new StatementAssignment(tmpVar.getRef(), Operators.getCastUnary(toType), assignment.getrValue2(), assignment.getSource(), Comment.NO_COMMENTS); assignment.setrValue2(tmpVar.getRef()); @@ -259,7 +258,7 @@ public interface ProgramExpressionBinary extends ProgramExpression { throw new InternalError("Cannot cast declared type!" + variable.toString()); } else { Scope blockScope = symbols.getScope(currentScope); - VariableIntermediate 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); @@ -274,7 +273,7 @@ public interface ProgramExpressionBinary extends ProgramExpression { assignment.setOperator(Operators.getCastUnary(toType)); } else { Scope blockScope = symbols.getScope(currentScope); - VariableIntermediate 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); diff --git a/src/main/java/dk/camelot64/kickc/model/iterator/ProgramValueIterator.java b/src/main/java/dk/camelot64/kickc/model/iterator/ProgramValueIterator.java index 1b0ed3986..96c5d7d9e 100644 --- a/src/main/java/dk/camelot64/kickc/model/iterator/ProgramValueIterator.java +++ b/src/main/java/dk/camelot64/kickc/model/iterator/ProgramValueIterator.java @@ -251,7 +251,7 @@ public class ProgramValueIterator { } else if(value == null || value instanceof VariableRef || value instanceof VariableVersion || - value instanceof VariableIntermediate || + value instanceof Variable || value instanceof ProcedureRef || value instanceof ConstantLiteral || value instanceof ConstantRef || diff --git a/src/main/java/dk/camelot64/kickc/model/symbols/Scope.java b/src/main/java/dk/camelot64/kickc/model/symbols/Scope.java index 923735e0a..94a4f657e 100644 --- a/src/main/java/dk/camelot64/kickc/model/symbols/Scope.java +++ b/src/main/java/dk/camelot64/kickc/model/symbols/Scope.java @@ -103,9 +103,9 @@ public abstract class Scope implements Symbol, Serializable { return add(new VariableUnversioned(name, this, type, dataSegment)); } - public VariableIntermediate addVariableIntermediate() { + public Variable addVariableIntermediate() { String name = allocateIntermediateVariableName(); - return add(new VariableIntermediate(name, this, SymbolType.VAR, getSegmentData())); + return add(new Variable(name, this, SymbolType.VAR, getSegmentData(), true, false)); } /** diff --git a/src/main/java/dk/camelot64/kickc/model/symbols/Variable.java b/src/main/java/dk/camelot64/kickc/model/symbols/Variable.java index 2baa7385d..e92358855 100644 --- a/src/main/java/dk/camelot64/kickc/model/symbols/Variable.java +++ b/src/main/java/dk/camelot64/kickc/model/symbols/Variable.java @@ -5,13 +5,21 @@ import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.values.VariableRef; /** A Variable (or a Constant) */ -public abstract class Variable extends SymbolVariable { +public class Variable extends SymbolVariable { - /** If the variable is assigned to an ASM register, this contains the register. If null the variable has no allocation (yet). Constants are never assigned to registers. */ + /** true if the variable is intermediate. */ + private boolean isIntermediate; + + /* true if the variable is a PHI version. (the variable has storage strategy PHI)*/ + private boolean isVersion; + + /** 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 Variable(String name, Scope scope, SymbolType type, String dataSegment) { + public Variable(String name, Scope scope, SymbolType type, String dataSegment, boolean isIntermediate, boolean isVersion) { super(name, scope, type, dataSegment); + this.isIntermediate = isIntermediate; + this.isVersion = isVersion; } public Registers.Register getAllocation() { @@ -22,7 +30,13 @@ public abstract class Variable extends SymbolVariable { this.allocation = allocation; } - public abstract boolean isVersioned(); + public boolean isVersioned() { + return isVersion; + } + + public boolean isIntermediate() { + return isIntermediate; + } public VariableRef getRef() { return new VariableRef(this); diff --git a/src/main/java/dk/camelot64/kickc/model/symbols/VariableIntermediate.java b/src/main/java/dk/camelot64/kickc/model/symbols/VariableIntermediate.java deleted file mode 100644 index 318e16f3d..000000000 --- a/src/main/java/dk/camelot64/kickc/model/symbols/VariableIntermediate.java +++ /dev/null @@ -1,20 +0,0 @@ -package dk.camelot64.kickc.model.symbols; - -import dk.camelot64.kickc.model.types.SymbolType; - -/** - * A Symbol (variable, jump label, etc.) - */ -public class VariableIntermediate extends Variable { - - public VariableIntermediate(String name, Scope scope, SymbolType type, String dataSegment) { - super(name, scope, type, dataSegment); - } - - @Override - public boolean isVersioned() { - return false; - } - - -} diff --git a/src/main/java/dk/camelot64/kickc/model/symbols/VariableUnversioned.java b/src/main/java/dk/camelot64/kickc/model/symbols/VariableUnversioned.java index 66bad94cb..5be31028b 100644 --- a/src/main/java/dk/camelot64/kickc/model/symbols/VariableUnversioned.java +++ b/src/main/java/dk/camelot64/kickc/model/symbols/VariableUnversioned.java @@ -11,7 +11,7 @@ public class VariableUnversioned extends Variable { private Integer nextVersionNumber; public VariableUnversioned( String name, Scope scope, SymbolType type, String dataSegment) { - super(name, scope, type, dataSegment); + super(name, scope, type, dataSegment, false, false); this.nextVersionNumber = 0; } @@ -22,11 +22,6 @@ public class VariableUnversioned extends Variable { return nextVersionNumber++; } - @Override - public boolean isVersioned() { - return false; - } - public VariableVersion createVersion() { VariableVersion version = new VariableVersion(this, this.getNextVersionNumber()); getScope().add(version); diff --git a/src/main/java/dk/camelot64/kickc/model/symbols/VariableVersion.java b/src/main/java/dk/camelot64/kickc/model/symbols/VariableVersion.java index 098b49141..ddd00774d 100644 --- a/src/main/java/dk/camelot64/kickc/model/symbols/VariableVersion.java +++ b/src/main/java/dk/camelot64/kickc/model/symbols/VariableVersion.java @@ -8,7 +8,7 @@ public class VariableVersion extends Variable { private String versionOfName; public VariableVersion(VariableUnversioned versionOf, int version) { - super(versionOf.getLocalName() + "#" + version, versionOf.getScope(), versionOf.getType(), versionOf.getDataSegment()); + super(versionOf.getLocalName() + "#" + version, versionOf.getScope(), versionOf.getType(), versionOf.getDataSegment(), false, true); this.setDeclaredAlignment(versionOf.getDeclaredAlignment()); this.setDeclaredAsRegister(versionOf.isDeclaredAsRegister()); this.setDeclaredAsMemory(versionOf.isDeclaredAsMemory()); @@ -27,27 +27,14 @@ public class VariableVersion extends Variable { String name, SymbolType type, String versionOfName) { - super(name, null, type, Scope.SEGMENT_DATA_DEFAULT); + super(name, null, type, Scope.SEGMENT_DATA_DEFAULT, false, true); this.versionOfName = versionOfName; } - @Override - public boolean isVersioned() { - return true; - } - public VariableUnversioned getVersionOf() { return (VariableUnversioned) getScope().getVariable(versionOfName); } - public String getVersionOfName() { - return versionOfName; - } - - public void setVersionOfName(String versionOfName) { - this.versionOfName = versionOfName; - } - @Override public boolean equals(Object o) { if(this == o) { diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java index d00ebe7c9..6878f86b8 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java @@ -892,7 +892,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor comments = ensureUnusedComments(getCommentsSymbol(ctx)); RValue rVal = exprVal; if(exprVal instanceof LValue) { @@ -1239,7 +1239,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor(); } - VariableIntermediate tmpVar = getCurrentScope().addVariableIntermediate(); + Variable tmpVar = getCurrentScope().addVariableIntermediate(); VariableRef tmpVarRef = tmpVar.getRef(); String procedureName; @@ -1965,7 +1965,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor()).get(deref.getIndex()); if(idx2VarRef == null) { - VariableIntermediate 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(idx2Var.getRef(), deref.getIndex(), Operators.MULTIPLY, sizeOfTargetType, currentStmt.getSource(), Comment.NO_COMMENTS); @@ -104,7 +103,7 @@ public class Pass1PointerSizeofFix extends Pass1Base { isPointerPlusConst = false; getLog().append("Fixing pointer addition " + assignment.toString(getProgram(), false)); LValue lValue = assignment.getlValue(); - VariableIntermediate tmpVar = getScope().getScope(block.getScope()).addVariableIntermediate(); + Variable tmpVar = getScope().getScope(block.getScope()).addVariableIntermediate(); tmpVar.setTypeInferred(SymbolTypeInference.inferType(getScope(), assignment.getlValue())); assignment.setlValue(tmpVar.getRef()); ConstantRef sizeOfTargetType = OperatorSizeOf.getSizeOfConstantVar(getProgram().getScope(), pointerType.getElementType()); @@ -116,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)); - VariableIntermediate 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()); diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindBlockScopes.java b/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindBlockScopes.java index cf205791f..9050238e0 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindBlockScopes.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindBlockScopes.java @@ -78,8 +78,8 @@ public class Pass1UnwindBlockScopes extends Pass1Base { unwound.setDeclaredRegister((var.getDeclaredRegister())); unwound.setDeclaredExport(var.isDeclaredExport()); unwoundSymbols.put(symbol.getRef(), unwound.getRef()); - } else if(symbol instanceof VariableIntermediate) { - VariableIntermediate unwound = procedure.addVariableIntermediate(); + } else if(symbol instanceof Variable && ((Variable) symbol).isIntermediate()) { + Variable unwound = procedure.addVariableIntermediate(); unwoundSymbols.put(symbol.getRef(), unwound.getRef()); } else if(symbol instanceof BlockScope) { // Recurse! diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindStructValues.java b/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindStructValues.java index 675266547..b001a9b5e 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindStructValues.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindStructValues.java @@ -212,7 +212,7 @@ public class Pass1UnwindStructValues extends Pass1Base { for(Variable member : structDefinition.getAllVariables(false)) { Variable memberVariable; if(variable.getRef().isIntermediate()) { - memberVariable = scope.add(new VariableIntermediate(variable.getLocalName() + "_" + member.getLocalName(), scope, member.getType(), variable.getDataSegment())); + memberVariable = scope.add(new Variable(variable.getLocalName() + "_" + member.getLocalName(), scope, member.getType(), variable.getDataSegment(), true, false)); } else { memberVariable = scope.addVariable(variable.getLocalName() + "_" + member.getLocalName(), member.getType(), variable.getDataSegment()); } @@ -407,7 +407,7 @@ public class Pass1UnwindStructValues extends Pass1Base { ConstantRef memberOffsetConstant = PassNStructPointerRewriting.getMemberOffsetConstant(getScope(), structDefinition, memberName); Variable member = structDefinition.getMember(memberName); Scope scope = getScope().getScope(currentBlock.getScope()); - VariableIntermediate 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 @@ -448,7 +448,7 @@ public class Pass1UnwindStructValues extends Pass1Base { ConstantRef memberOffsetConstant = PassNStructPointerRewriting.getMemberOffsetConstant(getScope(), structDefinition, memberName); Variable member = structDefinition.getMember(memberName); Scope scope = getScope().getScope(currentBlock.getScope()); - VariableIntermediate 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 diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass2DeInlineWordDerefIdx.java b/src/main/java/dk/camelot64/kickc/passes/Pass2DeInlineWordDerefIdx.java index 267a085ab..6b68d89ff 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass2DeInlineWordDerefIdx.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass2DeInlineWordDerefIdx.java @@ -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.VariableIntermediate; +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.AssignmentRValue; @@ -35,7 +35,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()); - VariableIntermediate tmpVar = currentScope.addVariableIntermediate(); + Variable tmpVar = currentScope.addVariableIntermediate(); stmtIt.previous(); StatementAssignment tmpVarAssignment = new StatementAssignment(tmpVar.getRef(), dereferenceIndexed.getPointer(), Operators.PLUS, indexValue, currentStmt.getSource(), Comment.NO_COMMENTS); stmtIt.add(tmpVarAssignment); diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass2FixInlineConstructors.java b/src/main/java/dk/camelot64/kickc/passes/Pass2FixInlineConstructors.java index fe0bab84e..f48aaf2b2 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass2FixInlineConstructors.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass2FixInlineConstructors.java @@ -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.VariableIntermediate; +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; @@ -82,7 +82,7 @@ public class Pass2FixInlineConstructors extends Pass2SsaOptimization { public void addLiteralWordConstructor(OperatorBinary constructOperator, SymbolType constructType, SymbolType subType, ProgramExpression programExpression, List listValues, Statement currentStmt, ListIterator stmtIt, ControlFlowBlock currentBlock) { // Convert list to a word constructor in a new tmp variable Scope currentScope = Pass2FixInlineConstructors.this.getScope().getScope(currentBlock.getScope()); - VariableIntermediate tmpVar = currentScope.addVariableIntermediate(); + Variable tmpVar = currentScope.addVariableIntermediate(); //tmpVar.setTypeInferred(constructType); // Move backward - to insert before the current statement stmtIt.previous(); diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass2MultiplyToShiftRewriting.java b/src/main/java/dk/camelot64/kickc/passes/Pass2MultiplyToShiftRewriting.java index ccfb9306b..78078eb7f 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass2MultiplyToShiftRewriting.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass2MultiplyToShiftRewriting.java @@ -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.VariableIntermediate; +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.ConstantInteger; @@ -74,12 +74,12 @@ public class Pass2MultiplyToShiftRewriting extends Pass2SsaOptimization { long powVal = 1L <=powVal) { // First add shifts - VariableIntermediate varShift = scope.addVariableIntermediate(); + Variable varShift = scope.addVariableIntermediate(); varShift.setType(resultType); stmtIt.add(new StatementAssignment(varShift.getRef(), building, Operators.SHIFT_LEFT, new ConstantInteger(shiftCount, SymbolType.BYTE), assignment.getSource(), Comment.NO_COMMENTS)); shiftCount = 0; // Then add rvalue1 - VariableIntermediate varAdd = scope.addVariableIntermediate(); + Variable varAdd = scope.addVariableIntermediate(); varAdd.setType(resultType); stmtIt.add(new StatementAssignment(varAdd.getRef(), varShift.getRef(), Operators.PLUS, assignment.getrValue1(), assignment.getSource(), Comment.NO_COMMENTS)); building = varAdd.getRef(); @@ -93,7 +93,7 @@ public class Pass2MultiplyToShiftRewriting extends Pass2SsaOptimization { } // add remaining shifts if(shiftCount>0) { - VariableIntermediate varShift = scope.addVariableIntermediate(); + Variable varShift = scope.addVariableIntermediate(); varShift.setType(resultType); stmtIt.add(new StatementAssignment(varShift.getRef(), building, Operators.SHIFT_LEFT, new ConstantInteger(shiftCount, SymbolType.BYTE), assignment.getSource(), Comment.NO_COMMENTS)); building = varShift.getRef(); diff --git a/src/main/java/dk/camelot64/kickc/passes/PassNAddBooleanCasts.java b/src/main/java/dk/camelot64/kickc/passes/PassNAddBooleanCasts.java index 5b05d1ed8..825a842ea 100644 --- a/src/main/java/dk/camelot64/kickc/passes/PassNAddBooleanCasts.java +++ b/src/main/java/dk/camelot64/kickc/passes/PassNAddBooleanCasts.java @@ -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.VariableIntermediate; +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())); - VariableIntermediate 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); - VariableIntermediate 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 VariableIntermediate addBooleanCast(RValue rValue, SymbolType rValueType, Statement currentStmt, ListIterator stmtIt, ControlFlowBlock currentBlock) { + public Variable addBooleanCast(RValue rValue, SymbolType rValueType, Statement currentStmt, ListIterator stmtIt, ControlFlowBlock currentBlock) { Scope currentScope = getScope().getScope(currentBlock.getScope()); stmtIt.previous(); - VariableIntermediate tmpVar = currentScope.addVariableIntermediate(); + Variable tmpVar = currentScope.addVariableIntermediate(); tmpVar.setTypeInferred(SymbolType.BOOLEAN); // Go straight to xxx!=0 instead of casting to bool ConstantValue nullValue; diff --git a/src/main/java/dk/camelot64/kickc/passes/PassNStructPointerRewriting.java b/src/main/java/dk/camelot64/kickc/passes/PassNStructPointerRewriting.java index 3c58e402c..6ea7e0a5a 100644 --- a/src/main/java/dk/camelot64/kickc/passes/PassNStructPointerRewriting.java +++ b/src/main/java/dk/camelot64/kickc/passes/PassNStructPointerRewriting.java @@ -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()); - VariableIntermediate 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()); - VariableIntermediate 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()); - VariableIntermediate memberAddress1 = scope.addVariableIntermediate(); + Variable memberAddress1 = scope.addVariableIntermediate(); memberAddress1.setType(memberType); - VariableIntermediate 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()); - VariableIntermediate memberAddress = scope.addVariableIntermediate(); + Variable memberAddress = scope.addVariableIntermediate(); memberAddress.setType(new SymbolTypePointer(memberType)); // Add statement $1 = ptr_struct + OFFSET_STRUCT_NAME_MEMBER stmtIt.previous();