public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: QUOTES_IN_INSN
@ 2005-05-13 13:35 Jan Beulich
  2005-05-13 16:20 ` QUOTES_IN_INSN Hans-Peter Nilsson
  2005-05-17 13:14 ` QUOTES_IN_INSN Nick Clifton
  0 siblings, 2 replies; 9+ messages in thread
From: Jan Beulich @ 2005-05-13 13:35 UTC (permalink / raw)
  To: hp, binutils

[-- Attachment #1: Type: text/plain, Size: 11269 bytes --]

>>>> Hans-Peter Nilsson <hp@bitrange.com> 11.05.05 20:05:40 >>>
>On Wed, 11 May 2005, Jan Beulich wrote:
>
>> >>> Hans-Peter Nilsson <hp@bitrange.com> 11.05.05 18:37:00 >>>
>> >On Wed, 11 May 2005, Jan Beulich wrote:
>> >> gas/testsuite/
>> >> 2005-05-11  Jan Beulich  <jbeulich@novell.com>
>> >>
>> >> 	* gas/mmix/err-byte1.s: Don't expect specific error text on line 10.
>> >
>> >Can you explain this, please?  Your message said nothing about it.
>> >Briefly, it looks like you introduce a regression in the error
>> >message.  What is the exact change in the error output?
>>
>> There are now two messages on the same subject. I simply
>> didn't want to check for both indivually; if you'd rather have
>> me do it that way, I'll do.
>
>Yes, please.  At least one of the checks should be explicitly
>for something like "unterminated string".  Your patch changed
>the test to match *any* error message on that line, which is
>what I oppose.

Below/attached.

Jan

gas/
2005-05-13  Jan Beulich  <jbeulich@novell.com>

	* read.c (_find_end_of_line): New.
	(find_end_of_line): New.
	(HANDLE_CONDITIONAL_ASSEMBLY): Use it.
	(read_a_source_file): Use it.
	(s_globl): Use it.
	(s_macro): Use it.
	(get_line_sb): Use it.
	(s_errwarn): Replace discard_rest_of_line by ignore_rest_of_line.
	(s_comm_internal): Likewise.
	(s_lsym): Likewise.
	(s_macro): Likewise.
	(s_ignore): Use ignore_rest_of_line.
	* read.h (find_end_of_line): Prototype.
	(discard_rest_of_line): Remove prototype. #define to
	ignore_rest_of_line.

gas/testsuite/
2005-05-13  Jan Beulich  <jbeulich@novell.com>

	* gas/mmix/err-byte1.s: Adjust expected error text on line 10.

--- /home/jbeulich/src/binutils/mainline/2005-05-13/gas/read.c	2005-05-09 11:57:39.000000000 +0200
+++ 2005-05-13/gas/read.c	2005-05-13 13:30:37.884610120 +0200
@@ -221,6 +221,7 @@ static segT get_known_segmented_expressi
 static void pobegin (void);
 static int get_line_sb (sb *);
 static void generate_file_debug (void);
+static char *_find_end_of_line (char *, int, int);
 \f
 void
 read_begin (void)
@@ -519,9 +520,11 @@ pobegin (void)
 #define HANDLE_CONDITIONAL_ASSEMBLY()					\
   if (ignore_input ())							\
     {									\
-      while (!is_end_of_line[(unsigned char) *input_line_pointer++])	\
-	if (input_line_pointer == buffer_limit)				\
-	  break;							\
+      char *eol = find_end_of_line (input_line_pointer, flag_m68k_mri);	\
+      input_line_pointer = (input_line_pointer <= buffer_limit		\
+			    && eol >= buffer_limit)			\
+			   ? buffer_limit				\
+			   : eol + 1;					\
       continue;								\
     }
 
@@ -719,9 +722,7 @@ read_a_source_file (char *name)
 		  int len;
 
 		  /* Find the end of the current expanded macro line.  */
-		  for (s = input_line_pointer - 1; *s; ++s)
-		    if (is_end_of_line[(unsigned char) *s])
-		      break;
+		  s = find_end_of_line (input_line_pointer - 1, flag_m68k_mri);
 
 		  if (s != last_eol)
 		    {
@@ -911,34 +912,10 @@ read_a_source_file (char *name)
 		    }
 		  else
 		    {
-		      int inquote = 0;
-#ifdef QUOTES_IN_INSN
-		      int inescape = 0;
-#endif
-
 		      /* WARNING: c has char, which may be end-of-line.  */
 		      /* Also: input_line_pointer->`\0` where c was.  */
 		      *input_line_pointer = c;
-		      while (!is_end_of_line[(unsigned char) *input_line_pointer]
-			     || inquote
-#ifdef TC_EOL_IN_INSN
-			     || TC_EOL_IN_INSN (input_line_pointer)
-#endif
-			     )
-			{
-			  if (flag_m68k_mri && *input_line_pointer == '\'')
-			    inquote = !inquote;
-#ifdef QUOTES_IN_INSN
-			  if (inescape)
-			    inescape = 0;
-			  else if (*input_line_pointer == '"')
-			    inquote = !inquote;
-			  else if (*input_line_pointer == '\\')
-			    inescape = 1;
-#endif
-			  input_line_pointer++;
-			}
-
+		      input_line_pointer = _find_end_of_line (input_line_pointer, flag_m68k_mri, 1);
 		      c = *input_line_pointer;
 		      *input_line_pointer = '\0';
 
@@ -1459,7 +1436,7 @@ s_comm_internal (int param,
   if (name == p)
     {
       as_bad (_("expected symbol name"));
-      discard_rest_of_line ();
+      ignore_rest_of_line ();
       goto out;
     }
 
@@ -1785,7 +1762,7 @@ s_errwarn (int err)
 	{
 	  as_bad (_("%s argument must be a string"),
 		  err ? ".error" : ".warning");
-	  discard_rest_of_line ();
+	  ignore_rest_of_line ();
 	  return;
 	}
 
@@ -1966,7 +1943,7 @@ s_globl (int ignore ATTRIBUTE_UNUSED)
 void
 s_irp (int irpc)
 {
-  char *file;
+  char *file, *eol;
   unsigned int line;
   sb s;
   const char *err;
@@ -1975,8 +1952,9 @@ s_irp (int irpc)
   as_where (&file, &line);
 
   sb_new (&s);
-  while (!is_end_of_line[(unsigned char) *input_line_pointer])
-    sb_add_char (&s, *input_line_pointer++);
+  eol = find_end_of_line (input_line_pointer, 0);
+  sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
+  input_line_pointer = eol;
 
   sb_new (&out);
 
@@ -2224,7 +2202,7 @@ s_lsym (int ignore ATTRIBUTE_UNUSED)
   if (name == p)
     {
       as_bad (_("expected symbol name"));
-      discard_rest_of_line ();
+      ignore_rest_of_line ();
       return;
     }
 
@@ -2286,8 +2264,7 @@ s_lsym (int ignore ATTRIBUTE_UNUSED)
 static int
 get_line_sb (sb *line)
 {
-  char quote1, quote2, inquote;
-  unsigned char c;
+  char *eol;
 
   if (input_line_pointer[-1] == '\n')
     bump_line_counters ();
@@ -2299,45 +2276,16 @@ get_line_sb (sb *line)
 	return 0;
     }
 
-  /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
-     code needs to be changed.  */
-  if (!flag_m68k_mri)
-    quote1 = '"';
-  else
-    quote1 = '\0';
-
-  quote2 = '\0';
-  if (flag_m68k_mri)
-    quote2 = '\'';
-#ifdef LEX_IS_STRINGQUOTE
-  quote2 = '\'';
-#endif
-
-  inquote = '\0';
-
-  while ((c = * input_line_pointer ++) != 0
-	 && (!is_end_of_line[c]
-	     || (inquote != '\0' && c != '\n')))
-    {
-      if (inquote == c)
-	inquote = '\0';
-      else if (inquote == '\0')
-	{
-	  if (c == quote1)
-	    inquote = quote1;
-	  else if (c == quote2)
-	    inquote = quote2;
-	}
-
-      sb_add_char (line, c);
-    }
+  eol = find_end_of_line (input_line_pointer, flag_m68k_mri);
+  sb_add_buffer (line, input_line_pointer, eol - input_line_pointer);
+  input_line_pointer = eol;
 
   /* Don't skip multiple end-of-line characters, because that breaks support
      for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
      characters but isn't.  Instead just skip one end of line character and
      return the character skipped so that the caller can re-insert it if
      necessary.   */
-  return c;
+  return *input_line_pointer++;
 }
 
 /* Define a macro.  This is an interface to macro.c.  */
@@ -2345,7 +2293,7 @@ get_line_sb (sb *line)
 void
 s_macro (int ignore ATTRIBUTE_UNUSED)
 {
-  char *file;
+  char *file, *eol;
   unsigned int line;
   sb s;
   const char *err;
@@ -2354,8 +2302,9 @@ s_macro (int ignore ATTRIBUTE_UNUSED)
   as_where (&file, &line);
 
   sb_new (&s);
-  while (!is_end_of_line[(unsigned char) *input_line_pointer])
-    sb_add_char (&s, *input_line_pointer++);
+  eol = find_end_of_line (input_line_pointer, 0);
+  sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
+  input_line_pointer = eol;
 
   if (line_label != NULL)
     {
@@ -2877,7 +2826,7 @@ s_set (int equiv)
   if (name == end_name)
     {
       as_bad (_("expected symbol name"));
-      discard_rest_of_line ();
+      ignore_rest_of_line ();
       return;
     }
 
@@ -3222,19 +3171,6 @@ ignore_rest_of_line (void)
   know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
 }
 
-void
-discard_rest_of_line (void)
-{
-  while (input_line_pointer < buffer_limit
-	 && !is_end_of_line[(unsigned char) *input_line_pointer])
-    input_line_pointer++;
-
-  input_line_pointer++;
-
-  /* Return pointing just after end-of-line.  */
-  know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
-}
-
 /* Sets frag for given symbol to zero_address_frag, except when the
    symbol frag is already set to a dummy listing frag.  */
 
@@ -5298,11 +5234,7 @@ do_s_func (int end_p, const char *defaul
 void
 s_ignore (int arg ATTRIBUTE_UNUSED)
 {
-  while (!is_end_of_line[(unsigned char) *input_line_pointer])
-    {
-      ++input_line_pointer;
-    }
-  ++input_line_pointer;
+  ignore_rest_of_line ();
 }
 
 void
@@ -5340,3 +5272,51 @@ input_scrub_insert_file (char *path)
   input_scrub_include_file (path, input_line_pointer);
   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
 }
+
+/* Find the end of a line, considering quotation and escaping of quotes.  */
+
+#if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
+# define TC_SINGLE_QUOTE_STRINGS 1
+#endif
+
+static char *
+_find_end_of_line (char *s, int mri_string, int insn ATTRIBUTE_UNUSED)
+{
+  char inquote = '\0';
+  int inescape = 0;
+
+  while (!is_end_of_line[(unsigned char) *s]
+	 || (inquote && !ISCNTRL (*s))
+	 || (inquote == '\'' && flag_mri)
+#ifdef TC_EOL_IN_INSN
+	 || (insn && TC_EOL_IN_INSN (s))
+#endif
+	)
+    {
+      if (mri_string && *s == '\'')
+	inquote ^= *s;
+      else if (inescape)
+	inescape = 0;
+      else if (*s == '\\')
+	inescape = 1;
+      else if (!inquote
+	       ? *s == '"'
+#ifdef TC_SINGLE_QUOTE_STRINGS
+		 || (TC_SINGLE_QUOTE_STRINGS && *s == '\'')
+#endif
+	       : *s == inquote)
+	inquote ^= *s;
+      ++s;
+    }
+  if (inquote)
+    as_warn (_("missing closing `%c'"), inquote);
+  if (inescape)
+    as_warn (_("stray `\\'"));
+  return s;
+}
+
+char *
+find_end_of_line (char *s, int mri_string)
+{
+  return _find_end_of_line (s, mri_string, 0);
+}
--- /home/jbeulich/src/binutils/mainline/2005-05-13/gas/read.h	2005-05-06 08:34:42.000000000 +0200
+++ 2005-05-13/gas/read.h	2005-05-10 11:26:28.000000000 +0200
@@ -56,6 +56,7 @@ extern char lex_type[];
 extern char is_end_of_line[];
 
 extern int is_it_end_of_statement (void);
+extern char *find_end_of_line (char *, int);
 
 extern int target_big_endian;
 
@@ -113,7 +114,7 @@ extern void emit_expr (expressionS *exp,
 extern void equals (char *sym_name, int reassign);
 extern void float_cons (int float_type);
 extern void ignore_rest_of_line (void);
-extern void discard_rest_of_line (void);
+#define discard_rest_of_line ignore_rest_of_line
 extern int output_leb128 (char *, valueT, int sign);
 extern void pseudo_set (symbolS * symbolP);
 extern void read_a_source_file (char *name);
--- /home/jbeulich/src/binutils/mainline/2005-05-13/gas/testsuite/gas/mmix/err-byte1.s	2001-10-30 16:20:07.000000000 +0100
+++ 2005-05-13/gas/testsuite/gas/mmix/err-byte1.s	2005-05-13 12:10:13.000000000 +0200
@@ -1,5 +1,5 @@
 % { dg-do assemble { target mmix-*-* } }
-% { dg-error "unterminated string" "" { target mmix-*-* } 10 }
+% { dg-error "unterminated string|missing closing" "" { target mmix-*-* } 10 }
 % { dg-bogus "end of file" "" { xfail mmix-*-* } 0 }
 
 # Note that the error is detected in the preformatter, before the text


[-- Attachment #2: binutils-mainline-find-eol.patch --]
[-- Type: text/plain, Size: 9928 bytes --]

gas/
2005-05-13  Jan Beulich  <jbeulich@novell.com>

	* read.c (_find_end_of_line): New.
	(find_end_of_line): New.
	(HANDLE_CONDITIONAL_ASSEMBLY): Use it.
	(read_a_source_file): Use it.
	(s_globl): Use it.
	(s_macro): Use it.
	(get_line_sb): Use it.
	(s_errwarn): Replace discard_rest_of_line by ignore_rest_of_line.
	(s_comm_internal): Likewise.
	(s_lsym): Likewise.
	(s_macro): Likewise.
	(s_ignore): Use ignore_rest_of_line.
	* read.h (find_end_of_line): Prototype.
	(discard_rest_of_line): Remove prototype. #define to
	ignore_rest_of_line.

gas/testsuite/
2005-05-13  Jan Beulich  <jbeulich@novell.com>

	* gas/mmix/err-byte1.s: Adjust expected error text on line 10.

--- /home/jbeulich/src/binutils/mainline/2005-05-13/gas/read.c	2005-05-09 11:57:39.000000000 +0200
+++ 2005-05-13/gas/read.c	2005-05-13 13:30:37.884610120 +0200
@@ -221,6 +221,7 @@ static segT get_known_segmented_expressi
 static void pobegin (void);
 static int get_line_sb (sb *);
 static void generate_file_debug (void);
+static char *_find_end_of_line (char *, int, int);
 \f
 void
 read_begin (void)
@@ -519,9 +520,11 @@ pobegin (void)
 #define HANDLE_CONDITIONAL_ASSEMBLY()					\
   if (ignore_input ())							\
     {									\
-      while (!is_end_of_line[(unsigned char) *input_line_pointer++])	\
-	if (input_line_pointer == buffer_limit)				\
-	  break;							\
+      char *eol = find_end_of_line (input_line_pointer, flag_m68k_mri);	\
+      input_line_pointer = (input_line_pointer <= buffer_limit		\
+			    && eol >= buffer_limit)			\
+			   ? buffer_limit				\
+			   : eol + 1;					\
       continue;								\
     }
 
@@ -719,9 +722,7 @@ read_a_source_file (char *name)
 		  int len;
 
 		  /* Find the end of the current expanded macro line.  */
-		  for (s = input_line_pointer - 1; *s; ++s)
-		    if (is_end_of_line[(unsigned char) *s])
-		      break;
+		  s = find_end_of_line (input_line_pointer - 1, flag_m68k_mri);
 
 		  if (s != last_eol)
 		    {
@@ -911,34 +912,10 @@ read_a_source_file (char *name)
 		    }
 		  else
 		    {
-		      int inquote = 0;
-#ifdef QUOTES_IN_INSN
-		      int inescape = 0;
-#endif
-
 		      /* WARNING: c has char, which may be end-of-line.  */
 		      /* Also: input_line_pointer->`\0` where c was.  */
 		      *input_line_pointer = c;
-		      while (!is_end_of_line[(unsigned char) *input_line_pointer]
-			     || inquote
-#ifdef TC_EOL_IN_INSN
-			     || TC_EOL_IN_INSN (input_line_pointer)
-#endif
-			     )
-			{
-			  if (flag_m68k_mri && *input_line_pointer == '\'')
-			    inquote = !inquote;
-#ifdef QUOTES_IN_INSN
-			  if (inescape)
-			    inescape = 0;
-			  else if (*input_line_pointer == '"')
-			    inquote = !inquote;
-			  else if (*input_line_pointer == '\\')
-			    inescape = 1;
-#endif
-			  input_line_pointer++;
-			}
-
+		      input_line_pointer = _find_end_of_line (input_line_pointer, flag_m68k_mri, 1);
 		      c = *input_line_pointer;
 		      *input_line_pointer = '\0';
 
@@ -1459,7 +1436,7 @@ s_comm_internal (int param,
   if (name == p)
     {
       as_bad (_("expected symbol name"));
-      discard_rest_of_line ();
+      ignore_rest_of_line ();
       goto out;
     }
 
@@ -1785,7 +1762,7 @@ s_errwarn (int err)
 	{
 	  as_bad (_("%s argument must be a string"),
 		  err ? ".error" : ".warning");
-	  discard_rest_of_line ();
+	  ignore_rest_of_line ();
 	  return;
 	}
 
@@ -1966,7 +1943,7 @@ s_globl (int ignore ATTRIBUTE_UNUSED)
 void
 s_irp (int irpc)
 {
-  char *file;
+  char *file, *eol;
   unsigned int line;
   sb s;
   const char *err;
@@ -1975,8 +1952,9 @@ s_irp (int irpc)
   as_where (&file, &line);
 
   sb_new (&s);
-  while (!is_end_of_line[(unsigned char) *input_line_pointer])
-    sb_add_char (&s, *input_line_pointer++);
+  eol = find_end_of_line (input_line_pointer, 0);
+  sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
+  input_line_pointer = eol;
 
   sb_new (&out);
 
@@ -2224,7 +2202,7 @@ s_lsym (int ignore ATTRIBUTE_UNUSED)
   if (name == p)
     {
       as_bad (_("expected symbol name"));
-      discard_rest_of_line ();
+      ignore_rest_of_line ();
       return;
     }
 
@@ -2286,8 +2264,7 @@ s_lsym (int ignore ATTRIBUTE_UNUSED)
 static int
 get_line_sb (sb *line)
 {
-  char quote1, quote2, inquote;
-  unsigned char c;
+  char *eol;
 
   if (input_line_pointer[-1] == '\n')
     bump_line_counters ();
@@ -2299,45 +2276,16 @@ get_line_sb (sb *line)
 	return 0;
     }
 
-  /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
-     code needs to be changed.  */
-  if (!flag_m68k_mri)
-    quote1 = '"';
-  else
-    quote1 = '\0';
-
-  quote2 = '\0';
-  if (flag_m68k_mri)
-    quote2 = '\'';
-#ifdef LEX_IS_STRINGQUOTE
-  quote2 = '\'';
-#endif
-
-  inquote = '\0';
-
-  while ((c = * input_line_pointer ++) != 0
-	 && (!is_end_of_line[c]
-	     || (inquote != '\0' && c != '\n')))
-    {
-      if (inquote == c)
-	inquote = '\0';
-      else if (inquote == '\0')
-	{
-	  if (c == quote1)
-	    inquote = quote1;
-	  else if (c == quote2)
-	    inquote = quote2;
-	}
-
-      sb_add_char (line, c);
-    }
+  eol = find_end_of_line (input_line_pointer, flag_m68k_mri);
+  sb_add_buffer (line, input_line_pointer, eol - input_line_pointer);
+  input_line_pointer = eol;
 
   /* Don't skip multiple end-of-line characters, because that breaks support
      for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
      characters but isn't.  Instead just skip one end of line character and
      return the character skipped so that the caller can re-insert it if
      necessary.   */
-  return c;
+  return *input_line_pointer++;
 }
 
 /* Define a macro.  This is an interface to macro.c.  */
@@ -2345,7 +2293,7 @@ get_line_sb (sb *line)
 void
 s_macro (int ignore ATTRIBUTE_UNUSED)
 {
-  char *file;
+  char *file, *eol;
   unsigned int line;
   sb s;
   const char *err;
@@ -2354,8 +2302,9 @@ s_macro (int ignore ATTRIBUTE_UNUSED)
   as_where (&file, &line);
 
   sb_new (&s);
-  while (!is_end_of_line[(unsigned char) *input_line_pointer])
-    sb_add_char (&s, *input_line_pointer++);
+  eol = find_end_of_line (input_line_pointer, 0);
+  sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
+  input_line_pointer = eol;
 
   if (line_label != NULL)
     {
@@ -2877,7 +2826,7 @@ s_set (int equiv)
   if (name == end_name)
     {
       as_bad (_("expected symbol name"));
-      discard_rest_of_line ();
+      ignore_rest_of_line ();
       return;
     }
 
@@ -3222,19 +3171,6 @@ ignore_rest_of_line (void)
   know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
 }
 
-void
-discard_rest_of_line (void)
-{
-  while (input_line_pointer < buffer_limit
-	 && !is_end_of_line[(unsigned char) *input_line_pointer])
-    input_line_pointer++;
-
-  input_line_pointer++;
-
-  /* Return pointing just after end-of-line.  */
-  know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
-}
-
 /* Sets frag for given symbol to zero_address_frag, except when the
    symbol frag is already set to a dummy listing frag.  */
 
@@ -5298,11 +5234,7 @@ do_s_func (int end_p, const char *defaul
 void
 s_ignore (int arg ATTRIBUTE_UNUSED)
 {
-  while (!is_end_of_line[(unsigned char) *input_line_pointer])
-    {
-      ++input_line_pointer;
-    }
-  ++input_line_pointer;
+  ignore_rest_of_line ();
 }
 
 void
@@ -5340,3 +5272,51 @@ input_scrub_insert_file (char *path)
   input_scrub_include_file (path, input_line_pointer);
   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
 }
+
+/* Find the end of a line, considering quotation and escaping of quotes.  */
+
+#if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
+# define TC_SINGLE_QUOTE_STRINGS 1
+#endif
+
+static char *
+_find_end_of_line (char *s, int mri_string, int insn ATTRIBUTE_UNUSED)
+{
+  char inquote = '\0';
+  int inescape = 0;
+
+  while (!is_end_of_line[(unsigned char) *s]
+	 || (inquote && !ISCNTRL (*s))
+	 || (inquote == '\'' && flag_mri)
+#ifdef TC_EOL_IN_INSN
+	 || (insn && TC_EOL_IN_INSN (s))
+#endif
+	)
+    {
+      if (mri_string && *s == '\'')
+	inquote ^= *s;
+      else if (inescape)
+	inescape = 0;
+      else if (*s == '\\')
+	inescape = 1;
+      else if (!inquote
+	       ? *s == '"'
+#ifdef TC_SINGLE_QUOTE_STRINGS
+		 || (TC_SINGLE_QUOTE_STRINGS && *s == '\'')
+#endif
+	       : *s == inquote)
+	inquote ^= *s;
+      ++s;
+    }
+  if (inquote)
+    as_warn (_("missing closing `%c'"), inquote);
+  if (inescape)
+    as_warn (_("stray `\\'"));
+  return s;
+}
+
+char *
+find_end_of_line (char *s, int mri_string)
+{
+  return _find_end_of_line (s, mri_string, 0);
+}
--- /home/jbeulich/src/binutils/mainline/2005-05-13/gas/read.h	2005-05-06 08:34:42.000000000 +0200
+++ 2005-05-13/gas/read.h	2005-05-10 11:26:28.000000000 +0200
@@ -56,6 +56,7 @@ extern char lex_type[];
 extern char is_end_of_line[];
 
 extern int is_it_end_of_statement (void);
+extern char *find_end_of_line (char *, int);
 
 extern int target_big_endian;
 
@@ -113,7 +114,7 @@ extern void emit_expr (expressionS *exp,
 extern void equals (char *sym_name, int reassign);
 extern void float_cons (int float_type);
 extern void ignore_rest_of_line (void);
-extern void discard_rest_of_line (void);
+#define discard_rest_of_line ignore_rest_of_line
 extern int output_leb128 (char *, valueT, int sign);
 extern void pseudo_set (symbolS * symbolP);
 extern void read_a_source_file (char *name);
--- /home/jbeulich/src/binutils/mainline/2005-05-13/gas/testsuite/gas/mmix/err-byte1.s	2001-10-30 16:20:07.000000000 +0100
+++ 2005-05-13/gas/testsuite/gas/mmix/err-byte1.s	2005-05-13 12:10:13.000000000 +0200
@@ -1,5 +1,5 @@
 % { dg-do assemble { target mmix-*-* } }
-% { dg-error "unterminated string" "" { target mmix-*-* } 10 }
+% { dg-error "unterminated string|missing closing" "" { target mmix-*-* } 10 }
 % { dg-bogus "end of file" "" { xfail mmix-*-* } 0 }
 
 # Note that the error is detected in the preformatter, before the text

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: QUOTES_IN_INSN
  2005-05-13 13:35 QUOTES_IN_INSN Jan Beulich
@ 2005-05-13 16:20 ` Hans-Peter Nilsson
  2005-05-17 13:14 ` QUOTES_IN_INSN Nick Clifton
  1 sibling, 0 replies; 9+ messages in thread
From: Hans-Peter Nilsson @ 2005-05-13 16:20 UTC (permalink / raw)
  To: Jan Beulich; +Cc: binutils

On Fri, 13 May 2005, Jan Beulich wrote:
> 2005-05-13  Jan Beulich  <jbeulich@novell.com>
>
> 	* gas/mmix/err-byte1.s: Adjust expected error text on line 10.

I'm happy.  But still a bit curious what the new error output is
for that test (not curious enough to try the patch, though. ;-)

brgds, H-P
PS. Your mailer still sends separate Message-Ids for the reply
to the list and to me (where the same one should be used), so I
see two separate replies.  Perhaps you can the developers of
that mailer; something says you're closer than me to the
developers of "Novell GroupWise Internet Agent 6.5.4".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: QUOTES_IN_INSN
  2005-05-13 13:35 QUOTES_IN_INSN Jan Beulich
  2005-05-13 16:20 ` QUOTES_IN_INSN Hans-Peter Nilsson
@ 2005-05-17 13:14 ` Nick Clifton
  1 sibling, 0 replies; 9+ messages in thread
From: Nick Clifton @ 2005-05-17 13:14 UTC (permalink / raw)
  To: Jan Beulich; +Cc: hp, binutils

Hi Jan,

> gas/
> 2005-05-13  Jan Beulich  <jbeulich@novell.com>
> 
> 	* read.c (_find_end_of_line): New.
> 	(find_end_of_line): New.
> 	(HANDLE_CONDITIONAL_ASSEMBLY): Use it.
> 	(read_a_source_file): Use it.
> 	(s_globl): Use it.
> 	(s_macro): Use it.
> 	(get_line_sb): Use it.
> 	(s_errwarn): Replace discard_rest_of_line by ignore_rest_of_line.
> 	(s_comm_internal): Likewise.
> 	(s_lsym): Likewise.
> 	(s_macro): Likewise.
> 	(s_ignore): Use ignore_rest_of_line.
> 	* read.h (find_end_of_line): Prototype.
> 	(discard_rest_of_line): Remove prototype. #define to
> 	ignore_rest_of_line.
> 
> gas/testsuite/
> 2005-05-13  Jan Beulich  <jbeulich@novell.com>
> 
> 	* gas/mmix/err-byte1.s: Adjust expected error text on line 10.

Approved - please apply.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: QUOTES_IN_INSN
       [not found] <s282446a.086@emea1-mh.id2.novell.com>
@ 2005-05-11 19:05 ` Hans-Peter Nilsson
  0 siblings, 0 replies; 9+ messages in thread
From: Hans-Peter Nilsson @ 2005-05-11 19:05 UTC (permalink / raw)
  To: Jan Beulich; +Cc: binutils

On Wed, 11 May 2005, Jan Beulich wrote:

> >>> Hans-Peter Nilsson <hp@bitrange.com> 11.05.05 18:37:00 >>>
> >On Wed, 11 May 2005, Jan Beulich wrote:
> >> gas/testsuite/
> >> 2005-05-11  Jan Beulich  <jbeulich@novell.com>
> >>
> >> 	* gas/mmix/err-byte1.s: Don't expect specific error text on line 10.
> >
> >Can you explain this, please?  Your message said nothing about it.
> >Briefly, it looks like you introduce a regression in the error
> >message.  What is the exact change in the error output?
>
> There are now two messages on the same subject. I simply
> didn't want to check for both indivually; if you'd rather have
> me do it that way, I'll do.

Yes, please.  At least one of the checks should be explicitly
for something like "unterminated string".  Your patch changed
the test to match *any* error message on that line, which is
what I oppose.

Can you please quote the whole error output from the changed
test?

> This appears to be the only
> testcase
> that ever cared to check that unterminated strings are caught,
> which I found kind of surprising...

Sorry. O:-)

(And the specific reason I do it in the mmix-specific parts of
the testsuite is the munging I do in mmix_handle_mmixal called
for some sanity checking, IIRC.)

brgds, H-P

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: QUOTES_IN_INSN
@ 2005-05-11 17:32 Jan Beulich
  0 siblings, 0 replies; 9+ messages in thread
From: Jan Beulich @ 2005-05-11 17:32 UTC (permalink / raw)
  To: hp; +Cc: binutils

>>> Hans-Peter Nilsson <hp@bitrange.com> 11.05.05 18:37:00 >>>
>On Wed, 11 May 2005, Jan Beulich wrote:
>> gas/testsuite/
>> 2005-05-11  Jan Beulich  <jbeulich@novell.com>
>>
>> 	* gas/mmix/err-byte1.s: Don't expect specific error text on line 10.
>
>Can you explain this, please?  Your message said nothing about it.
>Briefly, it looks like you introduce a regression in the error
>message.  What is the exact change in the error output?

There are now two messages on the same subject. I simply didn't want to check for both indivually; if you'd rather have me do it that way, I'll do. This appears to be the only testcase that ever cared to check that unterminated strings are caught, which I found kind of surprising...

Jan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: QUOTES_IN_INSN
  2005-05-11  9:13 QUOTES_IN_INSN Jan Beulich
@ 2005-05-11 16:44 ` Hans-Peter Nilsson
  0 siblings, 0 replies; 9+ messages in thread
From: Hans-Peter Nilsson @ 2005-05-11 16:44 UTC (permalink / raw)
  To: Jan Beulich; +Cc: binutils

On Wed, 11 May 2005, Jan Beulich wrote:
> gas/testsuite/
> 2005-05-11  Jan Beulich  <jbeulich@novell.com>
>
> 	* gas/mmix/err-byte1.s: Don't expect specific error text on line 10.

Can you explain this, please?  Your message said nothing about it.
Briefly, it looks like you introduce a regression in the error
message.  What is the exact change in the error output?

> --- /home/jbeulich/src/binutils/mainline/2005-05-06/gas/testsuite/gas/mmix/err-byte1.s	2001-10-30 16:20:07.000000000 +0100
> +++ 2005-05-06/gas/testsuite/gas/mmix/err-byte1.s	2005-05-11 09:30:22.556891072 +0200
> @@ -1,5 +1,5 @@
>  % { dg-do assemble { target mmix-*-* } }
> -% { dg-error "unterminated string" "" { target mmix-*-* } 10 }
> +% { dg-error "" "" { target mmix-*-* } 10 }
>  % { dg-bogus "end of file" "" { xfail mmix-*-* } 0 }
>
>  # Note that the error is detected in the preformatter, before the text

brgds, H-P

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: QUOTES_IN_INSN
@ 2005-05-11  9:13 Jan Beulich
  2005-05-11 16:44 ` QUOTES_IN_INSN Hans-Peter Nilsson
  0 siblings, 1 reply; 9+ messages in thread
From: Jan Beulich @ 2005-05-11  9:13 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 11678 bytes --]

>>> Ian Lance Taylor <ian@airs.com> 02.05.05 20:49:50 >>>
>"Jan Beulich" <JBeulich@novell.com> writes:
>
>> Currently, only ia64 defines this. In order to facilitate passing
>> strings to macros I think the code protected by this needs to be
>> generally enabled, otherwise stuff like
>> 
>> 	.macro m str
>> 	 .asciz "\str"
>> 	.endm
>> 
>> 	m "foo;bar"
>> 
>> doesn't work (whereas a plain
>> 
>> 	.asciz "foo;bar"
>> 
>> does obviously work).
>> 
>> Are there any contra-indications to such a change (i.e. are there
>> targets that can't tolerate this)?
>
>I would expect that this would work OK.
>
>> In any case, shouldn't the code in read.c currently protected by
>> this be dealing with '\n' specially (to at least increment the line
>> counter)? What is the intended meaning of a quoted '\n' anyway?
>> Shouldn't there rather be a warning about a missing closing quote
>> (and the line be terminated there)?
>
>I believe the MRI assembler allows you to quote a newline.  It's true
>that bump_line_counters should be called in that case.  I don't know
>about ia64.

An attempt to address this.

Also eliminating the code duplication in discard_rest_of_line and
ignore_rest_of_line. Over time, the former should perhaps be replaced by
the latter in all sources.

Built and tested natively on x86_64-unknown-linux-gnu and as cross tools
for a large number of targets.

Jan

gas/
2005-05-11  Jan Beulich  <jbeulich@novell.com>

	* read.c (_find_end_of_line): New.
	(find_end_of_line): New.
	(HANDLE_CONDITIONAL_ASSEMBLY): Use it.
	(read_a_source_file): Use it.
	(s_globl): Use it.
	(s_macro): Use it.
	(get_line_sb): Use it.
	(s_errwarn): Replace discard_rest_of_line by ignore_rest_of_line.
	(s_comm_internal): Likewise.
	(s_lsym): Likewise.
	(s_macro): Likewise.
	(s_ignore): Use ignore_rest_of_line.
	* read.h (find_end_of_line): Prototype.
	(discard_rest_of_line): Remove prototype. #define to
	ignore_rest_of_line.

gas/testsuite/
2005-05-11  Jan Beulich  <jbeulich@novell.com>

	* gas/mmix/err-byte1.s: Don't expect specific error text on line 10.

--- /home/jbeulich/src/binutils/mainline/2005-05-06/gas/read.c	2005-05-06 08:34:42.000000000 +0200
+++ 2005-05-06/gas/read.c	2005-05-10 17:57:38.719687512 +0200
@@ -221,6 +221,7 @@ static segT get_known_segmented_expressi
 static void pobegin (void);
 static int get_line_sb (sb *);
 static void generate_file_debug (void);
+static char *_find_end_of_line (char *, int, int);
 \f
 void
 read_begin (void)
@@ -519,9 +520,11 @@ pobegin (void)
 #define HANDLE_CONDITIONAL_ASSEMBLY()					\
   if (ignore_input ())							\
     {									\
-      while (!is_end_of_line[(unsigned char) *input_line_pointer++])	\
-	if (input_line_pointer == buffer_limit)				\
-	  break;							\
+      char *eol = find_end_of_line (input_line_pointer, flag_m68k_mri);	\
+      input_line_pointer = (input_line_pointer <= buffer_limit		\
+			    && eol >= buffer_limit)			\
+			   ? buffer_limit				\
+			   : eol + 1;					\
       continue;								\
     }
 
@@ -719,9 +722,7 @@ read_a_source_file (char *name)
 		  int len;
 
 		  /* Find the end of the current expanded macro line.  */
-		  for (s = input_line_pointer - 1; *s; ++s)
-		    if (is_end_of_line[(unsigned char) *s])
-		      break;
+		  s = find_end_of_line (input_line_pointer - 1, flag_m68k_mri);
 
 		  if (s != last_eol)
 		    {
@@ -911,34 +912,10 @@ read_a_source_file (char *name)
 		    }
 		  else
 		    {
-		      int inquote = 0;
-#ifdef QUOTES_IN_INSN
-		      int inescape = 0;
-#endif
-
 		      /* WARNING: c has char, which may be end-of-line.  */
 		      /* Also: input_line_pointer->`\0` where c was.  */
 		      *input_line_pointer = c;
-		      while (!is_end_of_line[(unsigned char) *input_line_pointer]
-			     || inquote
-#ifdef TC_EOL_IN_INSN
-			     || TC_EOL_IN_INSN (input_line_pointer)
-#endif
-			     )
-			{
-			  if (flag_m68k_mri && *input_line_pointer == '\'')
-			    inquote = !inquote;
-#ifdef QUOTES_IN_INSN
-			  if (inescape)
-			    inescape = 0;
-			  else if (*input_line_pointer == '"')
-			    inquote = !inquote;
-			  else if (*input_line_pointer == '\\')
-			    inescape = 1;
-#endif
-			  input_line_pointer++;
-			}
-
+		      input_line_pointer = _find_end_of_line (input_line_pointer, flag_m68k_mri, 1);
 		      c = *input_line_pointer;
 		      *input_line_pointer = '\0';
 
@@ -1459,7 +1436,7 @@ s_comm_internal (int param,
   if (name == p)
     {
       as_bad (_("expected symbol name"));
-      discard_rest_of_line ();
+      ignore_rest_of_line ();
       goto out;
     }
 
@@ -1785,7 +1762,7 @@ s_errwarn (int err)
 	{
 	  as_bad (_("%s argument must be a string"),
 		  err ? ".error" : ".warning");
-	  discard_rest_of_line ();
+	  ignore_rest_of_line ();
 	  return;
 	}
 
@@ -1966,7 +1943,7 @@ s_globl (int ignore ATTRIBUTE_UNUSED)
 void
 s_irp (int irpc)
 {
-  char *file;
+  char *file, *eol;
   unsigned int line;
   sb s;
   const char *err;
@@ -1975,8 +1952,9 @@ s_irp (int irpc)
   as_where (&file, &line);
 
   sb_new (&s);
-  while (!is_end_of_line[(unsigned char) *input_line_pointer])
-    sb_add_char (&s, *input_line_pointer++);
+  eol = find_end_of_line (input_line_pointer, 0);
+  sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
+  input_line_pointer = eol;
 
   sb_new (&out);
 
@@ -2224,7 +2202,7 @@ s_lsym (int ignore ATTRIBUTE_UNUSED)
   if (name == p)
     {
       as_bad (_("expected symbol name"));
-      discard_rest_of_line ();
+      ignore_rest_of_line ();
       return;
     }
 
@@ -2286,8 +2264,7 @@ s_lsym (int ignore ATTRIBUTE_UNUSED)
 static int
 get_line_sb (sb *line)
 {
-  char quote1, quote2, inquote;
-  unsigned char c;
+  char *eol;
 
   if (input_line_pointer[-1] == '\n')
     bump_line_counters ();
@@ -2299,45 +2276,16 @@ get_line_sb (sb *line)
 	return 0;
     }
 
-  /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
-     code needs to be changed.  */
-  if (!flag_m68k_mri)
-    quote1 = '"';
-  else
-    quote1 = '\0';
-
-  quote2 = '\0';
-  if (flag_m68k_mri)
-    quote2 = '\'';
-#ifdef LEX_IS_STRINGQUOTE
-  quote2 = '\'';
-#endif
-
-  inquote = '\0';
-
-  while ((c = * input_line_pointer ++) != 0
-	 && (!is_end_of_line[c]
-	     || (inquote != '\0' && c != '\n')))
-    {
-      if (inquote == c)
-	inquote = '\0';
-      else if (inquote == '\0')
-	{
-	  if (c == quote1)
-	    inquote = quote1;
-	  else if (c == quote2)
-	    inquote = quote2;
-	}
-
-      sb_add_char (line, c);
-    }
+  eol = find_end_of_line (input_line_pointer, flag_m68k_mri);
+  sb_add_buffer (line, input_line_pointer, eol - input_line_pointer);
+  input_line_pointer = eol;
 
   /* Don't skip multiple end-of-line characters, because that breaks support
      for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
      characters but isn't.  Instead just skip one end of line character and
      return the character skipped so that the caller can re-insert it if
      necessary.   */
-  return c;
+  return *input_line_pointer++;
 }
 
 /* Define a macro.  This is an interface to macro.c.  */
@@ -2345,7 +2293,7 @@ get_line_sb (sb *line)
 void
 s_macro (int ignore ATTRIBUTE_UNUSED)
 {
-  char *file;
+  char *file, *eol;
   unsigned int line;
   sb s;
   sb label;
@@ -2355,8 +2303,9 @@ s_macro (int ignore ATTRIBUTE_UNUSED)
   as_where (&file, &line);
 
   sb_new (&s);
-  while (!is_end_of_line[(unsigned char) *input_line_pointer])
-    sb_add_char (&s, *input_line_pointer++);
+  eol = find_end_of_line (input_line_pointer, 0);
+  sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
+  input_line_pointer = eol;
 
   sb_new (&label);
   if (line_label != NULL)
@@ -2872,7 +2821,7 @@ s_set (int equiv)
   if (name == end_name)
     {
       as_bad (_("expected symbol name"));
-      discard_rest_of_line ();
+      ignore_rest_of_line ();
       return;
     }
 
@@ -3217,19 +3166,6 @@ ignore_rest_of_line (void)
   know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
 }
 
-void
-discard_rest_of_line (void)
-{
-  while (input_line_pointer < buffer_limit
-	 && !is_end_of_line[(unsigned char) *input_line_pointer])
-    input_line_pointer++;
-
-  input_line_pointer++;
-
-  /* Return pointing just after end-of-line.  */
-  know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
-}
-
 /* Sets frag for given symbol to zero_address_frag, except when the
    symbol frag is already set to a dummy listing frag.  */
 
@@ -5293,11 +5229,7 @@ do_s_func (int end_p, const char *defaul
 void
 s_ignore (int arg ATTRIBUTE_UNUSED)
 {
-  while (!is_end_of_line[(unsigned char) *input_line_pointer])
-    {
-      ++input_line_pointer;
-    }
-  ++input_line_pointer;
+  ignore_rest_of_line ();
 }
 
 void
@@ -5335,3 +5267,51 @@ input_scrub_insert_file (char *path)
   input_scrub_include_file (path, input_line_pointer);
   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
 }
+
+/* Find the end of a line, considering quotation and escaping of quotes.  */
+
+#if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
+# define TC_SINGLE_QUOTE_STRINGS 1
+#endif
+
+static char *
+_find_end_of_line (char *s, int mri_string, int insn ATTRIBUTE_UNUSED)
+{
+  char inquote = '\0';
+  int inescape = 0;
+
+  while (!is_end_of_line[(unsigned char) *s]
+	 || (inquote && !ISCNTRL (*s))
+	 || (inquote == '\'' && flag_mri)
+#ifdef TC_EOL_IN_INSN
+	 || (insn && TC_EOL_IN_INSN (s))
+#endif
+	)
+    {
+      if (mri_string && *s == '\'')
+	inquote ^= *s;
+      else if (inescape)
+	inescape = 0;
+      else if (*s == '\\')
+	inescape = 1;
+      else if (!inquote
+	       ? *s == '"'
+#ifdef TC_SINGLE_QUOTE_STRINGS
+		 || (TC_SINGLE_QUOTE_STRINGS && *s == '\'')
+#endif
+	       : *s == inquote)
+	inquote ^= *s;
+      ++s;
+    }
+  if (inquote)
+    as_warn (_("missing closing `%c'"), inquote);
+  if (inescape)
+    as_warn (_("stray `\\'"));
+  return s;
+}
+
+char *
+find_end_of_line (char *s, int mri_string)
+{
+  return _find_end_of_line (s, mri_string, 0);
+}
--- /home/jbeulich/src/binutils/mainline/2005-05-06/gas/read.h	2005-05-06 08:34:42.000000000 +0200
+++ 2005-05-06/gas/read.h	2005-05-10 11:26:28.510701616 +0200
@@ -56,6 +56,7 @@ extern char lex_type[];
 extern char is_end_of_line[];
 
 extern int is_it_end_of_statement (void);
+extern char *find_end_of_line (char *, int);
 
 extern int target_big_endian;
 
@@ -113,7 +114,7 @@ extern void emit_expr (expressionS *exp,
 extern void equals (char *sym_name, int reassign);
 extern void float_cons (int float_type);
 extern void ignore_rest_of_line (void);
-extern void discard_rest_of_line (void);
+#define discard_rest_of_line ignore_rest_of_line
 extern int output_leb128 (char *, valueT, int sign);
 extern void pseudo_set (symbolS * symbolP);
 extern void read_a_source_file (char *name);
--- /home/jbeulich/src/binutils/mainline/2005-05-06/gas/testsuite/gas/mmix/err-byte1.s	2001-10-30 16:20:07.000000000 +0100
+++ 2005-05-06/gas/testsuite/gas/mmix/err-byte1.s	2005-05-11 09:30:22.556891072 +0200
@@ -1,5 +1,5 @@
 % { dg-do assemble { target mmix-*-* } }
-% { dg-error "unterminated string" "" { target mmix-*-* } 10 }
+% { dg-error "" "" { target mmix-*-* } 10 }
 % { dg-bogus "end of file" "" { xfail mmix-*-* } 0 }
 
 # Note that the error is detected in the preformatter, before the text


[-- Attachment #2: binutils-mainline-find-eol.patch --]
[-- Type: text/plain, Size: 10211 bytes --]

An attempt to address this.

Also eliminating the code duplication in discard_rest_of_line and
ignore_rest_of_line. Over time, the former should perhaps be replaced by
the latter in all sources.

Built and tested natively on x86_64-unknown-linux-gnu and as cross tools
for a large number of targets.

Jan

gas/
2005-05-11  Jan Beulich  <jbeulich@novell.com>

	* read.c (_find_end_of_line): New.
	(find_end_of_line): New.
	(HANDLE_CONDITIONAL_ASSEMBLY): Use it.
	(read_a_source_file): Use it.
	(s_globl): Use it.
	(s_macro): Use it.
	(get_line_sb): Use it.
	(s_errwarn): Replace discard_rest_of_line by ignore_rest_of_line.
	(s_comm_internal): Likewise.
	(s_lsym): Likewise.
	(s_macro): Likewise.
	(s_ignore): Use ignore_rest_of_line.
	* read.h (find_end_of_line): Prototype.
	(discard_rest_of_line): Remove prototype. #define to
	ignore_rest_of_line.

gas/testsuite/
2005-05-11  Jan Beulich  <jbeulich@novell.com>

	* gas/mmix/err-byte1.s: Don't expect specific error text on line 10.

--- /home/jbeulich/src/binutils/mainline/2005-05-06/gas/read.c	2005-05-06 08:34:42.000000000 +0200
+++ 2005-05-06/gas/read.c	2005-05-10 17:57:38.719687512 +0200
@@ -221,6 +221,7 @@ static segT get_known_segmented_expressi
 static void pobegin (void);
 static int get_line_sb (sb *);
 static void generate_file_debug (void);
+static char *_find_end_of_line (char *, int, int);
 \f
 void
 read_begin (void)
@@ -519,9 +520,11 @@ pobegin (void)
 #define HANDLE_CONDITIONAL_ASSEMBLY()					\
   if (ignore_input ())							\
     {									\
-      while (!is_end_of_line[(unsigned char) *input_line_pointer++])	\
-	if (input_line_pointer == buffer_limit)				\
-	  break;							\
+      char *eol = find_end_of_line (input_line_pointer, flag_m68k_mri);	\
+      input_line_pointer = (input_line_pointer <= buffer_limit		\
+			    && eol >= buffer_limit)			\
+			   ? buffer_limit				\
+			   : eol + 1;					\
       continue;								\
     }
 
@@ -719,9 +722,7 @@ read_a_source_file (char *name)
 		  int len;
 
 		  /* Find the end of the current expanded macro line.  */
-		  for (s = input_line_pointer - 1; *s; ++s)
-		    if (is_end_of_line[(unsigned char) *s])
-		      break;
+		  s = find_end_of_line (input_line_pointer - 1, flag_m68k_mri);
 
 		  if (s != last_eol)
 		    {
@@ -911,34 +912,10 @@ read_a_source_file (char *name)
 		    }
 		  else
 		    {
-		      int inquote = 0;
-#ifdef QUOTES_IN_INSN
-		      int inescape = 0;
-#endif
-
 		      /* WARNING: c has char, which may be end-of-line.  */
 		      /* Also: input_line_pointer->`\0` where c was.  */
 		      *input_line_pointer = c;
-		      while (!is_end_of_line[(unsigned char) *input_line_pointer]
-			     || inquote
-#ifdef TC_EOL_IN_INSN
-			     || TC_EOL_IN_INSN (input_line_pointer)
-#endif
-			     )
-			{
-			  if (flag_m68k_mri && *input_line_pointer == '\'')
-			    inquote = !inquote;
-#ifdef QUOTES_IN_INSN
-			  if (inescape)
-			    inescape = 0;
-			  else if (*input_line_pointer == '"')
-			    inquote = !inquote;
-			  else if (*input_line_pointer == '\\')
-			    inescape = 1;
-#endif
-			  input_line_pointer++;
-			}
-
+		      input_line_pointer = _find_end_of_line (input_line_pointer, flag_m68k_mri, 1);
 		      c = *input_line_pointer;
 		      *input_line_pointer = '\0';
 
@@ -1459,7 +1436,7 @@ s_comm_internal (int param,
   if (name == p)
     {
       as_bad (_("expected symbol name"));
-      discard_rest_of_line ();
+      ignore_rest_of_line ();
       goto out;
     }
 
@@ -1785,7 +1762,7 @@ s_errwarn (int err)
 	{
 	  as_bad (_("%s argument must be a string"),
 		  err ? ".error" : ".warning");
-	  discard_rest_of_line ();
+	  ignore_rest_of_line ();
 	  return;
 	}
 
@@ -1966,7 +1943,7 @@ s_globl (int ignore ATTRIBUTE_UNUSED)
 void
 s_irp (int irpc)
 {
-  char *file;
+  char *file, *eol;
   unsigned int line;
   sb s;
   const char *err;
@@ -1975,8 +1952,9 @@ s_irp (int irpc)
   as_where (&file, &line);
 
   sb_new (&s);
-  while (!is_end_of_line[(unsigned char) *input_line_pointer])
-    sb_add_char (&s, *input_line_pointer++);
+  eol = find_end_of_line (input_line_pointer, 0);
+  sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
+  input_line_pointer = eol;
 
   sb_new (&out);
 
@@ -2224,7 +2202,7 @@ s_lsym (int ignore ATTRIBUTE_UNUSED)
   if (name == p)
     {
       as_bad (_("expected symbol name"));
-      discard_rest_of_line ();
+      ignore_rest_of_line ();
       return;
     }
 
@@ -2286,8 +2264,7 @@ s_lsym (int ignore ATTRIBUTE_UNUSED)
 static int
 get_line_sb (sb *line)
 {
-  char quote1, quote2, inquote;
-  unsigned char c;
+  char *eol;
 
   if (input_line_pointer[-1] == '\n')
     bump_line_counters ();
@@ -2299,45 +2276,16 @@ get_line_sb (sb *line)
 	return 0;
     }
 
-  /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
-     code needs to be changed.  */
-  if (!flag_m68k_mri)
-    quote1 = '"';
-  else
-    quote1 = '\0';
-
-  quote2 = '\0';
-  if (flag_m68k_mri)
-    quote2 = '\'';
-#ifdef LEX_IS_STRINGQUOTE
-  quote2 = '\'';
-#endif
-
-  inquote = '\0';
-
-  while ((c = * input_line_pointer ++) != 0
-	 && (!is_end_of_line[c]
-	     || (inquote != '\0' && c != '\n')))
-    {
-      if (inquote == c)
-	inquote = '\0';
-      else if (inquote == '\0')
-	{
-	  if (c == quote1)
-	    inquote = quote1;
-	  else if (c == quote2)
-	    inquote = quote2;
-	}
-
-      sb_add_char (line, c);
-    }
+  eol = find_end_of_line (input_line_pointer, flag_m68k_mri);
+  sb_add_buffer (line, input_line_pointer, eol - input_line_pointer);
+  input_line_pointer = eol;
 
   /* Don't skip multiple end-of-line characters, because that breaks support
      for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
      characters but isn't.  Instead just skip one end of line character and
      return the character skipped so that the caller can re-insert it if
      necessary.   */
-  return c;
+  return *input_line_pointer++;
 }
 
 /* Define a macro.  This is an interface to macro.c.  */
@@ -2345,7 +2293,7 @@ get_line_sb (sb *line)
 void
 s_macro (int ignore ATTRIBUTE_UNUSED)
 {
-  char *file;
+  char *file, *eol;
   unsigned int line;
   sb s;
   sb label;
@@ -2355,8 +2303,9 @@ s_macro (int ignore ATTRIBUTE_UNUSED)
   as_where (&file, &line);
 
   sb_new (&s);
-  while (!is_end_of_line[(unsigned char) *input_line_pointer])
-    sb_add_char (&s, *input_line_pointer++);
+  eol = find_end_of_line (input_line_pointer, 0);
+  sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
+  input_line_pointer = eol;
 
   sb_new (&label);
   if (line_label != NULL)
@@ -2872,7 +2821,7 @@ s_set (int equiv)
   if (name == end_name)
     {
       as_bad (_("expected symbol name"));
-      discard_rest_of_line ();
+      ignore_rest_of_line ();
       return;
     }
 
@@ -3217,19 +3166,6 @@ ignore_rest_of_line (void)
   know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
 }
 
-void
-discard_rest_of_line (void)
-{
-  while (input_line_pointer < buffer_limit
-	 && !is_end_of_line[(unsigned char) *input_line_pointer])
-    input_line_pointer++;
-
-  input_line_pointer++;
-
-  /* Return pointing just after end-of-line.  */
-  know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
-}
-
 /* Sets frag for given symbol to zero_address_frag, except when the
    symbol frag is already set to a dummy listing frag.  */
 
@@ -5293,11 +5229,7 @@ do_s_func (int end_p, const char *defaul
 void
 s_ignore (int arg ATTRIBUTE_UNUSED)
 {
-  while (!is_end_of_line[(unsigned char) *input_line_pointer])
-    {
-      ++input_line_pointer;
-    }
-  ++input_line_pointer;
+  ignore_rest_of_line ();
 }
 
 void
@@ -5335,3 +5267,51 @@ input_scrub_insert_file (char *path)
   input_scrub_include_file (path, input_line_pointer);
   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
 }
+
+/* Find the end of a line, considering quotation and escaping of quotes.  */
+
+#if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
+# define TC_SINGLE_QUOTE_STRINGS 1
+#endif
+
+static char *
+_find_end_of_line (char *s, int mri_string, int insn ATTRIBUTE_UNUSED)
+{
+  char inquote = '\0';
+  int inescape = 0;
+
+  while (!is_end_of_line[(unsigned char) *s]
+	 || (inquote && !ISCNTRL (*s))
+	 || (inquote == '\'' && flag_mri)
+#ifdef TC_EOL_IN_INSN
+	 || (insn && TC_EOL_IN_INSN (s))
+#endif
+	)
+    {
+      if (mri_string && *s == '\'')
+	inquote ^= *s;
+      else if (inescape)
+	inescape = 0;
+      else if (*s == '\\')
+	inescape = 1;
+      else if (!inquote
+	       ? *s == '"'
+#ifdef TC_SINGLE_QUOTE_STRINGS
+		 || (TC_SINGLE_QUOTE_STRINGS && *s == '\'')
+#endif
+	       : *s == inquote)
+	inquote ^= *s;
+      ++s;
+    }
+  if (inquote)
+    as_warn (_("missing closing `%c'"), inquote);
+  if (inescape)
+    as_warn (_("stray `\\'"));
+  return s;
+}
+
+char *
+find_end_of_line (char *s, int mri_string)
+{
+  return _find_end_of_line (s, mri_string, 0);
+}
--- /home/jbeulich/src/binutils/mainline/2005-05-06/gas/read.h	2005-05-06 08:34:42.000000000 +0200
+++ 2005-05-06/gas/read.h	2005-05-10 11:26:28.510701616 +0200
@@ -56,6 +56,7 @@ extern char lex_type[];
 extern char is_end_of_line[];
 
 extern int is_it_end_of_statement (void);
+extern char *find_end_of_line (char *, int);
 
 extern int target_big_endian;
 
@@ -113,7 +114,7 @@ extern void emit_expr (expressionS *exp,
 extern void equals (char *sym_name, int reassign);
 extern void float_cons (int float_type);
 extern void ignore_rest_of_line (void);
-extern void discard_rest_of_line (void);
+#define discard_rest_of_line ignore_rest_of_line
 extern int output_leb128 (char *, valueT, int sign);
 extern void pseudo_set (symbolS * symbolP);
 extern void read_a_source_file (char *name);
--- /home/jbeulich/src/binutils/mainline/2005-05-06/gas/testsuite/gas/mmix/err-byte1.s	2001-10-30 16:20:07.000000000 +0100
+++ 2005-05-06/gas/testsuite/gas/mmix/err-byte1.s	2005-05-11 09:30:22.556891072 +0200
@@ -1,5 +1,5 @@
 % { dg-do assemble { target mmix-*-* } }
-% { dg-error "unterminated string" "" { target mmix-*-* } 10 }
+% { dg-error "" "" { target mmix-*-* } 10 }
 % { dg-bogus "end of file" "" { xfail mmix-*-* } 0 }
 
 # Note that the error is detected in the preformatter, before the text

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: QUOTES_IN_INSN
  2005-05-02  8:25 QUOTES_IN_INSN Jan Beulich
@ 2005-05-02 18:50 ` Ian Lance Taylor
  0 siblings, 0 replies; 9+ messages in thread
From: Ian Lance Taylor @ 2005-05-02 18:50 UTC (permalink / raw)
  To: Jan Beulich; +Cc: binutils

"Jan Beulich" <JBeulich@novell.com> writes:

> Currently, only ia64 defines this. In order to facilitate passing
> strings to macros I think the code protected by this needs to be
> generally enabled, otherwise stuff like
> 
> 	.macro m str
> 	 .asciz "\str"
> 	.endm
> 
> 	m "foo;bar"
> 
> doesn't work (whereas a plain
> 
> 	.asciz "foo;bar"
> 
> does obviously work).
> 
> Are there any contra-indications to such a change (i.e. are there
> targets that can't tolerate this)?

I would expect that this would work OK.

> In any case, shouldn't the code in read.c currently protected by
> this be dealing with '\n' specially (to at least increment the line
> counter)? What is the intended meaning of a quoted '\n' anyway?
> Shouldn't there rather be a warning about a missing closing quote
> (and the line be terminated there)?

I believe the MRI assembler allows you to quote a newline.  It's true
that bump_line_counters should be called in that case.  I don't know
about ia64.

> Additionally, as I'm seeing a number of similar issues in the macro
> handling code: Is there a formal specification somewhere about the
> expected behavior of both the assembler in general and the macro
> code in particular, so one could reasonably judge whether a certain
> construct being rejected or producing unexpected results is a bug

No.

Ian

^ permalink raw reply	[flat|nested] 9+ messages in thread

* QUOTES_IN_INSN
@ 2005-05-02  8:25 Jan Beulich
  2005-05-02 18:50 ` QUOTES_IN_INSN Ian Lance Taylor
  0 siblings, 1 reply; 9+ messages in thread
From: Jan Beulich @ 2005-05-02  8:25 UTC (permalink / raw)
  To: binutils

Currently, only ia64 defines this. In order to facilitate passing strings to macros I think the code protected by this needs to be generally enabled, otherwise stuff like

	.macro m str
	 .asciz "\str"
	.endm

	m "foo;bar"

doesn't work (whereas a plain

	.asciz "foo;bar"

does obviously work).

Are there any contra-indications to such a change (i.e. are there targets that can't tolerate this)?

In any case, shouldn't the code in read.c currently protected by this be dealing with '\n' specially (to at least increment the line counter)? What is the intended meaning of a quoted '\n' anyway? Shouldn't there rather be a warning about a missing closing quote (and the line be terminated there)?

Additionally, as I'm seeing a number of similar issues in the macro handling code: Is there a formal specification somewhere about the expected behavior of both the assembler in general and the macro code in particular, so one could reasonably judge whether a certain construct being rejected or producing unexpected results is a bug

Thanks, Jan

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-05-17 13:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-13 13:35 QUOTES_IN_INSN Jan Beulich
2005-05-13 16:20 ` QUOTES_IN_INSN Hans-Peter Nilsson
2005-05-17 13:14 ` QUOTES_IN_INSN Nick Clifton
     [not found] <s282446a.086@emea1-mh.id2.novell.com>
2005-05-11 19:05 ` QUOTES_IN_INSN Hans-Peter Nilsson
  -- strict thread matches above, loose matches on Subject: below --
2005-05-11 17:32 QUOTES_IN_INSN Jan Beulich
2005-05-11  9:13 QUOTES_IN_INSN Jan Beulich
2005-05-11 16:44 ` QUOTES_IN_INSN Hans-Peter Nilsson
2005-05-02  8:25 QUOTES_IN_INSN Jan Beulich
2005-05-02 18:50 ` QUOTES_IN_INSN Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).