Support {, } and | in assembly output
authorMaxim Kuznetsov <maks.kuznetsov@gmail.com>
Mon, 6 May 2013 19:35:44 +0000 (19:35 +0000)
committerH.J. Lu <hjl@gcc.gnu.org>
Mon, 6 May 2013 19:35:44 +0000 (12:35 -0700)
gcc/

2013-05-06  Maxim Kuznetsov  <maks.kuznetsov@gmail.com>

* final.c (do_assembler_dialects): Don't handle curly braces and
vertical bar escaped by % as dialect delimiters.
(output_asm_insn): Print curly braces and vertical bar if escaped
by % and ASSEMBLER_DIALECT defined.
* doc/tm.texi.in (ASSEMBLER_DIALECT): Document new standard escapes.
* doc/tm.texi: Regenerated.

gcc/testsuite/

2013-05-06  Maxim Kuznetsov  <maks.kuznetsov@gmail.com>

* gcc.target/i386/asm-dialect-2.c: New testcase.

From-SVN: r198641

gcc/ChangeLog
gcc/doc/tm.texi
gcc/doc/tm.texi.in
gcc/final.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/asm-dialect-2.c [new file with mode: 0644]

index 47868064267e6ab86e05e980c743cce1da9c8651..48f69ac967d19b77921ca6109a97f0e2a7635456 100644 (file)
@@ -1,3 +1,12 @@
+2013-05-06  Maxim Kuznetsov  <maks.kuznetsov@gmail.com>
+
+       * final.c (do_assembler_dialects): Don't handle curly braces and
+       vertical bar escaped by % as dialect delimiters.
+       (output_asm_insn): Print curly braces and vertical bar if escaped
+       by % and ASSEMBLER_DIALECT defined.
+       * doc/tm.texi.in (ASSEMBLER_DIALECT): Document new standard escapes.
+       * doc/tm.texi: Regenerated.
+
 2013-05-06  Steven Bosscher  <steven@gcc.gnu.org>
 
 
index ec7ef758086f5300d59d29cfedff3d01e4905f4a..2482eb484b06b4302cf89f5e9407443c9548c2ae 100644 (file)
@@ -8729,7 +8729,9 @@ first argument of @code{asm_fprintf}.  This construct outputs
 @code{ASSEMBLER_DIALECT} is zero, one, two, etc.  Any special characters
 within these strings retain their usual meaning.  If there are fewer
 alternatives within the braces than the value of
-@code{ASSEMBLER_DIALECT}, the construct outputs nothing.
+@code{ASSEMBLER_DIALECT}, the construct outputs nothing. If it's needed
+to print curly braces or @samp{|} character in assembler output directly,
+@samp{%@{}, @samp{%@}} and @samp{%|} can be used.
 
 If you do not define this macro, the characters @samp{@{}, @samp{|} and
 @samp{@}} do not have any special meaning when used in templates or
index a4187335b627c29b218f0217a82a4947a3228aa6..611d6813a56eb2369f1a12d44797dd6f4a0cee12 100644 (file)
@@ -8602,7 +8602,9 @@ first argument of @code{asm_fprintf}.  This construct outputs
 @code{ASSEMBLER_DIALECT} is zero, one, two, etc.  Any special characters
 within these strings retain their usual meaning.  If there are fewer
 alternatives within the braces than the value of
-@code{ASSEMBLER_DIALECT}, the construct outputs nothing.
+@code{ASSEMBLER_DIALECT}, the construct outputs nothing. If it's needed
+to print curly braces or @samp{|} character in assembler output directly,
+@samp{%@{}, @samp{%@}} and @samp{%|} can be used.
 
 If you do not define this macro, the characters @samp{@{}, @samp{|} and
 @samp{@}} do not have any special meaning when used in templates or
index f6974f4be27af755dce305c960341e5045b6a4f5..c836e5dc8428112cd4263b466f0c38a31f19f628 100644 (file)
@@ -3430,8 +3430,21 @@ do_assembler_dialects (const char *p, int *dialect)
            DIALECT_NUMBER of strings ending with '|'.  */
         for (i = 0; i < dialect_number; i++)
           {
-            while (*p && *p != '}' && *p++ != '|')
-             ;
+            while (*p && *p != '}')
+             {
+               if (*p == '|')
+                 {
+                   p++;
+                   break;
+                 }
+
+               /* Skip over any character after a percent sign.  */
+               if (*p == '%')
+                 p++;
+               if (*p)
+                 p++;
+             }
+
             if (*p == '}')
              break;
           }
@@ -3452,8 +3465,19 @@ do_assembler_dialects (const char *p, int *dialect)
                  output_operand_lossage ("unterminated assembly dialect alternative");
                  break;
                }
+
+             /* Skip over any character after a percent sign.  */
+             if (*p == '%' && p[1])
+               {
+                 p += 2;
+                 continue;
+               }
+
+             if (*p++ == '}')
+               break;
             }
-          while (*p++ != '}');
+          while (1);
+
           *dialect = 0;
         }
       else
@@ -3546,11 +3570,17 @@ output_asm_insn (const char *templ, rtx *operands)
 #endif
 
       case '%':
-       /* %% outputs a single %.  */
-       if (*p == '%')
+       /* %% outputs a single %.  %{, %} and %| print {, } and | respectively
+          if ASSEMBLER_DIALECT defined and these characters have a special
+          meaning as dialect delimiters.*/
+       if (*p == '%'
+#ifdef ASSEMBLER_DIALECT
+           || *p == '{' || *p == '}' || *p == '|'
+#endif
+           )
          {
+           putc (*p, asm_out_file);
            p++;
-           putc (c, asm_out_file);
          }
        /* %= outputs a number which is unique to each insn in the entire
           compilation.  This is useful for making local labels that are
index fb06bb164297493085560c8374630d45a1045121..73d27cf629692fcaab59ebb576a44476702e4933 100644 (file)
@@ -1,3 +1,7 @@
+2013-05-06  Maxim Kuznetsov  <maks.kuznetsov@gmail.com>
+
+       * gcc.target/i386/asm-dialect-2.c: New testcase.
+
 2013-05-06  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/57183
diff --git a/gcc/testsuite/gcc.target/i386/asm-dialect-2.c b/gcc/testsuite/gcc.target/i386/asm-dialect-2.c
new file mode 100644 (file)
index 0000000..8386d64
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-masm=att" } */
+/* { dg-final { scan-assembler "%{a}|" } } */
+
+int a, b;
+
+void f()
+{
+  /* Check for escaped curly braces support.  */
+  asm volatile ("{%%%{a%}%||%%%}b}" : :);
+}