X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCpeeph.c;h=0a5a8d2394d0a65a388d7182362481aa35848211;hb=5590d3c1d329fc2bac2d698f9abfde171bf443be;hp=dbcb3eb04a5bfa96581cc00a3c4907ce816f8345;hpb=29779804200986ce903b5086441b49265a122dc5;p=fw%2Fsdcc diff --git a/src/SDCCpeeph.c b/src/SDCCpeeph.c index dbcb3eb0..0a5a8d23 100644 --- a/src/SDCCpeeph.c +++ b/src/SDCCpeeph.c @@ -48,6 +48,10 @@ static bool matchLine (char *, char *, hTab **); #define FBYNAME(x) int x (hTab *vars, lineNode *currPl, lineNode *head, \ const char *cmdLine) +#if !OPT_DISABLE_PIC +void peepRules2pCode(peepRule *); +#endif + /*-----------------------------------------------------------------*/ /* pcDistance - afinds a label back ward or forward */ /*-----------------------------------------------------------------*/ @@ -272,10 +276,15 @@ printLine (lineNode * head, FILE * of) /* don't indent comments & labels */ if (head->line && (*head->line == ';' || - head->line[strlen (head->line) - 1] == ':')) + head->line[strlen (head->line) - 1] == ':')) { fprintf (of, "%s\n", head->line); - else + } else { + if (head->isInline && *head->line=='#') { + // comment out preprocessor directives in inline asm + fprintf (of, ";"); + } fprintf (of, "\t%s\n", head->line); + } head = head->next; } } @@ -531,12 +540,13 @@ bindVar (int key, char **s, hTab ** vtab) /* first get the value of the variable */ vvx = *s; - /* the value is ended by a ',' or space or newline or null */ + /* the value is ended by a ',' or space or newline or null or ) */ while (*vvx && *vvx != ',' && !isspace (*vvx) && *vvx != '\n' && - *vvx != ':') + *vvx != ':' && + *vvx != ')') { char ubb = 0; /* if we find a '(' then we need to balance it */ @@ -709,7 +719,9 @@ replaceRule (lineNode ** shead, lineNode * stail, peepRule * pr) { lineNode *cl = NULL; lineNode *pl = NULL, *lhead = NULL; - char lb[MAX_PATTERN_LEN]; + /* a long function name and long variable name can evaluate to + 4x max pattern length e.g. "mov dptr,((fie_var>>8)<<8)+fie_var" */ + char lb[MAX_PATTERN_LEN*4]; char *lbp; lineNode *comment = NULL; @@ -745,11 +757,13 @@ replaceRule (lineNode ** shead, lineNode * stail, peepRule * pr) l++; continue; } - while (*v) + while (*v) { *lbp++ = *v++; + } l++; - while (isdigit (*l)) + while (isdigit (*l)) { l++; + } continue; } *lbp++ = *l++; @@ -953,7 +967,6 @@ top: for (spl = *pls; spl; spl = spl->next) { - /* if inline assembler then no peep hole */ if (spl->isInline) continue; @@ -1041,7 +1054,7 @@ readFileIntoBuffer (char *fname) } /*-----------------------------------------------------------------*/ -/* initPeepHole - initiaises the peep hole optimizer stuff */ +/* initPeepHole - initialises the peep hole optimizer stuff */ /*-----------------------------------------------------------------*/ void initPeepHole () @@ -1057,4 +1070,15 @@ initPeepHole () readRules (s = readFileIntoBuffer (options.peep_file)); setToNull ((void **) &s); } + + +#if !OPT_DISABLE_PIC + /* Convert the peep rules into pcode. + NOTE: this is only support in the PIC port (at the moment) + */ + if (TARGET_IS_PIC) { + peepRules2pCode(rootRules); + } +#endif + }