From cd37d9c06133f6be846d2695d00e1d5b0792a085 Mon Sep 17 00:00:00 2001 From: frief Date: Sun, 20 Feb 2005 19:29:56 +0000 Subject: [PATCH] new keyword "labelRefCountChange" which allows peepholes to keep the correct label reference count when adding/removing references to labels. A peephole file using this is appended to patch #1144962. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3681 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCpeeph.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/src/SDCCpeeph.c b/src/SDCCpeeph.c index 6b67a1f6..26946581 100644 --- a/src/SDCCpeeph.c +++ b/src/SDCCpeeph.c @@ -572,6 +572,84 @@ FBYNAME (labelRefCount) return rc; } + +/* labelRefCountChange: + * takes two parameters: a variable (bound to a label name) + * and a signed int for changing the reference count. + * + * Please note, this function is not a conditional. It unconditionally + * changes the label. It should be passed as the 'last' function + * so it only is applied if all other conditions have been met. + * + * should always return TRUE + */ +FBYNAME (labelRefCountChange) +{ + int varNumber, RefCountDelta; + bool rc = FALSE; + + /* If we don't have the label hash table yet, build it. */ + if (!labelHash) + { + buildLabelRefCountHash (head); + } + + if (sscanf (cmdLine, "%*[ \t%]%d %i", &varNumber, &RefCountDelta) == 2) + { + char *label = hTabItemWithKey (vars, varNumber); + + if (label) + { + labelHashEntry *entry; + + entry = hTabFirstItemWK (labelHash, hashSymbolName (label)); + + while (entry) + { + if (!strcmp (label, entry->name)) + { + break; + } + entry = hTabNextItemWK (labelHash); + } + if (entry) + { + if (0 <= entry->refCount + RefCountDelta) + { + entry->refCount += RefCountDelta; + rc = TRUE; + } + else + { + fprintf (stderr, "*** internal error: label %s may not get" + " negative refCount in %s peephole.\n", + label, __FUNCTION__); + } + } + else + { + fprintf (stderr, "*** internal error: no label has entry for" + " %s in %s peephole.\n", + label, __FUNCTION__); + } + } + else + { + fprintf (stderr, "*** internal error: var %d not bound" + " in peephole %s rule.\n", + varNumber, __FUNCTION__); + } + } + else + { + fprintf (stderr, + "*** internal error: labelRefCount peephole restriction" + " malformed: %s\n", cmdLine); + } + return rc; +} + + /* Within the context of the lines currPl through endPl, determine ** if the variable var contains a symbol that is volatile. Returns ** TRUE only if it is certain that this was not volatile (the symbol @@ -963,6 +1041,9 @@ callFuncByName (char *fname, }, { "operandsNotRelated", operandsNotRelated + }, + { + "labelRefCountChange", labelRefCountChange } }; int i; -- 2.30.2