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
55 itable_h_insn (lf
*file
,
56 insn_table
*entry
, insn_entry
* instruction
, void *data
)
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
,
65 NULL
, NULL
, function_name_prefix_itable
);
66 lf_printf (file
, ",\n");
67 /* update summary info */
68 len
= strlen (instruction
->format_name
);
69 if (info
->sizeof_form
<= len
)
70 info
->sizeof_form
= len
+ 1;
71 len
= strlen (instruction
->name
);
72 if (info
->sizeof_name
<= len
)
73 info
->sizeof_name
= len
+ 1;
74 len
= strlen (filter_filename (instruction
->line
->file_name
));
75 if (info
->sizeof_file
<= len
)
76 info
->sizeof_file
= len
+ 1;
80 /* print the list of all the different options */
83 itable_print_enum (lf
*file
, filter
*set
, char *name
)
86 lf_printf (file
, "typedef enum {\n");
88 for (elem
= filter_next (set
, "");
89 elem
!= NULL
; elem
= filter_next (set
, elem
))
91 lf_printf (file
, "%sitable_%s_%s,\n",
92 options
.module
.itable
.prefix
.l
, name
, elem
);
93 if (strlen (options
.module
.itable
.prefix
.l
) > 0)
95 lf_indent_suppress (file
);
96 lf_printf (file
, "#define itable_%s_%s %sitable_%s_%s\n",
97 name
, elem
, options
.module
.itable
.prefix
.l
, name
, elem
);
100 lf_printf (file
, "nr_%sitable_%ss,\n", options
.module
.itable
.prefix
.l
,
103 lf_indent (file
, -2);
104 lf_printf (file
, "} %sitable_%ss;\n", options
.module
.itable
.prefix
.l
, name
);
105 if (strlen (options
.module
.itable
.prefix
.l
) > 0)
107 lf_indent_suppress (file
);
108 lf_printf (file
, "#define itable_%ss %sitable_%ss\n",
109 name
, options
.module
.itable
.prefix
.l
, name
);
110 lf_indent_suppress (file
);
111 lf_printf (file
, "#define nr_itable_%ss nr_%sitable_%ss\n",
112 name
, options
.module
.itable
.prefix
.l
, name
);
116 /* print an array of the option names as strings */
119 itable_print_names (lf
*file
, filter
*set
, char *name
)
122 lf_printf (file
, "const char *%sitable_%s_names[nr_%sitable_%ss + 1] = {\n",
123 options
.module
.itable
.prefix
.l
, name
,
124 options
.module
.itable
.prefix
.l
, name
);
125 lf_indent (file
, +2);
126 for (elem
= filter_next (set
, "");
127 elem
!= NULL
; elem
= filter_next (set
, elem
))
129 lf_printf (file
, "\"%s\",\n", elem
);
131 lf_printf (file
, "0,\n");
132 lf_indent (file
, -2);
133 lf_printf (file
, "};\n");
137 gen_itable_h (lf
*file
, insn_table
*isa
)
139 itable_info
*info
= ZALLOC (itable_info
);
141 /* output an enumerated type for each instruction */
142 lf_printf (file
, "typedef enum {\n");
143 insn_table_traverse_insn (file
, isa
, itable_h_insn
, info
);
144 lf_printf (file
, " nr_%sitable_entries,\n",
145 options
.module
.itable
.prefix
.l
);
146 lf_printf (file
, "} %sitable_index;\n", options
.module
.itable
.prefix
.l
);
147 lf_printf (file
, "\n");
149 /* output an enumeration type for each flag */
150 itable_print_enum (file
, isa
->flags
, "flag");
151 lf_printf (file
, "extern const char *%sitable_flag_names[];\n",
152 options
.module
.itable
.prefix
.l
);
153 lf_printf (file
, "\n");
155 /* output an enumeration of all the possible options */
156 itable_print_enum (file
, isa
->options
, "option");
157 lf_printf (file
, "extern const char *%sitable_option_names[];\n",
158 options
.module
.itable
.prefix
.l
);
159 lf_printf (file
, "\n");
161 /* output an enumeration of all the processor models */
162 itable_print_enum (file
, isa
->model
->processors
, "processor");
163 lf_printf (file
, "extern const char *%sitable_processor_names[];\n",
164 options
.module
.itable
.prefix
.l
);
165 lf_printf (file
, "\n");
167 /* output the table that contains the actual instruction info */
168 lf_printf (file
, "typedef struct _%sitable_instruction_info {\n",
169 options
.module
.itable
.prefix
.l
);
170 lf_printf (file
, " %sitable_index nr;\n", options
.module
.itable
.prefix
.l
);
171 lf_printf (file
, " char *format;\n");
172 lf_printf (file
, " char *form;\n");
173 lf_printf (file
, " char *flags;\n");
175 /* nr_itable_* may be zero, so we add 1 to avoid an
176 illegal zero-sized array. */
177 lf_printf (file
, " char flag[nr_%sitable_flags + 1];\n",
178 options
.module
.itable
.prefix
.l
);
179 lf_printf (file
, " char *options;\n");
180 lf_printf (file
, " char option[nr_%sitable_options + 1];\n",
181 options
.module
.itable
.prefix
.l
);
182 lf_printf (file
, " char *processors;\n");
183 lf_printf (file
, " char processor[nr_%sitable_processors + 1];\n",
184 options
.module
.itable
.prefix
.l
);
185 lf_printf (file
, " char *name;\n");
186 lf_printf (file
, " char *file;\n");
187 lf_printf (file
, " int line_nr;\n");
188 lf_printf (file
, "} %sitable_info;\n", options
.module
.itable
.prefix
.l
);
189 lf_printf (file
, "\n");
190 lf_printf (file
, "extern %sitable_info %sitable[nr_%sitable_entries];\n",
191 options
.module
.itable
.prefix
.l
, options
.module
.itable
.prefix
.l
,
192 options
.module
.itable
.prefix
.l
);
193 if (strlen (options
.module
.itable
.prefix
.l
) > 0)
195 lf_indent_suppress (file
);
196 lf_printf (file
, "#define itable %sitable\n",
197 options
.module
.itable
.prefix
.l
);
199 lf_printf (file
, "\n");
201 /* output an enum defining the max size of various itable members */
202 lf_printf (file
, "enum {\n");
203 lf_printf (file
, " sizeof_%sitable_form = %d,\n",
204 options
.module
.itable
.prefix
.l
, info
->sizeof_form
);
205 lf_printf (file
, " sizeof_%sitable_name = %d,\n",
206 options
.module
.itable
.prefix
.l
, info
->sizeof_name
);
207 lf_printf (file
, " sizeof_%sitable_file = %d,\n",
208 options
.module
.itable
.prefix
.l
, info
->sizeof_file
);
209 lf_printf (file
, "};\n");
213 /****************************************************************/
216 itable_print_set (lf
*file
, filter
*set
, filter
*members
)
219 lf_printf (file
, "\"");
220 elem
= filter_next (members
, "");
225 lf_printf (file
, "%s", elem
);
226 elem
= filter_next (members
, elem
);
229 lf_printf (file
, ",");
232 lf_printf (file
, "\",\n");
234 lf_printf (file
, "{");
235 for (elem
= filter_next (set
, "");
236 elem
!= NULL
; elem
= filter_next (set
, elem
))
238 if (filter_is_member (members
, elem
))
240 lf_printf (file
, " 1,");
244 lf_printf (file
, " 0,");
248 /* always print a dummy element, to avoid empty initializers. */
249 lf_printf (file
, " 99 },\n");
254 itable_c_insn (lf
*file
,
255 insn_table
*isa
, insn_entry
* instruction
, void *data
)
257 lf_printf (file
, "{ ");
258 lf_indent (file
, +2);
259 print_function_name (file
,
261 instruction
->format_name
,
262 NULL
, NULL
, function_name_prefix_itable
);
263 lf_printf (file
, ",\n");
264 lf_printf (file
, "\"");
265 print_insn_words (file
, instruction
);
266 lf_printf (file
, "\",\n");
267 lf_printf (file
, "\"%s\",\n", instruction
->format_name
);
269 itable_print_set (file
, isa
->flags
, instruction
->flags
);
270 itable_print_set (file
, isa
->options
, instruction
->options
);
271 itable_print_set (file
, isa
->model
->processors
, instruction
->processors
);
273 lf_printf (file
, "\"%s\",\n", instruction
->name
);
274 lf_printf (file
, "\"%s\",\n",
275 filter_filename (instruction
->line
->file_name
));
276 lf_printf (file
, "%d,\n", instruction
->line
->line_nr
);
277 lf_printf (file
, "},\n");
278 lf_indent (file
, -2);
283 gen_itable_c (lf
*file
, insn_table
*isa
)
286 lf_printf (file
, "#include \"%sitable.h\"\n",
287 options
.module
.itable
.prefix
.l
);
288 lf_printf (file
, "\n");
290 /* FIXME - output model data??? */
291 /* FIXME - output assembler data??? */
293 /* output the flag, option and processor name tables */
294 itable_print_names (file
, isa
->flags
, "flag");
295 itable_print_names (file
, isa
->options
, "option");
296 itable_print_names (file
, isa
->model
->processors
, "processor");
298 /* output the table that contains the actual instruction info */
299 lf_printf (file
, "%sitable_info %sitable[nr_%sitable_entries] = {\n",
300 options
.module
.itable
.prefix
.l
,
301 options
.module
.itable
.prefix
.l
, options
.module
.itable
.prefix
.l
);
302 insn_table_traverse_insn (file
, isa
, itable_c_insn
, NULL
);
304 lf_printf (file
, "};\n");