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
|
* Adds a cast to the left operand
|
||||||
|
*
|
||||||
* @param toType The toType to cast to
|
* @param toType The toType to cast to
|
||||||
*/
|
*/
|
||||||
void addLeftCast(SymbolType toType, ListIterator<Statement> stmtIt, ScopeRef currentScope, ProgramScope symbols);
|
void addLeftCast(SymbolType toType, ListIterator<Statement> stmtIt, ScopeRef currentScope, ProgramScope symbols);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a cast to the right operand
|
* Adds a cast to the right operand
|
||||||
|
*
|
||||||
* @param toType The toType to cast to
|
* @param toType The toType to cast to
|
||||||
*/
|
*/
|
||||||
void addRightCast(SymbolType toType, ListIterator<Statement> stmtIt, ScopeRef currentScope, ProgramScope symbols);
|
void addRightCast(SymbolType toType, ListIterator<Statement> stmtIt, ScopeRef currentScope, ProgramScope symbols);
|
||||||
@ -135,7 +137,7 @@ public interface ProgramExpressionBinary extends ProgramExpression {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RValue getRight() {
|
public RValue getRight() {
|
||||||
if(assignment.getrValue1()==null && assignment.getOperator()==null) {
|
if(assignment.getrValue1() == null && assignment.getOperator() == null) {
|
||||||
return assignment.getrValue2();
|
return assignment.getrValue2();
|
||||||
} else {
|
} else {
|
||||||
return new AssignmentRValue(assignment);
|
return new AssignmentRValue(assignment);
|
||||||
@ -160,13 +162,9 @@ public interface ProgramExpressionBinary extends ProgramExpression {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addRightCast(SymbolType toType, ListIterator<Statement> stmtIt, ScopeRef currentScope, ProgramScope symbols) {
|
public void addRightCast(SymbolType toType, ListIterator<Statement> stmtIt, ScopeRef currentScope, ProgramScope symbols) {
|
||||||
if(assignment.getrValue1()==null && assignment.getOperator()==null) {
|
if(assignment.getrValue1() == null && assignment.getOperator() == null) {
|
||||||
//if(assignment.getrValue2() instanceof ConstantInteger) {
|
assignment.setOperator(Operators.getCastUnary(toType));
|
||||||
// ((ConstantInteger) assignment.getrValue2()).setType(toType);
|
} else {
|
||||||
//} else {
|
|
||||||
assignment.setOperator(Operators.getCastUnary(toType));
|
|
||||||
//}
|
|
||||||
} else {
|
|
||||||
throw new InternalError("Not implemented!");
|
throw new InternalError("Not implemented!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,12 +203,20 @@ public interface ProgramExpressionBinary extends ProgramExpression {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addLeftCast(SymbolType toType, ListIterator<Statement> stmtIt, ScopeRef currentScope, ProgramScope symbols) {
|
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
|
@Override
|
||||||
public void addRightCast(SymbolType toType, ListIterator<Statement> stmtIt, ScopeRef currentScope, ProgramScope symbols) {
|
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() {
|
public ConstantBinary getConstantBinary() {
|
||||||
return (ConstantBinary)programValue.get();
|
return (ConstantBinary) programValue.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -28,6 +28,8 @@ public class ProgramExpressionIterator {
|
|||||||
ProgramValueIterator.execute(program.getScope(), (programValue, currentStmt, stmtIt, currentBlock) -> {
|
ProgramValueIterator.execute(program.getScope(), (programValue, currentStmt, stmtIt, currentBlock) -> {
|
||||||
if(programValue.get() instanceof ConstantBinary) {
|
if(programValue.get() instanceof ConstantBinary) {
|
||||||
handler.execute(new ProgramExpressionBinary.ProgramExpressionBinaryConstant(programValue), null, null, null);
|
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.SymbolType;
|
||||||
import dk.camelot64.kickc.model.types.SymbolTypePointer;
|
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> {
|
public class ConstantPointer implements ConstantEnumerable<Long> {
|
||||||
|
|
||||||
/** The memory location pointed to. */
|
/** The memory location pointed to. */
|
||||||
@ -52,11 +52,7 @@ public class ConstantPointer implements ConstantEnumerable<Long> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Program program) {
|
public String toString(Program program) {
|
||||||
if(program == null) {
|
return "(" + getType().getTypeName() + ") " + Long.toString(location);
|
||||||
return Long.toString(location);
|
|
||||||
} else {
|
|
||||||
return "(" + getType(program.getScope()).getTypeName() + ") " + Long.toString(location);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package dk.camelot64.kickc.passes;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.model.Program;
|
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.ProgramExpressionIterator;
|
||||||
import dk.camelot64.kickc.model.iterator.ProgramExpressionUnary;
|
import dk.camelot64.kickc.model.iterator.ProgramExpressionUnary;
|
||||||
import dk.camelot64.kickc.model.operators.OperatorCast;
|
import dk.camelot64.kickc.model.operators.OperatorCast;
|
||||||
import dk.camelot64.kickc.model.types.SymbolType;
|
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.ConstantInteger;
|
||||||
import dk.camelot64.kickc.model.values.ConstantValue;
|
import dk.camelot64.kickc.model.values.ConstantPointer;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@ -29,9 +30,15 @@ public class Pass2ConstantCastSimplification extends Pass2SsaOptimization {
|
|||||||
ConstantInteger constantInteger = (ConstantInteger) unary.getOperand();
|
ConstantInteger constantInteger = (ConstantInteger) unary.getOperand();
|
||||||
if(constantInteger.getType().equals(SymbolType.NUMBER)) {
|
if(constantInteger.getType().equals(SymbolType.NUMBER)) {
|
||||||
SymbolType castType = operatorCast.getToType();
|
SymbolType castType = operatorCast.getToType();
|
||||||
ConstantInteger newConstInt = new ConstantInteger(constantInteger.getInteger(), castType);
|
if(castType instanceof SymbolTypeIntegerFixed ) {
|
||||||
programExpression.set(newConstInt);
|
ConstantInteger newConstInt = new ConstantInteger(constantInteger.getInteger(), castType);
|
||||||
getLog().append("Simplifying constant integer cast "+newConstInt);
|
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) {
|
} else if(derefAssignment.getOperator()==null) {
|
||||||
return attemptInlineDeref(derefAssignment.getrValue2());
|
return attemptInlineDeref(derefAssignment.getrValue2());
|
||||||
} else if(derefAssignment.getOperator() instanceof OperatorCastPtr) {
|
} else if(derefAssignment.getOperator() instanceof OperatorCastPtr) {
|
||||||
throw new CompileError("Not implemented!");
|
//throw new CompileError("Not implemented!");
|
||||||
//return attemptInlineDeref(derefAssignment.getrValue2());
|
//return attemptInlineDeref(derefAssignment.getrValue2());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
byte* SCREEN = $400;
|
byte* SCREEN = $400;
|
||||||
*SCREEN = ~1;
|
*SCREEN = ~1ub;
|
||||||
|
|
||||||
for(byte c : 1..26) {
|
for(byte c : 1..26) {
|
||||||
SCREEN[c] = ~c;
|
SCREEN[c] = ~c;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user