* src/mcs51/gen.c, src/avr/gen.c, src/pic/gen.c, src/z80/gen.c,
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 3 Jul 2007 19:51:04 +0000 (19:51 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 3 Jul 2007 19:51:04 +0000 (19:51 +0000)
  src/pic16/gen.c, src/hc08/gen.c, src/ds390/gen.c: fixed RFE
  #1746528: SDCC should ignore ':' in inline assembler comments

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4874 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/avr/gen.c
src/ds390/gen.c
src/hc08/gen.c
src/mcs51/gen.c
src/pic/gen.c
src/pic16/gen.c
src/z80/gen.c

index e7410a8911582c7a83fdb44b7dee8450fb4bf9d5..56333864fe020682c8b091587a4ca50a9b36d06c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-07-03 Borut Razem <borut.razem AT siol.net>
+
+       * src/mcs51/gen.c, src/avr/gen.c, src/pic/gen.c, src/z80/gen.c,
+         src/pic16/gen.c, src/hc08/gen.c, src/ds390/gen.c: fixed RFE
+         #1746528: SDCC should ignore ':' in inline assembler comments
+
 2007-07-02 Maarten Brock <sourceforge.brock AT dse.nl>
 
        * device/include/mcs51/C8051F360.h: fixed bug #1746410, thanks Chris Jones
index 7c17501518f6b2e52645cd68e34217f0b4197c5f..7079f1cea52db0ba3f0a378fdf7022171a53a945 100644 (file)
@@ -2948,36 +2948,51 @@ genXor (iCode * ic, iCode * ifx)
 static void
 genInline (iCode * ic)
 {
-       char *buffer, *bp, *bp1;
-
-       _G.inLine += (!options.asmpeep);
-
-       buffer = bp = bp1 = Safe_calloc(1, strlen(IC_INLINE(ic))+1);
-       strcpy (buffer, IC_INLINE (ic));
-
-       /* emit each line as a code */
-       while (*bp) {
-               if (*bp == '\n') {
-                       *bp++ = '\0';
-                       emitcode (bp1, "");
-                       bp1 = bp;
-               }
-               else {
-                       if (*bp == ':') {
-                               bp++;
-                               *bp = '\0';
-                               bp++;
-                               emitcode (bp1, "");
-                               bp1 = bp;
-                       }
-                       else
-                               bp++;
-               }
-       }
-       if (bp1 != bp)
-               emitcode (bp1, "");
-       /*     emitcode("",buffer); */
-       _G.inLine -= (!options.asmpeep);
+  char *buffer, *bp, *bp1;
+  bool inComment = FALSE;
+
+  _G.inLine += (!options.asmpeep);
+
+  buffer = bp = bp1 = Safe_strdup (IC_INLINE (ic));
+
+  /* emit each line as a code */
+  while (*bp)
+    {
+      switch (*bp)
+        {
+        case ';':
+          inComment = TRUE;
+          ++bp;
+          break;
+
+        case '\n':
+          inComment = FALSE;
+          *bp++ = '\0';
+          emitcode (bp1, "");
+          bp1 = bp;
+          break;
+
+        default:
+          /* Add \n for labels, not dirs such as c:\mydir */
+          if (!inComment && (*bp == ':') && (isspace((unsigned char)bp[1])))
+            {
+              ++bp;
+              *bp = '\0';
+              ++bp;
+              emitcode (bp1, "");
+              bp1 = bp;
+            }
+          else
+            ++bp;
+          break;
+        }
+    }
+    if (bp1 != bp)
+      emitcode (bp1, "");
+
+    Safe_free (buffer);
+
+    _G.inLine -= (!options.asmpeep);
 }
 
 /*-----------------------------------------------------------------*/
index aa9a8983a554fb6ebb0bd7ae2dfa1d9252100283..24385894f7ce8bd8fb785dd752d68e3e8b953bfc 100644 (file)
@@ -8299,40 +8299,51 @@ static void
 genInline (iCode * ic)
 {
   char *buffer, *bp, *bp1;
+  bool inComment = FALSE;
 
   D (emitcode (";", "genInline"));
 
   _G.inLine += (!options.asmpeep);
 
-  buffer = bp = bp1 = Safe_strdup(IC_INLINE(ic));
+  buffer = bp = bp1 = Safe_strdup (IC_INLINE(ic));
 
   /* emit each line as a code */
   while (*bp)
     {
-      if (*bp == '\n')
+      switch (*bp)
         {
+        case ';':
+          inComment = TRUE;
+          ++bp;
+          break;
+
+        case '\n':
+          inComment = FALSE;
           *bp++ = '\0';
           emitcode (bp1, "");
           bp1 = bp;
-        }
-      else
-        {
+          break;
+
+        default:
           /* Add \n for labels, not dirs such as c:\mydir */
-          if ( (*bp == ':') && (isspace((unsigned char)bp[1])) )
+          if (!inComment && (*bp == ':') && (isspace((unsigned char)bp[1])))
             {
-              bp++;
+              ++bp;
               *bp = '\0';
-              bp++;
+              ++bp;
               emitcode (bp1, "");
               bp1 = bp;
             }
           else
-            bp++;
+            ++bp;
+          break;
         }
     }
   if (bp1 != bp)
     emitcode (bp1, "");
-  /*     emitcode("",buffer); */
+
+  Safe_free (buffer);
+
   _G.inLine -= (!options.asmpeep);
 }
 
index 388d2ab95c93305a277fc0d68b3ae5a95e5f2e46..d4cfc64481b4e1b731cd7160aa2466b6f2bf65f7 100644 (file)
@@ -5454,44 +5454,51 @@ static void
 genInline (iCode * ic)
 {
   char *buffer, *bp, *bp1;
+  bool inComment = FALSE;
 
   D(emitcode (";     genInline",""));
 
   _G.inLine += (!options.asmpeep);
 
-  buffer = bp = bp1 = Safe_calloc(1, strlen(IC_INLINE(ic))+1);
-  strcpy (buffer, IC_INLINE (ic));
+  buffer = bp = bp1 = Safe_strdup (IC_INLINE(ic));
 
   /* emit each line as a code */
   while (*bp)
     {
-      if (*bp == '\n')
-       {
-         *bp++ = '\0';
-         /* emitcode (bp1, ""); */
-         emitinline (ic, bp1);
-         bp1 = bp;
-       }
-      else
-       {
-         if (*bp == ':')
-           {
-             bp++;
-             *bp = '\0';
-             bp++;
-             emitcode (bp1, "");
-             bp1 = bp;
-           }
-         else
-           bp++;
-       }
+      switch (*bp)
+        {
+        case ';':
+          inComment = TRUE;
+          ++bp;
+          break;
+
+        case '\n':
+          inComment = FALSE;
+          *bp++ = '\0';
+          emitinline (ic, bp1);
+          bp1 = bp;
+          break;
+
+        default:
+          /* Add \n for labels, not dirs such as c:\mydir */
+          if (!inComment && (*bp == ':') && (isspace((unsigned char)bp[1])))
+            {
+              ++bp;
+              *bp = '\0';
+              ++bp;
+              emitcode (bp1, "");
+              bp1 = bp;
+            }
+          else
+            ++bp;
+          break;
+        }
     }
   if (bp1 != bp)
-    {
-      /* emitcode (bp1, ""); */
-      emitinline (ic, bp1);
-    }
-  /*     emitcode("",buffer); */
+    emitinline (ic, bp1);
+
+  Safe_free (buffer);
+
   _G.inLine -= (!options.asmpeep);
 }
 
index 957d58dca8dcff26bb363f35348308b930bc40fd..dbff5f9a619a3e96fe129341c8adf161507d83f1 100644 (file)
@@ -7681,40 +7681,51 @@ static void
 genInline (iCode * ic)
 {
   char *buffer, *bp, *bp1;
+  bool inComment = FALSE;
 
   D (emitcode (";", "genInline"));
 
   _G.inLine += (!options.asmpeep);
 
-  buffer = bp = bp1 = Safe_strdup(IC_INLINE(ic));
+  buffer = bp = bp1 = Safe_strdup (IC_INLINE (ic));
 
   /* emit each line as a code */
   while (*bp)
     {
-      if (*bp == '\n')
+      switch (*bp)
         {
+        case ';':
+          inComment = TRUE;
+          ++bp;
+          break;
+
+        case '\n':
+          inComment = FALSE;
           *bp++ = '\0';
           emitcode (bp1, "");
           bp1 = bp;
-        }
-      else
-        {
+          break;
+
+        default:
           /* Add \n for labels, not dirs such as c:\mydir */
-          if ( (*bp == ':') && (isspace((unsigned char)bp[1])) )
+          if (!inComment && (*bp == ':') && (isspace((unsigned char)bp[1])))
             {
-              bp++;
+              ++bp;
               *bp = '\0';
-              bp++;
+              ++bp;
               emitcode (bp1, "");
               bp1 = bp;
             }
           else
-            bp++;
+            ++bp;
+          break;
         }
     }
   if (bp1 != bp)
     emitcode (bp1, "");
-  /*     emitcode("",buffer); */
+
+  Safe_free (buffer);
+
   _G.inLine -= (!options.asmpeep);
 }
 
index fb514994de2692dc1787786dd2d4ed9d27581249..aaa1b58c442db8ccc3b0709b283c9857078382b7 100644 (file)
@@ -6213,42 +6213,53 @@ release :
 static void genInline (iCode *ic)
 {
   char *buffer, *bp, *bp1;
+  bool inComment = FALSE;
 
   FENTRY;
   DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
 
   _G.inLine += (!options.asmpeep);
 
-  buffer = bp = bp1 = Safe_calloc(1, strlen(IC_INLINE(ic))+1);
-  strcpy(buffer,IC_INLINE(ic));
+  buffer = bp = bp1 = Safe_strdup (IC_INLINE (ic));
 
-  /* emit each line as a code */
-  while (*bp) {
-    if (*bp == '\n') {
-      *bp++ = '\0';
-      
-      if(*bp1)
-        addpCode2pBlock(pb, newpCodeAsmDir(bp1, NULL)); // inline directly, no process
-      bp1 = bp;
-    } else {
-      if (*bp == ':') {
-        bp++;
-        *bp = '\0';
-        bp++;
-
-        /* print label, use this special format with NULL directive
-         * to denote that the argument should not be indented with tab */
-        addpCode2pBlock(pb, newpCodeAsmDir(NULL, bp1)); // inline directly, no process
-
-        bp1 = bp;
-      } else
-        bp++;
+  while (*bp)
+    {
+      switch (*bp)
+        {
+        case ';':
+          inComment = TRUE;
+          ++bp;
+          break;
+
+        case '\n':
+          inComment = FALSE;
+          *bp++ = '\0';
+          if (*bp1)
+            addpCode2pBlock(pb, newpCodeAsmDir(bp1, NULL)); // inline directly, no process
+          bp1 = bp;
+          break;
+
+        default:
+          /* Add \n for labels, not dirs such as c:\mydir */
+          if (!inComment && (*bp == ':') && (isspace((unsigned char)bp[1])))
+            {
+              ++bp;
+              *bp = '\0';
+              ++bp;
+              /* print label, use this special format with NULL directive
+               * to denote that the argument should not be indented with tab */
+              addpCode2pBlock(pb, newpCodeAsmDir(NULL, bp1)); // inline directly, no process
+              bp1 = bp;
+            }
+          else
+            ++bp;
+          break;
+        }
     }
-  }
   if ((bp1 != bp) && *bp1)
     addpCode2pBlock(pb, newpCodeAsmDir(bp1, NULL)); // inline directly, no process
 
-  Safe_free(buffer);
+  Safe_free (buffer);
 
   _G.inLine -= (!options.asmpeep);
 }
index 7f9dbe233b1fe782e292a873fe6e4482ede89c58..3648a37c17e05eec45e7638e5d4e12e98a1d5fd1 100644 (file)
@@ -8481,112 +8481,119 @@ static void genXor (iCode *ic, iCode *ifx)
 static void genInline (iCode *ic)
 {
   char *buffer, *bp, *bp1;
+  bool inComment = FALSE;
     
-       DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+  DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
 
-       _G.inLine += (!options.asmpeep);
+  _G.inLine += (!options.asmpeep);
 
-       buffer = bp = bp1 = Safe_calloc(1, strlen(IC_INLINE(ic))+1);
-       strcpy(buffer,IC_INLINE(ic));
-       
-       while((bp1=strstr(bp, "\\n"))) {
-         *bp1++ = '\n';
-         *bp1++ = ' ';
-         bp = bp1;
-        }
-        bp = bp1 = buffer;
+  buffer = bp = bp1 = Safe_strdup (IC_INLINE (ic));
+  
+  while((bp1=strstr(bp, "\\n"))) {
+    *bp1++ = '\n';
+    *bp1++ = ' ';
+    bp = bp1;
+  }
+  bp = bp1 = buffer;
 
 #if 0
   /* This is an experimental code for #pragma inline
      and is temporarily disabled for 2.5.0 release */
-        if(asmInlineMap)
-        {
-          symbol *sym;
-          char *s;
-          char *cbuf;
-          int cblen;
-
-            cbuf = Safe_strdup(buffer);
-            cblen = strlen(buffer)+1;
-            memset(cbuf, 0, cblen);
-
-            bp = buffer;
-            bp1 = cbuf;
-            while(*bp) {
-              if(*bp != '%')*bp1++ = *bp++;
-              else {
-                int i;
-
-                  bp++;
-                  i = *bp - '0';
-                  if(i>elementsInSet(asmInlineMap))break;
-                  
-                  bp++;
-                  s = indexSet(asmInlineMap, i);
-                  DEBUGpc("searching symbol s = `%s'", s);
-                  sym = findSym(SymbolTab, NULL, s);
-
-                  if(sym->reqv) {
-                    strcat(bp1, sym->reqv->operand.symOperand->regs[0]->name);
-                  } else {
-                    strcat(bp1, sym->rname);
-                  }
-                  
-                  while(*bp1)bp1++;
-              }
-              
-              if(strlen(bp1) > cblen - 16) {
-                int i = strlen(cbuf);
-                cblen += 50;
-                cbuf = realloc(cbuf, cblen);
-                memset(cbuf+i, 0, 50);
-                bp1 = cbuf + i;
-              }
-            }
+  if(asmInlineMap)
+  {
+    symbol *sym;
+    char *s;
+    char *cbuf;
+    int cblen;
+
+      cbuf = Safe_strdup(buffer);
+      cblen = strlen(buffer)+1;
+      memset(cbuf, 0, cblen);
+
+      bp = buffer;
+      bp1 = cbuf;
+      while(*bp) {
+        if(*bp != '%')*bp1++ = *bp++;
+        else {
+          int i;
+
+            bp++;
+            i = *bp - '0';
+            if(i>elementsInSet(asmInlineMap))break;
             
-            free(buffer);
-            buffer = Safe_strdup( cbuf );
-            free(cbuf);
+            bp++;
+            s = indexSet(asmInlineMap, i);
+            DEBUGpc("searching symbol s = `%s'", s);
+            sym = findSym(SymbolTab, NULL, s);
+
+            if(sym->reqv) {
+              strcat(bp1, sym->reqv->operand.symOperand->regs[0]->name);
+            } else {
+              strcat(bp1, sym->rname);
+            }
             
-            bp = bp1 = buffer;
+            while(*bp1)bp1++;
         }
+        
+        if(strlen(bp1) > cblen - 16) {
+          int i = strlen(cbuf);
+          cblen += 50;
+          cbuf = realloc(cbuf, cblen);
+          memset(cbuf+i, 0, 50);
+          bp1 = cbuf + i;
+        }
+      }
+      
+      free(buffer);
+      buffer = Safe_strdup( cbuf );
+      free(cbuf);
+      
+      bp = bp1 = buffer;
+  }
 #endif  /* 0 */
 
-       /* emit each line as a code */
-       while (*bp) {
-               if (*bp == '\n') {
-                       *bp++ = '\0';
+  /* emit each line as a code */
+  while (*bp)
+    {
+      switch (*bp)
+        {
+        case ';':
+          inComment = TRUE;
+          ++bp;
+          break;
 
-                       if(*bp1)
-                               pic16_addpCode2pBlock(pb, pic16_newpCodeAsmDir(bp1, NULL)); // inline directly, no process
-                       bp1 = bp;
-               } else {
-                       if (*bp == ':') {
-                               bp++;
-                               *bp = '\0';
-                               bp++;
-
-                               /* print label, use this special format with NULL directive
-                                * to denote that the argument should not be indented with tab */
-                               pic16_addpCode2pBlock(pb, pic16_newpCodeAsmDir(NULL, bp1)); // inline directly, no process
-                               bp1 = bp;
-                       } if (*bp == ';') {
-                               /* advance to end of line (prevent splitting of comments at ':' */
-                               while (*bp && *bp != '\n') {
-                                       bp++;
-                               } // while
-                       } else
-                               bp++;
-               }
-       }
+        case '\n':
+          inComment = FALSE;
+          *bp++ = '\0';
+          if (*bp1)
+            pic16_addpCode2pBlock(pb, pic16_newpCodeAsmDir(bp1, NULL)); // inline directly, no process
+          bp1 = bp;
+          break;
 
-       if ((bp1 != bp) && *bp1)
-               pic16_addpCode2pBlock(pb, pic16_newpCodeAsmDir(bp1, NULL)); // inline directly, no process
+        default:
+          /* Add \n for labels, not dirs such as c:\mydir */
+          if (!inComment && (*bp == ':') && (isspace((unsigned char)bp[1])))
+            {
+              ++bp;
+              *bp = '\0';
+              ++bp;
+              /* print label, use this special format with NULL directive
+               * to denote that the argument should not be indented with tab */
+              pic16_addpCode2pBlock(pb, pic16_newpCodeAsmDir(NULL, bp1)); // inline directly, no process
+              bp1 = bp;
+            }
+          else
+            ++bp;
+          break;
+        }
+    }
 
+  if ((bp1 != bp) && *bp1)
+    pic16_addpCode2pBlock(pb, pic16_newpCodeAsmDir(bp1, NULL)); // inline directly, no process
 
-    Safe_free(buffer);
+  Safe_free (buffer);
 
-    _G.inLine -= (!options.asmpeep);
+  _G.inLine -= (!options.asmpeep);
 }
 
 /*-----------------------------------------------------------------*/
index 0874fbe5ad561a9e914b552854427de49eb71c66..483c894e4e6947aec6d003f1b74f58324bf1214e 100644 (file)
@@ -5635,37 +5635,49 @@ static void
 genInline (iCode * ic)
 {
   char *buffer, *bp, *bp1;
+  bool inComment = FALSE;
 
   _G.lines.isInline += (!options.asmpeep);
 
-  buffer = bp = bp1 = Safe_calloc(1, strlen(IC_INLINE(ic))+1);
-  strcpy (buffer, IC_INLINE (ic));
+  buffer = bp = bp1 = Safe_strdup (IC_INLINE (ic));
 
   /* emit each line as a code */
   while (*bp)
     {
-      if (*bp == '\n')
+      switch (*bp)
         {
+        case ';':
+          inComment = TRUE;
+          ++bp;
+          break;
+
+        case '\n':
+          inComment = FALSE;
           *bp++ = '\0';
           emit2 (bp1);
           bp1 = bp;
-        }
-      else
-        {
-          if (*bp == ':')
+          break;
+
+        default:
+          /* Add \n for labels, not dirs such as c:\mydir */
+          if (!inComment && (*bp == ':') && (isspace((unsigned char)bp[1])))
             {
-              bp++;
+              ++bp;
               *bp = '\0';
-              bp++;
+              ++bp;
               emit2 (bp1);
               bp1 = bp;
             }
           else
-            bp++;
+            ++bp;
+          break;
         }
     }
   if (bp1 != bp)
     emit2 (bp1);
+
+  Safe_free (buffer);
+
   _G.lines.isInline -= (!options.asmpeep);
 
 }