[v2,22/65] kvx: use is_whitespace()

Message ID 018d8c82-9a91-45e2-9149-1cc081669c25@suse.com
State New
Headers
Series gas: whitespace handling |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Jan Beulich Jan. 27, 2025, 4:21 p.m. UTC
  Wherever blanks are permissible in input, tabs ought to be permissible,
too. This is particularly relevant when -f is passed to gas (alongside
appropriate input). Also convert open-coded checks where tabs were
already included. At the same time use is_end_of_stmt() instead of open-
coded checks in adjacent code.
---
read_token()'s check for \n looks odd to me; I'm hence leaving it alone.
---
v2: New.
  

Comments

Paul Iannetta Jan. 31, 2025, 12:34 p.m. UTC | #1
On Mon, Jan 27, 2025 at 05:21:48PM +0100, Jan Beulich wrote:
> Wherever blanks are permissible in input, tabs ought to be permissible,
> too. This is particularly relevant when -f is passed to gas (alongside
> appropriate input). Also convert open-coded checks where tabs were
> already included. At the same time use is_end_of_stmt() instead of open-
> coded checks in adjacent code.
> ---
> read_token()'s check for \n looks odd to me; I'm hence leaving it alone.
> ---
> v2: New.
> 
> --- a/gas/config/kvx-parse.c
> +++ b/gas/config/kvx-parse.c
> @@ -597,12 +597,12 @@ read_token (struct token_s *tok)
>      {
>        if ('0' <= str[*begin - i] && str[*begin - i] <= '9')
>  	last_imm_p = 1;
> -      else if (str[*begin - i] != ' ' && str[*begin - i] != '\t')
> +      else if (!is_whitespace (str[*begin - i]))
>  	break;
>      }
>  
>    /* Eat up all leading spaces.  */
> -  while (str[*begin] && (str[*begin] == ' ' || str[*begin] == '\n'))
> +  while (str[*begin] && (is_whitespace (str[*begin]) || str[*begin] == '\n'))
>      *begin += 1;
>  

I think the check str[*begin] == '\n' can be safely dropped.  This
should never happen.  Thank you for pointing it out.

