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
, lf
*file
, table_entry
*data
)
47 table_entry_print_cpp_line_nr (file
, data
->annex_line
);
48 lf_print__c_code (file
, data
->annex
);
49 lf_print__internal_reference (file
);
50 lf_printf (file
, "\n");
55 model_c_or_h_function (insn_table
*entry
,
56 lf
*file
, table_entry
*function
, char *prefix
)
58 if (function
->fields
[function_type
] == NULL
59 || function
->fields
[function_type
][0] == '\0')
61 error ("Model function type not specified for %s",
62 function
->fields
[function_name
]);
64 lf_printf (file
, "\n");
65 lf_print_function_type (file
, function
->fields
[function_type
], prefix
, " ");
66 lf_printf (file
, "%s\n(%s);\n",
67 function
->fields
[function_name
],
68 function
->fields
[function_param
]);
69 lf_printf (file
, "\n");
73 gen_model_h (insn_table
*table
, lf
*file
)
79 int model_create_p
= 0;
82 int model_mon_info_p
= 0;
83 int model_mon_info_free_p
= 0;
85 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
)
94 lf_printf (file
, " MODEL_%s,\n", model_ptr
->name
);
96 lf_printf (file
, " nr_models\n");
97 lf_printf (file
, "} model_enum;\n");
98 lf_printf (file
, "\n");
100 lf_printf (file
, "#define DEFAULT_MODEL MODEL_%s\n",
101 (models
) ? models
->name
: "NONE");
102 lf_printf (file
, "\n");
104 lf_printf (file
, "typedef struct _model_data model_data;\n");
105 lf_printf (file
, "typedef struct _model_time model_time;\n");
106 lf_printf (file
, "\n");
108 lf_printf (file
, "extern model_enum current_model;\n");
109 lf_printf (file
, "extern const char *model_name[ (int)nr_models ];\n");
111 "extern const char *const *const model_func_unit_name[ (int)nr_models ];\n");
113 "extern const model_time *const model_time_mapping[ (int)nr_models ];\n");
114 lf_printf (file
, "\n");
116 for (insn_ptr
= model_functions
; insn_ptr
; insn_ptr
= insn_ptr
->next
)
118 model_c_or_h_function (table
, file
, insn_ptr
->file_entry
,
120 name
= insn_ptr
->file_entry
->fields
[function_name
];
121 if (strcmp (name
, "model_create") == 0)
123 else if (strcmp (name
, "model_init") == 0)
125 else if (strcmp (name
, "model_halt") == 0)
127 else if (strcmp (name
, "model_mon_info") == 0)
128 model_mon_info_p
= 1;
129 else if (strcmp (name
, "model_mon_info_free") == 0)
130 model_mon_info_free_p
= 1;
135 lf_print_function_type (file
, "model_data *", "INLINE_MODEL", " ");
136 lf_printf (file
, "model_create\n");
137 lf_printf (file
, "(sim_cpu *cpu);\n");
138 lf_printf (file
, "\n");
143 lf_print_function_type (file
, "void", "INLINE_MODEL", " ");
144 lf_printf (file
, "model_init\n");
145 lf_printf (file
, "(model_data *model_ptr);\n");
146 lf_printf (file
, "\n");
151 lf_print_function_type (file
, "void", "INLINE_MODEL", " ");
152 lf_printf (file
, "model_halt\n");
153 lf_printf (file
, "(model_data *model_ptr);\n");
154 lf_printf (file
, "\n");
157 if (!model_mon_info_p
)
159 lf_print_function_type (file
, "model_print *", "INLINE_MODEL", " ");
160 lf_printf (file
, "model_mon_info\n");
161 lf_printf (file
, "(model_data *model_ptr);\n");
162 lf_printf (file
, "\n");
165 if (!model_mon_info_free_p
)
167 lf_print_function_type (file
, "void", "INLINE_MODEL", " ");
168 lf_printf (file
, "model_mon_info_free\n");
169 lf_printf (file
, "(model_data *model_ptr,\n");
170 lf_printf (file
, " model_print *info_ptr);\n");
171 lf_printf (file
, "\n");
174 lf_print_function_type (file
, "void", "INLINE_MODEL", " ");
175 lf_printf (file
, "model_set\n");
176 lf_printf (file
, "(const char *name);\n");
179 /****************************************************************/
181 typedef struct _model_c_passed_data model_c_passed_data
;
182 struct _model_c_passed_data
189 model_c_insn (insn_table
*entry
,
190 lf
*phony_file
, void *data
, insn
* instruction
, int depth
)
192 model_c_passed_data
*data_ptr
= (model_c_passed_data
*) data
;
193 lf
*file
= data_ptr
->file
;
194 char *current_name
= data_ptr
->model_ptr
->printable_name
;
195 table_model_entry
*model_ptr
= instruction
->file_entry
->model_first
;
199 if (model_ptr
->fields
[insn_model_name
] == current_name
)
201 lf_printf (file
, " { %-*s }, /* %s */\n",
202 max_model_fields_len
,
203 model_ptr
->fields
[insn_model_fields
],
204 instruction
->file_entry
->fields
[insn_name
]);
208 model_ptr
= model_ptr
->next
;
211 lf_printf (file
, " { %-*s }, /* %s */\n",
212 max_model_fields_len
,
213 data_ptr
->model_ptr
->insn_default
,
214 instruction
->file_entry
->fields
[insn_name
]);
218 model_c_function (insn_table
*table
,
219 lf
*file
, table_entry
*function
, const char *prefix
)
221 if (function
->fields
[function_type
] == NULL
222 || function
->fields
[function_type
][0] == '\0')
224 error ("Model function return type not specified for %s",
225 function
->fields
[function_name
]);
229 lf_printf (file
, "\n");
230 lf_print_function_type (file
, function
->fields
[function_type
], prefix
,
232 lf_printf (file
, "%s(%s)\n", function
->fields
[function_name
],
233 function
->fields
[function_param
]);
235 lf_printf (file
, "{\n");
238 lf_indent (file
, +2);
239 table_entry_print_cpp_line_nr (file
, function
->annex_line
);
240 lf_print__c_code (file
, function
->annex
);
241 lf_indent (file
, -2);
243 lf_printf (file
, "}\n");
244 lf_print__internal_reference (file
);
245 lf_printf (file
, "\n");
249 gen_model_c (insn_table
*table
, lf
*file
)
254 int model_create_p
= 0;
255 int model_init_p
= 0;
256 int model_halt_p
= 0;
257 int model_mon_info_p
= 0;
258 int model_mon_info_free_p
= 0;
260 lf_printf (file
, "\n");
261 lf_printf (file
, "#include \"cpu.h\"\n");
262 lf_printf (file
, "#include \"mon.h\"\n");
263 lf_printf (file
, "\n");
264 lf_printf (file
, "#ifdef HAVE_STDLIB_H\n");
265 lf_printf (file
, "#include <stdlib.h>\n");
266 lf_printf (file
, "#endif\n");
267 lf_printf (file
, "\n");
269 for (insn_ptr
= model_data
; insn_ptr
; insn_ptr
= insn_ptr
->next
)
271 model_c_or_h_data (table
, file
, insn_ptr
->file_entry
);
274 for (insn_ptr
= model_static
; insn_ptr
; insn_ptr
= insn_ptr
->next
)
276 model_c_or_h_function (table
, file
, insn_ptr
->file_entry
,
280 for (insn_ptr
= model_internal
; insn_ptr
; insn_ptr
= insn_ptr
->next
)
282 model_c_or_h_function (table
, file
, insn_ptr
->file_entry
,
283 "STATIC_INLINE_MODEL");
286 for (insn_ptr
= model_static
; insn_ptr
; insn_ptr
= insn_ptr
->next
)
288 model_c_function (table
, file
, insn_ptr
->file_entry
, "/*c*/STATIC");
291 for (insn_ptr
= model_internal
; insn_ptr
; insn_ptr
= insn_ptr
->next
)
293 model_c_function (table
, file
, insn_ptr
->file_entry
,
294 "STATIC_INLINE_MODEL");
297 for (insn_ptr
= model_functions
; insn_ptr
; insn_ptr
= insn_ptr
->next
)
299 model_c_function (table
, file
, insn_ptr
->file_entry
, "INLINE_MODEL");
300 name
= insn_ptr
->file_entry
->fields
[function_name
];
301 if (strcmp (name
, "model_create") == 0)
303 else if (strcmp (name
, "model_init") == 0)
305 else if (strcmp (name
, "model_halt") == 0)
307 else if (strcmp (name
, "model_mon_info") == 0)
308 model_mon_info_p
= 1;
309 else if (strcmp (name
, "model_mon_info_free") == 0)
310 model_mon_info_free_p
= 1;
315 lf_print_function_type (file
, "model_data *", "INLINE_MODEL", "\n");
316 lf_printf (file
, "model_create(sim_cpu *cpu)\n");
317 lf_printf (file
, "{\n");
318 lf_printf (file
, " return (model_data *)0;\n");
319 lf_printf (file
, "}\n");
320 lf_printf (file
, "\n");
325 lf_print_function_type (file
, "void", "INLINE_MODEL", "\n");
326 lf_printf (file
, "model_init(model_data *model_ptr)\n");
327 lf_printf (file
, "{\n");
328 lf_printf (file
, "}\n");
329 lf_printf (file
, "\n");
334 lf_print_function_type (file
, "void", "INLINE_MODEL", "\n");
335 lf_printf (file
, "model_halt(model_data *model_ptr)\n");
336 lf_printf (file
, "{\n");
337 lf_printf (file
, "}\n");
338 lf_printf (file
, "\n");
341 if (!model_mon_info_p
)
343 lf_print_function_type (file
, "model_print *", "INLINE_MODEL", "\n");
344 lf_printf (file
, "model_mon_info(model_data *model_ptr)\n");
345 lf_printf (file
, "{\n");
346 lf_printf (file
, " return (model_print *)0;\n");
347 lf_printf (file
, "}\n");
348 lf_printf (file
, "\n");
351 if (!model_mon_info_free_p
)
353 lf_print_function_type (file
, "void", "INLINE_MODEL", "\n");
354 lf_printf (file
, "model_mon_info_free(model_data *model_ptr,\n");
355 lf_printf (file
, " model_print *info_ptr)\n");
356 lf_printf (file
, "{\n");
357 lf_printf (file
, "}\n");
358 lf_printf (file
, "\n");
361 lf_printf (file
, "/* Insn functional unit info */\n");
362 for (model_ptr
= models
; model_ptr
; model_ptr
= model_ptr
->next
)
364 model_c_passed_data data
;
366 lf_printf (file
, "static const model_time model_time_%s[] = {\n",
369 data
.model_ptr
= model_ptr
;
370 insn_table_traverse_insn (table
, NULL
, (void *) &data
, model_c_insn
);
372 lf_printf (file
, "};\n");
373 lf_printf (file
, "\n");
374 lf_printf (file
, "\f\n");
377 lf_printf (file
, "#ifndef _INLINE_C_\n");
379 "const model_time *const model_time_mapping[ (int)nr_models ] = {\n");
380 lf_printf (file
, " (const model_time *const)0,\n");
381 for (model_ptr
= models
; model_ptr
; model_ptr
= model_ptr
->next
)
383 lf_printf (file
, " model_time_%s,\n", model_ptr
->name
);
385 lf_printf (file
, "};\n");
386 lf_printf (file
, "#endif\n");
387 lf_printf (file
, "\n");
389 lf_printf (file
, "\f\n");
390 lf_printf (file
, "/* map model enumeration into printable string */\n");
391 lf_printf (file
, "#ifndef _INLINE_C_\n");
392 lf_printf (file
, "const char *model_name[ (int)nr_models ] = {\n");
393 lf_printf (file
, " \"NONE\",\n");
394 for (model_ptr
= models
; model_ptr
; model_ptr
= model_ptr
->next
)
396 lf_printf (file
, " \"%s\",\n", model_ptr
->printable_name
);
398 lf_printf (file
, "};\n");
399 lf_printf (file
, "#endif\n");
400 lf_printf (file
, "\n");
402 lf_print_function_type (file
, "void", "INLINE_MODEL", "\n");
403 lf_printf (file
, "model_set(const char *name)\n");
404 lf_printf (file
, "{\n");
407 lf_printf (file
, " model_enum model;\n");
409 " for(model = MODEL_%s; model < nr_models; model++) {\n",
411 lf_printf (file
, " if(strcmp(name, model_name[model]) == 0) {\n");
412 lf_printf (file
, " current_model = model;\n");
413 lf_printf (file
, " return;\n");
414 lf_printf (file
, " }\n");
415 lf_printf (file
, " }\n");
416 lf_printf (file
, "\n");
418 " error(\"Unknown model '%%s', Models which are known are:%%s\n\",\n");
419 lf_printf (file
, " name,\n");
420 lf_printf (file
, " \"");
421 for (model_ptr
= models
; model_ptr
; model_ptr
= model_ptr
->next
)
423 lf_printf (file
, "\\n\\t%s", model_ptr
->printable_name
);
425 lf_printf (file
, "\");\n");
429 lf_printf (file
, " error(\"No models are currently known about\");\n");
432 lf_printf (file
, "}\n");
440 gen_model_h (lf
*file
, insn_table
*table
)
442 lf_print__this_file_is_empty (file
, "suffering bit rot");
447 gen_model_c (lf
*file
, insn_table
*table
)
449 lf_print__this_file_is_empty (file
, "suffering bit rot");