2002-11-21 Andrew Cagney <ac131313@redhat.com>
[deliverable/binutils-gdb.git] / sim / igen / gen-model.c
1 /* The IGEN simulator generator for GDB, the GNU Debugger.
2
3 Copyright 2002 Free Software Foundation, Inc.
4
5 Contributed by Andrew Cagney.
6
7 This file is part of GDB.
8
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.
13
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.
18
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. */
23
24
25 #include "misc.h"
26 #include "lf.h"
27 #include "table.h"
28
29 #include "filter.h"
30
31 #include "ld-decode.h"
32 #include "ld-insn.h"
33
34 #include "gen-model.h"
35
36 #ifndef NULL
37 #define NULL 0
38 #endif
39
40
41 #if 0
42 static void
43 model_c_or_h_data(insn_table *table,
44 lf *file,
45 table_entry *data)
46 {
47 if (data->annex) {
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");
52 }
53 }
54
55 static void
56 model_c_or_h_function(insn_table *entry,
57 lf *file,
58 table_entry *function,
59 char *prefix)
60 {
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]);
64 }
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");
71 }
72
73 void
74 gen_model_h(insn_table *table, lf *file)
75 {
76 insn *insn_ptr;
77 model *model_ptr;
78 insn *macro;
79 char *name;
80 int model_create_p = 0;
81 int model_init_p = 0;
82 int model_halt_p = 0;
83 int model_mon_info_p = 0;
84 int model_mon_info_free_p = 0;
85
86 for(macro = model_macros; macro; macro = macro->next) {
87 model_c_or_h_data(table, file, macro->file_entry);
88 }
89
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);
94 }
95 lf_printf(file, " nr_models\n");
96 lf_printf(file, "} model_enum;\n");
97 lf_printf(file, "\n");
98
99 lf_printf(file, "#define DEFAULT_MODEL MODEL_%s\n", (models) ? models->name : "NONE");
100 lf_printf(file, "\n");
101
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");
105
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");
111
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)
116 model_create_p = 1;
117 else if (strcmp (name, "model_init") == 0)
118 model_init_p = 1;
119 else if (strcmp (name, "model_halt") == 0)
120 model_halt_p = 1;
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;
125 }
126
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");
132 }
133
134 if (!model_init_p) {
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");
139 }
140
141 if (!model_halt_p) {
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");
146 }
147
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");
153 }
154
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");
161 }
162
163 lf_print_function_type(file, "void", "INLINE_MODEL", " ");
164 lf_printf(file, "model_set\n");
165 lf_printf(file, "(const char *name);\n");
166 }
167
168 /****************************************************************/
169
170 typedef struct _model_c_passed_data model_c_passed_data;
171 struct _model_c_passed_data {
172 lf *file;
173 model *model_ptr;
174 };
175
176 static void
177 model_c_insn(insn_table *entry,
178 lf *phony_file,
179 void *data,
180 insn *instruction,
181 int depth)
182 {
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;
187
188 while (model_ptr) {
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]);
194 return;
195 }
196
197 model_ptr = model_ptr->next;
198 }
199
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]);
204 }
205
206 static void
207 model_c_function(insn_table *table,
208 lf *file,
209 table_entry *function,
210 const char *prefix)
211 {
212 if (function->fields[function_type] == NULL
213 || function->fields[function_type][0] == '\0')
214 {
215 error("Model function return type not specified for %s",
216 function->fields[function_name]);
217 }
218 else
219 {
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]);
225 }
226 lf_printf(file, "{\n");
227 if (function->annex)
228 {
229 lf_indent(file, +2);
230 table_entry_print_cpp_line_nr(file, function->annex_line);
231 lf_print__c_code(file, function->annex);
232 lf_indent(file, -2);
233 }
234 lf_printf(file, "}\n");
235 lf_print__internal_reference(file);
236 lf_printf(file, "\n");
237 }
238
239 void
240 gen_model_c(insn_table *table, lf *file)
241 {
242 insn *insn_ptr;
243 model *model_ptr;
244 char *name;
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;
250
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");
259
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);
262 }
263
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");
266 }
267
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");
270 }
271
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");
274 }
275
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");
278 }
279
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)
284 model_create_p = 1;
285 else if (strcmp (name, "model_init") == 0)
286 model_init_p = 1;
287 else if (strcmp (name, "model_halt") == 0)
288 model_halt_p = 1;
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;
293 }
294
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");
302 }
303
304 if (!model_init_p) {
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");
310 }
311
312 if (!model_halt_p) {
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");
318 }
319
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");
327 }
328
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");
336 }
337
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;
341
342 lf_printf(file, "static const model_time model_time_%s[] = {\n", model_ptr->name);
343 data.file = file;
344 data.model_ptr = model_ptr;
345 insn_table_traverse_insn(table,
346 NULL, (void *)&data,
347 model_c_insn);
348
349 lf_printf(file, "};\n");
350 lf_printf(file, "\n");
351 lf_printf(file, "\f\n");
352 }
353
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);
359 }
360 lf_printf(file, "};\n");
361 lf_printf(file, "#endif\n");
362 lf_printf(file, "\n");
363
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);
371 }
372 lf_printf(file, "};\n");
373 lf_printf(file, "#endif\n");
374 lf_printf(file, "\n");
375
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");
379 if (models) {
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);
393 }
394 lf_printf(file, "\");\n");
395 } else {
396 lf_printf(file, " error(\"No models are currently known about\");\n");
397 }
398
399 lf_printf(file, "}\n");
400 }
401
402 #endif
403
404
405
406 void
407 gen_model_h (lf *file,
408 insn_table *table)
409 {
410 lf_print__this_file_is_empty (file, "suffering bit rot");
411 }
412
413
414 void
415 gen_model_c (lf *file,
416 insn_table *table)
417 {
418 lf_print__this_file_is_empty (file, "suffering bit rot");
419 }
This page took 0.03892 seconds and 4 git commands to generate.