>    *end = *begin;
> @@ -624,7 +624,9 @@ read_token (struct token_s *tok)
>        }
>  
>        if (str[*begin] == '.'
> -	  && (!(*begin > 0 && (str[*begin - 1] == ' ' || is_delim(str[*begin - 1])))
> +	  && (!(*begin > 0
> +		&& (is_whitespace (str[*begin - 1])
> +		    || is_delim (str[*begin - 1])))
>  	    || last_imm_p))
>  	modifier_p = 1;
>  
> @@ -633,7 +635,8 @@ read_token (struct token_s *tok)
>  	*end += 1;
>  
>        /* Stop when reaching the start of the new token. */
> -      while (!(!str[*end] || is_delim (str[*end]) || str[*end] == ' ' || (modifier_p && str[*end] == '.')))
> +      while (!(!str[*end] || is_delim (str[*end]) || is_whitespace (str[*end])
> +	     || (modifier_p && str[*end] == '.')))
>  	*end += 1;
>  
>      }
> --- a/gas/config/tc-kvx.c
> +++ b/gas/config/tc-kvx.c
> @@ -1279,7 +1279,7 @@ md_assemble (char *line)
>    if (get_byte_counter (now_seg) & 3)
>      as_fatal ("code segment not word aligned in md_assemble");
>  
> -  while (line_cursor && line_cursor[0] && (line_cursor[0] == ' '))
> +  while (is_whitespace (line_cursor[0]))
>      line_cursor++;
>  
>    /* ;; was converted to "be" by line hook          */
> @@ -2125,7 +2125,7 @@ kvx_md_start_line_hook (void)
>  {
>    char *t;
>  
> -  for (t = input_line_pointer; t && t[0] == ' '; t++);
> +  for (t = input_line_pointer; is_whitespace (t[0]); t++);
>  
>    /* Detect illegal syntax patterns:
>     * - two bundle ends on the same line: ;; ;;
> @@ -2144,9 +2144,9 @@ kvx_md_start_line_hook (void)
>        while (tmp_t && tmp_t[0])
>  	{
>  	  while (tmp_t && tmp_t[0] &&
> -		 ((tmp_t[0] == ' ') || (tmp_t[0] == '\n')))
> +		 (is_whitespace (tmp_t[0]) || is_end_of_stmt (tmp_t[0])))
>  	    {
> -	      if (tmp_t[0] == '\n')
> +	      if (is_end_of_stmt (tmp_t[0]))
>  		newline_seen = true;
>  	      tmp_t++;
>  	    }
> 
> 
> 
> 
> 

Thank you for doing this. I've applied your patch and tested it, and
it looks fine to me.

Paul
  

Patch

--- a/gas/config/kvx-parse.c
+++ b/gas/config/kvx-parse.c
@@ -597,12 +597,12 @@  read_token (struct token_s *tok)
     {
       if ('0' <= str[*begin - i] && str[*begin - i] <= '9')
 	last_imm_p = 1;
-      else if (str[*begin - i] != ' ' && str[*begin - i] != '\t')
+      else if (!is_whitespace (str[*begin - i]))
 	break;
     }
 
   /* Eat up all leading spaces.  */
-  while (str[*begin] && (str[*begin] == ' ' || str[*begin] == '\n'))
+  while (str[*begin] && (is_whitespace (str[*begin]) || str[*begin] == '\n'))
     *begin += 1;
 
   *end = *begin;
@@ -624,7 +624,9 @@  read_token (struct token_s *tok)
       }
 
       if (str[*begin] == '.'
-	  && (!(*begin > 0 && (str[*begin - 1] == ' ' || is_delim(str[*begin - 1])))
+	  && (!(*begin > 0
+		&& (is_whitespace (str[*begin - 1])
+		    || is_delim (str[*begin - 1])))
 	    || last_imm_p))
 	modifier_p = 1;
 
@@ -633,7 +635,8 @@  read_token (struct token_s *tok)
 	*end += 1;
 
       /* Stop when reaching the start of the new token. */
-      while (!(!str[*end] || is_delim (str[*end]) || str[*end] == ' ' || (modifier_p && str[*end] == '.')))
+      while (!(!str[*end] || is_delim (str[*end]) || is_whitespace (str[*end])
+	     || (modifier_p && str[*end] == '.')))
 	*end += 1;
 
     }
--- a/gas/config/tc-kvx.c
+++ b/gas/config/tc-kvx.c
@@ -1279,7 +1279,7 @@  md_assemble (char *line)
   if (get_byte_counter (now_seg) & 3)
     as_fatal ("code segment not word aligned in md_assemble");
 
-  while (line_cursor && line_cursor[0] && (line_cursor[0] == ' '))
+  while (is_whitespace (line_cursor[0]))
     line_cursor++;
 
   /* ;; was converted to "be" by line hook          */
@@ -2125,7 +2125,7 @@  kvx_md_start_line_hook (void)
 {
   char *t;
 
-  for (t = input_line_pointer; t && t[0] == ' '; t++);
+  for (t = input_line_pointer; is_whitespace (t[0]); t++);
 
   /* Detect illegal syntax patterns:
    * - two bundle ends on the same line: ;; ;;
@@ -2144,9 +2144,9 @@  kvx_md_start_line_hook (void)
       while (tmp_t && tmp_t[0])
 	{
 	  while (tmp_t && tmp_t[0] &&
-		 ((tmp_t[0] == ' ') || (tmp_t[0] == '\n')))
+		 (is_whitespace (tmp_t[0]) || is_end_of_stmt (tmp_t[0])))
 	    {
-	      if (tmp_t[0] == '\n')
+	      if (is_end_of_stmt (tmp_t[0]))
 		newline_seen = true;
 	      tmp_t++;
 	    }