1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-23 23:32:55 +00:00

Eliminated VariableIntermediate.

This commit is contained in:
jespergravgaard 2019-09-27 22:31:46 +02:00
parent a749cce83d
commit dd2b23bc33
17 changed files with 63 additions and 90 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -892,7 +892,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
RValue exprVal = (RValue) this.visit(ctx.commaExpr());
if(notConsumed(exprVal)) {
// Make a tmpVar to create the statement
VariableIntermediate tmpVar = getCurrentScope().addVariableIntermediate();
Variable tmpVar = getCurrentScope().addVariableIntermediate();
List<Comment> comments = ensureUnusedComments(getCommentsSymbol(ctx));
RValue rVal = exprVal;
if(exprVal instanceof LValue) {
@ -1239,7 +1239,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());
VariableIntermediate tmpVar = getCurrentScope().addVariableIntermediate();
Variable tmpVar = getCurrentScope().addVariableIntermediate();
VariableRef tmpVarRef = tmpVar.getRef();
Statement stmtTmpVar = new StatementAssignment(tmpVarRef, lValue.getRef(), Operators.NEQ, beyondLastVal, statementSource, Comment.NO_COMMENTS);
sequence.addStatement(stmtTmpVar);
@ -1783,7 +1783,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);
VariableIntermediate tmpVar = getCurrentScope().addVariableIntermediate();
Variable tmpVar = getCurrentScope().addVariableIntermediate();
VariableRef tmpVarRef = tmpVar.getRef();
Statement stmt = new StatementAssignment(tmpVarRef, operator, child, new StatementSource(ctx), ensureUnusedComments(getCommentsSymbol(ctx)));
sequence.addStatement(stmt);
@ -1800,7 +1800,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());
VariableIntermediate tmpVar = getCurrentScope().addVariableIntermediate();
Variable tmpVar = getCurrentScope().addVariableIntermediate();
VariableRef tmpVarRef = tmpVar.getRef();
Statement stmt = new StatementAssignment(tmpVarRef, Operators.SIZEOF, child, new StatementSource(ctx), ensureUnusedComments(getCommentsSymbol(ctx)));
sequence.addStatement(stmt);
@ -1818,7 +1818,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());
VariableIntermediate tmpVar = getCurrentScope().addVariableIntermediate();
Variable tmpVar = getCurrentScope().addVariableIntermediate();
VariableRef tmpVarRef = tmpVar.getRef();
Statement stmt = new StatementAssignment(tmpVarRef, Operators.TYPEID, child, new StatementSource(ctx), ensureUnusedComments(getCommentsSymbol(ctx)));
sequence.addStatement(stmt);
@ -1836,7 +1836,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
} else {
parameters = new ArrayList<>();
}
VariableIntermediate tmpVar = getCurrentScope().addVariableIntermediate();
Variable tmpVar = getCurrentScope().addVariableIntermediate();
VariableRef tmpVarRef = tmpVar.getRef();
String procedureName;
@ -1965,7 +1965,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
if(left instanceof ConstantValue && right instanceof ConstantValue) {
return new ConstantBinary((ConstantValue) left, (OperatorBinary) operator, (ConstantValue) right);
} else {
VariableIntermediate tmpVar = getCurrentScope().addVariableIntermediate();
Variable tmpVar = getCurrentScope().addVariableIntermediate();
VariableRef tmpVarRef = tmpVar.getRef();
Statement stmt = new StatementAssignment(tmpVarRef, left, operator, right, new StatementSource(ctx), ensureUnusedComments(getCommentsSymbol(ctx)));
sequence.addStatement(stmt);
@ -1994,7 +1994,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
} else if(child instanceof ConstantValue) {
return new ConstantUnary((OperatorUnary) operator, (ConstantValue) child);
} else {
VariableIntermediate tmpVar = getCurrentScope().addVariableIntermediate();
Variable tmpVar = getCurrentScope().addVariableIntermediate();
VariableRef tmpVarRef = tmpVar.getRef();
Statement stmt = new StatementAssignment(tmpVarRef, operator, child, new StatementSource(ctx), ensureUnusedComments(getCommentsSymbol(ctx)));
sequence.addStatement(stmt);

View File

@ -11,7 +11,6 @@ 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.Variable;
import dk.camelot64.kickc.model.symbols.VariableIntermediate;
import java.util.ArrayList;
import java.util.List;
@ -76,7 +75,7 @@ public class Pass1FixLValuesLoHi extends Pass1Base {
Variable intermediateVar = programScope.getVariable(intermediate.getVariable());
Scope currentScope = intermediateVar.getScope();
// Let assignment put value into a tmp Var
VariableIntermediate tmpVar = currentScope.addVariableIntermediate();
Variable tmpVar = currentScope.addVariableIntermediate();
VariableRef tmpVarRef = tmpVar.getRef();
statementLValue.setlValue(tmpVarRef);
PassNTypeInference.updateInferedTypeLValue(getProgram(), statementLValue);

View File

@ -12,7 +12,6 @@ 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.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.types.SymbolTypePointer;
@ -61,7 +60,7 @@ public class Pass1PointerSizeofFix extends Pass1Base {
getLog().append("Fixing pointer array-indexing " + deref.toString(getProgram()));
VariableRef idx2VarRef = handled.getOrDefault(currentStmt, new LinkedHashMap<>()).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());

View File

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

View File

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

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.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);

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.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<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());
VariableIntermediate tmpVar = currentScope.addVariableIntermediate();
Variable tmpVar = currentScope.addVariableIntermediate();
//tmpVar.setTypeInferred(constructType);
// Move backward - to insert before the current statement
stmtIt.previous();

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.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 <<pow2;
if(remains>=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();

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.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<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();
VariableIntermediate 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

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