1 /* The IGEN simulator generator for GDB, the GNU Debugger.
3 Copyright 2002-2021 Free Software Foundation, Inc.
5 Contributed by Andrew Cagney.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
31 #include "ld-decode.h"
35 #include "gen-itable.h"
38 typedef struct _itable_info
48 itable_h_insn (lf
*file
,
49 insn_table
*entry
, insn_entry
* instruction
, void *data
)
52 itable_info
*info
= data
;
53 lf_print__line_ref (file
, instruction
->line
);
54 lf_printf (file
, " ");
55 print_function_name (file
,
57 instruction
->format_name
,
58 NULL
, NULL
, function_name_prefix_itable
);
59 lf_printf (file
, ",\n");
60 /* update summary info */
61 len
= strlen (instruction
->format_name
);
62 if (info
->sizeof_form
<= len
)
63 info
->sizeof_form
= len
+ 1;
64 len
= strlen (instruction
->name
);
65 if (info
->sizeof_name
<= len
)
66 info
->sizeof_name
= len
+ 1;
67 len
= strlen (filter_filename (instruction
->line
->file_name
));
68 if (info
->sizeof_file
<= len
)
69 info
->sizeof_file
= len
+ 1;
73 /* print the list of all the different options */
76 itable_print_enum (lf
*file
, filter
*set
, char *name
)
79 lf_printf (file
, "typedef enum {\n");
81 for (elem
= filter_next (set
, "");
82 elem
!= NULL
; elem
= filter_next (set
, elem
))
84 lf_printf (file
, "%sitable_%s_%s,\n",
85 options
.module
.itable
.prefix
.l
, name
, elem
);
86 if (strlen (options
.module
.itable
.prefix
.l
) > 0)
88 lf_indent_suppress (file
);
89 lf_printf (file
, "#define itable_%s_%s %sitable_%s_%s\n",
90 name
, elem
, options
.module
.itable
.prefix
.l
, name
, elem
);
93 lf_printf (file
, "nr_%sitable_%ss,\n", options
.module
.itable
.prefix
.l
,
97 lf_printf (file
, "} %sitable_%ss;\n", options
.module
.itable
.prefix
.l
, name
);
98 if (strlen (options
.module
.itable
.prefix
.l
) > 0)
100 lf_indent_suppress (file
);
101 lf_printf (file
, "#define itable_%ss %sitable_%ss\n",
102 name
, options
.module
.itable
.prefix
.l
, name
);
103 lf_indent_suppress (file
);
104 lf_printf (file
, "#define nr_itable_%ss nr_%sitable_%ss\n",
105 name
, options
.module
.itable
.prefix
.l
, name
);
109 /* print an array of the option names as strings */
112 itable_print_names (lf
*file
, filter
*set
, char *name
)
115 lf_printf (file
, "const char *%sitable_%s_names[nr_%sitable_%ss + 1] = {\n",
116 options
.module
.itable
.prefix
.l
, name
,
117 options
.module
.itable
.prefix
.l
, name
);
118 lf_indent (file
, +2);
119 for (elem
= filter_next (set
, "");
120 elem
!= NULL
; elem
= filter_next (set
, elem
))
122 lf_printf (file
, "\"%s\",\n", elem
);
124 lf_printf (file
, "0,\n");
125 lf_indent (file
, -2);
126 lf_printf (file
, "};\n");
130 gen_itable_h (lf
*file
, insn_table
*isa
)
132 itable_info
*info
= ZALLOC (itable_info
);
134 /* output an enumerated type for each instruction */
135 lf_printf (file
, "typedef enum {\n");
136 insn_table_traverse_insn (file
, isa
, itable_h_insn
, info
);
137 lf_printf (file
, " nr_%sitable_entries,\n",
138 options
.module
.itable
.prefix
.l
);
139 lf_printf (file
, "} %sitable_index;\n", options
.module
.itable
.prefix
.l
);
140 lf_printf (file
, "\n");
142 /* output an enumeration type for each flag */
143 itable_print_enum (file
, isa
->flags
, "flag");
144 lf_printf (file
, "extern const char *%sitable_flag_names[];\n",
145 options
.module
.itable
.prefix
.l
);
146 lf_printf (file
, "\n");
148 /* output an enumeration of all the possible options */
149 itable_print_enum (file
, isa
->options
, "option");
150 lf_printf (file
, "extern const char *%sitable_option_names[];\n",
151 options
.module
.itable
.prefix
.l
);
152 lf_printf (file
, "\n");
154 /* output an enumeration of all the processor models */
155 itable_print_enum (file
, isa
->model
->processors
, "processor");
156 lf_printf (file
, "extern const char *%sitable_processor_names[];\n",
157 options
.module
.itable
.prefix
.l
);
158 lf_printf (file
, "\n");
160 /* output the table that contains the actual instruction info */
161 lf_printf (file
, "typedef struct _%sitable_instruction_info {\n",
162 options
.module
.itable
.prefix
.l
);
163 lf_printf (file
, " %sitable_index nr;\n", options
.module
.itable
.prefix
.l
);
164 lf_printf (file
, " char *format;\n");
165 lf_printf (file
, " char *form;\n");
166 lf_printf (file
, " char *flags;\n");
168 /* nr_itable_* may be zero, so we add 1 to avoid an
169 illegal zero-sized array. */
170 lf_printf (file
, " char flag[nr_%sitable_flags + 1];\n",
171 options
.module
.itable
.prefix
.l
);
172 lf_printf (file
, " char *options;\n");
173 lf_printf (file
, " char option[nr_%sitable_options + 1];\n",
174 options
.module
.itable
.prefix
.l
);
175 lf_printf (file
, " char *processors;\n");
176 lf_printf (file
, " char processor[nr_%sitable_processors + 1];\n",
177 options
.module
.itable
.prefix
.l
);
178 lf_printf (file
, " char *name;\n");
179 lf_printf (file
, " char *file;\n");
180 lf_printf (file
, " int line_nr;\n");
181 lf_printf (file
, "} %sitable_info;\n", options
.module
.itable
.prefix
.l
);
182 lf_printf (file
, "\n");
183 lf_printf (file
, "extern %sitable_info %sitable[nr_%sitable_entries];\n",
184 options
.module
.itable
.prefix
.l
, options
.module
.itable
.prefix
.l
,
185 options
.module
.itable
.prefix
.l
);
186 if (strlen (options
.module
.itable
.prefix
.l
) > 0)
188 lf_indent_suppress (file
);
189 lf_printf (file
, "#define itable %sitable\n",
190 options
.module
.itable
.prefix
.l
);
192 lf_printf (file
, "\n");
194 /* output an enum defining the max size of various itable members */
195 lf_printf (file
, "enum {\n");
196 lf_printf (file
, " sizeof_%sitable_form = %d,\n",
197 options
.module
.itable
.prefix
.l
, info
->sizeof_form
);
198 lf_printf (file
, " sizeof_%sitable_name = %d,\n",
199 options
.module
.itable
.prefix
.l
, info
->sizeof_name
);
200 lf_printf (file
, " sizeof_%sitable_file = %d,\n",
201 options
.module
.itable
.prefix
.l
, info
->sizeof_file
);
202 lf_printf (file
, "};\n");
206 /****************************************************************/
209 itable_print_set (lf
*file
, filter
*set
, filter
*members
)
212 lf_printf (file
, "\"");
213 elem
= filter_next (members
, "");
218 lf_printf (file
, "%s", elem
);
219 elem
= filter_next (members
, elem
);
222 lf_printf (file
, ",");
225 lf_printf (file
, "\",\n");
227 lf_printf (file
, "{");
228 for (elem
= filter_next (set
, "");
229 elem
!= NULL
; elem
= filter_next (set
, elem
))
231 if (filter_is_member (members
, elem
))
233 lf_printf (file
, " 1,");
237 lf_printf (file
, " 0,");
241 /* always print a dummy element, to avoid empty initializers. */
242 lf_printf (file
, " 99 },\n");
247 itable_c_insn (lf
*file
,
248 insn_table
*isa
, insn_entry
* instruction
, void *data
)
250 lf_printf (file
, "{ ");
251 lf_indent (file
, +2);
252 print_function_name (file
,
254 instruction
->format_name
,
255 NULL
, NULL
, function_name_prefix_itable
);
256 lf_printf (file
, ",\n");
257 lf_printf (file
, "\"");
258 print_insn_words (file
, instruction
);
259 lf_printf (file
, "\",\n");
260 lf_printf (file
, "\"%s\",\n", instruction
->format_name
);
262 itable_print_set (file
, isa
->flags
, instruction
->flags
);
263 itable_print_set (file
, isa
->options
, instruction
->options
);
264 itable_print_set (file
, isa
->model
->processors
, instruction
->processors
);
266 lf_printf (file
, "\"%s\",\n", instruction
->name
);
267 lf_printf (file
, "\"%s\",\n",
268 filter_filename (instruction
->line
->file_name
));
269 lf_printf (file
, "%d,\n", instruction
->line
->line_nr
);
270 lf_printf (file
, "},\n");
271 lf_indent (file
, -2);
276 gen_itable_c (lf
*file
, insn_table
*isa
)
279 lf_printf (file
, "#include \"%sitable.h\"\n",
280 options
.module
.itable
.prefix
.l
);
281 lf_printf (file
, "\n");
283 /* FIXME - output model data??? */
284 /* FIXME - output assembler data??? */
286 /* output the flag, option and processor name tables */
287 itable_print_names (file
, isa
->flags
, "flag");
288 itable_print_names (file
, isa
->options
, "option");
289 itable_print_names (file
, isa
->model
->processors
, "processor");
291 /* output the table that contains the actual instruction info */
292 lf_printf (file
, "%sitable_info %sitable[nr_%sitable_entries] = {\n",
293 options
.module
.itable
.prefix
.l
,
294 options
.module
.itable
.prefix
.l
, options
.module
.itable
.prefix
.l
);
295 insn_table_traverse_insn (file
, isa
, itable_c_insn
, NULL
);
297 lf_printf (file
, "};\n");