Added support fun for long shifts
[fw/sdcc] / src / SDCCpeeph.c
index dbcb3eb04a5bfa96581cc00a3c4907ce816f8345..0ae38500ffee4d56c6503cb49da3918c02c34eb7 100644 (file)
@@ -272,10 +272,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 +536,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 +715,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 +753,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 +963,6 @@ top:
 
       for (spl = *pls; spl; spl = spl->next)
        {
-
          /* if inline assembler then no peep hole */
          if (spl->isInline)
            continue;