1 /* This file is part of the program psim.
3 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #include "ld-decode.h"
34 #include "gen-itable.h"
42 typedef struct _itable_info
{
50 itable_h_insn (lf
*file
,
52 insn_entry
*instruction
,
56 itable_info
*info
= data
;
57 lf_print__line_ref (file
, instruction
->line
);
58 lf_printf (file
, " ");
59 print_function_name (file
,
61 instruction
->format_name
,
64 function_name_prefix_itable
);
65 lf_printf (file
, ",\n");
66 /* update summary info */
67 len
= strlen (instruction
->format_name
);
68 if (info
->sizeof_form
<= len
)
69 info
->sizeof_form
= len
+ 1;
70 len
= strlen (instruction
->name
);
71 if (info
->sizeof_name
<= len
)
72 info
->sizeof_name
= len
+ 1;
73 len
= strlen (filter_filename (instruction
->line
->file_name
));
74 if (info
->sizeof_file
<= len
)
75 info
->sizeof_file
= len
+ 1;
79 /* print the list of all the different options */
82 itable_print_enum (lf
*file
,
87 lf_printf (file
, "typedef enum {\n");
89 for (elem
= filter_next (set
, "");
91 elem
= filter_next (set
, elem
))
93 lf_printf (file
, "%sitable_%s_%s,\n",
94 options
.module
.itable
.prefix
.l
, name
, elem
);
95 if (strlen (options
.module
.itable
.prefix
.l
) > 0)
97 lf_indent_suppress (file
);
98 lf_printf (file
, "#define itable_%s_%s %sitable_%s_%s\n",
99 name
, elem
, options
.module
.itable
.prefix
.l
, name
, elem
);
102 lf_printf (file
, "nr_%sitable_%ss,\n", options
.module
.itable
.prefix
.l
, name
);
104 lf_indent (file
, -2);
105 lf_printf (file
, "} %sitable_%ss;\n", options
.module
.itable
.prefix
.l
, name
);
106 if (strlen (options
.module
.itable
.prefix
.l
) > 0)
108 lf_indent_suppress (file
);
109 lf_printf (file
, "#define itable_%ss %sitable_%ss\n",
110 name
, options
.module
.itable
.prefix
.l
, name
);
111 lf_indent_suppress (file
);
112 lf_printf (file
, "#define nr_itable_%ss nr_%sitable_%ss\n",
113 name
, options
.module
.itable
.prefix
.l
, name
);
117 /* print an array of the option names as strings */
120 itable_print_names (lf
*file
,
125 lf_printf (file
, "const char *%sitable_%s_names[nr_%sitable_%ss + 1] = {\n",
126 options
.module
.itable
.prefix
.l
, name
,
127 options
.module
.itable
.prefix
.l
, name
);
128 lf_indent (file
, +2);
129 for (elem
= filter_next (set
, "");
131 elem
= filter_next (set
, elem
))
133 lf_printf (file
, "\"%s\",\n", elem
);
135 lf_printf (file
, "0,\n");
136 lf_indent (file
, -2);
137 lf_printf (file
, "};\n");
141 gen_itable_h (lf
*file
,
144 itable_info
*info
= ZALLOC (itable_info
);
146 /* output an enumerated type for each instruction */
147 lf_printf (file
, "typedef enum {\n");
148 insn_table_traverse_insn (file
, isa
, itable_h_insn
, info
);
149 lf_printf (file
, " nr_%sitable_entries,\n", options
.module
.itable
.prefix
.l
);
150 lf_printf (file
, "} %sitable_index;\n", options
.module
.itable
.prefix
.l
);
151 lf_printf (file
, "\n");
153 /* output an enumeration type for each flag */
154 itable_print_enum (file
, isa
->flags
, "flag");
155 lf_printf (file
, "extern const char *%sitable_flag_names[];\n",
156 options
.module
.itable
.prefix
.l
);
157 lf_printf (file
, "\n");
159 /* output an enumeration of all the possible options */
160 itable_print_enum (file
, isa
->options
, "option");
161 lf_printf (file
, "extern const char *%sitable_option_names[];\n",
162 options
.module
.itable
.prefix
.l
);
163 lf_printf (file
, "\n");
165 /* output an enumeration of all the processor models */
166 itable_print_enum (file
, isa
->model
->processors
, "processor");
167 lf_printf (file
, "extern const char *%sitable_processor_names[];\n",
168 options
.module
.itable
.prefix
.l
);
169 lf_printf (file
, "\n");
171 /* output the table that contains the actual instruction info */
172 lf_printf (file
, "typedef struct _%sitable_instruction_info {\n",
173 options
.module
.itable
.prefix
.l
);
174 lf_printf (file
, " %sitable_index nr;\n", options
.module
.itable
.prefix
.l
);
175 lf_printf (file
, " char *format;\n");
176 lf_printf (file
, " char *form;\n");
177 lf_printf (file
, " char *flags;\n");
179 /* nr_itable_* may be zero, so we add 1 to avoid an
180 illegal zero-sized array. */
181 lf_printf (file
, " char flag[nr_%sitable_flags + 1];\n",
182 options
.module
.itable
.prefix
.l
);
183 lf_printf (file
, " char *options;\n");
184 lf_printf (file
, " char option[nr_%sitable_options + 1];\n",
185 options
.module
.itable
.prefix
.l
);
186 lf_printf (file
, " char *processors;\n");
187 lf_printf (file
, " char processor[nr_%sitable_processors + 1];\n",
188 options
.module
.itable
.prefix
.l
);
189 lf_printf (file
, " char *name;\n");
190 lf_printf (file
, " char *file;\n");
191 lf_printf (file
, " int line_nr;\n");
192 lf_printf (file
, "} %sitable_info;\n", options
.module
.itable
.prefix
.l
);
193 lf_printf (file
, "\n");
194 lf_printf (file
, "extern %sitable_info %sitable[nr_%sitable_entries];\n",
195 options
.module
.itable
.prefix
.l
, options
.module
.itable
.prefix
.l
,
196 options
.module
.itable
.prefix
.l
);
197 if (strlen (options
.module
.itable
.prefix
.l
) > 0)
199 lf_indent_suppress (file
);
200 lf_printf (file
, "#define itable %sitable\n",
201 options
.module
.itable
.prefix
.l
);
203 lf_printf (file
, "\n");
205 /* output an enum defining the max size of various itable members */
206 lf_printf (file
, "enum {\n");
207 lf_printf (file
, " sizeof_%sitable_form = %d,\n",
208 options
.module
.itable
.prefix
.l
, info
->sizeof_form
);
209 lf_printf (file
, " sizeof_%sitable_name = %d,\n",
210 options
.module
.itable
.prefix
.l
, info
->sizeof_name
);
211 lf_printf (file
, " sizeof_%sitable_file = %d,\n",
212 options
.module
.itable
.prefix
.l
, info
->sizeof_file
);
213 lf_printf (file
, "};\n");
217 /****************************************************************/
220 itable_print_set (lf
*file
,
225 lf_printf (file
, "\"");
226 elem
= filter_next (members
, "");
231 lf_printf (file
, "%s", elem
);
232 elem
= filter_next (members
, elem
);
235 lf_printf (file
, ",");
238 lf_printf (file
, "\",\n");
240 lf_printf(file
, "{");
241 for (elem
= filter_next (set
, "");
243 elem
= filter_next (set
, elem
))
245 if (filter_is_member (members
, elem
))
247 lf_printf (file
, " 1,");
251 lf_printf (file
, " 0,");
255 /* always print a dummy element, to avoid empty initializers. */
256 lf_printf(file
, " 99 },\n");
261 itable_c_insn (lf
*file
,
263 insn_entry
*instruction
,
266 lf_printf (file
, "{ ");
267 lf_indent (file
, +2);
268 print_function_name (file
,
270 instruction
->format_name
,
273 function_name_prefix_itable
);
274 lf_printf (file
, ",\n");
275 lf_printf (file
, "\"");
276 print_insn_words (file
, instruction
);
277 lf_printf (file
, "\",\n");
278 lf_printf (file
, "\"%s\",\n", instruction
->format_name
);
280 itable_print_set (file
, isa
->flags
, instruction
->flags
);
281 itable_print_set (file
, isa
->options
, instruction
->options
);
282 itable_print_set (file
, isa
->model
->processors
, instruction
->processors
);
284 lf_printf(file
, "\"%s\",\n", instruction
->name
);
285 lf_printf(file
, "\"%s\",\n",
286 filter_filename (instruction
->line
->file_name
));
287 lf_printf(file
, "%d,\n", instruction
->line
->line_nr
);
288 lf_printf(file
, "},\n");
289 lf_indent (file
, -2);
294 gen_itable_c (lf
*file
,
298 lf_printf(file
, "#include \"%sitable.h\"\n", options
.module
.itable
.prefix
.l
);
299 lf_printf(file
, "\n");
301 /* FIXME - output model data??? */
302 /* FIXME - output assembler data??? */
304 /* output the flag, option and processor name tables */
305 itable_print_names (file
, isa
->flags
, "flag");
306 itable_print_names (file
, isa
->options
, "option");
307 itable_print_names (file
, isa
->model
->processors
, "processor");
309 /* output the table that contains the actual instruction info */
310 lf_printf (file
, "%sitable_info %sitable[nr_%sitable_entries] = {\n",
311 options
.module
.itable
.prefix
.l
,
312 options
.module
.itable
.prefix
.l
,
313 options
.module
.itable
.prefix
.l
);
314 insn_table_traverse_insn (file
, isa
, itable_c_insn
, NULL
);
316 lf_printf(file
, "};\n");