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. */
31 #include "ld-decode.h"
34 #include "gen-model.h"
43 model_c_or_h_data(insn_table
*table
,
48 table_entry_print_cpp_line_nr(file
, data
->annex_line
);
49 lf_print__c_code(file
, data
->annex
);
50 lf_print__internal_reference(file
);
51 lf_printf(file
, "\n");
56 model_c_or_h_function(insn_table
*entry
,
58 table_entry
*function
,
61 if (function
->fields
[function_type
] == NULL
62 || function
->fields
[function_type
][0] == '\0') {
63 error("Model function type not specified for %s", function
->fields
[function_name
]);
65 lf_printf(file
, "\n");
66 lf_print_function_type(file
, function
->fields
[function_type
], prefix
, " ");
67 lf_printf(file
, "%s\n(%s);\n",
68 function
->fields
[function_name
],
69 function
->fields
[function_param
]);
70 lf_printf(file
, "\n");
74 gen_model_h(insn_table
*table
, lf
*file
)
80 int model_create_p
= 0;
83 int model_mon_info_p
= 0;
84 int model_mon_info_free_p
= 0;
86 for(macro
= model_macros
; macro
; macro
= macro
->next
) {
87 model_c_or_h_data(table
, file
, macro
->file_entry
);
90 lf_printf(file
, "typedef enum _model_enum {\n");
91 lf_printf(file
, " MODEL_NONE,\n");
92 for (model_ptr
= models
; model_ptr
; model_ptr
= model_ptr
->next
) {
93 lf_printf(file
, " MODEL_%s,\n", model_ptr
->name
);
95 lf_printf(file
, " nr_models\n");
96 lf_printf(file
, "} model_enum;\n");
97 lf_printf(file
, "\n");
99 lf_printf(file
, "#define DEFAULT_MODEL MODEL_%s\n", (models
) ? models
->name
: "NONE");
100 lf_printf(file
, "\n");
102 lf_printf(file
, "typedef struct _model_data model_data;\n");
103 lf_printf(file
, "typedef struct _model_time model_time;\n");
104 lf_printf(file
, "\n");
106 lf_printf(file
, "extern model_enum current_model;\n");
107 lf_printf(file
, "extern const char *model_name[ (int)nr_models ];\n");
108 lf_printf(file
, "extern const char *const *const model_func_unit_name[ (int)nr_models ];\n");
109 lf_printf(file
, "extern const model_time *const model_time_mapping[ (int)nr_models ];\n");
110 lf_printf(file
, "\n");
112 for(insn_ptr
= model_functions
; insn_ptr
; insn_ptr
= insn_ptr
->next
) {
113 model_c_or_h_function(table
, file
, insn_ptr
->file_entry
, "INLINE_MODEL");
114 name
= insn_ptr
->file_entry
->fields
[function_name
];
115 if (strcmp (name
, "model_create") == 0)
117 else if (strcmp (name
, "model_init") == 0)
119 else if (strcmp (name
, "model_halt") == 0)
121 else if (strcmp (name
, "model_mon_info") == 0)
122 model_mon_info_p
= 1;
123 else if (strcmp (name
, "model_mon_info_free") == 0)
124 model_mon_info_free_p
= 1;
127 if (!model_create_p
) {
128 lf_print_function_type(file
, "model_data *", "INLINE_MODEL", " ");
129 lf_printf(file
, "model_create\n");
130 lf_printf(file
, "(sim_cpu *cpu);\n");
131 lf_printf(file
, "\n");
135 lf_print_function_type(file
, "void", "INLINE_MODEL", " ");
136 lf_printf(file
, "model_init\n");
137 lf_printf(file
, "(model_data *model_ptr);\n");
138 lf_printf(file
, "\n");
142 lf_print_function_type(file
, "void", "INLINE_MODEL", " ");
143 lf_printf(file
, "model_halt\n");
144 lf_printf(file
, "(model_data *model_ptr);\n");
145 lf_printf(file
, "\n");
148 if (!model_mon_info_p
) {
149 lf_print_function_type(file
, "model_print *", "INLINE_MODEL", " ");
150 lf_printf(file
, "model_mon_info\n");
151 lf_printf(file
, "(model_data *model_ptr);\n");
152 lf_printf(file
, "\n");
155 if (!model_mon_info_free_p
) {
156 lf_print_function_type(file
, "void", "INLINE_MODEL", " ");
157 lf_printf(file
, "model_mon_info_free\n");
158 lf_printf(file
, "(model_data *model_ptr,\n");
159 lf_printf(file
, " model_print *info_ptr);\n");
160 lf_printf(file
, "\n");
163 lf_print_function_type(file
, "void", "INLINE_MODEL", " ");
164 lf_printf(file
, "model_set\n");
165 lf_printf(file
, "(const char *name);\n");
168 /****************************************************************/
170 typedef struct _model_c_passed_data model_c_passed_data
;
171 struct _model_c_passed_data
{
177 model_c_insn(insn_table
*entry
,
183 model_c_passed_data
*data_ptr
= (model_c_passed_data
*)data
;
184 lf
*file
= data_ptr
->file
;
185 char *current_name
= data_ptr
->model_ptr
->printable_name
;
186 table_model_entry
*model_ptr
= instruction
->file_entry
->model_first
;
189 if (model_ptr
->fields
[insn_model_name
] == current_name
) {
190 lf_printf(file
, " { %-*s }, /* %s */\n",
191 max_model_fields_len
,
192 model_ptr
->fields
[insn_model_fields
],
193 instruction
->file_entry
->fields
[insn_name
]);
197 model_ptr
= model_ptr
->next
;
200 lf_printf(file
, " { %-*s }, /* %s */\n",
201 max_model_fields_len
,
202 data_ptr
->model_ptr
->insn_default
,
203 instruction
->file_entry
->fields
[insn_name
]);
207 model_c_function(insn_table
*table
,
209 table_entry
*function
,
212 if (function
->fields
[function_type
] == NULL
213 || function
->fields
[function_type
][0] == '\0')
215 error("Model function return type not specified for %s",
216 function
->fields
[function_name
]);
220 lf_printf(file
, "\n");
221 lf_print_function_type(file
, function
->fields
[function_type
], prefix
, "\n");
222 lf_printf(file
, "%s(%s)\n",
223 function
->fields
[function_name
],
224 function
->fields
[function_param
]);
226 lf_printf(file
, "{\n");
230 table_entry_print_cpp_line_nr(file
, function
->annex_line
);
231 lf_print__c_code(file
, function
->annex
);
234 lf_printf(file
, "}\n");
235 lf_print__internal_reference(file
);
236 lf_printf(file
, "\n");
240 gen_model_c(insn_table
*table
, lf
*file
)
245 int model_create_p
= 0;
246 int model_init_p
= 0;
247 int model_halt_p
= 0;
248 int model_mon_info_p
= 0;
249 int model_mon_info_free_p
= 0;
251 lf_printf(file
, "\n");
252 lf_printf(file
, "#include \"cpu.h\"\n");
253 lf_printf(file
, "#include \"mon.h\"\n");
254 lf_printf(file
, "\n");
255 lf_printf(file
, "#ifdef HAVE_STDLIB_H\n");
256 lf_printf(file
, "#include <stdlib.h>\n");
257 lf_printf(file
, "#endif\n");
258 lf_printf(file
, "\n");
260 for(insn_ptr
= model_data
; insn_ptr
; insn_ptr
= insn_ptr
->next
) {
261 model_c_or_h_data(table
, file
, insn_ptr
->file_entry
);
264 for(insn_ptr
= model_static
; insn_ptr
; insn_ptr
= insn_ptr
->next
) {
265 model_c_or_h_function(table
, file
, insn_ptr
->file_entry
, "/*h*/STATIC");
268 for(insn_ptr
= model_internal
; insn_ptr
; insn_ptr
= insn_ptr
->next
) {
269 model_c_or_h_function(table
, file
, insn_ptr
->file_entry
, "STATIC_INLINE_MODEL");
272 for(insn_ptr
= model_static
; insn_ptr
; insn_ptr
= insn_ptr
->next
) {
273 model_c_function(table
, file
, insn_ptr
->file_entry
, "/*c*/STATIC");
276 for(insn_ptr
= model_internal
; insn_ptr
; insn_ptr
= insn_ptr
->next
) {
277 model_c_function(table
, file
, insn_ptr
->file_entry
, "STATIC_INLINE_MODEL");
280 for(insn_ptr
= model_functions
; insn_ptr
; insn_ptr
= insn_ptr
->next
) {
281 model_c_function(table
, file
, insn_ptr
->file_entry
, "INLINE_MODEL");
282 name
= insn_ptr
->file_entry
->fields
[function_name
];
283 if (strcmp (name
, "model_create") == 0)
285 else if (strcmp (name
, "model_init") == 0)
287 else if (strcmp (name
, "model_halt") == 0)
289 else if (strcmp (name
, "model_mon_info") == 0)
290 model_mon_info_p
= 1;
291 else if (strcmp (name
, "model_mon_info_free") == 0)
292 model_mon_info_free_p
= 1;
295 if (!model_create_p
) {
296 lf_print_function_type(file
, "model_data *", "INLINE_MODEL", "\n");
297 lf_printf(file
, "model_create(sim_cpu *cpu)\n");
298 lf_printf(file
, "{\n");
299 lf_printf(file
, " return (model_data *)0;\n");
300 lf_printf(file
, "}\n");
301 lf_printf(file
, "\n");
305 lf_print_function_type(file
, "void", "INLINE_MODEL", "\n");
306 lf_printf(file
, "model_init(model_data *model_ptr)\n");
307 lf_printf(file
, "{\n");
308 lf_printf(file
, "}\n");
309 lf_printf(file
, "\n");
313 lf_print_function_type(file
, "void", "INLINE_MODEL", "\n");
314 lf_printf(file
, "model_halt(model_data *model_ptr)\n");
315 lf_printf(file
, "{\n");
316 lf_printf(file
, "}\n");
317 lf_printf(file
, "\n");
320 if (!model_mon_info_p
) {
321 lf_print_function_type(file
, "model_print *", "INLINE_MODEL", "\n");
322 lf_printf(file
, "model_mon_info(model_data *model_ptr)\n");
323 lf_printf(file
, "{\n");
324 lf_printf(file
, " return (model_print *)0;\n");
325 lf_printf(file
, "}\n");
326 lf_printf(file
, "\n");
329 if (!model_mon_info_free_p
) {
330 lf_print_function_type(file
, "void", "INLINE_MODEL", "\n");
331 lf_printf(file
, "model_mon_info_free(model_data *model_ptr,\n");
332 lf_printf(file
, " model_print *info_ptr)\n");
333 lf_printf(file
, "{\n");
334 lf_printf(file
, "}\n");
335 lf_printf(file
, "\n");
338 lf_printf(file
, "/* Insn functional unit info */\n");
339 for(model_ptr
= models
; model_ptr
; model_ptr
= model_ptr
->next
) {
340 model_c_passed_data data
;
342 lf_printf(file
, "static const model_time model_time_%s[] = {\n", model_ptr
->name
);
344 data
.model_ptr
= model_ptr
;
345 insn_table_traverse_insn(table
,
349 lf_printf(file
, "};\n");
350 lf_printf(file
, "\n");
351 lf_printf(file
, "\f\n");
354 lf_printf(file
, "#ifndef _INLINE_C_\n");
355 lf_printf(file
, "const model_time *const model_time_mapping[ (int)nr_models ] = {\n");
356 lf_printf(file
, " (const model_time *const)0,\n");
357 for(model_ptr
= models
; model_ptr
; model_ptr
= model_ptr
->next
) {
358 lf_printf(file
, " model_time_%s,\n", model_ptr
->name
);
360 lf_printf(file
, "};\n");
361 lf_printf(file
, "#endif\n");
362 lf_printf(file
, "\n");
364 lf_printf(file
, "\f\n");
365 lf_printf(file
, "/* map model enumeration into printable string */\n");
366 lf_printf(file
, "#ifndef _INLINE_C_\n");
367 lf_printf(file
, "const char *model_name[ (int)nr_models ] = {\n");
368 lf_printf(file
, " \"NONE\",\n");
369 for (model_ptr
= models
; model_ptr
; model_ptr
= model_ptr
->next
) {
370 lf_printf(file
, " \"%s\",\n", model_ptr
->printable_name
);
372 lf_printf(file
, "};\n");
373 lf_printf(file
, "#endif\n");
374 lf_printf(file
, "\n");
376 lf_print_function_type(file
, "void", "INLINE_MODEL", "\n");
377 lf_printf(file
, "model_set(const char *name)\n");
378 lf_printf(file
, "{\n");
380 lf_printf(file
, " model_enum model;\n");
381 lf_printf(file
, " for(model = MODEL_%s; model < nr_models; model++) {\n", models
->name
);
382 lf_printf(file
, " if(strcmp(name, model_name[model]) == 0) {\n");
383 lf_printf(file
, " current_model = model;\n");
384 lf_printf(file
, " return;\n");
385 lf_printf(file
, " }\n");
386 lf_printf(file
, " }\n");
387 lf_printf(file
, "\n");
388 lf_printf(file
, " error(\"Unknown model '%%s', Models which are known are:%%s\n\",\n");
389 lf_printf(file
, " name,\n");
390 lf_printf(file
, " \"");
391 for(model_ptr
= models
; model_ptr
; model_ptr
= model_ptr
->next
) {
392 lf_printf(file
, "\\n\\t%s", model_ptr
->printable_name
);
394 lf_printf(file
, "\");\n");
396 lf_printf(file
, " error(\"No models are currently known about\");\n");
399 lf_printf(file
, "}\n");
407 gen_model_h (lf
*file
,
410 lf_print__this_file_is_empty (file
, "suffering bit rot");
415 gen_model_c (lf
*file
,
418 lf_print__this_file_is_empty (file
, "suffering bit rot");