1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-14 23:04:57 +00:00

Working on skipping unneeded lda #>0 / lda #<0. Fixed word+byte type inference.

This commit is contained in:
jespergravgaard 2017-11-27 01:04:12 +01:00
parent cd06dd2016
commit d1d6724e0b
4 changed files with 34 additions and 5 deletions

View File

@ -70,8 +70,10 @@ public class AsmProgramStaticRegisterValues {
}
if (instructionType.getMnemnonic().equals("lda") && instructionType.getAddressingMode().equals(AsmAddressingMode.IMM)) {
current.setA(instruction.getParameter());
current.setaMem(null);
try {
int immValue = Integer.parseInt(instruction.getParameter());
int immValue = getImmValue(instruction);
current.setZ(immValue == 0);
current.setN(immValue > 127);
} catch (NumberFormatException e) {
@ -83,8 +85,9 @@ public class AsmProgramStaticRegisterValues {
}
if (instructionType.getMnemnonic().equals("ldx") && instructionType.getAddressingMode().equals(AsmAddressingMode.IMM)) {
current.setX(instruction.getParameter());
current.setxMem(null);
try {
int immValue = Integer.parseInt(instruction.getParameter());
int immValue = getImmValue(instruction);
current.setZ(immValue == 0);
current.setN(immValue > 127);
} catch (NumberFormatException e) {
@ -96,8 +99,9 @@ public class AsmProgramStaticRegisterValues {
}
if (instructionType.getMnemnonic().equals("ldy") && instructionType.getAddressingMode().equals(AsmAddressingMode.IMM)) {
current.setY(instruction.getParameter());
current.setyMem(null);
try {
int immValue = Integer.parseInt(instruction.getParameter());
int immValue = getImmValue(instruction);
current.setZ(immValue == 0);
current.setN(immValue > 127);
} catch (NumberFormatException e) {
@ -133,6 +137,18 @@ public class AsmProgramStaticRegisterValues {
return current;
}
private int getImmValue(AsmInstruction instruction) {
int immValue;
if(instruction.getParameter().equals("<0")) {
immValue = 0;
} else if(instruction.getParameter().equals(">0")) {
immValue = 0;
} else{
immValue = Integer.parseInt(instruction.getParameter());
}
return immValue;
}
/**
* Known values of registers/flags at an instruction. null where value is unknown.
*/

View File

@ -168,10 +168,10 @@ public class SymbolTypeInference {
if (isSByte(type1) && isSByte(type2)) {
return SymbolType.SBYTE;
}
if (isWord(type1) && isWord(type2)) {
if (isWord(type1) && isWord(type2) || isByte(type2)) {
return SymbolType.WORD;
}
if (isSWord(type1) && isSWord(type2)) {
if (isSWord(type1) && isSWord(type2) || isSByte(type2)) {
return SymbolType.SWORD;
}
throw new RuntimeException("Type inference case not handled " + type1 + " " + "+" + " " + type2);

View File

@ -24,6 +24,10 @@ public class TestPrograms extends TestCase {
helper = new ReferenceHelper("dk/camelot64/kickc/test/ref/");
}
public void testImmZero() throws IOException, URISyntaxException {
compileAndCompare("immzero");
}
public void testWordExpr() throws IOException, URISyntaxException {
compileAndCompare("wordexpr");
}

View File

@ -0,0 +1,9 @@
// Tests that immediate zero values are reused - even when assigning to words
void main() {
byte i = 0;
word w = (word)0;
for ( byte j : 0..10) {
i = j;
w = w + j;
}
}