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:
parent
7e174898b8
commit
b097b5c2c5
@ -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);
|
||||
@ -135,7 +137,7 @@ public interface ProgramExpressionBinary extends ProgramExpression {
|
||||
|
||||
@Override
|
||||
public RValue getRight() {
|
||||
if(assignment.getrValue1()==null && assignment.getOperator()==null) {
|
||||
if(assignment.getrValue1() == null && assignment.getOperator() == null) {
|
||||
return assignment.getrValue2();
|
||||
} else {
|
||||
return new AssignmentRValue(assignment);
|
||||
@ -160,13 +162,9 @@ 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 {
|
||||
if(assignment.getrValue1() == null && assignment.getOperator() == null) {
|
||||
assignment.setOperator(Operators.getCastUnary(toType));
|
||||
} else {
|
||||
throw new InternalError("Not implemented!");
|
||||
}
|
||||
}
|
||||
@ -205,12 +203,20 @@ public interface ProgramExpressionBinary extends ProgramExpression {
|
||||
|
||||
@Override
|
||||
public void addLeftCast(SymbolType toType, ListIterator<Statement> stmtIt, ScopeRef currentScope, ProgramScope symbols) {
|
||||
throw new InternalError("Not implemented!");
|
||||
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) {
|
||||
throw new InternalError("Not implemented!");
|
||||
if(conditionalJump.getrValue2() instanceof ConstantValue) {
|
||||
conditionalJump.setrValue2(new ConstantCastValue(toType, (ConstantValue) conditionalJump.getrValue2()));
|
||||
} else {
|
||||
throw new InternalError("Not implemented!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -226,7 +232,7 @@ public interface ProgramExpressionBinary extends ProgramExpression {
|
||||
}
|
||||
|
||||
public ConstantBinary getConstantBinary() {
|
||||
return (ConstantBinary)programValue.get();
|
||||
return (ConstantBinary) programValue.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -5,7 +5,7 @@ import dk.camelot64.kickc.model.symbols.ProgramScope;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypePointer;
|
||||
|
||||
/** Constant pointer (meaning it points to a constant location)*/
|
||||
/** Constant pointer (meaning it points to a constant location) */
|
||||
public class ConstantPointer implements ConstantEnumerable<Long> {
|
||||
|
||||
/** The memory location pointed to. */
|
||||
@ -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
|
||||
|
@ -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();
|
||||
ConstantInteger newConstInt = new ConstantInteger(constantInteger.getInteger(), castType);
|
||||
programExpression.set(newConstInt);
|
||||
getLog().append("Simplifying constant integer cast "+newConstInt);
|
||||
if(castType instanceof SymbolTypeIntegerFixed ) {
|
||||
ConstantInteger newConstInt = new ConstantInteger(constantInteger.getInteger(), castType);
|
||||
programExpression.set(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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
void main() {
|
||||
byte* SCREEN = $400;
|
||||
*SCREEN = ~1;
|
||||
*SCREEN = ~1ub;
|
||||
|
||||
for(byte c : 1..26) {
|
||||
SCREEN[c] = ~c;
|
||||
|
Loading…
x
Reference in New Issue
Block a user