1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-02-26 09:29:18 +00:00

Working on fixing test errors.

This commit is contained in:
jespergravgaard 2019-05-07 01:46:23 +02:00
parent 7e174898b8
commit b097b5c2c5
6 changed files with 35 additions and 24 deletions

View File

@ -44,12 +44,14 @@ public interface ProgramExpressionBinary extends ProgramExpression {
/**
* Adds a cast to the left operand
*
* @param toType The toType to cast to
*/
void addLeftCast(SymbolType toType, ListIterator<Statement> stmtIt, ScopeRef currentScope, ProgramScope symbols);
/**
* Adds a cast to the right operand
*
* @param toType The toType to cast to
*/
void addRightCast(SymbolType toType, ListIterator<Statement> stmtIt, ScopeRef currentScope, ProgramScope symbols);
@ -161,11 +163,7 @@ public interface ProgramExpressionBinary extends ProgramExpression {
@Override
public void addRightCast(SymbolType toType, ListIterator<Statement> stmtIt, ScopeRef currentScope, ProgramScope symbols) {
if(assignment.getrValue1() == null && assignment.getOperator() == null) {
//if(assignment.getrValue2() instanceof ConstantInteger) {
// ((ConstantInteger) assignment.getrValue2()).setType(toType);
//} else {
assignment.setOperator(Operators.getCastUnary(toType));
//}
} else {
throw new InternalError("Not implemented!");
}
@ -205,13 +203,21 @@ public interface ProgramExpressionBinary extends ProgramExpression {
@Override
public void addLeftCast(SymbolType toType, ListIterator<Statement> stmtIt, ScopeRef currentScope, ProgramScope symbols) {
if(conditionalJump.getrValue1() instanceof ConstantValue) {
conditionalJump.setrValue1(new ConstantCastValue(toType, (ConstantValue) conditionalJump.getrValue1()));
} else {
throw new InternalError("Not implemented!");
}
}
@Override
public void addRightCast(SymbolType toType, ListIterator<Statement> stmtIt, ScopeRef currentScope, ProgramScope symbols) {
if(conditionalJump.getrValue2() instanceof ConstantValue) {
conditionalJump.setrValue2(new ConstantCastValue(toType, (ConstantValue) conditionalJump.getrValue2()));
} else {
throw new InternalError("Not implemented!");
}
}
}

View File

@ -28,6 +28,8 @@ public class ProgramExpressionIterator {
ProgramValueIterator.execute(program.getScope(), (programValue, currentStmt, stmtIt, currentBlock) -> {
if(programValue.get() instanceof ConstantBinary) {
handler.execute(new ProgramExpressionBinary.ProgramExpressionBinaryConstant(programValue), null, null, null);
} else if(programValue.get() instanceof ConstantUnary) {
handler.execute(new ProgramExpressionUnary.ProgramExpressionUnaryConstant(programValue), null, null, null);
}
});

View File

@ -52,11 +52,7 @@ public class ConstantPointer implements ConstantEnumerable<Long> {
@Override
public String toString(Program program) {
if(program == null) {
return Long.toString(location);
} else {
return "(" + getType(program.getScope()).getTypeName() + ") " + Long.toString(location);
}
return "(" + getType().getTypeName() + ") " + Long.toString(location);
}
@Override

View File

@ -1,13 +1,14 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.iterator.ProgramExpression;
import dk.camelot64.kickc.model.iterator.ProgramExpressionIterator;
import dk.camelot64.kickc.model.iterator.ProgramExpressionUnary;
import dk.camelot64.kickc.model.operators.OperatorCast;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypeIntegerFixed;
import dk.camelot64.kickc.model.types.SymbolTypePointer;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantValue;
import dk.camelot64.kickc.model.values.ConstantPointer;
import java.util.concurrent.atomic.AtomicBoolean;
@ -29,9 +30,15 @@ public class Pass2ConstantCastSimplification extends Pass2SsaOptimization {
ConstantInteger constantInteger = (ConstantInteger) unary.getOperand();
if(constantInteger.getType().equals(SymbolType.NUMBER)) {
SymbolType castType = operatorCast.getToType();
if(castType instanceof SymbolTypeIntegerFixed ) {
ConstantInteger newConstInt = new ConstantInteger(constantInteger.getInteger(), castType);
programExpression.set(newConstInt);
getLog().append("Simplifying constant integer cast "+newConstInt);
getLog().append("Simplifying constant integer cast " + newConstInt.toString());
} else if(castType instanceof SymbolTypePointer) {
ConstantPointer newConstPointer = new ConstantPointer(constantInteger.getInteger(), ((SymbolTypePointer) castType).getElementType());
programExpression.set(newConstPointer);
getLog().append("Simplifying constant pointer cast " + newConstPointer.toString());
}
}
}
}

View File

@ -83,7 +83,7 @@ public class Pass2InlineDerefIdx extends Pass2SsaOptimization {
} else if(derefAssignment.getOperator()==null) {
return attemptInlineDeref(derefAssignment.getrValue2());
} else if(derefAssignment.getOperator() instanceof OperatorCastPtr) {
throw new CompileError("Not implemented!");
//throw new CompileError("Not implemented!");
//return attemptInlineDeref(derefAssignment.getrValue2());
}
return null;

View File

@ -1,7 +1,7 @@
void main() {
byte* SCREEN = $400;
*SCREEN = ~1;
*SCREEN = ~1ub;
for(byte c : 1..26) {
SCREEN[c] = ~c;