From: Mike Frysinger <vapier@gentoo.org>
To: gdb-patches@sourceware.org
Subject: [PATCH] sim: igen: constify itable data structures
Date: Sat, 24 Dec 2022 21:30:39 -0500 [thread overview]
Message-ID: <20221225023039.1477-1-vapier@gentoo.org> (raw)
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
reply other threads:[~2022-12-25 2:33 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20221225023039.1477-1-vapier@gentoo.org \
--to=vapier@gentoo.org \
--cc=gdb-patches@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).