1 /* The IGEN simulator generator for GDB, the GNU Debugger.
3 Copyright 2002 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 2 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, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
33 #include "ld-decode.h"
37 #include "gen-itable.h"
45 typedef struct _itable_info
{
53 itable_h_insn (lf
*file
,
55 insn_entry
*instruction
,
59 itable_info
*info
= data
;
60 lf_print__line_ref (file
, instruction
->line
);
61 lf_printf (file
, " ");
62 print_function_name (file
,
64 instruction
->format_name
,
67 function_name_prefix_itable
);
68 lf_printf (file
, ",\n");
69 /* update summary info */
70 len
= strlen (instruction
->format_name
);
71 if (info
->sizeof_form
<= len
)
72 info
->sizeof_form
= len
+ 1;
73 len
= strlen (instruction
->name
);
74 if (info
->sizeof_name
<= len
)
75 info
->sizeof_name
= len
+ 1;
76 len
= strlen (filter_filename (instruction
->line
->file_name
));
77 if (info
->sizeof_file
<= len
)
78 info
->sizeof_file
= len
+ 1;
82 /* print the list of all the different options */
85 itable_print_enum (lf
*file
,
90 lf_printf (file
, "typedef enum {\n");
92 for (elem
= filter_next (set
, "");
94 elem
= filter_next (set
, elem
))
96 lf_printf (file
, "%sitable_%s_%s,\n",
97 options
.module
.itable
.prefix
.l
, name
, elem
);
98 if (strlen (options
.module
.itable
.prefix
.l
) > 0)
100 lf_indent_suppress (file
);
101 lf_printf (file
, "#define itable_%s_%s %sitable_%s_%s\n",
102 name
, elem
, options
.module
.itable
.prefix
.l
, name
, elem
);
105 lf_printf (file
, "nr_%sitable_%ss,\n", options
.module
.itable
.prefix
.l
, name
);
107 lf_indent (file
, -2);
108 lf_printf (file
, "} %sitable_%ss;\n", options
.module
.itable
.prefix
.l
, name
);
109 if (strlen (options
.module
.itable
.prefix
.l
) > 0)
111 lf_indent_suppress (file
);
112 lf_printf (file
, "#define itable_%ss %sitable_%ss\n",
113 name
, options
.module
.itable
.prefix
.l
, name
);
114 lf_indent_suppress (file
);
115 lf_printf (file
, "#define nr_itable_%ss nr_%sitable_%ss\n",
116 name
, options
.module
.itable
.prefix
.l
, name
);
120 /* print an array of the option names as strings */
123 itable_print_names (lf
*file
,
128 lf_printf (file
, "const char *%sitable_%s_names[nr_%sitable_%ss + 1] = {\n",
129 options
.module
.itable
.prefix
.l
, name
,
130 options
.module
.itable
.prefix
.l
, name
);
131 lf_indent (file
, +2);
132 for (elem
= filter_next (set
, "");
134 elem
= filter_next (set
, elem
))
136 lf_printf (file
, "\"%s\",\n", elem
);
138 lf_printf (file
, "0,\n");
139 lf_indent (file
, -2);
140 lf_printf (file
, "};\n");
144 gen_itable_h (lf
*file
,
147 itable_info
*info
= ZALLOC (itable_info
);
149 /* output an enumerated type for each instruction */
150 lf_printf (file
, "typedef enum {\n");
151 insn_table_traverse_insn (file
, isa
, itable_h_insn
, info
);
152 lf_printf (file
, " nr_%sitable_entries,\n", options
.module
.itable
.prefix
.l
);
153 lf_printf (file
, "} %sitable_index;\n", options
.module
.itable
.prefix
.l
);
154 lf_printf (file
, "\n");
156 /* output an enumeration type for each flag */
157 itable_print_enum (file
, isa
->flags
, "flag");
158 lf_printf (file
, "extern const char *%sitable_flag_names[];\n",
159 options
.module
.itable
.prefix
.l
);
160 lf_printf (file
, "\n");
162 /* output an enumeration of all the possible options */
163 itable_print_enum (file
, isa
->options
, "option");
164 lf_printf (file
, "extern const char *%sitable_option_names[];\n",
165 options
.module
.itable
.prefix
.l
);
166 lf_printf (file
, "\n");
168 /* output an enumeration of all the processor models */
169 itable_print_enum (file
, isa
->model
->processors
, "processor");
170 lf_printf (file
, "extern const char *%sitable_processor_names[];\n",
171 options
.module
.itable
.prefix
.l
);
172 lf_printf (file
, "\n");
174 /* output the table that contains the actual instruction info */
175 lf_printf (file
, "typedef struct _%sitable_instruction_info {\n",
176 options
.module
.itable
.prefix
.l
);
177 lf_printf (file
, " %sitable_index nr;\n", options
.module
.itable
.prefix
.l
);
178 lf_printf (file
, " char *format;\n");
179 lf_printf (file
, " char *form;\n");
180 lf_printf (file
, " char *flags;\n");
182 /* nr_itable_* may be zero, so we add 1 to avoid an
183 illegal zero-sized array. */
184 lf_printf (file
, " char flag[nr_%sitable_flags + 1];\n",
185 options
.module
.itable
.prefix
.l
);
186 lf_printf (file
, " char *options;\n");
187 lf_printf (file
, " char option[nr_%sitable_options + 1];\n",
188 options
.module
.itable
.prefix
.l
);
189 lf_printf (file
, " char *processors;\n");
190 lf_printf (file
, " char processor[nr_%sitable_processors + 1];\n",
191 options
.module
.itable
.prefix
.l
);
192 lf_printf (file
, " char *name;\n");
193 lf_printf (file
, " char *file;\n");
194 lf_printf (file
, " int line_nr;\n");
195 lf_printf (file
, "} %sitable_info;\n", options
.module
.itable
.prefix
.l
);
196 lf_printf (file
, "\n");
197 lf_printf (file
, "extern %sitable_info %sitable[nr_%sitable_entries];\n",
198 options
.module
.itable
.prefix
.l
, options
.module
.itable
.prefix
.l
,
199 options
.module
.itable
.prefix
.l
);
200 if (strlen (options
.module
.itable
.prefix
.l
) > 0)
202 lf_indent_suppress (file
);
203 lf_printf (file
, "#define itable %sitable\n",
204 options
.module
.itable
.prefix
.l
);
206 lf_printf (file
, "\n");
208 /* output an enum defining the max size of various itable members */
209 lf_printf (file
, "enum {\n");
210 lf_printf (file
, " sizeof_%sitable_form = %d,\n",
211 options
.module
.itable
.prefix
.l
, info
->sizeof_form
);
212 lf_printf (file
, " sizeof_%sitable_name = %d,\n",
213 options
.module
.itable
.prefix
.l
, info
->sizeof_name
);
214 lf_printf (file
, " sizeof_%sitable_file = %d,\n",
215 options
.module
.itable
.prefix
.l
, info
->sizeof_file
);
216 lf_printf (file
, "};\n");
220 /****************************************************************/
223 itable_print_set (lf
*file
,
228 lf_printf (file
, "\"");
229 elem
= filter_next (members
, "");
234 lf_printf (file
, "%s", elem
);
235 elem
= filter_next (members
, elem
);
238 lf_printf (file
, ",");
241 lf_printf (file
, "\",\n");
243 lf_printf(file
, "{");
244 for (elem
= filter_next (set
, "");
246 elem
= filter_next (set
, elem
))
248 if (filter_is_member (members
, elem
))
250 lf_printf (file
, " 1,");
254 lf_printf (file
, " 0,");
258 /* always print a dummy element, to avoid empty initializers. */
259 lf_printf(file
, " 99 },\n");
264 itable_c_insn (lf
*file
,
266 insn_entry
*instruction
,
269 lf_printf (file
, "{ ");
270 lf_indent (file
, +2);
271 print_function_name (file
,
273 instruction
->format_name
,
276 function_name_prefix_itable
);
277 lf_printf (file
, ",\n");
278 lf_printf (file
, "\"");
279 print_insn_words (file
, instruction
);
280 lf_printf (file
, "\",\n");
281 lf_printf (file
, "\"%s\",\n", instruction
->format_name
);
283 itable_print_set (file
, isa
->flags
, instruction
->flags
);
284 itable_print_set (file
, isa
->options
, instruction
->options
);
285 itable_print_set (file
, isa
->model
->processors
, instruction
->processors
);
287 lf_printf(file
, "\"%s\",\n", instruction
->name
);
288 lf_printf(file
, "\"%s\",\n",
289 filter_filename (instruction
->line
->file_name
));
290 lf_printf(file
, "%d,\n", instruction
->line
->line_nr
);
291 lf_printf(file
, "},\n");
292 lf_indent (file
, -2);
297 gen_itable_c (lf
*file
,
301 lf_printf(file
, "#include \"%sitable.h\"\n", options
.module
.itable
.prefix
.l
);
302 lf_printf(file
, "\n");
304 /* FIXME - output model data??? */
305 /* FIXME - output assembler data??? */
307 /* output the flag, option and processor name tables */
308 itable_print_names (file
, isa
->flags
, "flag");
309 itable_print_names (file
, isa
->options
, "option");
310 itable_print_names (file
, isa
->model
->processors
, "processor");
312 /* output the table that contains the actual instruction info */
313 lf_printf (file
, "%sitable_info %sitable[nr_%sitable_entries] = {\n",
314 options
.module
.itable
.prefix
.l
,
315 options
.module
.itable
.prefix
.l
,
316 options
.module
.itable
.prefix
.l
);
317 insn_table_traverse_insn (file
, isa
, itable_c_insn
, NULL
);
319 lf_printf(file
, "};\n");