From 9b6292c6f1828886ea5bacb609e63403823e3c06 Mon Sep 17 00:00:00 2001 From: johanknol Date: Wed, 29 Jan 2003 13:59:43 +0000 Subject: [PATCH] Changed OP_DEFS and OP_USES from macros to function to catch symbol abuse git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2189 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCBBlock.c | 8 ++++---- src/SDCCcse.c | 42 +++++++++++++++++++++--------------------- src/SDCCicode.c | 22 +++++++++++++++++++++- src/SDCCicode.h | 11 +++++++++-- src/SDCCloop.c | 8 ++++---- src/ds390/ralloc.c | 6 +++--- src/mcs51/ralloc.c | 6 +++--- src/pic/ralloc.c | 6 +++--- src/xa51/ralloc.c | 6 +++--- src/z80/ralloc.c | 2 +- 10 files changed, 72 insertions(+), 45 deletions(-) diff --git a/src/SDCCBBlock.c b/src/SDCCBBlock.c index 2d879cef..9b809bed 100644 --- a/src/SDCCBBlock.c +++ b/src/SDCCBBlock.c @@ -562,7 +562,7 @@ replaceSymBySym (set * sset, operand * src, operand * dest) { bitVectUnSetBit (OP_USES (IC_COND (ic)), ic->key); IC_COND (ic) = operandFromOperand (dest); - OP_USES (dest) = bitVectSetBit (OP_USES (dest), ic->key); + OP_USES_SET ((dest), bitVectSetBit (OP_USES (dest), ic->key)); continue; } @@ -571,7 +571,7 @@ replaceSymBySym (set * sset, operand * src, operand * dest) bitVectUnSetBit (OP_USES (IC_RIGHT (ic)), ic->key); IC_RIGHT (ic) = operandFromOperand (dest); IC_RIGHT (ic)->isaddr = 0; - OP_USES (dest) = bitVectSetBit (OP_USES (dest), ic->key); + OP_USES_SET ((dest), bitVectSetBit (OP_USES (dest), ic->key)); } if (isOperandEqual (IC_LEFT (ic), src)) @@ -587,7 +587,7 @@ replaceSymBySym (set * sset, operand * src, operand * dest) IC_LEFT (ic) = operandFromOperand (dest); IC_LEFT (ic)->isaddr = 0; } - OP_USES (dest) = bitVectSetBit (OP_USES (dest), ic->key); + OP_USES_SET ((dest), bitVectSetBit (OP_USES (dest), ic->key)); } /* special case for pointer sets */ @@ -597,7 +597,7 @@ replaceSymBySym (set * sset, operand * src, operand * dest) bitVectUnSetBit (OP_USES (IC_RESULT (ic)), ic->key); IC_RESULT (ic) = operandFromOperand (dest); IC_RESULT (ic)->isaddr = 1; - OP_USES (dest) = bitVectSetBit (OP_USES (dest), ic->key); + OP_USES_SET ((dest), bitVectSetBit (OP_USES (dest), ic->key)); } } } diff --git a/src/SDCCcse.c b/src/SDCCcse.c index a5ea44f3..319c3e22 100644 --- a/src/SDCCcse.c +++ b/src/SDCCcse.c @@ -102,7 +102,7 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) { bitVectUnSetBit (OP_USES (from), lic->key); - OP_USES (to) = bitVectSetBit (OP_USES (to), lic->key); + OP_USES_SET ((to), bitVectSetBit (OP_USES (to), lic->key)); siaddr = IC_COND (lic)->isaddr; IC_COND (lic) = operandFromOperand (to); IC_COND (lic)->isaddr = siaddr; @@ -118,7 +118,7 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) { bitVectUnSetBit (OP_USES (from), lic->key); - OP_USES (to) = bitVectSetBit (OP_USES (to), lic->key); + OP_USES_SET ((to), bitVectSetBit (OP_USES (to), lic->key)); siaddr = IC_COND (lic)->isaddr; IC_JTCOND (lic) = operandFromOperand (to); IC_JTCOND (lic)->isaddr = siaddr; @@ -133,7 +133,7 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) if (POINTER_SET (lic)) { bitVectUnSetBit (OP_USES (from), lic->key); - OP_USES (to) = bitVectSetBit (OP_USES (to), lic->key); + OP_USES_SET ((to), bitVectSetBit (OP_USES (to), lic->key)); /* also check if the "from" was in the non-dominating pointer sets and replace it with "to" in the bitVector */ @@ -147,7 +147,7 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) else { bitVectUnSetBit (OP_DEFS (from), lic->key); - OP_DEFS (to) = bitVectSetBit (OP_DEFS (to), lic->key); + OP_DEFS_SET ((to), bitVectSetBit (OP_DEFS (to), lic->key)); } siaddr = IC_RESULT (lic)->isaddr; IC_RESULT (lic) = operandFromOperand (to); @@ -158,7 +158,7 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) IC_RIGHT (lic) && IC_RIGHT (lic)->key == from->key) { bitVectUnSetBit (OP_USES (from), lic->key); - OP_USES (to) = bitVectSetBit (OP_USES (to), lic->key); + OP_USES_SET ((to), bitVectSetBit (OP_USES (to), lic->key)); siaddr = IC_RIGHT (lic)->isaddr; IC_RIGHT (lic) = operandFromOperand (to); IC_RIGHT (lic)->isaddr = siaddr; @@ -168,7 +168,7 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) IC_LEFT (lic) && IC_LEFT (lic)->key == from->key) { bitVectUnSetBit (OP_USES (from), lic->key); - OP_USES (to) = bitVectSetBit (OP_USES (to), lic->key); + OP_USES_SET ((to), bitVectSetBit (OP_USES (to), lic->key)); siaddr = IC_LEFT (lic)->isaddr; IC_LEFT (lic) = operandFromOperand (to); IC_LEFT (lic)->isaddr = siaddr; @@ -1081,7 +1081,7 @@ ifxOptimize (iCode * ic, set * cseSet, /* if it remains an IFX the update the use Set */ - OP_USES (IC_COND (ic)) = bitVectSetBit (OP_USES (IC_COND (ic)), ic->key); + OP_USES_SET ((IC_COND (ic)), bitVectSetBit (OP_USES (IC_COND (ic)), ic->key)); setUsesDefs (IC_COND (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); return; } @@ -1399,8 +1399,8 @@ cseBBlock (eBBlock * ebb, int computeOnly, if (ic->op == PCALL || ic->op == CALL || ic->op == RECEIVE) { /* add to defSet of the symbol */ - OP_DEFS (IC_RESULT (ic)) = - bitVectSetBit (OP_DEFS (IC_RESULT (ic)), ic->key); + OP_DEFS_SET ((IC_RESULT (ic)), + bitVectSetBit (OP_DEFS (IC_RESULT (ic)), ic->key)); /* add to the definition set of this block */ ebb->defSet = bitVectSetBit (ebb->defSet, ic->key); ebb->ldefs = bitVectSetBit (ebb->ldefs, ic->key); @@ -1438,8 +1438,8 @@ cseBBlock (eBBlock * ebb, int computeOnly, /* the lookup could have changed it */ if (IS_SYMOP (IC_LEFT (ic))) { - OP_USES (IC_LEFT (ic)) = - bitVectSetBit (OP_USES (IC_LEFT (ic)), ic->key); + OP_USES_SET ((IC_LEFT (ic)), + bitVectSetBit (OP_USES (IC_LEFT (ic)), ic->key)); setUsesDefs (IC_LEFT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); } @@ -1463,8 +1463,8 @@ cseBBlock (eBBlock * ebb, int computeOnly, /* if jumptable then mark the usage */ if (ic->op == JUMPTABLE) { - OP_USES (IC_JTCOND (ic)) = - bitVectSetBit (OP_USES (IC_JTCOND (ic)), ic->key); + OP_USES_SET ((IC_JTCOND (ic)), + bitVectSetBit (OP_USES (IC_JTCOND (ic)), ic->key)); setUsesDefs (IC_JTCOND (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); continue; @@ -1684,16 +1684,16 @@ cseBBlock (eBBlock * ebb, int computeOnly, /* add the left & right to the defUse set */ if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic))) { - OP_USES (IC_LEFT (ic)) = - bitVectSetBit (OP_USES (IC_LEFT (ic)), ic->key); + OP_USES_SET ((IC_LEFT (ic)), + bitVectSetBit (OP_USES (IC_LEFT (ic)), ic->key)); setUsesDefs (IC_LEFT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); } if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic))) { - OP_USES (IC_RIGHT (ic)) = - bitVectSetBit (OP_USES (IC_RIGHT (ic)), ic->key); + OP_USES_SET ((IC_RIGHT (ic)), + bitVectSetBit (OP_USES (IC_RIGHT (ic)), ic->key)); setUsesDefs (IC_RIGHT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); } @@ -1702,8 +1702,8 @@ cseBBlock (eBBlock * ebb, int computeOnly, /* in the defuseSet if it a pointer or array access */ if (POINTER_SET (defic)) { - OP_USES (IC_RESULT (ic)) = - bitVectSetBit (OP_USES (IC_RESULT (ic)), ic->key); + OP_USES_SET ((IC_RESULT (ic)), + bitVectSetBit (OP_USES (IC_RESULT (ic)), ic->key)); setUsesDefs (IC_RESULT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); deleteItemIf (&cseSet, ifPointerGet, IC_RESULT (ic)); ebb->ptrsSet = bitVectSetBit (ebb->ptrsSet, IC_RESULT (ic)->key); @@ -1721,8 +1721,8 @@ cseBBlock (eBBlock * ebb, int computeOnly, else /* add the result to defintion set */ if (IC_RESULT (ic)) { - OP_DEFS (IC_RESULT (ic)) = - bitVectSetBit (OP_DEFS (IC_RESULT (ic)), ic->key); + OP_DEFS_SET ((IC_RESULT (ic)), + bitVectSetBit (OP_DEFS (IC_RESULT (ic)), ic->key)); ebb->defSet = bitVectSetBit (ebb->defSet, ic->key); ebb->outDefs = bitVectCplAnd (ebb->outDefs, OP_DEFS (IC_RESULT (ic))); ebb->ldefs = bitVectSetBit (ebb->ldefs, ic->key); diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 390c6c72..4ab359dc 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -115,6 +115,26 @@ iCodeTable codeTable[] = {ARRAYINIT, "arrayInit", picGenericOne, NULL}, }; +// this makes it more easy to catch bugs +struct bitVect *OP_DEFS(struct operand *op) { + assert (IS_SYMOP(op)); + return OP_SYMBOL(op)->defs; +} +struct bitVect *OP_DEFS_SET(struct operand *op, struct bitVect *bv) { + assert (IS_SYMOP(op)); + OP_SYMBOL(op)->defs=bv; + return bv; +} +struct bitVect *OP_USES(struct operand *op) { + assert (IS_SYMOP(op)); + return OP_SYMBOL(op)->uses; +} +struct bitVect *OP_USES_SET(struct operand *op, struct bitVect *bv) { + assert (IS_SYMOP(op)); + OP_SYMBOL(op)->uses=bv; + return bv; +} + /*-----------------------------------------------------------------*/ /* checkConstantRange: check a constant against the type */ /*-----------------------------------------------------------------*/ @@ -2868,7 +2888,7 @@ geniCodeParms (ast * parms, value *argVals, int *stack, /* assign */ operand *top = operandFromSymbol (argVals->sym); /* clear useDef and other bitVectors */ - OP_USES (top) = OP_DEFS (top) = OP_SYMBOL(top)->clashes = NULL; + OP_USES_SET ((top), OP_DEFS_SET ((top), OP_SYMBOL(top)->clashes = NULL)); geniCodeAssign (top, pval, 1); } else diff --git a/src/SDCCicode.h b/src/SDCCicode.h index f171bca1..1c77db92 100644 --- a/src/SDCCicode.h +++ b/src/SDCCicode.h @@ -276,8 +276,15 @@ iCodeTable; #define SET_RESULT_RIGHT(ic) {SET_ISADDR(IC_RIGHT(ic),0); SET_ISADDR(IC_RESULT(ic),0);} #define IS_ASSIGN_ICODE(ic) (ASSIGNMENT(ic) && !POINTER_SET(ic)) -#define OP_DEFS(op) op->operand.symOperand->defs -#define OP_USES(op) op->operand.symOperand->uses +#if 0 // this causes too much, extremely difficult to find, bugs + #define OP_DEFS(op) op->operand.symOperand->defs + #define OP_USES(op) op->operand.symOperand->uses +#else + struct bitVect *OP_DEFS(struct operand *); + struct bitVect *OP_DEFS_SET(struct operand *, struct bitVect *); + struct bitVect *OP_USES(struct operand *); + struct bitVect *OP_USES_SET(struct operand *, struct bitVect *); +#endif /*-----------------------------------------------------------------*/ /* forward references for functions */ /*-----------------------------------------------------------------*/ diff --git a/src/SDCCloop.c b/src/SDCCloop.c index 238cf250..2819c859 100644 --- a/src/SDCCloop.c +++ b/src/SDCCloop.c @@ -887,10 +887,10 @@ basicInduction (region * loopReg, eBBlock ** ebbs, int count) iCode *newic = newiCode ('=', NULL, operandFromOperand (IC_RIGHT (ic))); IC_RESULT (newic) = operandFromOperand (IC_RESULT (ic)); - OP_DEFS (IC_RESULT (newic)) = - bitVectSetBit (OP_DEFS (IC_RESULT (newic)), newic->key); - OP_USES (IC_RIGHT (newic)) = - bitVectSetBit (OP_USES (IC_RIGHT (newic)), newic->key); + OP_DEFS_SET ((IC_RESULT (newic)), + bitVectSetBit (OP_DEFS (IC_RESULT (newic)), newic->key)); + OP_USES_SET ((IC_RIGHT (newic)), + bitVectSetBit (OP_USES (IC_RIGHT (newic)), newic->key)); /* and add it */ if (eblock->sch && eblock->sch->op == LABEL) addiCodeToeBBlock (eblock, newic, eblock->sch->next); diff --git a/src/ds390/ralloc.c b/src/ds390/ralloc.c index 7174970b..0d177999 100644 --- a/src/ds390/ralloc.c +++ b/src/ds390/ralloc.c @@ -2028,7 +2028,7 @@ pack: remiCodeFromeBBlock (ebp, ic); bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key); hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL); - OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key); + OP_DEFS_SET ((IC_RESULT (dic)), bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key)); return 1; } @@ -2882,7 +2882,7 @@ packRegisters (eBBlock * ebp) remiCodeFromeBBlock (ebp, ic); bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key); hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL); - OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key); + OP_DEFS_SET ((IC_RESULT (dic)), bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key)); ic = ic->prev; } else @@ -2905,7 +2905,7 @@ packRegisters (eBBlock * ebp) remiCodeFromeBBlock (ebp, ic); bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key); hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL); - OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key); + OP_DEFS_SET ((IC_RESULT (dic)), bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key)); ic = ic->prev; } } diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index b95be782..4185bfd8 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -1854,7 +1854,7 @@ pack: remiCodeFromeBBlock (ebp, ic); bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key); hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL); - OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key); + OP_DEFS_SET ((IC_RESULT (dic)), bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key)); return 1; } @@ -2678,7 +2678,7 @@ packRegisters (eBBlock * ebp) remiCodeFromeBBlock (ebp, ic); bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key); hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL); - OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key); + OP_DEFS_SET ((IC_RESULT (dic)), bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key)); ic = ic->prev; } else @@ -2701,7 +2701,7 @@ packRegisters (eBBlock * ebp) remiCodeFromeBBlock (ebp, ic); bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key); hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL); - OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key); + OP_DEFS_SET ((IC_RESULT (dic)), bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key)); ic = ic->prev; } } diff --git a/src/pic/ralloc.c b/src/pic/ralloc.c index d4ab0afc..c1505709 100644 --- a/src/pic/ralloc.c +++ b/src/pic/ralloc.c @@ -2839,7 +2839,7 @@ pack: remiCodeFromeBBlock (ebp, ic); bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key); hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL); - OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key); + OP_DEFS_SET ((IC_RESULT (dic)), bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key)); return 1; @@ -3675,7 +3675,7 @@ packRegisters (eBBlock * ebp) remiCodeFromeBBlock (ebp, ic); bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key); hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL); - OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key); + OP_DEFS_SET ((IC_RESULT (dic)), bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key)); ic = ic->prev; } else @@ -3696,7 +3696,7 @@ packRegisters (eBBlock * ebp) bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key); remiCodeFromeBBlock (ebp, ic); hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL); - OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key); + OP_DEFS_SET ((IC_RESULT (dic)), bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key)); ic = ic->prev; } } diff --git a/src/xa51/ralloc.c b/src/xa51/ralloc.c index 92ba2bdb..d7ac59b6 100755 --- a/src/xa51/ralloc.c +++ b/src/xa51/ralloc.c @@ -1437,7 +1437,7 @@ packRegsForAssign (iCode * ic, eBBlock * ebp) remiCodeFromeBBlock (ebp, ic); bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key); hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL); - OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key); + OP_DEFS_SET ((IC_RESULT (dic)), bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key)); return 1; } @@ -1994,7 +1994,7 @@ static void packRegisters (eBBlock * ebp) { remiCodeFromeBBlock (ebp, ic); bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key); hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL); - OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key); + OP_DEFS_SET ((IC_RESULT (dic)), bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key)); ic = ic->prev; } else @@ -2017,7 +2017,7 @@ static void packRegisters (eBBlock * ebp) { remiCodeFromeBBlock (ebp, ic); bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key); hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL); - OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key); + OP_DEFS_SET ((IC_RESULT (dic)), bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key)); ic = ic->prev; } } diff --git a/src/z80/ralloc.c b/src/z80/ralloc.c index 72331e49..d3fd4a6f 100644 --- a/src/z80/ralloc.c +++ b/src/z80/ralloc.c @@ -1675,7 +1675,7 @@ pack: // PENDING: Check vs mcs51 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key); hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL); - OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key); + OP_DEFS_SET ((IC_RESULT (dic)), bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key)); return 1; } -- 2.39.5