public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] sim: igen: constify itable data structures
@ 2022-12-25  2:30 Mike Frysinger
  0 siblings, 0 replies; only message in thread
From: Mike Frysinger @ 2022-12-25  2:30 UTC (permalink / raw)
  To: gdb-patches

These are const data arrays of strings and numbers.  We don't want
or need them to be writable, so mark them all const.
---
 sim/igen/gen-itable.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/sim/igen/gen-itable.c b/sim/igen/gen-itable.c
index 21c13c9547e8..05bcf468bc91 100644
--- a/sim/igen/gen-itable.c
+++ b/sim/igen/gen-itable.c
@@ -114,7 +114,8 @@ static void
 itable_print_names (lf *file, const filter *set, const char *name)
 {
   const char *elem;
-  lf_printf (file, "const char *%sitable_%s_names[nr_%sitable_%ss + 1] = {\n",
+  lf_printf (file,
+	     "const char * const %sitable_%s_names[nr_%sitable_%ss + 1] = {\n",
 	     options.module.itable.prefix.l, name,
 	     options.module.itable.prefix.l, name);
   lf_indent (file, +2);
@@ -143,19 +144,19 @@ gen_itable_h (lf *file, const insn_table *isa)
 
   /* output an enumeration type for each flag */
   itable_print_enum (file, isa->flags, "flag");
-  lf_printf (file, "extern const char *%sitable_flag_names[];\n",
+  lf_printf (file, "extern const char * const %sitable_flag_names[];\n",
 	     options.module.itable.prefix.l);
   lf_printf (file, "\n");
 
   /* output an enumeration of all the possible options */
   itable_print_enum (file, isa->options, "option");
-  lf_printf (file, "extern const char *%sitable_option_names[];\n",
+  lf_printf (file, "extern const char * const %sitable_option_names[];\n",
 	     options.module.itable.prefix.l);
   lf_printf (file, "\n");
 
   /* output an enumeration of all the processor models */
   itable_print_enum (file, isa->model->processors, "processor");
-  lf_printf (file, "extern const char *%sitable_processor_names[];\n",
+  lf_printf (file, "extern const char * const %sitable_processor_names[];\n",
 	     options.module.itable.prefix.l);
   lf_printf (file, "\n");
 
@@ -163,26 +164,27 @@ gen_itable_h (lf *file, const insn_table *isa)
   lf_printf (file, "typedef struct _%sitable_instruction_info {\n",
 	     options.module.itable.prefix.l);
   lf_printf (file, "  %sitable_index nr;\n", options.module.itable.prefix.l);
-  lf_printf (file, "  char *format;\n");
-  lf_printf (file, "  char *form;\n");
-  lf_printf (file, "  char *flags;\n");
+  lf_printf (file, "  const char *format;\n");
+  lf_printf (file, "  const char *form;\n");
+  lf_printf (file, "  const char *flags;\n");
 
   /* nr_itable_* may be zero, so we add 1 to avoid an
      illegal zero-sized array. */
-  lf_printf (file, "  char flag[nr_%sitable_flags + 1];\n",
+  lf_printf (file, "  const char flag[nr_%sitable_flags + 1];\n",
 	     options.module.itable.prefix.l);
-  lf_printf (file, "  char *options;\n");
-  lf_printf (file, "  char option[nr_%sitable_options + 1];\n",
+  lf_printf (file, "  const char *options;\n");
+  lf_printf (file, "  const char option[nr_%sitable_options + 1];\n",
 	     options.module.itable.prefix.l);
-  lf_printf (file, "  char *processors;\n");
-  lf_printf (file, "  char processor[nr_%sitable_processors + 1];\n",
+  lf_printf (file, "  const char *processors;\n");
+  lf_printf (file, "  const char processor[nr_%sitable_processors + 1];\n",
 	     options.module.itable.prefix.l);
-  lf_printf (file, "  char *name;\n");
-  lf_printf (file, "  char *file;\n");
+  lf_printf (file, "  const char *name;\n");
+  lf_printf (file, "  const char *file;\n");
   lf_printf (file, "  int line_nr;\n");
   lf_printf (file, "} %sitable_info;\n", options.module.itable.prefix.l);
   lf_printf (file, "\n");
-  lf_printf (file, "extern %sitable_info %sitable[nr_%sitable_entries];\n",
+  lf_printf (file,
+	     "extern const %sitable_info %sitable[nr_%sitable_entries];\n",
 	     options.module.itable.prefix.l, options.module.itable.prefix.l,
 	     options.module.itable.prefix.l);
   if (strlen (options.module.itable.prefix.l) > 0)
@@ -293,7 +295,7 @@ gen_itable_c (lf *file, const insn_table *isa)
   itable_print_names (file, isa->model->processors, "processor");
 
   /* output the table that contains the actual instruction info */
-  lf_printf (file, "%sitable_info %sitable[nr_%sitable_entries] = {\n",
+  lf_printf (file, "const %sitable_info %sitable[nr_%sitable_entries] = {\n",
 	     options.module.itable.prefix.l,
 	     options.module.itable.prefix.l, options.module.itable.prefix.l);
   insn_table_traverse_insn (file, isa, itable_c_insn, NULL);
-- 
2.39.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-25  2:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-25  2:30 [PATCH] sim: igen: constify itable data structures Mike Frysinger

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).