sim: igen: constify itable data structures

These are const data arrays of strings and numbers.  We don't want
or need them to be writable, so mark them all const.
This commit is contained in:
Mike Frysinger 2022-12-24 01:20:14 -05:00
parent bba234157f
commit 5d3539bd6b

View File

@ -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);