public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Subject: [PATCH 4/4] gas: expose flag_macro_alternate globally
Date: Wed, 8 Mar 2023 17:09:22 +0100	[thread overview]
Message-ID: <06908d40-8d11-9540-6932-efb4f54dba0f@suse.com> (raw)
In-Reply-To: <bdf364c0-c333-095b-47e0-24948906071e@suse.com>

Yet again with the removal of gasp about 20 years ago this extra level
of indirection isn't necessary anymore either. Drop macro.c's local
variable and make as.c's global.

While doing the conversion, switch the variable to "bool".

--- a/gas/as.c
+++ b/gas/as.c
@@ -125,8 +125,6 @@ static struct defsym_list *defsyms;
 
 static long start_time;
 
-static int flag_macro_alternate;
-
 \f
 #ifdef USE_EMULATIONS
 #define EMULATION_ENVIRON "AS_EMULATION"
@@ -1307,7 +1305,7 @@ gas_init (void)
   input_scrub_begin ();
   expr_begin ();
 
-  macro_init (flag_macro_alternate);
+  macro_init ();
 
   dwarf2_init ();
 
--- a/gas/as.h
+++ b/gas/as.h
@@ -305,6 +305,9 @@ COMMON int flag_keep_locals; /* -L */
 /* True if we are assembling in MRI mode.  */
 COMMON int flag_mri;
 
+/* True if alternate macro mode is in effect.  */
+COMMON bool flag_macro_alternate;
+
 /* Should the data section be made read-only and appended to the text
    section?  */
 COMMON unsigned char flag_readonly_data_in_text; /* -R */
--- a/gas/macro.c
+++ b/gas/macro.c
@@ -34,7 +34,7 @@
 #define ISSEP(x) \
  ((x) == ' ' || (x) == '\t' || (x) == ',' || (x) == '"' || (x) == ';' \
   || (x) == ')' || (x) == '(' \
-  || ((macro_alternate || flag_mri) && ((x) == '<' || (x) == '>')))
+  || ((flag_macro_alternate || flag_mri) && ((x) == '<' || (x) == '>')))
 
 #define ISBASE(x) \
   ((x) == 'b' || (x) == 'B' \
@@ -50,10 +50,6 @@ htab_t macro_hash;
 
 int macro_defined;
 
-/* Whether we are in alternate syntax mode.  */
-
-static int macro_alternate;
-
 /* Whether we should strip '@' characters.  */
 
 #define macro_strip_at false
@@ -74,12 +70,11 @@ macro_del_f (void *ent)
 /* Initialize macro processing.  */
 
 void
-macro_init (int alternate)
+macro_init (void)
 {
   macro_hash = htab_create_alloc (16, hash_string_tuple, eq_string_tuple,
 				  macro_del_f, notes_calloc, NULL);
   macro_defined = 0;
-  macro_alternate = alternate;
 }
 
 void
@@ -88,14 +83,6 @@ macro_end (void)
   htab_delete (macro_hash);
 }
 
-/* Switch in and out of alternate mode on the fly.  */
-
-void
-macro_set_alternate (int alternate)
-{
-  macro_alternate = alternate;
-}
-
 /* Read input lines till we get to a TO string.
    Increase nesting depth if we get a FROM string.
    Put the results into sb at PTR.
@@ -284,7 +271,7 @@ get_token (size_t idx, sb *in, sb *name)
 	}
     }
   /* Ignore trailing &.  */
-  if (macro_alternate && idx < in->len && in->ptr[idx] == '&')
+  if (flag_macro_alternate && idx < in->len && in->ptr[idx] == '&')
     idx++;
   return idx;
 }
