1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-02-17 10:30:43 +00:00

Fixed a few tests. +0 in derefidx and rangenext() on signed words.

This commit is contained in:
jespergravgaard 2019-05-18 12:23:13 +02:00
parent 855434afa9
commit 13cc9e453c
9 changed files with 50 additions and 8 deletions

View File

@ -0,0 +1,6 @@
ldy #{c1}
lda {z2}
sta ({z1}),y
iny
lda {z2}+1
sta ({z1}),y

View File

@ -0,0 +1,6 @@
ldy #{c1}
lda {z2}
sta ({z1}),y
iny
lda {z2}+1
sta ({z1}),y

View File

@ -0,0 +1,5 @@
lda {z2}
sta ({z1}),y
iny
lda {z2}+1
sta ({z1}),y

View File

@ -0,0 +1,5 @@
lda {z2}
sta ({z1}),y
iny
lda {z2}+1
sta ({z1}),y

View File

@ -230,7 +230,11 @@ public class AsmFormat {
if(number.longValue() >= 0L && number.longValue() <= 255L) {
return SHORT_ASM_NUMBERS[number.intValue()];
} else {
return String.format("$%x", number.longValue());
if(number.longValue()<0) {
return String.format("-$%x", -number.longValue());
} else {
return String.format("$%x", number.longValue());
}
}
}
throw new RuntimeException("Unsupported number type " + number);

View File

@ -118,7 +118,7 @@ public class SymbolTypeInference {
} else if(rValue instanceof RangeComparison) {
return ((RangeComparison) rValue).getType();
} else if(rValue instanceof RangeNext) {
return SymbolType.BYTE;
return inferType(symbols, ((RangeNext) rValue).getRangeFirst());
} else if(rValue instanceof ProcedureRef) {
Procedure procedure = symbols.getProcedure((ProcedureRef) rValue);
return procedure.getType();

View File

@ -907,6 +907,10 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
// Assign loop variable with first value
RValue rangeLastValue = (RValue) visit(rangeLastCtx);
RValue rangeFirstValue = (RValue) visit(rangeFirstCtx);
if(varType!=null) {
if(rangeFirstValue instanceof ConstantInteger) ((ConstantInteger) rangeFirstValue).setType(varType);
if(rangeLastValue instanceof ConstantInteger) ((ConstantInteger) rangeLastValue).setType(varType);
}
Statement stmtInit = new StatementAssignment(lValue.getRef(), rangeFirstValue, new StatementSource(ctx), Comment.NO_COMMENTS);
sequence.addStatement(stmtInit);
// Add label
@ -1348,11 +1352,16 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
RValue child = (RValue) this.visit(ctx.expr());
String op = ((TerminalNode) ctx.getChild(0)).getSymbol().getText();
Operator operator = Operators.getUnary(op);
VariableIntermediate tmpVar = getCurrentScope().addVariableIntermediate();
VariableRef tmpVarRef = tmpVar.getRef();
Statement stmt = new StatementAssignment(tmpVarRef, operator, child, new StatementSource(ctx), ensureUnusedComments(getCommentsSymbol(ctx)));
sequence.addStatement(stmt);
return tmpVarRef;
// Special handling of negative literal number
if(child instanceof ConstantInteger && operator.equals(Operators.NEG)) {
return new ConstantInteger(-((ConstantInteger) child).getInteger(), ((ConstantInteger) child).getType());
} else {
VariableIntermediate tmpVar = getCurrentScope().addVariableIntermediate();
VariableRef tmpVarRef = tmpVar.getRef();
Statement stmt = new StatementAssignment(tmpVarRef, operator, child, new StatementSource(ctx), ensureUnusedComments(getCommentsSymbol(ctx)));
sequence.addStatement(stmt);
return tmpVarRef;
}
}
@Override

View File

@ -93,6 +93,13 @@ public class Pass2ConstantAdditionElimination extends Pass2SsaOptimization {
return true;
}
}
if(pointerDereferenceIndexed.getIndex() instanceof ConstantInteger ) {
if(((ConstantInteger)pointerDereferenceIndexed.getIndex()).getValue()==0L) {
value.set(new PointerDereferenceSimple(pointerDereferenceIndexed.getPointer()));
getLog().append("Simplified zero-index dereference" + value.get().toString());
return true;
}
}
return false;
}

View File

@ -65,7 +65,7 @@ public class TestPrograms {
@Test
public void testTernaryInference() throws IOException, URISyntaxException {
compileAndCompare("ternary-inference");
compileAndCompare("ternary-inference", log());
}
@Test