1 /* The IGEN simulator generator for GDB, the GNU Debugger.
3 Copyright 2002-2018 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"
43 typedef struct _itable_info
53 itable_h_insn (lf
*file
,
54 insn_table
*entry
, insn_entry
* instruction
, void *data
)
57 itable_info
*info
= data
;
58 lf_print__line_ref (file
, instruction
->line
);
59 lf_printf (file
, " ");
60 print_function_name (file
,
62 instruction
->format_name
,
63 NULL
, NULL
, function_name_prefix_itable
);
64 lf_printf (file
, ",\n");
65 /* update summary info */
66 len
= strlen (instruction
->format_name
);
67 if (info
->sizeof_form
<= len
)
68 info
->sizeof_form
= len
+ 1;
69 len
= strlen (instruction
->name
);
70 if (info
->sizeof_name
<= len
)
71 info
->sizeof_name
= len
+ 1;
72 len
= strlen (filter_filename (instruction
->line
->file_name
));
73 if (info
->sizeof_file
<= len
)
74 info
->sizeof_file
= len
+ 1;
78 /* print the list of all the different options */
81 itable_print_enum (lf
*file
, filter
*set
, char *name
)
84 lf_printf (file
, "typedef enum {\n");
86 for (elem
= filter_next (set
, "");
87 elem
!= NULL
; elem
= filter_next (set
, elem
))
89 lf_printf (file
, "%sitable_%s_%s,\n",
90 options
.module
.itable
.prefix
.l
, name
, elem
);
91 if (strlen (options
.module
.itable
.prefix
.l
) > 0)
93 lf_indent_suppress (file
);
94 lf_printf (file
, "#define itable_%s_%s %sitable_%s_%s\n",
95 name
, elem
, options
.module
.itable
.prefix
.l
, name
, elem
);
98 lf_printf (file
, "nr_%sitable_%ss,\n", options
.module
.itable
.prefix
.l
,
101 lf_indent (file
, -2);
102 lf_printf (file
, "} %sitable_%ss;\n", options
.module
.itable
.prefix
.l
, name
);
103 if (strlen (options
.module
.itable
.prefix
.l
) > 0)
105 lf_indent_suppress (file
);
106 lf_printf (file
, "#define itable_%ss %sitable_%ss\n",
107 name
, options
.module
.itable
.prefix
.l
, name
);
108 lf_indent_suppress (file
);
109 lf_printf (file
, "#define nr_itable_%ss nr_%sitable_%ss\n",
110 name
, options
.module
.itable
.prefix
.l
, name
);
114 /* print an array of the option names as strings */
117 itable_print_names (lf
*file
, filter
*set
, char *name
)
120 lf_printf (file
, "const char *%sitable_%s_names[nr_%sitable_%ss + 1] = {\n",
121 options
.module
.itable
.prefix
.l
, name
,
122 options
.module
.itable
.prefix
.l
, name
);
123 lf_indent (file
, +2);
124 for (elem
= filter_next (set
, "");
125 elem
!= NULL
; elem
= filter_next (set
, elem
))
127 lf_printf (file
, "\"%s\",\n", elem
);
129 lf_printf (file
, "0,\n");
130 lf_indent (file
, -2);
131 lf_printf (file
, "};\n");
135 gen_itable_h (lf
*file
, insn_table
*isa
)
137 itable_info
*info
= ZALLOC (itable_info
);
139 /* output an enumerated type for each instruction */
140 lf_printf (file
, "typedef enum {\n");
141 insn_table_traverse_insn (file
, isa
, itable_h_insn
, info
);
142 lf_printf (file
, " nr_%sitable_entries,\n",
143 options
.module
.itable
.prefix
.l
);
144 lf_printf (file
, "} %sitable_index;\n", options
.module
.itable
.prefix
.l
);
145 lf_printf (file
, "\n");
147 /* output an enumeration type for each flag */
148 itable_print_enum (file
, isa
->flags
, "flag");
149 lf_printf (file
, "extern const char *%sitable_flag_names[];\n",
150 options
.module
.itable
.prefix
.l
);
151 lf_printf (file
, "\n");
153 /* output an enumeration of all the possible options */
154 itable_print_enum (file
, isa
->options
, "option");
155 lf_printf (file
, "extern const char *%sitable_option_names[];\n",
156 options
.module
.itable
.prefix
.l
);
157 lf_printf (file
, "\n");
159 /* output an enumeration of all the processor models */
160 itable_print_enum (file
, isa
->model
->processors
, "processor");
161 lf_printf (file
, "extern const char *%sitable_processor_names[];\n",
162 options
.module
.itable
.prefix
.l
);
163 lf_printf (file
, "\n");
165 /* output the table that contains the actual instruction info */
166 lf_printf (file
, "typedef struct _%sitable_instruction_info {\n",
167 options
.module
.itable
.prefix
.l
);
168 lf_printf (file
, " %sitable_index nr;\n", options
.module
.itable
.prefix
.l
);
169 lf_printf (file
, " char *format;\n");
170 lf_printf (file
, " char *form;\n");
171 lf_printf (file
, " char *flags;\n");
173 /* nr_itable_* may be zero, so we add 1 to avoid an
174 illegal zero-sized array. */
175 lf_printf (file
, " char flag[nr_%sitable_flags + 1];\n",
176 options
.module
.itable
.prefix
.l
);
177 lf_printf (file
, " char *options;\n");
178 lf_printf (file
, " char option[nr_%sitable_options + 1];\n",
179 options
.module
.itable
.prefix
.l
);
180 lf_printf (file
, " char *processors;\n");
181 lf_printf (file
, " char processor[nr_%sitable_processors + 1];\n",
182 options
.module
.itable
.prefix
.l
);
183 lf_printf (file
, " char *name;\n");
184 lf_printf (file
, " char *file;\n");
185 lf_printf (file
, " int line_nr;\n");
186 lf_printf (file
, "} %sitable_info;\n", options
.module
.itable
.prefix
.l
);
187 lf_printf (file
, "\n");
188 lf_printf (file
, "extern %sitable_info %sitable[nr_%sitable_entries];\n",
189 options
.module
.itable
.prefix
.l
, options
.module
.itable
.prefix
.l
,
190 options
.module
.itable
.prefix
.l
);
191 if (strlen (options
.module
.itable
.prefix
.l
) > 0)
193 lf_indent_suppress (file
);
194 lf_printf (file
, "#define itable %sitable\n",
195 options
.module
.itable
.prefix
.l
);
197 lf_printf (file
, "\n");
199 /* output an enum defining the max size of various itable members */
200 lf_printf (file
, "enum {\n");
201 lf_printf (file
, " sizeof_%sitable_form = %d,\n",
202 options
.module
.itable
.prefix
.l
, info
->sizeof_form
);
203 lf_printf (file
, " sizeof_%sitable_name = %d,\n",
204 options
.module
.itable
.prefix
.l
, info
->sizeof_name
);
205 lf_printf (file
, " sizeof_%sitable_file = %d,\n",
206 options
.module
.itable
.prefix
.l
, info
->sizeof_file
);
207 lf_printf (file
, "};\n");
211 /****************************************************************/
214 itable_print_set (lf
*file
, filter
*set
, filter
*members
)
217 lf_printf (file
, "\"");
218 elem
= filter_next (members
, "");
223 lf_printf (file
, "%s", elem
);
224 elem
= filter_next (members
, elem
);
227 lf_printf (file
, ",");
230 lf_printf (file
, "\",\n");
232 lf_printf (file
, "{");
233 for (elem
= filter_next (set
, "");
234 elem
!= NULL
; elem
= filter_next (set
, elem
))
236 if (filter_is_member (members
, elem
))
238 lf_printf (file
, " 1,");
242 lf_printf (file
, " 0,");
246 /* always print a dummy element, to avoid empty initializers. */
247 lf_printf (file
, " 99 },\n");
252 itable_c_insn (lf
*file
,
253 insn_table
*isa
, insn_entry
* instruction
, void *data
)
255 lf_printf (file
, "{ ");
256 lf_indent (file
, +2);
257 print_function_name (file
,
259 instruction
->format_name
,
260 NULL
, NULL
, function_name_prefix_itable
);
261 lf_printf (file
, ",\n");
262 lf_printf (file
, "\"");
263 print_insn_words (file
, instruction
);
264 lf_printf (file
, "\",\n");
265 lf_printf (file
, "\"%s\",\n", instruction
->format_name
);
267 itable_print_set (file
, isa
->flags
, instruction
->flags
);
268 itable_print_set (file
, isa
->options
, instruction
->options
);
269 itable_print_set (file
, isa
->model
->processors
, instruction
->processors
);
271 lf_printf (file
, "\"%s\",\n", instruction
->name
);
272 lf_printf (file
, "\"%s\",\n",
273 filter_filename (instruction
->line
->file_name
));
274 lf_printf (file
, "%d,\n", instruction
->line
->line_nr
);
275 lf_printf (file
, "},\n");
276 lf_indent (file
, -2);
281 gen_itable_c (lf
*file
, insn_table
*isa
)
284 lf_printf (file
, "#include \"%sitable.h\"\n",
285 options
.module
.itable
.prefix
.l
);
286 lf_printf (file
, "\n");
288 /* FIXME - output model data??? */
289 /* FIXME - output assembler data??? */
291 /* output the flag, option and processor name tables */
292 itable_print_names (file
, isa
->flags
, "flag");
293 itable_print_names (file
, isa
->options
, "option");
294 itable_print_names (file
, isa
->model
->processors
, "processor");
296 /* output the table that contains the actual instruction info */
297 lf_printf (file
, "%sitable_info %sitable[nr_%sitable_entries] = {\n",
298 options
.module
.itable
.prefix
.l
,
299 options
.module
.itable
.prefix
.l
, options
.module
.itable
.prefix
.l
);
300 insn_table_traverse_insn (file
, isa
, itable_c_insn
, NULL
);
302 lf_printf (file
, "};\n");