X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCpeeph.c;h=dfd7d84cd3372d46ed12da9582c7ee56fdc53d68;hb=2f2a3fe9e32b02c8abbab24080c0d9f70319c3f5;hp=0a5a8d2394d0a65a388d7182362481aa35848211;hpb=db2e33e7577a10b93dea39ff7e35458beeb0c3d0;p=fw%2Fsdcc diff --git a/src/SDCCpeeph.c b/src/SDCCpeeph.c index 0a5a8d23..dfd7d84c 100644 --- a/src/SDCCpeeph.c +++ b/src/SDCCpeeph.c @@ -24,11 +24,9 @@ -------------------------------------------------------------------------*/ #include "common.h" -#include "SDCCpeeph.h" -#include "newalloc.h" -peepRule *rootRules = NULL; -peepRule *currRule = NULL; +static peepRule *rootRules = NULL; +static peepRule *currRule = NULL; #define HTAB_SIZE 53 typedef struct @@ -38,7 +36,13 @@ typedef struct } labelHashEntry; -hTab *labelHash = NULL; +static hTab *labelHash = NULL; + +static struct +{ + allocTrace values; + allocTrace labels; +} _G; static int hashSymbolName (const char *name); static void buildLabelRefCountHash (lineNode * head); @@ -85,6 +89,23 @@ pcDistance (lineNode * cpos, char *lbl, bool back) return 0; } +/*-----------------------------------------------------------------*/ +/* flat24bitModeAndPortDS390 - */ +/*-----------------------------------------------------------------*/ +FBYNAME (flat24bitModeAndPortDS390) +{ + return ((strcmp(port->target,"ds390") == 0) && + (options.model == MODEL_FLAT24)); +} + +/*-----------------------------------------------------------------*/ +/* portIsDS390 - return true if port is DS390 */ +/*-----------------------------------------------------------------*/ +FBYNAME (portIsDS390) +{ + return (strcmp(port->target,"ds390") == 0); +} + /*-----------------------------------------------------------------*/ /* flat24bitMode - will check to see if we are in flat24 mode */ /*-----------------------------------------------------------------*/ @@ -93,6 +114,14 @@ FBYNAME (flat24bitMode) return (options.model == MODEL_FLAT24); } +/*-----------------------------------------------------------------*/ +/* xramMovcOption - check if using movc to read xram */ +/*-----------------------------------------------------------------*/ +FBYNAME (xramMovcOption) +{ + return (options.xram_movc && (strcmp(port->target,"mcs51") == 0)); +} + /*-----------------------------------------------------------------*/ /* labelInRange - will check to see if label %5 is within range */ /*-----------------------------------------------------------------*/ @@ -105,7 +134,7 @@ FBYNAME (labelInRange) if (!lbl) return FALSE; - /* if the previous teo instructions are "ljmp"s then don't + /* if the previous two instructions are "ljmp"s then don't do it since it can be part of a jump table */ if (currPl->prev && currPl->prev->prev && strstr (currPl->prev->line, "ljmp") && @@ -245,10 +274,20 @@ callFuncByName (char *fname, "24bitMode", flat24bitMode } , + { + "xramMovcOption", xramMovcOption + } + , { "labelRefCount", labelRefCount } , + { + "portIsDS390", portIsDS390 + }, + { + "24bitModeAndPortDS390", flat24bitModeAndPortDS390 + } }; int i; @@ -300,14 +339,14 @@ newPeepRule (lineNode * match, { peepRule *pr; - pr = Safe_calloc (1, sizeof (peepRule)); + pr = Safe_alloc ( sizeof (peepRule)); pr->match = match; pr->replace = replace; pr->restart = restart; if (cond && *cond) { - pr->cond = Safe_calloc (1, strlen (cond) + 1); + pr->cond = Safe_alloc ( strlen (cond) + 1); strcpy (pr->cond, cond); } else @@ -332,8 +371,8 @@ newLineNode (char *line) { lineNode *pl; - pl = Safe_calloc (1, sizeof (lineNode)); - pl->line = Safe_calloc (1, strlen (line) + 1); + pl = Safe_alloc ( sizeof (lineNode)); + pl->line = Safe_alloc ( strlen (line) + 1); strcpy (pl->line, line); return pl; } @@ -568,10 +607,10 @@ bindVar (int key, char **s, hTab ** vtab) *s = vvx; *vv = '\0'; /* got value */ - vvx = Safe_calloc (1, strlen (vval) + 1); + vvx = traceAlloc (&_G.values, Safe_alloc(strlen (vval) + 1)); strcpy (vvx, vval); - hTabAddItem (vtab, key, vvx); + hTabAddItem (vtab, key, vvx); } /*-----------------------------------------------------------------*/ @@ -659,7 +698,6 @@ matchRule (lineNode * pl, lineNode *spl; /* source pl */ lineNode *rpl; /* rule peep line */ - hTabClearAll (pr->vars); /* setToNull((void **) &pr->vars); */ /* pr->vars = newHashTable(100); */ @@ -745,6 +783,7 @@ replaceRule (lineNode ** shead, lineNode * stail, peepRule * pr) lbp = lb; l = pl->line; + while (*l) { /* if the line contains a variable */ @@ -891,7 +930,7 @@ buildLabelRefCountHash (lineNode * head) { labelHashEntry *entry; - entry = Safe_calloc (1, sizeof (labelHashEntry)); + entry = traceAlloc (&_G.labels, Safe_alloc(sizeof (labelHashEntry))); memcpy (entry->name, label, labelLen); entry->name[labelLen] = 0; @@ -944,6 +983,21 @@ buildLabelRefCountHash (lineNode * head) #endif } +/* How does this work? + peepHole + For each rule, + For each line, + Try to match + If it matches, + replace and restart. + + matchRule + matchLine + + Where is stuff allocated? + +*/ + /*-----------------------------------------------------------------*/ /* peepHole - matches & substitutes rules */ /*-----------------------------------------------------------------*/ @@ -953,43 +1007,63 @@ peepHole (lineNode ** pls) lineNode *spl; peepRule *pr; lineNode *mtail = NULL; + bool restart; + + assert(labelHash == NULL); + + do + { + restart = FALSE; + + /* for all rules */ + for (pr = rootRules; pr; pr = pr->next) + { + for (spl = *pls; spl; spl = spl->next) + { + /* if inline assembler then no peep hole */ + if (spl->isInline) + continue; + + mtail = NULL; + + /* Tidy up any data stored in the hTab */ + + /* if it matches */ + if (matchRule (spl, &mtail, pr, *pls)) + { + + /* then replace */ + if (spl == *pls) + replaceRule (pls, mtail, pr); + else + replaceRule (&spl, mtail, pr); + + /* if restart rule type then + start at the top again */ + if (pr->restart) + { + restart = TRUE; + } + } + + if (pr->vars) + { + hTabDeleteAll (pr->vars); + Safe_free (pr->vars); + pr->vars = NULL; + } + + freeTrace (&_G.values); + } + } + } while (restart == TRUE); if (labelHash) { hTabDeleteAll (labelHash); + freeTrace (&_G.labels); } labelHash = NULL; - -top: - /* for all rules */ - for (pr = rootRules; pr; pr = pr->next) - { - - for (spl = *pls; spl; spl = spl->next) - { - /* if inline assembler then no peep hole */ - if (spl->isInline) - continue; - - mtail = NULL; - - /* if it matches */ - if (matchRule (spl, &mtail, pr, *pls)) - { - - /* then replace */ - if (spl == *pls) - replaceRule (pls, mtail, pr); - else - replaceRule (&spl, mtail, pr); - - /* if restart rule type then - start at the top again */ - if (pr->restart) - goto top; - } - } - } } @@ -1027,7 +1101,7 @@ readFileIntoBuffer (char *fname) } else { - rs = Safe_calloc (1, strlen (lb) + 1); + rs = Safe_alloc ( strlen (lb) + 1); strcpy (rs, lb); } nch = 0; @@ -1046,7 +1120,7 @@ readFileIntoBuffer (char *fname) } else { - rs = Safe_calloc (1, strlen (lb) + 1); + rs = Safe_alloc ( strlen (lb) + 1); strcpy (rs, lb); } }