mirror of
https://github.com/cc65/cc65.git
synced 2025-08-08 06:25:17 +00:00
Fixed ability to do actual type conversion from bit-fields to integers. Note this doesn't try to fix the signedness issues.
This commit is contained in:
@@ -59,8 +59,8 @@ static void DoConversion (ExprDesc* Expr, const Type* NewType)
|
|||||||
/* Emit code to convert the given expression to a new type. */
|
/* Emit code to convert the given expression to a new type. */
|
||||||
{
|
{
|
||||||
Type* OldType;
|
Type* OldType;
|
||||||
unsigned OldSize;
|
unsigned OldBits;
|
||||||
unsigned NewSize;
|
unsigned NewBits;
|
||||||
|
|
||||||
|
|
||||||
/* Remember the old type */
|
/* Remember the old type */
|
||||||
@@ -83,8 +83,12 @@ static void DoConversion (ExprDesc* Expr, const Type* NewType)
|
|||||||
/* Get the sizes of the types. Since we've excluded void types, checking
|
/* Get the sizes of the types. Since we've excluded void types, checking
|
||||||
** for known sizes makes sense here.
|
** for known sizes makes sense here.
|
||||||
*/
|
*/
|
||||||
OldSize = CheckedSizeOf (OldType);
|
if (ED_IsBitField (Expr)) {
|
||||||
NewSize = CheckedSizeOf (NewType);
|
OldBits = Expr->BitWidth;
|
||||||
|
} else {
|
||||||
|
OldBits = CheckedSizeOf (OldType) * CHAR_BITS;
|
||||||
|
}
|
||||||
|
NewBits = CheckedSizeOf (NewType) * CHAR_BITS;
|
||||||
|
|
||||||
/* lvalue? */
|
/* lvalue? */
|
||||||
if (ED_IsLVal (Expr)) {
|
if (ED_IsLVal (Expr)) {
|
||||||
@@ -97,7 +101,7 @@ static void DoConversion (ExprDesc* Expr, const Type* NewType)
|
|||||||
** If both sizes are equal, do also leave the value alone.
|
** If both sizes are equal, do also leave the value alone.
|
||||||
** If the new size is larger, we must convert the value.
|
** If the new size is larger, we must convert the value.
|
||||||
*/
|
*/
|
||||||
if (NewSize > OldSize) {
|
if (NewBits > OldBits) {
|
||||||
/* Load the value into the primary */
|
/* Load the value into the primary */
|
||||||
LoadExpr (CF_NONE, Expr);
|
LoadExpr (CF_NONE, Expr);
|
||||||
|
|
||||||
@@ -114,10 +118,6 @@ static void DoConversion (ExprDesc* Expr, const Type* NewType)
|
|||||||
** to handle sign extension correctly.
|
** to handle sign extension correctly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Get the current and new size of the value */
|
|
||||||
unsigned OldBits = OldSize * 8;
|
|
||||||
unsigned NewBits = NewSize * 8;
|
|
||||||
|
|
||||||
/* Check if the new datatype will have a smaller range. If it
|
/* Check if the new datatype will have a smaller range. If it
|
||||||
** has a larger range, things are OK, since the value is
|
** has a larger range, things are OK, since the value is
|
||||||
** internally already represented by a long.
|
** internally already represented by a long.
|
||||||
@@ -151,7 +151,7 @@ static void DoConversion (ExprDesc* Expr, const Type* NewType)
|
|||||||
** not equal, add conversion code. Be sure to convert chars
|
** not equal, add conversion code. Be sure to convert chars
|
||||||
** correctly.
|
** correctly.
|
||||||
*/
|
*/
|
||||||
if (OldSize != NewSize) {
|
if (OldBits != NewBits) {
|
||||||
|
|
||||||
/* Load the value into the primary */
|
/* Load the value into the primary */
|
||||||
LoadExpr (CF_NONE, Expr);
|
LoadExpr (CF_NONE, Expr);
|
||||||
@@ -167,6 +167,11 @@ static void DoConversion (ExprDesc* Expr, const Type* NewType)
|
|||||||
ExitPoint:
|
ExitPoint:
|
||||||
/* The expression has always the new type */
|
/* The expression has always the new type */
|
||||||
ReplaceType (Expr, NewType);
|
ReplaceType (Expr, NewType);
|
||||||
|
|
||||||
|
/* Bit-fields are converted to integers */
|
||||||
|
if (ED_IsBitField (Expr)) {
|
||||||
|
ED_DisBitField (Expr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user