From: bernhardheld Date: Fri, 20 Jan 2006 21:58:55 +0000 (+0000) Subject: * src/SDCCicode.c (geniCodeAdd, geniCodeArray): use char for array offset if possible X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=47bb725c96ea3f78ac860012cf1feb35cf66bfb2;p=fw%2Fsdcc * src/SDCCicode.c (geniCodeAdd, geniCodeArray): use char for array offset if possible * src/SDCCast.c (getLeftResultType): 255 fits in char, not 256 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4022 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index b4c2f675..61b509a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-01-20 Bernhard Held + + * src/SDCCicode.c (geniCodeAdd, geniCodeArray): use char for array + offset if possible + * src/SDCCast.c (getLeftResultType): 255 fits in char, not 256 + 2006-01-18 Bernhard Held * src/SDCCast.c (backPatchLabels): fixed bug #1408066: made it diff --git a/src/SDCCast.c b/src/SDCCast.c index 9e49cd43..dcddefdb 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -2239,7 +2239,7 @@ getLeftResultType (ast *tree, RESULT_TYPE resultType) case '[': if (!IS_ARRAY (LTYPE (tree))) return resultType; - if (DCL_ELEM (LTYPE (tree)) > 0 && DCL_ELEM (LTYPE (tree)) <= 256) + if (DCL_ELEM (LTYPE (tree)) > 0 && DCL_ELEM (LTYPE (tree)) <= 255) return RESULT_TYPE_CHAR; return resultType; default: diff --git a/src/SDCCicode.c b/src/SDCCicode.c index e24cc395..30503b61 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -2410,11 +2410,7 @@ geniCodeAdd (operand * left, operand * right, RESULT_TYPE resultType, int lvl) size = operandFromLit (getSize (ltype->next)); SPEC_USIGN (getSpec (operandType (size))) = 1; indexUnsigned = IS_UNSIGNED (getSpec (operandType (right))); - right = geniCodeMultiply (right, - size, - (getArraySizePtr(left) >= INTSIZE) ? - RESULT_TYPE_INT : - RESULT_TYPE_CHAR); + right = geniCodeMultiply (right, size, resultType); /* Even if right is a 'unsigned char', the result will be a 'signed int' due to the promotion rules. It doesn't make sense when accessing arrays, so let's fix it here: */ @@ -2513,6 +2509,14 @@ geniCodeArray (operand * left, operand * right, int lvl) operand *size; sym_link *ltype = operandType (left); bool indexUnsigned; + RESULT_TYPE resultType; + + resultType = (getArraySizePtr(left) >= INTSIZE) ? RESULT_TYPE_INT : RESULT_TYPE_CHAR; + if (DCL_ELEM (ltype)) + { + if (DCL_ELEM (ltype) * getSize (ltype->next) <= 255) + resultType = RESULT_TYPE_CHAR; + } if (IS_PTR (ltype)) { @@ -2521,22 +2525,13 @@ geniCodeArray (operand * left, operand * right, int lvl) left = geniCodeRValue (left, FALSE); } - return geniCodeDerefPtr (geniCodeAdd (left, - right, - (getArraySizePtr(left) >= INTSIZE) ? - RESULT_TYPE_INT : - RESULT_TYPE_CHAR, - lvl), + return geniCodeDerefPtr (geniCodeAdd (left, right, resultType, lvl), lvl); } size = operandFromLit (getSize (ltype->next)); SPEC_USIGN (getSpec (operandType (size))) = 1; indexUnsigned = IS_UNSIGNED (getSpec (operandType (right))); - right = geniCodeMultiply (right, - size, - (getArraySizePtr(left) >= INTSIZE) ? - RESULT_TYPE_INT : - RESULT_TYPE_CHAR); + right = geniCodeMultiply (right, size, resultType); /* Even if right is a 'unsigned char', the result will be a 'signed int' due to the promotion rules. It doesn't make sense when accessing arrays, so let's fix it here: */ if (indexUnsigned)