1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-22 21:29:50 +00:00

Refactored all casts to pointers to use the generic OperatorCastPtr.

This commit is contained in:
Jesper Gravgaard 2018-08-11 11:38:19 +02:00
parent 129de6c3ec
commit 39e7ce3df1
7 changed files with 1 additions and 77 deletions

View File

@ -115,7 +115,7 @@ public class AsmFormat {
} else {
return getAsmConstant(program, new ConstantBinary(new ConstantInteger((long)0xff), Operators.BOOL_AND, operand), outerPrecedence, codeScope);
}
} else if(operator instanceof OperatorCastPtr || Operators.CAST_WORD.equals(operator) || Operators.CAST_SWORD.equals(operator) || Operators.CAST_PTRBY.equals(operator)|| Operators.CAST_PTRSBY.equals(operator)) {
} else if(operator instanceof OperatorCastPtr || Operators.CAST_WORD.equals(operator) || Operators.CAST_SWORD.equals(operator) ) {
SymbolType operandType = SymbolTypeInference.inferType(program.getScope(), operand);
if(SymbolType.isWord(operandType) || SymbolType.isSWord(operandType) || SymbolType.isByte(operandType) || SymbolType.isSByte(operandType) || operandType instanceof SymbolTypePointer) {
// No cast needed

View File

@ -1,4 +0,0 @@
lda {z2}
sta {z1}
lda {z2}+1
sta {z1}+1

View File

@ -1,30 +0,0 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypePointer;
import dk.camelot64.kickc.model.types.SymbolTypeSimple;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
import dk.camelot64.kickc.model.values.ConstantPointer;
/** Unary Cast to byte pointer operator ( (byte*) x ) */
public class OperatorCastPtrByte extends OperatorUnary {
public OperatorCastPtrByte(int precedence) {
super("((byte*))", "_ptrby_", precedence);
}
@Override
public ConstantLiteral calculateLiteral(ConstantLiteral value) {
if(value instanceof ConstantInteger) {
return new ConstantPointer(((ConstantInteger) value).getInteger(), SymbolType.BYTE);
}
throw new CompileError("Calculation not implemented " + getOperator() + " " + value );
}
@Override
public SymbolType inferType(SymbolTypeSimple operandType) {
return new SymbolTypePointer(SymbolType.BYTE);
}
}

View File

@ -1,30 +0,0 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypePointer;
import dk.camelot64.kickc.model.types.SymbolTypeSimple;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
import dk.camelot64.kickc.model.values.ConstantPointer;
/** Unary Cast to signed byte pointer operator ( (signed byte*) x ) */
public class OperatorCastPtrSignedByte extends OperatorUnary {
public OperatorCastPtrSignedByte(int precedence) {
super("((signed byte*))", "_ptrsby_", precedence);
}
@Override
public ConstantLiteral calculateLiteral(ConstantLiteral value) {
if(value instanceof ConstantInteger) {
return new ConstantPointer(((ConstantInteger) value).getInteger(), SymbolType.SBYTE);
}
throw new CompileError("Calculation not implemented " + getOperator() + " " + value );
}
@Override
public SymbolType inferType(SymbolTypeSimple operandType) {
return new SymbolTypePointer(SymbolType.SBYTE);
}
}

View File

@ -25,8 +25,6 @@ public class Operators {
public static final OperatorUnary CAST_SWORD = new OperatorCastSWord(2);
public static final OperatorUnary CAST_DWORD = new OperatorCastDWord(2);
public static final OperatorUnary CAST_SDWORD = new OperatorCastSDWord(2);
public static final OperatorUnary CAST_PTRBY = new OperatorCastPtrByte(2);
public static final OperatorUnary CAST_PTRSBY = new OperatorCastPtrSignedByte(2);
public static final OperatorUnary CAST_BOOL= new OperatorCastBool(2);
public static final OperatorBinary MULTIPLY = new OperatorMultiply(3);
public static final OperatorBinary DIVIDE = new OperatorDivide(3);
@ -150,10 +148,6 @@ public class Operators {
return CAST_SDWORD;
} else if(SymbolType.BOOLEAN.equals(castType)) {
return CAST_BOOL;
} else if(castType instanceof SymbolTypePointer && SymbolType.BYTE.equals(((SymbolTypePointer) castType).getElementType())) {
return CAST_PTRBY;
} else if(castType instanceof SymbolTypePointer && SymbolType.SBYTE.equals(((SymbolTypePointer) castType).getElementType())) {
return CAST_PTRSBY;
} else if(castType instanceof SymbolTypePointer) {
return new OperatorCastPtr(CAST_BYTE.getPrecedence(), ((SymbolTypePointer) castType).getElementType());
} else {

View File

@ -52,12 +52,6 @@ public class Pass2NopCastElimination extends Pass2SsaOptimization {
} else if(SymbolType.isSWord(rValType) && Operators.CAST_WORD.equals(assignment.getOperator())) {
isNopCast = true;
toType = SymbolType.WORD;
} else if(SymbolType.isWord(rValType) && Operators.CAST_PTRBY.equals(assignment.getOperator())) {
isNopCast = true;
toType = new SymbolTypePointer(SymbolType.BYTE);
} else if(SymbolType.isWord(rValType) && Operators.CAST_PTRSBY.equals(assignment.getOperator())) {
isNopCast = true;
toType = new SymbolTypePointer(SymbolType.SBYTE);
} else if(SymbolType.isWord(rValType) && assignment.getOperator() instanceof OperatorCastPtr) {
isNopCast = true;
OperatorCastPtr castOperator = (OperatorCastPtr) (assignment.getOperator());