static peepRule *currRule = NULL;
#define HTAB_SIZE 53
-typedef struct
- {
- char name[SDCC_NAME_MAX + 1];
- int refCount;
- }
-labelHashEntry;
-static hTab *labelHash = NULL;
+hTab *labelHash = NULL;
static struct
{
static void buildLabelRefCountHash (lineNode * head);
static bool matchLine (char *, char *, hTab **);
-bool isLabelDefinition (const char *line, const char **start, int *len);
-#define FBYNAME(x) int x (hTab *vars, lineNode *currPl, lineNode *endPl, \
+#define FBYNAME(x) static int x (hTab *vars, lineNode *currPl, lineNode *endPl, \
lineNode *head, char *cmdLine)
#if !OPT_DISABLE_PIC
/* pcDistance - afinds a label back ward or forward */
/*-----------------------------------------------------------------*/
-int
+static int
pcDistance (lineNode * cpos, char *lbl, bool back)
{
lineNode *pl = cpos;
{
if (pl->line &&
- *pl->line != ';' &&
- pl->line[strlen (pl->line) - 1] != ':' &&
+ !pl->isComment &&
+ !pl->isLabel &&
!pl->isDebug) {
if (port->peep.getSize) {
dist += port->peep.getSize(pl);
for(pl = currPl; pl; pl = pl->next) {
if (pl->line && !pl->isDebug && !pl->isComment &&
- pl->line[strlen(pl->line)-1] == ':') {
+ pl->isLabel) {
if (strncmp(pl->line, label, len) == 0) break; /* Found Label */
if (strlen(pl->line) != 7 || !ISCHARDIGIT(*(pl->line)) ||
!ISCHARDIGIT(*(pl->line+1)) || !ISCHARDIGIT(*(pl->line+2)) ||
return TRUE; /* safe for a peephole to remove it :) */
}
+/*-----------------------------------------------------------------*/
+/* deadMove - Check, if a pop/push pair can be removed */
+/*-----------------------------------------------------------------*/
+FBYNAME (deadMove)
+{
+ char *op = hTabItemWithKey (vars, 1);
+
+ if (port->peep.deadMove)
+ return port->peep.deadMove (op, currPl, head);
+
+ fprintf (stderr, "Function deadMove not initialized in port structure\n");
+ return FALSE;
+}
/*-----------------------------------------------------------------*/
/* operandsNotSame - check if %1 & %2 are the same */
return TRUE;
}
+/*-----------------------------------------------------------------*/
+/* labelHashEntry- searches for a label in the list labelHash */
+/* Builds labelHash, if it does not yet exist. */
+/* Returns the labelHashEntry or NULL */
+/*-----------------------------------------------------------------*/
+labelHashEntry *
+getLabelRef (const char *label, lineNode *head)
+{
+ labelHashEntry *entry;
+
+ /* If we don't have the label hash table yet, build it. */
+ if (!labelHash)
+ {
+ buildLabelRefCountHash (head);
+ }
+
+ entry = hTabFirstItemWK (labelHash, hashSymbolName (label));
+
+ while (entry)
+ {
+ if (!strcmp (label, entry->name))
+ {
+ break;
+ }
+ entry = hTabNextItemWK (labelHash);
+ }
+ return entry;
+}
/* labelRefCount:
int varNumber, expectedRefCount;
bool rc = FALSE;
- /* If we don't have the label hash table yet, build it. */
- if (!labelHash)
- {
- buildLabelRefCountHash (head);
- }
-
if (sscanf (cmdLine, "%*[ \t%]%d %d", &varNumber, &expectedRefCount) == 2)
{
char *label = hTabItemWithKey (vars, varNumber);
if (label)
{
- labelHashEntry *entry;
-
- entry = hTabFirstItemWK (labelHash, hashSymbolName (label));
+ labelHashEntry *entry = getLabelRef (label, head);
- while (entry)
- {
- if (!strcmp (label, entry->name))
- {
- break;
- }
- entry = hTabNextItemWK (labelHash);
- }
if (entry)
{
#if 0
/*-----------------------------------------------------------------*/
/* callFuncByName - calls a function as defined in the table */
/*-----------------------------------------------------------------*/
-int
+static int
callFuncByName (char *fname,
hTab * vars,
lineNode * currPl,
{
"okToRemoveSLOC", okToRemoveSLOC
},
+ {
+ "deadMove", deadMove
+ },
{
"24bitModeAndPortDS390", flat24bitModeAndPortDS390
},
/* don't indent comments & labels */
if (head->line &&
- (*head->line == ';' ||
- head->line[strlen (head->line) - 1] == ':')) {
+ (head->isComment || head->isLabel)) {
fprintf (of, "%s\n", head->line);
} else {
if (head->isInline && *head->line=='#') {
/*-----------------------------------------------------------------*/
/* newPeepRule - creates a new peeprule and attach it to the root */
/*-----------------------------------------------------------------*/
-peepRule *
+static peepRule *
newPeepRule (lineNode * match,
lineNode * replace,
char *cond,
if (!isComment || (isComment && !options.noPeepComments))
{
+ const char *dummy1;
+ int dummy2;
+
if (!currL)
*head = currL = newLineNode (lines);
else
currL = connectLine (currL, newLineNode (lines));
currL->isComment = isComment;
+ currL->isLabel = isLabelDefinition (currL->line, &dummy1, &dummy2,
+ TRUE);
}
}
csl = shead;
while (1)
{
- const char *labelStart;
- int labelLength;
-
/* skip over any comments */
while (csl!=stail->next && csl->isComment)
csl = csl->next;
if (csl==stail->next)
break;
- if (isLabelDefinition(csl->line, &labelStart, &labelLength))
+ if (csl->isLabel)
{
/* found a source line label; look for it in the replacment lines */
crl = rhead;
else
lhead = cl = newLineNode (lb);
cl->isComment = pl->isComment;
+ cl->isLabel = pl->isLabel;
}
/* add the comments if any to the head of list */
* and len will be it's length.
*/
bool
-isLabelDefinition (const char *line, const char **start, int *len)
+isLabelDefinition (const char *line, const char **start, int *len,
+ bool isPeepRule)
{
const char *cp = line;
*start = cp;
- while (ISCHARALNUM (*cp) || (*cp == '$') || (*cp == '_'))
+ while (ISCHARALNUM (*cp) || (*cp == '$') || (*cp == '_') ||
+ (isPeepRule && (*cp == '%')))
{
cp++;
}
labelHash = newHashTable (HTAB_SIZE);
/* First pass: locate all the labels. */
- line = head;
-
- while (line)
+ for (line = head; line; line = line->next)
{
- if (isLabelDefinition (line->line, &label, &labelLen)
- && labelLen <= SDCC_NAME_MAX)
+ if (line->isLabel ||
+ line->isInline)
{
- labelHashEntry *entry;
+ /* run isLabelDefinition to:
+ - look for labels in inline assembler
+ - calculate labelLen
+ */
+ if (isLabelDefinition (line->line, &label, &labelLen, FALSE) &&
+ labelLen <= SDCC_NAME_MAX)
+ {
+ labelHashEntry *entry;
- entry = traceAlloc (&_G.labels, Safe_alloc(sizeof (labelHashEntry)));
+ entry = traceAlloc (&_G.labels, Safe_alloc(sizeof (labelHashEntry)));
- memcpy (entry->name, label, labelLen);
- entry->name[labelLen] = 0;
- entry->refCount = -1;
+ memcpy (entry->name, label, labelLen);
+ entry->name[labelLen] = 0;
+ entry->refCount = -1;
- /* Assume function entry points are referenced somewhere, */
- /* even if we can't find a reference (might be from outside */
- /* the function) */
- if (line->ic && (line->ic->op == FUNCTION))
- entry->refCount++;
+ /* Assume function entry points are referenced somewhere, */
+ /* even if we can't find a reference (might be from outside */
+ /* the function) */
+ if (line->ic && (line->ic->op == FUNCTION))
+ entry->refCount++;
- hTabAddItem (&labelHash, hashSymbolName (entry->name), entry);
+ hTabAddItem (&labelHash, hashSymbolName (entry->name), entry);
+ }
}
- line = line->next;
}