1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-26 18:29:54 +00:00

Fixed last errors for ssa_mem var-model.

This commit is contained in:
jespergravgaard 2020-02-12 23:26:20 +01:00
parent 687705f5d2
commit 600a80dbcc
4 changed files with 49 additions and 31 deletions

View File

@ -1,9 +1,12 @@
package dk.camelot64.kickc.asm;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.ConstantNotLiteral;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.operators.*;
import dk.camelot64.kickc.model.symbols.*;
import dk.camelot64.kickc.model.symbols.Procedure;
import dk.camelot64.kickc.model.symbols.Symbol;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypeInference;
import dk.camelot64.kickc.model.types.SymbolTypePointer;
@ -116,14 +119,18 @@ public class AsmFormat {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
}
ConstantLiteral constantLiteral = operand.calculateLiteral(program.getScope());
if(constantLiteral instanceof ConstantInteger && Operators.CAST_BYTE.equals(operator) && SymbolType.BYTE.contains(((ConstantInteger) constantLiteral).getValue())) {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
}
if(constantLiteral instanceof ConstantInteger && Operators.CAST_SBYTE.equals(operator) && SymbolType.SBYTE.contains(((ConstantInteger) constantLiteral).getValue())) {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
try {
ConstantLiteral constantLiteral = operand.calculateLiteral(program.getScope());
if(constantLiteral instanceof ConstantInteger && Operators.CAST_BYTE.equals(operator) && SymbolType.BYTE.contains(((ConstantInteger) constantLiteral).getValue())) {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
}
if(constantLiteral instanceof ConstantInteger && Operators.CAST_SBYTE.equals(operator) && SymbolType.SBYTE.contains(((ConstantInteger) constantLiteral).getValue())) {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
}
} catch(ConstantNotLiteral e) {
// Not literal - do the cast
}
// Cast is needed
return getAsmConstant(program, new ConstantBinary(new ConstantInteger((long) 0xff), Operators.BOOL_AND, operand), outerPrecedence, codeScope);
@ -133,18 +140,22 @@ public class AsmFormat {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
}
ConstantLiteral constantLiteral = operand.calculateLiteral(program.getScope());
if(constantLiteral instanceof ConstantInteger && Operators.CAST_WORD.equals(operator) && SymbolType.WORD.contains(((ConstantInteger) constantLiteral).getValue())) {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
}
if(constantLiteral instanceof ConstantInteger && Operators.CAST_SWORD.equals(operator) && SymbolType.SWORD.contains(((ConstantInteger) constantLiteral).getValue())) {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
}
if(constantLiteral instanceof ConstantInteger && (operator instanceof OperatorCastPtr) && SymbolType.WORD.contains(((ConstantInteger) constantLiteral).getValue())) {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
try {
ConstantLiteral constantLiteral = operand.calculateLiteral(program.getScope());
if(constantLiteral instanceof ConstantInteger && Operators.CAST_WORD.equals(operator) && SymbolType.WORD.contains(((ConstantInteger) constantLiteral).getValue())) {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
}
if(constantLiteral instanceof ConstantInteger && Operators.CAST_SWORD.equals(operator) && SymbolType.SWORD.contains(((ConstantInteger) constantLiteral).getValue())) {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
}
if(constantLiteral instanceof ConstantInteger && (operator instanceof OperatorCastPtr) && SymbolType.WORD.contains(((ConstantInteger) constantLiteral).getValue())) {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
}
} catch(ConstantNotLiteral e) {
// Not literal - do the cast
}
// Cast is needed
return getAsmConstant(program, new ConstantBinary(new ConstantInteger((long) 0xffff), Operators.BOOL_AND, operand), outerPrecedence, codeScope);
@ -154,14 +165,18 @@ public class AsmFormat {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
}
ConstantLiteral constantLiteral = operand.calculateLiteral(program.getScope());
if(constantLiteral instanceof ConstantInteger && Operators.CAST_DWORD.equals(operator) && SymbolType.DWORD.contains(((ConstantInteger) constantLiteral).getValue())) {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
}
if(constantLiteral instanceof ConstantInteger && Operators.CAST_SDWORD.equals(operator) && SymbolType.SDWORD.contains(((ConstantInteger) constantLiteral).getValue())) {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
try {
ConstantLiteral constantLiteral = operand.calculateLiteral(program.getScope());
if(constantLiteral instanceof ConstantInteger && Operators.CAST_DWORD.equals(operator) && SymbolType.DWORD.contains(((ConstantInteger) constantLiteral).getValue())) {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
}
if(constantLiteral instanceof ConstantInteger && Operators.CAST_SDWORD.equals(operator) && SymbolType.SDWORD.contains(((ConstantInteger) constantLiteral).getValue())) {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
}
} catch(ConstantNotLiteral e) {
// Not literal - do the cast
}
// Cast is needed
return getAsmConstant(program, new ConstantBinary(new ConstantInteger((long) 0xffffffffL), Operators.BOOL_AND, operand), outerPrecedence, codeScope);
@ -278,6 +293,7 @@ public class AsmFormat {
/**
* Fix characters in an ASM parameter/label name. Handles '@:$#'
*
* @param source The source string
* @return The fixed string
*/

View File

@ -24,6 +24,8 @@ public class Initializers {
if(typeSpec.getType() instanceof SymbolTypeIntegerFixed) {
// Add an zero value initializer
return new ConstantInteger(0L, typeSpec.getType());
} else if(typeSpec.getType().equals(SymbolType.BOOLEAN)) {
return new ConstantBool(false);
} else if(typeSpec.getType() instanceof SymbolTypeStruct) {
// Add an zero-struct initializer
SymbolTypeStruct typeStruct = (SymbolTypeStruct) typeSpec.getType();

View File

@ -1,7 +1,7 @@
// Tests creating a long (32bit) pointer on zeropage for 45GS02 flat memory access
void main() {
unsigned long long_ptr = 0x12345678;
char long_ptr_zp = (char)&long_ptr;
__zp char long_ptr_zp = (char)&long_ptr;
asm {
nop
lda (long_ptr_zp),y

View File

@ -6,6 +6,6 @@
// And then allocate a 2-byte-variable
void main() {
const int* SCREEN = 0x0400;
for(int i=0;i<10;i++)
for(__zp int i=0;i<10;i++)
SCREEN[(char)i] = i;
}