[PATCH v3 1/2] aarch64 gas: Refactor aarch64_option_table
Alice Carlotti
alice.carlotti@arm.com
Thu Jul 10 00:14:37 GMT 2025
Specify a function to call for each option, instead of always updating
an integer variable. This allows options to be recorded as a different
type or as non-global variables in other translation units.
diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index 3dfb0774cddbc5e37bcc1b94c4963386d70e7e68..2365530379a9c24b04edc350b352144173e34a7e 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -10533,27 +10533,66 @@ const struct option md_longopts[] = {
const size_t md_longopts_size = sizeof (md_longopts);
+
+static int
+aarch64_record_big_endian (void)
+{
+ target_big_endian = 1;
+ return 1;
+}
+
+static int
+aarch64_record_little_endian (void)
+{
+ target_big_endian = 0;
+ return 1;
+}
+
+#ifdef DEBUG_AARCH64
+static int
+aarch64_record_debug_dump (void)
+{
+ debug_dump = 1;
+ return 1;
+}
+#endif /* DEBUG_AARCH64 */
+
+static int
+aarch64_record_verbose_error (void)
+{
+ verbose_error_p = 1;
+ return 1;
+}
+
+static int
+aarch64_record_no_verbose_error (void)
+{
+ verbose_error_p = 0;
+ return 1;
+}
+
struct aarch64_option_table
{
const char *option; /* Option name to match. */
const char *help; /* Help information. */
- int *var; /* Variable to change. */
- int value; /* What to change it to. */
+ int (*func) (void); /* Function to record option. */
char *deprecated; /* If non-null, print this message. */
};
static struct aarch64_option_table aarch64_opts[] = {
- {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
- {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
- NULL},
+ {"mbig-endian", N_("assemble for big-endian"), &aarch64_record_big_endian,
+ NULL},
+ {"mlittle-endian", N_("assemble for little-endian"),
+ &aarch64_record_little_endian, NULL},
#ifdef DEBUG_AARCH64
- {"mdebug-dump", N_("temporary switch for dumping"), &debug_dump, 1, NULL},
+ {"mdebug-dump", N_("temporary switch for dumping"),
+ &aarch64_record_debug_dump, NULL},
#endif /* DEBUG_AARCH64 */
- {"mverbose-error", N_("output verbose error messages"), &verbose_error_p, 1,
- NULL},
+ {"mverbose-error", N_("output verbose error messages"),
+ &aarch64_record_verbose_error, NULL},
{"mno-verbose-error", N_("do not output verbose error messages"),
- &verbose_error_p, 0, NULL},
- {NULL, NULL, NULL, 0, NULL}
+ &aarch64_record_no_verbose_error, NULL},
+ {NULL, NULL, NULL, NULL}
};
struct aarch64_cpu_option_table
@@ -11154,10 +11193,8 @@ md_parse_option (int c, const char *arg)
as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
arg ? arg : "", _(opt->deprecated));
- if (opt->var != NULL)
- *opt->var = opt->value;
-
- return 1;
+ /* Call the option recorder. */
+ return opt->func ();
}
}
@@ -11173,7 +11210,7 @@ md_parse_option (int c, const char *arg)
as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
_(lopt->deprecated));
- /* Call the sup-option parser. */
+ /* Call the sub-option parser. */
return lopt->func (arg + strlen (lopt->option) - 1);
}
}
More information about the Binutils
mailing list