From: epetrich Date: Wed, 1 Oct 2003 07:27:32 +0000 (+0000) Subject: * src/SDCCicode.c (geniCodeJumpTable, geniCodeSwitch): fixed X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=77fcb4b638332e6c6494f5060c716ae6fe3c94b8;p=fw%2Fsdcc * src/SDCCicode.c (geniCodeJumpTable, geniCodeSwitch): fixed the other part of bug #814548 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2915 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 519e8748..b9f92fe7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-10-01 Erik Petrich + + * src/SDCCicode.c (geniCodeJumpTable, geniCodeSwitch): fixed + the other part of bug #814548 + 2003-09-30 Bernhard Held * src/SDCCcse.c: fixed part of bug #814548 diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 0833e41d..a59ed4ef 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -3288,7 +3288,8 @@ geniCodeJumpTable (operand * cond, value * caseVals, ast * tree) if (min) { cond = geniCodeSubtract (cond, operandFromLit (min)); - setOperandType (cond, UCHARTYPE); + if (!IS_LITERAL(getSpec(operandType(cond)))) + setOperandType (cond, UCHARTYPE); } /* now create the jumptable */ @@ -3309,6 +3310,29 @@ geniCodeSwitch (ast * tree,int lvl) operand *cond = geniCodeRValue (ast2iCode (tree->left,lvl+1), FALSE); value *caseVals = tree->values.switchVals.swVals; symbol *trueLabel, *falseLabel; + + /* If the condition is a literal, then just jump to the */ + /* appropriate case label. */ + if (IS_LITERAL(getSpec(operandType(cond)))) + { + int switchVal, caseVal; + + switchVal = (int) floatFromVal (cond->operand.valOperand); + while (caseVals) + { + caseVal = (int) floatFromVal (caseVals); + if (caseVal == switchVal) + { + SNPRINTF (buffer, sizeof(buffer), "_case_%d_%d", + tree->values.switchVals.swNum, caseVal); + trueLabel = newiTempLabel (buffer); + geniCodeGoto (trueLabel); + goto jumpTable; + } + caseVals = caseVals->next; + } + goto defaultOrBreak; + } /* if we can make this a jump table */ if (geniCodeJumpTable (cond, caseVals, tree)) @@ -3333,7 +3357,7 @@ geniCodeSwitch (ast * tree,int lvl) } - +defaultOrBreak: /* if default is present then goto break else break */ if (tree->values.switchVals.swDefault) {