mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-04-22 03:38:31 +00:00
Fix to problem with two ROL fragments by @SijmenSchoon. Moved NotLiteralException singleton behing a function. Closes #604
This commit is contained in:
parent
c36da71ecd
commit
5979efaa25
src
main
fragment/mos6502-common
java/dk/camelot64/kickc
model
ConstantNotLiteral.java
operators
OperatorAddressOf.javaOperatorCastDWord.javaOperatorCastPtr.javaOperatorCastWord.javaOperatorDecrement.javaOperatorGetHigh.javaOperatorGetLow.javaOperatorIncrement.javaOperatorMultiply.javaOperatorPlus.java
values
passes
kc/lib
test/java/dk/camelot64/kickc/test
@ -1,7 +1,7 @@
|
||||
cpx #0
|
||||
beq !e+
|
||||
!:
|
||||
ror
|
||||
lsr
|
||||
dex
|
||||
bne !-
|
||||
!e:
|
||||
|
@ -1,6 +1,7 @@
|
||||
cpy #0
|
||||
beq !e+
|
||||
!:
|
||||
ror
|
||||
dex
|
||||
lsr
|
||||
dey
|
||||
bne !-
|
||||
!e:
|
||||
|
@ -7,9 +7,13 @@ package dk.camelot64.kickc.model;
|
||||
public class ConstantNotLiteral extends RuntimeException {
|
||||
|
||||
/** Global singleton (saves initialization time for the exception stacktrace)*/
|
||||
public static final ConstantNotLiteral EXCEPTION = new ConstantNotLiteral("Constant not literal!");
|
||||
private static final ConstantNotLiteral EXCEPTION = new ConstantNotLiteral("Constant not literal!");
|
||||
|
||||
private ConstantNotLiteral(String message) {
|
||||
public static ConstantNotLiteral getException() {
|
||||
return EXCEPTION;
|
||||
}
|
||||
|
||||
public ConstantNotLiteral(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ public class OperatorAddressOf extends OperatorUnary {
|
||||
|
||||
@Override
|
||||
public ConstantLiteral calculateLiteral(ConstantLiteral operand, ProgramScope scope) {
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,7 +22,7 @@ public class OperatorCastDWord extends OperatorCast {
|
||||
} else if(value instanceof ConstantPointer) {
|
||||
return new ConstantInteger(0xffff & ((ConstantPointer) value).getLocation(), SymbolType.DWORD);
|
||||
} else if(value instanceof ConstantString) {
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
throw new CompileError("Calculation not implemented " + getOperator() + " " + value );
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public class OperatorCastPtr extends OperatorCast {
|
||||
} else if(value instanceof ConstantPointer) {
|
||||
return new ConstantPointer(((ConstantPointer) value).getLocation(), pointerType.getElementType());
|
||||
} else if(value instanceof ConstantString){
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
throw new InternalError("Calculation not implemented " + getOperator() + " " + value);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class OperatorCastWord extends OperatorCast {
|
||||
} else if(value instanceof ConstantPointer) {
|
||||
return new ConstantInteger(0xffff & ((ConstantPointer) value).getLocation(), SymbolType.WORD);
|
||||
} else if(value instanceof ConstantString) {
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
throw new CompileError("Calculation not implemented " + getOperator() + " " + value );
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public class OperatorDecrement extends OperatorUnary {
|
||||
} else if(operand instanceof ConstantPointer) {
|
||||
return new ConstantPointer(0xffff&(((ConstantPointer) operand).getLocation()-1), ((ConstantPointer) operand).getElementType());
|
||||
}
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,12 +28,12 @@ public class OperatorGetHigh extends OperatorUnary {
|
||||
} else if(SymbolType.BYTE.equals(operandInt.getType()) || SymbolType.SBYTE.equals(operandInt.getType())) {
|
||||
return new ConstantInteger(0L, SymbolType.BYTE);
|
||||
} else if(SymbolType.NUMBER.equals(operandInt.getType())) {
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
} else if(operand instanceof ConstantPointer) {
|
||||
return new ConstantInteger(((ConstantPointer) operand).getLocation()>>8);
|
||||
} else if(operand instanceof ConstantString) {
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
throw new CompileError("Calculation not implemented " + getOperator() + " " + operand );
|
||||
}
|
||||
|
@ -28,14 +28,14 @@ public class OperatorGetLow extends OperatorUnary {
|
||||
} else if(SymbolType.BYTE.equals(operandInt.getType()) || SymbolType.SBYTE.equals(operandInt.getType())) {
|
||||
return operandInt;
|
||||
} else if(SymbolType.NUMBER.equals(operandInt.getType())) {
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
} else if(operand instanceof ConstantPointer) {
|
||||
return new ConstantInteger(((ConstantPointer) operand).getLocation()&0xff);
|
||||
} else if(operand instanceof ConstantString) {
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,7 @@ public class OperatorIncrement extends OperatorUnary {
|
||||
} else if(operand instanceof ConstantPointer) {
|
||||
return new ConstantPointer(0xffff&(((ConstantPointer) operand).getLocation()+1), ((ConstantPointer) operand).getElementType());
|
||||
}
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,7 +17,7 @@ public class OperatorMultiply extends OperatorBinary {
|
||||
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
|
||||
return new ConstantInteger(((ConstantInteger) left).getInteger() * ((ConstantInteger) right).getInteger());
|
||||
}
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,7 +23,7 @@ public class OperatorPlus extends OperatorBinary {
|
||||
} else if(left instanceof ConstantEnumerable && right instanceof ConstantEnumerable) {
|
||||
return new ConstantInteger(((ConstantEnumerable) left).getInteger() + ((ConstantEnumerable) right).getInteger());
|
||||
} else if(left instanceof ConstantString && right instanceof ConstantInteger) {
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
throw new CompileError("Calculation not implemented " + left + " " + getOperator() + " " + right);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class ConstantArrayFilled implements ConstantArray {
|
||||
|
||||
@Override
|
||||
public ConstantLiteral calculateLiteral(ProgramScope scope) {
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -64,7 +64,7 @@ public class ConstantArrayKickAsm implements ConstantArray {
|
||||
|
||||
@Override
|
||||
public ConstantLiteral calculateLiteral(ProgramScope scope) {
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,7 +52,7 @@ public class ConstantArrayList implements ConstantArray {
|
||||
|
||||
@Override
|
||||
public ConstantLiteral calculateLiteral(ProgramScope scope) {
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,7 +31,7 @@ public class ConstantStructValue implements ConstantValue {
|
||||
|
||||
@Override
|
||||
public ConstantLiteral calculateLiteral(ProgramScope scope) {
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
|
||||
public SymbolTypeStruct getStructType() {
|
||||
|
@ -60,12 +60,12 @@ public class ConstantSymbolPointer implements ConstantValue {
|
||||
int zp = ((Registers.RegisterZpMem) allocation).getZp();
|
||||
return new ConstantInteger((long) zp, SymbolType.BYTE);
|
||||
} else if(allocation != null && Registers.RegisterType.MAIN_MEM.equals(allocation.getType())) {
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
}
|
||||
}
|
||||
// We cannot calculate a literal value
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,7 +28,7 @@ public class StructZero implements ConstantValue {
|
||||
|
||||
@Override
|
||||
public ConstantLiteral calculateLiteral(ProgramScope scope) {
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
throw ConstantNotLiteral.getException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -106,7 +106,7 @@ public class Pass2ConstantIfs extends Pass2SsaOptimization {
|
||||
* Examine the intervals of the conditions to see if they
|
||||
*
|
||||
* @param conditional The conditional
|
||||
* @return The literal value of the condition
|
||||
* @return The literal value of the condition. Null if not literal.
|
||||
*/
|
||||
private ConstantLiteral findConditionLiteralInterval(StatementConditionalJump conditional) {
|
||||
if(conditional.getrValue1() != null && conditional.getrValue2() != null) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dk.camelot64.kickc.passes;
|
||||
|
||||
import dk.camelot64.kickc.model.ConstantNotLiteral;
|
||||
import dk.camelot64.kickc.model.InternalError;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
|
||||
@ -65,7 +66,12 @@ public class PassNFinalizeNumberTypeConversions extends Pass2SsaOptimization {
|
||||
else
|
||||
throw new InternalError("Cannot cast declared type!" + constant.toString());
|
||||
} else {
|
||||
ConstantLiteral constantLiteral = constantCastValue.getValue().calculateLiteral(getProgram().getScope());
|
||||
ConstantLiteral constantLiteral;
|
||||
try {
|
||||
constantLiteral = constantCastValue.getValue().calculateLiteral(getProgram().getScope());
|
||||
} catch (ConstantNotLiteral e) {
|
||||
throw new InternalError("Cannot cast declared type!" + constantCastValue.toString());
|
||||
}
|
||||
SymbolType smallestUnsigned = SymbolTypeConversion.getSmallestUnsignedFixedIntegerType(constantLiteral, getScope());
|
||||
if(smallestUnsigned != null) {
|
||||
constantCastValue.setToType(smallestUnsigned);
|
||||
|
@ -38,7 +38,7 @@ char keyboard_matrix_row_bitmask[8] = { %11111110, %11111101, %11111011, %111101
|
||||
// Keyboard matrix column bitmasks for a specific keybooard matrix column when reading the keyboard. (columns are numbered 0-7)
|
||||
char keyboard_matrix_col_bitmask[8] = { %00000001, %00000010, %00000100, %00001000, %00010000, %00100000, %01000000, %10000000 };
|
||||
|
||||
// Initialize keyboard reading by setting CIA#$ Data Direction Registers
|
||||
// Initialize keyboard reading by setting CIA#1 Data Direction Registers
|
||||
void keyboard_init() {
|
||||
// Keyboard Matrix Columns Write Mode
|
||||
CIA1->PORT_A_DDR = $ff;
|
||||
|
@ -3662,6 +3662,11 @@ public class TestPrograms {
|
||||
compileAndCompare("runtime-unused-procedure.c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCml2020() throws IOException, URISyntaxException {
|
||||
compileAndCompare("complex/cml2020/demo.c", log());
|
||||
}
|
||||
|
||||
//@Test
|
||||
//public void testRobozzle64() throws IOException, URISyntaxException {
|
||||
// compileAndCompare("complex/robozzle_c64/robozzle64.c", log().verboseSSAOptimize().verboseLoopUnroll());
|
||||
|
Loading…
x
Reference in New Issue
Block a user