mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-11 04:29:53 +00:00
add type cast in simple assignment of numbers; allow integer constants to be finalized to a fixed value; bugfix memcpy
This commit is contained in:
parent
28729cbd45
commit
4aec255c95
@ -1,4 +1,4 @@
|
|||||||
//KICKC FRAGMENT CACHE f8d7c2682 f8d7c43d0
|
//KICKC FRAGMENT CACHE f8d7c0934 f8d7c2682
|
||||||
//FRAGMENT vbuz1=vbuc1
|
//FRAGMENT vbuz1=vbuc1
|
||||||
lda #{c1}
|
lda #{c1}
|
||||||
sta {z1}
|
sta {z1}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//KICKC FRAGMENT CACHE f8d7c2682 f8d7c43d0
|
//KICKC FRAGMENT CACHE f8d7c0934 f8d7c2682
|
||||||
//FRAGMENT _deref_pbuc1=vbuc2
|
//FRAGMENT _deref_pbuc1=vbuc2
|
||||||
lda #{c2}
|
lda #{c2}
|
||||||
sta {c1}
|
sta {c1}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//KICKC FRAGMENT CACHE f8d7c2682 f8d7c43d0
|
//KICKC FRAGMENT CACHE f8d7c0934 f8d7c2682
|
||||||
//FRAGMENT vbuz1=vbuc1
|
//FRAGMENT vbuz1=vbuc1
|
||||||
lda #{c1}
|
lda #{c1}
|
||||||
sta {z1}
|
sta {z1}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//KICKC FRAGMENT CACHE f8d7c2682 f8d7c43d0
|
//KICKC FRAGMENT CACHE f8d7c0934 f8d7c2682
|
||||||
//FRAGMENT vbuz1=vbuc1
|
//FRAGMENT vbuz1=vbuc1
|
||||||
lda #{c1}
|
lda #{c1}
|
||||||
sta {z1}
|
sta {z1}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//KICKC FRAGMENT CACHE f8d7c2682 f8d7c43d0
|
//KICKC FRAGMENT CACHE f8d7c0934 f8d7c2682
|
||||||
//FRAGMENT vbuz1=_deref_pbuc1
|
//FRAGMENT vbuz1=_deref_pbuc1
|
||||||
lda {c1}
|
lda {c1}
|
||||||
sta {z1}
|
sta {z1}
|
||||||
|
@ -851,7 +851,7 @@ public interface ProgramValue {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void set(Value val) {
|
public void set(Value val) {
|
||||||
memsetValue.setSize((ConstantRef) val);
|
memsetValue.setSize((ConstantValue) val);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -872,7 +872,7 @@ public interface ProgramValue {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void set(Value val) {
|
public void set(Value val) {
|
||||||
memcpyValue.setSize((ConstantRef) val);
|
memcpyValue.setSize((ConstantValue) val);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import dk.camelot64.kickc.model.iterator.ProgramExpressionIterator;
|
|||||||
import dk.camelot64.kickc.model.types.SymbolType;
|
import dk.camelot64.kickc.model.types.SymbolType;
|
||||||
import dk.camelot64.kickc.model.types.SymbolTypeConversion;
|
import dk.camelot64.kickc.model.types.SymbolTypeConversion;
|
||||||
import dk.camelot64.kickc.model.types.SymbolTypeInference;
|
import dk.camelot64.kickc.model.types.SymbolTypeInference;
|
||||||
|
import dk.camelot64.kickc.model.types.SymbolTypeIntegerFixed;
|
||||||
import dk.camelot64.kickc.model.values.RValue;
|
import dk.camelot64.kickc.model.values.RValue;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
@ -27,6 +28,20 @@ public class PassNAddNumberTypeConversions extends Pass2SsaOptimization {
|
|||||||
ProgramExpressionBinary binary = (ProgramExpressionBinary) binaryExpression;
|
ProgramExpressionBinary binary = (ProgramExpressionBinary) binaryExpression;
|
||||||
RValue left = binary.getLeft();
|
RValue left = binary.getLeft();
|
||||||
RValue right = binary.getRight();
|
RValue right = binary.getRight();
|
||||||
|
|
||||||
|
// for simple assignments the right-hand-side is converted to the type of the left-hand side (6.5.16.1.2)
|
||||||
|
if(binary instanceof ProgramExpressionBinary.ProgramExpressionBinaryAssignmentLValue ||
|
||||||
|
binary instanceof ProgramExpressionBinary.ProgramExpressionBinaryAssignmentRValue)
|
||||||
|
{
|
||||||
|
SymbolType leftType = SymbolTypeInference.inferType(getProgram().getScope(), left);
|
||||||
|
SymbolType rightType = SymbolTypeInference.inferType(getProgram().getScope(), right);
|
||||||
|
if (leftType instanceof SymbolTypeIntegerFixed && SymbolType.NUMBER.equals(rightType))
|
||||||
|
{
|
||||||
|
getLog().append("Adding cast to assignment (" + leftType + ") " + binary.getRight().toString() + " in " + ((currentStmt == null) ? "" : currentStmt.toString(getProgram(), false)));
|
||||||
|
binary.addRightCast(leftType, stmtIt, currentBlock == null ? null : currentBlock.getScope(), getScope());
|
||||||
|
modified.set(true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
SymbolType castType = SymbolTypeConversion.getNumberCastType(left, right, getScope(), currentStmt);
|
SymbolType castType = SymbolTypeConversion.getNumberCastType(left, right, getScope(), currentStmt);
|
||||||
if(castType != null) {
|
if(castType != null) {
|
||||||
// Convert both left and right to the found type
|
// Convert both left and right to the found type
|
||||||
@ -40,11 +55,11 @@ public class PassNAddNumberTypeConversions extends Pass2SsaOptimization {
|
|||||||
if(SymbolType.NUMBER.equals(rightType)) {
|
if(SymbolType.NUMBER.equals(rightType)) {
|
||||||
getLog().append("Adding number conversion cast (" + castType + ") " + binary.getRight().toString() + " in " + ((currentStmt==null)?"":currentStmt.toString(getProgram(), false)));
|
getLog().append("Adding number conversion cast (" + castType + ") " + binary.getRight().toString() + " in " + ((currentStmt==null)?"":currentStmt.toString(getProgram(), false)));
|
||||||
binary.addRightCast(castType, stmtIt, currentBlock==null?null:currentBlock.getScope(), getScope());
|
binary.addRightCast(castType, stmtIt, currentBlock==null?null:currentBlock.getScope(), getScope());
|
||||||
|
|
||||||
modified.set(true);
|
modified.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return modified.get();
|
return modified.get();
|
||||||
}
|
}
|
||||||
|
@ -28,12 +28,12 @@ public class PassNFinalizeNumberTypeConversions extends Pass2SsaOptimization {
|
|||||||
ProgramValueIterator.execute(getProgram(), (programValue, currentStmt, stmtIt, currentBlock) -> {
|
ProgramValueIterator.execute(getProgram(), (programValue, currentStmt, stmtIt, currentBlock) -> {
|
||||||
if(programValue.get() instanceof ConstantInteger) {
|
if(programValue.get() instanceof ConstantInteger) {
|
||||||
ConstantInteger constantInteger = (ConstantInteger) programValue.get();
|
ConstantInteger constantInteger = (ConstantInteger) programValue.get();
|
||||||
if(SymbolType.UNUMBER.equals(constantInteger.getType())) {
|
if(SymbolType.UNUMBER.equals(constantInteger.getType()) || (SymbolType.NUMBER.equals(constantInteger.getType()) && constantInteger.getValue()>=0)) {
|
||||||
SymbolType integerType = SymbolTypeConversion.getSmallestUnsignedFixedIntegerType(constantInteger, getScope());
|
SymbolType integerType = SymbolTypeConversion.getSmallestUnsignedFixedIntegerType(constantInteger, getScope());
|
||||||
programValue.set(new ConstantInteger(constantInteger.getValue(), integerType));
|
programValue.set(new ConstantInteger(constantInteger.getValue(), integerType));
|
||||||
getLog().append("Finalized unsigned number type "+programValue.get().toString(getProgram()));
|
getLog().append("Finalized unsigned number type "+programValue.get().toString(getProgram()));
|
||||||
modified.set(true);
|
modified.set(true);
|
||||||
} else if(SymbolType.SNUMBER.equals(constantInteger.getType())) {
|
} else if(SymbolType.SNUMBER.equals(constantInteger.getType()) || (SymbolType.NUMBER.equals(constantInteger.getType()) && constantInteger.getValue()<0)) {
|
||||||
SymbolType integerType = SymbolTypeConversion.getSmallestSignedFixedIntegerType(constantInteger, getScope());
|
SymbolType integerType = SymbolTypeConversion.getSmallestSignedFixedIntegerType(constantInteger, getScope());
|
||||||
programValue.set(new ConstantInteger(constantInteger.getValue(), integerType));
|
programValue.set(new ConstantInteger(constantInteger.getValue(), integerType));
|
||||||
getLog().append("Finalized signed number type "+programValue.get().toString(getProgram()));
|
getLog().append("Finalized signed number type "+programValue.get().toString(getProgram()));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user