@@ -296,8 +283,8 @@ getstring (size_t idx, sb *in, sb *acc)
 {
   while (idx < in->len
 	 && (in->ptr[idx] == '"'
-	     || (in->ptr[idx] == '<' && (macro_alternate || flag_mri))
-	     || (in->ptr[idx] == '\'' && macro_alternate)))
+	     || (in->ptr[idx] == '<' && (flag_macro_alternate || flag_mri))
+	     || (in->ptr[idx] == '\'' && flag_macro_alternate)))
     {
       if (in->ptr[idx] == '<')
 	{
@@ -336,7 +323,7 @@ getstring (size_t idx, sb *in, sb *acc)
 	      else
 		escaped = 0;
 
-	      if (macro_alternate && in->ptr[idx] == '!')
+	      if (flag_macro_alternate && in->ptr[idx] == '!')
 		{
 		  idx ++;
 
@@ -390,7 +377,7 @@ get_any_string (size_t idx, sb *in, sb *
 	  while (idx < in->len && !ISSEP (in->ptr[idx]))
 	    sb_add_char (out, in->ptr[idx++]);
 	}
-      else if (in->ptr[idx] == '%' && macro_alternate)
+      else if (in->ptr[idx] == '%' && flag_macro_alternate)
 	{
 	  /* Turn the following expression into a string.  */
 	  expressionS ex;
@@ -410,10 +397,10 @@ get_any_string (size_t idx, sb *in, sb *
 	  sb_add_string (out, buf);
 	}
       else if (in->ptr[idx] == '"'
-	       || (in->ptr[idx] == '<' && (macro_alternate || flag_mri))
-	       || (macro_alternate && in->ptr[idx] == '\''))
+	       || (in->ptr[idx] == '<' && (flag_macro_alternate || flag_mri))
+	       || (flag_macro_alternate && in->ptr[idx] == '\''))
 	{
-	  if (macro_alternate && ! macro_strip_at && in->ptr[idx] != '<')
+	  if (flag_macro_alternate && ! macro_strip_at && in->ptr[idx] != '<')
 	    {
 	      /* Keep the quotes.  */
 	      sb_add_char (out, '"');
@@ -437,7 +424,7 @@ get_any_string (size_t idx, sb *in, sb *
 			 && in->ptr[idx] != '\t'))
 		 && in->ptr[idx] != ','
 		 && (in->ptr[idx] != '<'
-		     || (! macro_alternate && ! flag_mri)))
+		     || (! flag_macro_alternate && ! flag_mri)))
 	    {
 	      char tchar = in->ptr[idx];
 
@@ -904,7 +891,7 @@ macro_expand_body (sb *in, sb *out, form
 	      src = sub_actual (src, in, &t, formal_hash, '\'', out, 0);
 	    }
 	}
-      else if ((macro_alternate || flag_mri)
+      else if ((flag_macro_alternate || flag_mri)
 	       && is_name_beginner (in->ptr[src])
 	       && (! inquote
 		   || ! macro_strip_at
@@ -1093,9 +1080,9 @@ macro_expand (size_t idx, sb *in, macro_
       while (scan < in->len
 	     && !ISSEP (in->ptr[scan])
 	     && !(flag_mri && in->ptr[scan] == '\'')
-	     && (!macro_alternate && in->ptr[scan] != '='))
+	     && (!flag_macro_alternate && in->ptr[scan] != '='))
 	scan++;
-      if (scan < in->len && !macro_alternate && in->ptr[scan] == '=')
+      if (scan < in->len && !flag_macro_alternate && in->ptr[scan] == '=')
 	{
 	  is_keyword = 1;
 
--- a/gas/macro.h
+++ b/gas/macro.h
@@ -83,9 +83,8 @@ extern htab_t macro_hash;
 
 extern int buffer_and_nest (const char *, const char *, sb *,
 			    size_t (*) (sb *));
-extern void macro_init (int);
+extern void macro_init (void);
 extern void macro_end (void);
-extern void macro_set_alternate (int);
 extern macro_entry *define_macro (sb *, sb *, size_t (*) (sb *));
 extern int check_macro (const char *, sb *, const char **, macro_entry **);
 extern void delete_macro (const char *);
--- a/gas/read.c
+++ b/gas/read.c
@@ -1578,7 +1578,7 @@ static void
 s_altmacro (int on)
 {
   demand_empty_rest_of_line ();
-  macro_set_alternate (on);
+  flag_macro_alternate = on;
 }
 
 /* Read a symbol name from input_line_pointer.


      parent reply	other threads:[~2023-03-08 16:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08 16:05 [PATCH 0/4] gas: tidy macro interfacing after removal of gasp Jan Beulich
2023-03-08 16:07 ` [PATCH 1/4] gas: drop function pointer parameter from macro_init() Jan Beulich
2023-03-08 16:08 ` [PATCH 2/4] gas: isolate macro_strip_at to macro.c Jan Beulich
2023-03-08 16:08 ` [PATCH 3/4] gas: use flag_mri directly in macro processing Jan Beulich
2023-03-08 16:09 ` Jan Beulich [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=06908d40-8d11-9540-6932-efb4f54dba0f@suse.com \
    --to=jbeulich@suse.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).