From 45d4771584d7f28097f3fbb0a3ce1743c418685f Mon Sep 17 00:00:00 2001 From: uz Date: Sun, 30 Aug 2009 09:01:04 +0000 Subject: [PATCH] For bit fields contained within single bytes, try to do character operations instead of word sized ops. git-svn-id: svn://svn.cc65.org/cc65/trunk@4089 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/assignment.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/cc65/assignment.c b/src/cc65/assignment.c index 24fccfaa3..af414ff50 100644 --- a/src/cc65/assignment.c +++ b/src/cc65/assignment.c @@ -161,12 +161,22 @@ void Assignment (ExprDesc* Expr) } else if (ED_IsBitField (Expr)) { unsigned Mask; - unsigned Flags = TypeOf (Expr->Type); + unsigned Flags; + + /* If the bit-field fits within one byte, do the following operations + * with bytes. + */ + if (Expr->BitOffs / CHAR_BITS == (Expr->BitOffs + Expr->BitWidth - 1) / CHAR_BITS) { + Expr->Type = type_uchar; + } + + /* Determine code generator flags */ + Flags = TypeOf (Expr->Type); /* Assignment to a bit field. Get the address on stack for the store. */ PushAddr (Expr); - /* Load the value from the location as an unsigned */ + /* Load the value from the location */ Expr->Flags &= ~E_BITFIELD; LoadExpr (CF_NONE, Expr); @@ -180,7 +190,9 @@ void Assignment (ExprDesc* Expr) /* Read the expression on the right side of the '=' */ hie1 (&Expr2); - /* Do type conversion if necessary */ + /* Do type conversion if necessary. Beware: Do not use char type + * here! + */ TypeConversion (&Expr2, ltype); /* If necessary, load the value into the primary register */ @@ -198,6 +210,9 @@ void Assignment (ExprDesc* Expr) /* Generate a store instruction */ Store (Expr, 0); + /* Restore the expression type */ + Expr->Type = ltype; + } else { /* Get the address on stack if needed */ -- 2.39.5