2002-11-21 Andrew Cagney <ac131313@redhat.com>
[binutils-gdb.git] / sim / igen / igen.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
26 #include <getopt.h>
27
28 #include "misc.h"
29 #include "lf.h"
30 #include "table.h"
31 #include "config.h"
32 #include "filter.h"
33
34 #include "igen.h"
35
36 #include "ld-insn.h"
37 #include "ld-decode.h"
38 #include "ld-cache.h"
39
40 #include "gen.h"
41
42 #include "gen-model.h"
43 #include "gen-icache.h"
44 #include "gen-itable.h"
45 #include "gen-idecode.h"
46 #include "gen-semantics.h"
47 #include "gen-engine.h"
48 #include "gen-support.h"
49 #include "gen-engine.h"
50
51
52 /****************************************************************/
53
54
55 /* Semantic functions */
56
57 int
58 print_semantic_function_formal (lf *file,
59 int nr_prefetched_words)
60 {
61 int nr = 0;
62 int word_nr;
63 if (options.gen.icache || nr_prefetched_words < 0)
64 {
65 nr += lf_printf (file, "SIM_DESC sd,\n");
66 nr += lf_printf (file, "%sidecode_cache *cache_entry,\n",
67 options.module.global.prefix.l);
68 nr += lf_printf (file, "%sinstruction_address cia",
69 options.module.global.prefix.l);
70 }
71 else if (options.gen.smp)
72 {
73 nr += lf_printf (file, "sim_cpu *cpu,\n");
74 for (word_nr = 0; word_nr < nr_prefetched_words; word_nr++)
75 {
76 nr += lf_printf (file, "%sinstruction_word instruction_%d,\n",
77 options.module.global.prefix.l,
78 word_nr);
79 }
80 nr += lf_printf (file, "%sinstruction_address cia",
81 options.module.global.prefix.l);
82 }
83 else
84 {
85 nr += lf_printf (file, "SIM_DESC sd,\n");
86 for (word_nr = 0; word_nr < nr_prefetched_words; word_nr++)
87 {
88 nr += lf_printf (file, "%sinstruction_word instruction_%d,\n",
89 options.module.global.prefix.l,
90 word_nr);
91 }
92 nr += lf_printf (file, "%sinstruction_address cia",
93 options.module.global.prefix.l);
94 }
95 return nr;
96 }
97
98 int
99 print_semantic_function_actual (lf *file,
100 int nr_prefetched_words)
101 {
102 int nr = 0;
103 int word_nr;
104 if (options.gen.icache || nr_prefetched_words < 0)
105 {
106 nr += lf_printf (file, "sd, cache_entry, cia");
107 }
108 else
109 {
110 if (options.gen.smp)
111 nr += lf_printf (file, "cpu");
112 else
113 nr += lf_printf (file, "sd");
114 for (word_nr = 0; word_nr < nr_prefetched_words; word_nr++)
115 nr += lf_printf (file, ", instruction_%d", word_nr);
116 nr += lf_printf (file, ", cia");
117 }
118 return nr;
119 }
120
121 int
122 print_semantic_function_type (lf *file)
123 {
124 int nr = 0;
125 nr += lf_printf (file, "%sinstruction_address",
126 options.module.global.prefix.l);
127 return nr;
128 }
129
130
131 /* Idecode functions */
132
133 int
134 print_icache_function_formal (lf *file,
135 int nr_prefetched_words)
136 {
137 int nr = 0;
138 int word_nr;
139 if (options.gen.smp)
140 nr += lf_printf (file, "sim_cpu *cpu,\n");
141 else
142 nr += lf_printf (file, "SIM_DESC sd,\n");
143 for (word_nr = 0; word_nr < nr_prefetched_words; word_nr++)
144 nr += lf_printf (file, " %sinstruction_word instruction_%d,\n",
145 options.module.global.prefix.l, word_nr);
146 nr += lf_printf (file, " %sinstruction_address cia,\n",
147 options.module.global.prefix.l);
148 nr += lf_printf (file, " %sidecode_cache *cache_entry",
149 options.module.global.prefix.l);
150 return nr;
151 }
152
153 int
154 print_icache_function_actual (lf *file,
155 int nr_prefetched_words)
156 {
157 int nr = 0;
158 int word_nr;
159 if (options.gen.smp)
160 nr += lf_printf (file, "cpu");
161 else
162 nr += lf_printf (file, "sd");
163 for (word_nr = 0; word_nr < nr_prefetched_words; word_nr++)
164 nr += lf_printf (file, ", instruction_%d", word_nr);
165 nr += lf_printf (file, ", cia, cache_entry");
166 return nr;
167 }
168
169 int
170 print_icache_function_type (lf *file)
171 {
172 int nr;
173 if (options.gen.semantic_icache)
174 {
175 nr = print_semantic_function_type (file);
176 }
177 else
178 {
179 nr = lf_printf (file, "%sidecode_semantic *",
180 options.module.global.prefix.l);
181 }
182 return nr;
183 }
184
185
186 /* Function names */
187
188 static int
189 print_opcode_bits (lf *file,
190 opcode_bits *bits)
191 {
192 int nr = 0;
193 if (bits == NULL)
194 return nr;
195 nr += lf_putchr (file, '_');
196 nr += lf_putstr (file, bits->field->val_string);
197 if (bits->opcode->is_boolean && bits->value == 0)
198 nr += lf_putint (file, bits->opcode->boolean_constant);
199 else if (!bits->opcode->is_boolean) {
200 if (bits->opcode->last < bits->field->last)
201 nr += lf_putint (file, bits->value << (bits->field->last - bits->opcode->last));
202 else
203 nr += lf_putint (file, bits->value);
204 }
205 nr += print_opcode_bits (file, bits->next);
206 return nr;
207 }
208
209 static int
210 print_c_name (lf *file,
211 const char *name)
212 {
213 int nr = 0;
214 const char *pos;
215 for (pos = name; *pos != '\0'; pos++)
216 {
217 switch (*pos)
218 {
219 case '/':
220 case '-':
221 break;
222 case ' ':
223 case '.':
224 nr += lf_putchr (file, '_');
225 break;
226 default:
227 nr += lf_putchr (file, *pos);
228 break;
229 }
230 }
231 return nr;
232 }
233
234 extern int
235 print_function_name (lf *file,
236 const char *basename,
237 const char *format_name,
238 const char *model_name,
239 opcode_bits *expanded_bits,
240 lf_function_name_prefixes prefix)
241 {
242 int nr = 0;
243 /* the prefix */
244 switch (prefix)
245 {
246 case function_name_prefix_semantics:
247 nr += lf_printf (file, "%s", options.module.semantics.prefix.l);
248 nr += lf_printf (file, "semantic_");
249 break;
250 case function_name_prefix_idecode:
251 nr += lf_printf (file, "%s", options.module.idecode.prefix.l);
252 nr += lf_printf (file, "idecode_");
253 break;
254 case function_name_prefix_itable:
255 nr += lf_printf (file, "%sitable_", options.module.itable.prefix.l);
256 break;
257 case function_name_prefix_icache:
258 nr += lf_printf (file, "%s", options.module.icache.prefix.l);
259 nr += lf_printf (file, "icache_");
260 break;
261 case function_name_prefix_engine:
262 nr += lf_printf (file, "%s", options.module.engine.prefix.l);
263 nr += lf_printf (file, "engine_");
264 default:
265 break;
266 }
267
268 if (model_name != NULL)
269 {
270 nr += print_c_name (file, model_name);
271 nr += lf_printf (file, "_");
272 }
273
274 /* the function name */
275 nr += print_c_name (file, basename);
276
277 /* the format name if available */
278 if (format_name != NULL)
279 {
280 nr += lf_printf (file, "_");
281 nr += print_c_name (file, format_name);
282 }
283
284 /* the suffix */
285 nr += print_opcode_bits (file, expanded_bits);
286
287 return nr;
288 }
289
290
291 void
292 print_my_defines (lf *file,
293 const char *basename,
294 const char *format_name,
295 opcode_bits *expanded_bits)
296 {
297 /* #define MY_INDEX xxxxx */
298 lf_indent_suppress (file);
299 lf_printf (file, "#undef MY_INDEX\n");
300 lf_indent_suppress (file);
301 lf_printf (file, "#define MY_INDEX ");
302 print_function_name (file,
303 basename, format_name, NULL,
304 NULL,
305 function_name_prefix_itable);
306 lf_printf (file, "\n");
307 /* #define MY_PREFIX xxxxxx */
308 lf_indent_suppress (file);
309 lf_printf (file, "#undef ");
310 print_function_name (file,
311 basename, format_name, NULL,
312 expanded_bits,
313 function_name_prefix_none);
314 lf_printf (file, "\n");
315 lf_indent_suppress (file);
316 lf_printf (file, "#undef MY_PREFIX\n");
317 lf_indent_suppress (file);
318 lf_printf (file, "#define MY_PREFIX ");
319 print_function_name (file,
320 basename, format_name, NULL,
321 expanded_bits,
322 function_name_prefix_none);
323 lf_printf (file, "\n");
324 /* #define MY_NAME xxxxxx */
325 lf_indent_suppress (file);
326 lf_indent_suppress (file);
327 lf_printf (file, "#undef MY_NAME\n");
328 lf_indent_suppress (file);
329 lf_printf (file, "#define MY_NAME \"");
330 print_function_name (file,
331 basename, format_name, NULL,
332 expanded_bits,
333 function_name_prefix_none);
334 lf_printf (file, "\"\n");
335 }
336
337
338 static int
339 print_itrace_prefix (lf *file)
340 {
341 const char *prefix = "trace_prefix (";
342 int indent = strlen (prefix);
343 lf_printf (file, "%sSD, CPU, cia, CIA, TRACE_LINENUM_P (CPU), \\\n", prefix);
344 lf_indent (file, +indent);
345 lf_printf (file, "%sitable[MY_INDEX].file, \\\n", options.module.itable.prefix.l);
346 lf_printf (file, "%sitable[MY_INDEX].line_nr, \\\n", options.module.itable.prefix.l);
347 lf_printf (file, "\"");
348 return indent;
349 }
350
351
352 static void
353 print_itrace_format (lf *file,
354 insn_mnemonic_entry *assembler)
355 {
356 /* pass=1 is fmt string; pass=2 is arguments */
357 int pass;
358 /* print the format string */
359 for (pass = 1; pass <= 2; pass++)
360 {
361 const char *chp = assembler->format;
362 chp++; /* skip the leading quote */
363 /* write out the format/args */
364 while (*chp != '\0')
365 {
366 if (chp[0] == '\\' && (chp[1] == '<' || chp[1] == '>'))
367 {
368 if (pass == 1)
369 lf_putchr (file, chp[1]);
370 chp += 2;
371 }
372 else if (chp[0] == '<' || chp[0] == '%')
373 {
374 /* parse [ "%" ... ] "<" [ func "#" ] param ">" */
375 const char *fmt;
376 const char *func;
377 int strlen_func;
378 const char *param;
379 int strlen_param;
380 /* the "%" ... "<" format */
381 fmt = chp;
382 while (chp[0] != '<' && chp[0] != '\0')
383 chp++;
384 if (chp[0] != '<')
385 error (assembler->line, "Missing `<' after `%%'\n");
386 chp++;
387 /* [ "func" # ] OR "param" */
388 func = chp;
389 param = chp;
390 while (chp[0] != '>' && chp[0] != '#' && chp[0] != '\0')
391 chp++;
392 strlen_func = chp - func;
393 if (chp[0] == '#')
394 {
395 chp++;
396 param = chp;
397 while (chp[0] != '>' && chp[0] != '\0')
398 chp++;
399 }
400 strlen_param = chp - param;
401 if (chp[0] != '>')
402 error (assembler->line, "Missing closing `>' in assembler string\n");
403 chp++;
404 /* now process it */
405 if (pass == 2)
406 lf_printf (file, ", \\\n");
407 if (strncmp (fmt, "<", 1) == 0)
408 /* implicit long int format */
409 {
410 if (pass == 1)
411 lf_printf (file, "%%ld");
412 else
413 {
414 lf_printf (file, "(long) ");
415 lf_write (file, param, strlen_param);
416 }
417 }
418 else if (strncmp (fmt, "%<", 2) == 0)
419 /* explicit format */
420 {
421 if (pass == 1)
422 lf_printf (file, "%%");
423 else
424 lf_write (file, param, strlen_param);
425 }
426 else if (strncmp (fmt, "%s<", 3) == 0)
427 /* string format */
428 {
429 if (pass == 1)
430 lf_printf (file, "%%s");
431 else
432 {
433 lf_printf (file, "%sstr_", options.module.global.prefix.l);
434 lf_write (file, func, strlen_func);
435 lf_printf (file, " (SD_, ");
436 lf_write (file, param, strlen_param);
437 lf_printf (file, ")");
438 }
439 }
440 else if (strncmp (fmt, "%lx<", 4) == 0)
441 /* simple hex */
442 {
443 if (pass == 1)
444 lf_printf (file, "%%lx");
445 else
446 {
447 lf_printf (file, "(unsigned long) ");
448 lf_write (file, param, strlen_param);
449 }
450 }
451 else if (strncmp (fmt, "%#lx<", 5) == 0)
452 /* simple hex with 0x prefix*/
453 {
454 if (pass == 1)
455 lf_printf (file, "%%#lx");
456 else
457 {
458 lf_printf (file, "(unsigned long) ");
459 lf_write (file, param, strlen_param);
460 }
461 }
462 else if (strncmp (fmt, "%08lx<", 6) == 0)
463 /* simple hex */
464 {
465 if (pass == 1)
466 lf_printf (file, "%%08lx");
467 else
468 {
469 lf_printf (file, "(unsigned long) ");
470 lf_write (file, param, strlen_param);
471 }
472 }
473 else
474 error (assembler->line, "Unknown assembler string format\n");
475 }
476 else
477 {
478 if (pass == 1)
479 lf_putchr (file, chp[0]);
480 chp += 1;
481 }
482 }
483 }
484 lf_printf (file, ");\n");
485 }
486
487
488 void
489 print_itrace (lf *file,
490 insn_entry *insn,
491 int idecode)
492 {
493 /* NB: Here we escape each EOLN. This is so that the the compiler
494 treats a trace function call as a single line. Consequently any
495 errors in the line are refered back to the same igen assembler
496 source line */
497 const char *phase = (idecode) ? "DECODE" : "INSN";
498 lf_printf (file, "\n");
499 lf_indent_suppress (file);
500 lf_printf (file, "#if defined (WITH_TRACE)\n");
501 lf_printf (file, "/* generate a trace prefix if any tracing enabled */\n");
502 lf_printf (file, "if (TRACE_ANY_P (CPU))\n");
503 lf_printf (file, " {\n");
504 lf_indent (file, +4);
505 {
506 if (insn->mnemonics != NULL)
507 {
508 insn_mnemonic_entry *assembler = insn->mnemonics;
509 int is_first = 1;
510 do
511 {
512 if (assembler->condition != NULL)
513 {
514 int indent;
515 lf_printf (file, "%sif (%s)\n",
516 is_first ? "" : "else ",
517 assembler->condition);
518 lf_indent (file, +2);
519 lf_print__line_ref (file, assembler->line);
520 indent = print_itrace_prefix (file);
521 print_itrace_format (file, assembler);
522 lf_print__internal_ref (file);
523 lf_indent (file, -indent);
524 lf_indent (file, -2);
525 if (assembler->next == NULL)
526 error (assembler->line, "Missing final unconditional assembler\n");
527 }
528 else
529 {
530 int indent;
531 if (!is_first)
532 {
533 lf_printf (file, "else\n");
534 lf_indent (file, +2);
535 }
536 lf_print__line_ref (file, assembler->line);
537 indent = print_itrace_prefix (file);
538 print_itrace_format (file, assembler);
539 lf_print__internal_ref (file);
540 lf_indent (file, -indent);
541 if (!is_first)
542 lf_indent (file, -2);
543 if (assembler->next != NULL)
544 error (assembler->line, "Unconditional assembler is not last\n");
545 }
546 is_first = 0;
547 assembler = assembler->next;
548 }
549 while (assembler != NULL);
550 }
551 else
552 {
553 int indent;
554 lf_indent (file, +2);
555 lf_print__line_ref (file, insn->line);
556 indent = print_itrace_prefix (file);
557 lf_printf (file, "%%s\", \\\n");
558 lf_printf (file, "itable[MY_INDEX].name);\n");
559 lf_print__internal_ref (file);
560 lf_indent (file, -indent);
561 lf_indent (file, -2);
562 }
563 lf_printf (file, "/* trace the instruction execution if enabled */\n");
564 lf_printf (file, "if (TRACE_%s_P (CPU))\n", phase);
565 lf_printf (file, " trace_generic (SD, CPU, TRACE_%s_IDX, \" %%s\", itable[MY_INDEX].name);\n", phase);
566 }
567 lf_indent (file, -4);
568 lf_printf (file, " }\n");
569 lf_indent_suppress (file);
570 lf_printf (file, "#endif\n");
571 }
572
573
574 void
575 print_sim_engine_abort (lf *file,
576 const char *message)
577 {
578 lf_printf (file, "sim_engine_abort (SD, CPU, cia, ");
579 lf_printf (file, "\"%s\"", message);
580 lf_printf (file, ");\n");
581 }
582
583
584 void
585 print_include (lf *file,
586 igen_module module)
587 {
588 lf_printf (file, "#include \"%s%s.h\"\n", module.prefix.l, module.suffix.l);
589 }
590
591 void
592 print_include_inline (lf *file,
593 igen_module module)
594 {
595 lf_printf (file, "#if C_REVEALS_MODULE_P (%s_INLINE)\n", module.suffix.u);
596 lf_printf (file, "#include \"%s%s.c\"\n", module.prefix.l, module.suffix.l);
597 lf_printf (file, "#else\n");
598 print_include (file, module);
599 lf_printf (file, "#endif\n");
600 lf_printf (file, "\n");
601 }
602
603 void
604 print_includes (lf *file)
605 {
606 lf_printf (file, "\n");
607 lf_printf (file, "#include \"sim-inline.c\"\n");
608 lf_printf (file, "\n");
609 print_include_inline (file, options.module.itable);
610 print_include_inline (file, options.module.idecode);
611 print_include_inline (file, options.module.support);
612 }
613
614
615 /****************************************************************/
616
617
618 static void
619 gen_semantics_h (lf *file,
620 insn_list *semantics,
621 int max_nr_words)
622 {
623 int word_nr;
624 insn_list *semantic;
625 for (word_nr = -1; word_nr <= max_nr_words; word_nr++)
626 {
627 lf_printf (file, "typedef ");
628 print_semantic_function_type (file);
629 lf_printf (file, " %sidecode_semantic",
630 options.module.global.prefix.l);
631 if (word_nr >= 0)
632 lf_printf (file, "_%d", word_nr);
633 lf_printf (file, "\n(");
634 lf_indent (file, +1);
635 print_semantic_function_formal (file, word_nr);
636 lf_indent (file, -1);
637 lf_printf (file, ");\n");
638 lf_printf (file, "\n");
639 }
640 switch (options.gen.code)
641 {
642 case generate_calls:
643 for (semantic = semantics; semantic != NULL; semantic = semantic->next)
644 {
645 /* Ignore any special/internal instructions */
646 if (semantic->insn->nr_words == 0)
647 continue;
648 print_semantic_declaration (file,
649 semantic->insn,
650 semantic->expanded_bits,
651 semantic->opcodes,
652 semantic->nr_prefetched_words);
653 }
654 break;
655 case generate_jumps:
656 lf_print__this_file_is_empty (file, "generating jumps");
657 break;
658 }
659 }
660
661
662 static void
663 gen_semantics_c (lf *file,
664 insn_list *semantics,
665 cache_entry *cache_rules)
666 {
667 if (options.gen.code == generate_calls)
668 {
669 insn_list *semantic;
670 print_includes (file);
671 print_include (file, options.module.semantics);
672 lf_printf (file, "\n");
673
674 for (semantic = semantics; semantic != NULL; semantic = semantic->next)
675 {
676 /* Ignore any special/internal instructions */
677 if (semantic->insn->nr_words == 0)
678 continue;
679 print_semantic_definition (file,
680 semantic->insn,
681 semantic->expanded_bits,
682 semantic->opcodes,
683 cache_rules,
684 semantic->nr_prefetched_words);
685 }
686 }
687 else
688 {
689 lf_print__this_file_is_empty (file, "generating jump engine");
690 }
691 }
692
693
694 /****************************************************************/
695
696
697 static void
698 gen_icache_h (lf *file,
699 insn_list *semantic,
700 function_entry *functions,
701 int max_nr_words)
702 {
703 int word_nr;
704 for (word_nr = 0; word_nr <= max_nr_words; word_nr++)
705 {
706 lf_printf (file, "typedef ");
707 print_icache_function_type(file);
708 lf_printf (file, " %sidecode_icache_%d\n(",
709 options.module.global.prefix.l,
710 word_nr);
711 print_icache_function_formal(file, word_nr);
712 lf_printf (file, ");\n");
713 lf_printf (file, "\n");
714 }
715 if (options.gen.code == generate_calls
716 && options.gen.icache)
717 {
718 function_entry_traverse (file, functions,
719 print_icache_internal_function_declaration,
720 NULL);
721 while (semantic != NULL)
722 {
723 print_icache_declaration (file,
724 semantic->insn,
725 semantic->expanded_bits,
726 semantic->opcodes,
727 semantic->nr_prefetched_words);
728 semantic = semantic->next;
729 }
730 }
731 else
732 {
733 lf_print__this_file_is_empty (file, "generating jump engine");
734 }
735 }
736
737 static void
738 gen_icache_c (lf *file,
739 insn_list *semantic,
740 function_entry *functions,
741 cache_entry *cache_rules)
742 {
743 /* output `internal' invalid/floating-point unavailable functions
744 where needed */
745 if (options.gen.code == generate_calls
746 && options.gen.icache)
747 {
748 lf_printf (file, "\n");
749 lf_printf (file, "#include \"cpu.h\"\n");
750 lf_printf (file, "#include \"idecode.h\"\n");
751 lf_printf (file, "#include \"semantics.h\"\n");
752 lf_printf (file, "#include \"icache.h\"\n");
753 lf_printf (file, "#include \"support.h\"\n");
754 lf_printf (file, "\n");
755 function_entry_traverse (file, functions,
756 print_icache_internal_function_definition,
757 NULL);
758 lf_printf (file, "\n");
759 while (semantic != NULL)
760 {
761 print_icache_definition (file,
762 semantic->insn,
763 semantic->expanded_bits,
764 semantic->opcodes,
765 cache_rules,
766 semantic->nr_prefetched_words);
767 semantic = semantic->next;
768 }
769 }
770 else
771 {
772 lf_print__this_file_is_empty (file, "generating jump engine");
773 }
774 }
775
776
777 /****************************************************************/
778
779
780 static void
781 gen_idecode_h (lf *file,
782 gen_table *gen,
783 insn_table *insns,
784 cache_entry *cache_rules)
785 {
786 lf_printf (file, "typedef unsigned%d %sinstruction_word;\n",
787 options.insn_bit_size, options.module.global.prefix.l);
788 if (options.gen.delayed_branch)
789 {
790 lf_printf (file, "typedef struct _%sinstruction_address {\n",
791 options.module.global.prefix.l);
792 lf_printf (file, " address_word ip; /* instruction pointer */\n");
793 lf_printf (file, " address_word dp; /* delayed-slot pointer */\n");
794 lf_printf (file, "} %sinstruction_address;\n", options.module.global.prefix.l);
795 }
796 else
797 {
798 lf_printf (file, "typedef address_word %sinstruction_address;\n",
799 options.module.global.prefix.l);
800
801 }
802 if (options.gen.nia == nia_is_invalid
803 && strlen (options.module.global.prefix.u) > 0)
804 {
805 lf_indent_suppress (file);
806 lf_printf (file, "#define %sINVALID_INSTRUCTION_ADDRESS ",
807 options.module.global.prefix.u);
808 lf_printf (file, "INVALID_INSTRUCTION_ADDRESS\n");
809 }
810 lf_printf (file, "\n");
811 print_icache_struct (file, insns, cache_rules);
812 lf_printf (file, "\n");
813 if (options.gen.icache)
814 {
815 ERROR ("FIXME - idecode with icache suffering from bit-rot");
816 }
817 else
818 {
819 gen_list *entry;
820 for (entry = gen->tables; entry != NULL; entry = entry->next)
821 {
822 print_idecode_issue_function_header (file,
823 (options.gen.multi_sim
824 ? entry->model->name
825 : NULL),
826 is_function_declaration,
827 1/*ALWAYS ONE WORD*/);
828 }
829 if (options.gen.multi_sim)
830 {
831 print_idecode_issue_function_header (file,
832 NULL,
833 is_function_variable,
834 1/*ALWAYS ONE WORD*/);
835 }
836 }
837 }
838
839
840 static void
841 gen_idecode_c (lf *file,
842 gen_table *gen,
843 insn_table *isa,
844 cache_entry *cache_rules)
845 {
846 /* the intro */
847 print_includes (file);
848 print_include_inline (file, options.module.semantics);
849 lf_printf (file, "\n");
850
851 print_idecode_globals (file);
852 lf_printf (file, "\n");
853
854 switch (options.gen.code)
855 {
856 case generate_calls:
857 {
858 gen_list *entry;
859 for (entry = gen->tables; entry != NULL; entry = entry->next)
860 {
861 print_idecode_lookups (file, entry->table, cache_rules);
862
863 /* output the main idecode routine */
864 if (!options.gen.icache)
865 {
866 print_idecode_issue_function_header (file,
867 (options.gen.multi_sim
868 ? entry->model->name
869 : NULL),
870 1/*is definition*/,
871 1/*ALWAYS ONE WORD*/);
872 lf_printf (file, "{\n");
873 lf_indent (file, +2);
874 lf_printf (file, "%sinstruction_address nia;\n",
875 options.module.global.prefix.l);
876 print_idecode_body (file, entry->table, "nia =");
877 lf_printf (file, "return nia;");
878 lf_indent (file, -2);
879 lf_printf (file, "}\n");
880 }
881 }
882 break;
883 }
884 case generate_jumps:
885 {
886 lf_print__this_file_is_empty (file, "generating a jump engine");
887 break;
888 }
889 }
890 }
891
892
893 /****************************************************************/
894
895
896 static void
897 gen_run_c (lf *file,
898 gen_table *gen)
899 {
900 gen_list *entry;
901 lf_printf (file, "#include \"sim-main.h\"\n");
902 lf_printf (file, "#include \"engine.h\"\n");
903 lf_printf (file, "#include \"idecode.h\"\n");
904 lf_printf (file, "#include \"bfd.h\"\n");
905 lf_printf (file, "\n");
906
907 if (options.gen.multi_sim)
908 {
909 print_idecode_issue_function_header (file, NULL, is_function_variable, 1);
910 lf_printf (file, "\n");
911 print_engine_run_function_header (file, NULL, is_function_variable);
912 lf_printf (file, "\n");
913 }
914
915 lf_printf (file, "void\n");
916 lf_printf (file, "sim_engine_run (SIM_DESC sd,\n");
917 lf_printf (file, " int next_cpu_nr,\n");
918 lf_printf (file, " int nr_cpus,\n");
919 lf_printf (file, " int siggnal)\n");
920 lf_printf (file, "{\n");
921 lf_indent (file, +2);
922 if (options.gen.multi_sim)
923 {
924 lf_printf (file, "int mach;\n");
925 lf_printf (file, "if (STATE_ARCHITECTURE (sd) == NULL)\n");
926 lf_printf (file, " mach = 0;\n");
927 lf_printf (file, "else\n");
928 lf_printf (file, " mach = STATE_ARCHITECTURE (sd)->mach;\n");
929 lf_printf (file, "switch (mach)\n");
930 lf_printf (file, " {\n");
931 lf_indent (file, +2);
932 for (entry = gen->tables; entry != NULL; entry = entry->next)
933 {
934 if (options.gen.default_model != NULL
935 && (strcmp (entry->model->name, options.gen.default_model) == 0
936 || strcmp (entry->model->full_name, options.gen.default_model) == 0))
937 lf_printf (file, "default:\n");
938 lf_printf (file, "case bfd_mach_%s:\n", entry->model->full_name);
939 lf_indent (file, +2);
940 print_function_name (file,
941 "issue",
942 NULL, /* format name */
943 NULL, /* NO processor */
944 NULL, /* expanded bits */
945 function_name_prefix_idecode);
946 lf_printf (file, " = ");
947 print_function_name (file,
948 "issue",
949 NULL, /* format name */
950 entry->model->name,
951 NULL, /* expanded bits */
952 function_name_prefix_idecode);
953 lf_printf (file, ";\n");
954 print_function_name (file,
955 "run",
956 NULL, /* format name */
957 NULL, /* NO processor */
958 NULL, /* expanded bits */
959 function_name_prefix_engine);
960 lf_printf (file, " = ");
961 print_function_name (file,
962 "run",
963 NULL, /* format name */
964 entry->model->name,
965 NULL, /* expanded bits */
966 function_name_prefix_engine);
967 lf_printf (file, ";\n");
968 lf_printf (file, "break;\n");
969 lf_indent (file, -2);
970 }
971 if (options.gen.default_model == NULL)
972 {
973 lf_printf (file, "default:\n");
974 lf_indent (file, +2);
975 lf_printf (file, "sim_engine_abort (sd, NULL, NULL_CIA,\n");
976 lf_printf (file, " \"sim_engine_run - unknown machine\");\n");
977 lf_printf (file, "break;\n");
978 lf_indent (file, -2);
979 }
980 lf_indent (file, -2);
981 lf_printf (file, " }\n");
982 }
983 print_function_name (file,
984 "run",
985 NULL, /* format name */
986 NULL, /* NO processor */
987 NULL, /* expanded bits */
988 function_name_prefix_engine);
989 lf_printf (file, " (sd, next_cpu_nr, nr_cpus, siggnal);\n");
990 lf_indent (file, -2);
991 lf_printf (file, "}\n");
992 }
993
994 /****************************************************************/
995
996 static gen_table *
997 do_gen (insn_table *isa,
998 decode_table *decode_rules)
999 {
1000 gen_table *gen;
1001 if (decode_rules == NULL)
1002 error (NULL, "Must specify a decode table\n");
1003 if (isa == NULL)
1004 error (NULL, "Must specify an instruction table\n");
1005 if (decode_table_max_word_nr (decode_rules) > 0)
1006 options.gen.multi_word = decode_table_max_word_nr (decode_rules);
1007 gen = make_gen_tables (isa, decode_rules);
1008 gen_tables_expand_insns (gen);
1009 gen_tables_expand_semantics (gen);
1010 return gen;
1011 }
1012
1013 /****************************************************************/
1014
1015 igen_options options;
1016
1017 int
1018 main (int argc,
1019 char **argv,
1020 char **envp)
1021 {
1022 cache_entry *cache_rules = NULL;
1023 lf_file_references file_references = lf_include_references;
1024 decode_table *decode_rules = NULL;
1025 insn_table *isa = NULL;
1026 gen_table *gen = NULL;
1027 char *real_file_name = NULL;
1028 int is_header = 0;
1029 int ch;
1030 lf *standard_out = lf_open ("-", "stdout", lf_omit_references, lf_is_text, "igen");
1031
1032 INIT_OPTIONS ();
1033
1034 if (argc == 1)
1035 {
1036 printf ("Usage:\n");
1037 printf ("\n");
1038 printf (" igen <config-opts> ... <input-opts>... <output-opts>...\n");
1039 printf ("\n");
1040 printf ("Config options:\n");
1041 printf ("\n");
1042 printf (" -B <bit-size>\n");
1043 printf ("\t Set the number of bits in an instruction (deprecated).\n");
1044 printf ("\t This option can now be set directly in the instruction table.\n");
1045 printf ("\n");
1046 printf (" -D <data-structure>\n");
1047 printf ("\t Dump the specified data structure to stdout. Valid structures include:\n");
1048 printf ("\t processor-names - list the names of all the processors (models)\n");
1049 printf ("\n");
1050 printf (" -F <filter-list>\n");
1051 printf ("\t Filter out any instructions with a non-empty flags field that contains\n");
1052 printf ("\t a flag not listed in the <filter-list>.\n");
1053 printf ("\n");
1054 printf (" -H <high-bit>\n");
1055 printf ("\t Set the number of the high (most significant) instruction bit (deprecated).\n");
1056 printf ("\t This option can now be set directly in the instruction table.\n");
1057 printf ("\n");
1058 printf (" -I <directory>\n");
1059 printf ("\t Add <directory> to the list of directories searched when opening a file\n");
1060 printf ("\n");
1061 printf (" -M <model-list>\n");
1062 printf ("\t Filter out any instructions that do not support at least one of the listed\n");
1063 printf ("\t models (An instructions with no model information is considered to support\n");
1064 printf ("\t all models.).\n");
1065 printf ("\n");
1066 printf (" -N <nr-cpus>\n");
1067 printf ("\t Generate a simulator supporting <nr-cpus>\n");
1068 printf ("\t Specify `-N 0' to disable generation of the SMP. Specifying `-N 1' will\n");
1069 printf ("\t still generate an SMP enabled simulator but will only support one CPU.\n");
1070 printf ("\n");
1071 printf (" -T <mechanism>\n");
1072 printf ("\t Override the decode mechanism specified by the decode rules\n");
1073 printf ("\n");
1074 printf (" -P <prefix>\n");
1075 printf ("\t Prepend global names (except itable) with the string <prefix>.\n");
1076 printf ("\t Specify -P <module>=<prefix> to set a specific <module>'s prefix.\n");
1077 printf ("\n");
1078 printf (" -S <suffix>\n");
1079 printf ("\t Replace a global name (suffix) (except itable) with the string <suffix>.\n");
1080 printf ("\t Specify -S <module>=<suffix> to change a specific <module>'s name (suffix).\n");
1081 printf ("\n");
1082 printf (" -Werror\n");
1083 printf ("\t Make warnings errors\n");
1084 printf (" -Wnodiscard\n");
1085 printf ("\t Suppress warnings about discarded functions and instructions\n");
1086 printf (" -Wnowidth\n");
1087 printf ("\t Suppress warnings about instructions with invalid widths\n");
1088 printf (" -Wnounimplemented\n");
1089 printf ("\t Suppress warnings about unimplemented instructions\n");
1090 printf ("\n");
1091 printf (" -G [!]<gen-option>\n");
1092 printf ("\t Any of the following options:\n");
1093 printf ("\n");
1094 printf ("\t decode-duplicate - Override the decode rules, forcing the duplication of\n");
1095 printf ("\t semantic functions\n");
1096 printf ("\t decode-combine - Combine any duplicated entries within a table\n");
1097 printf ("\t decode-zero-reserved - Override the decode rules, forcing reserved bits to be\n");
1098 printf ("\t treated as zero.\n");
1099 printf ("\t decode-switch-is-goto - Overfide the padded-switch code type as a goto-switch\n");
1100 printf ("\n");
1101 printf ("\t gen-conditional-issue - conditionally issue each instruction\n");
1102 printf ("\t gen-delayed-branch - need both cia and nia passed around\n");
1103 printf ("\t gen-direct-access - use #defines to directly access values\n");
1104 printf ("\t gen-zero-r<N> - arch assumes GPR(<N>) == 0, keep it that way\n");
1105 printf ("\t gen-icache[=<N> - generate an instruction cracking cache of size <N>\n");
1106 printf ("\t Default size is %d\n", options.gen.icache_size);
1107 printf ("\t gen-insn-in-icache - save original instruction when cracking\n");
1108 printf ("\t gen-multi-sim[=MODEL] - generate multiple simulators - one per model\n");
1109 printf ("\t If specified MODEL is made the default architecture.\n");
1110 printf ("\t By default, a single simulator that will\n");
1111 printf ("\t execute any instruction is generated\n");
1112 printf ("\t gen-multi-word - generate code allowing for multi-word insns\n");
1113 printf ("\t gen-semantic-icache - include semantic code in cracking functions\n");
1114 printf ("\t gen-slot-verification - perform slot verification as part of decode\n");
1115 printf ("\t gen-nia-invalid - NIA defaults to nia_invalid\n");
1116 printf ("\t gen-nia-void - do not compute/return NIA\n");
1117 printf ("\n");
1118 printf ("\t trace-combine - report combined entries a rule application\n");
1119 printf ("\t trace-entries - report entries after a rules application\n");
1120 printf ("\t trace-rule-rejection - report each rule as rejected\n");
1121 printf ("\t trace-rule-selection - report each rule as selected\n");
1122 printf ("\t trace-insn-insertion - report each instruction as it is inserted into a decode table\n");
1123 printf ("\t trace-rule-expansion - report each instruction as it is expanded (before insertion into a decode table)\n");
1124 printf ("\t trace-all - enable all trace options\n");
1125 printf ("\n");
1126 printf ("\t field-widths - instruction formats specify widths (deprecated)\n");
1127 printf ("\t By default, an instruction format specifies bit\n");
1128 printf ("\t positions\n");
1129 printf ("\t This option can now be set directly in the\n");
1130 printf ("\t instruction table\n");
1131 printf ("\t jumps - use jumps instead of function calls\n");
1132 printf ("\t omit-line-numbers - do not include line number information in the output\n");
1133 printf ("\n");
1134 printf ("Input options:\n");
1135 printf ("\n");
1136 printf (" -k <cache-rules> (deprecated)\n");
1137 printf (" -o <decode-rules>\n");
1138 printf (" -i <instruction-table>\n");
1139 printf ("\n");
1140 printf ("Output options:\n");
1141 printf ("\n");
1142 printf (" -x Perform expansion (required)\n");
1143 printf (" -n <real-name> Specify the real name of the next output file\n");
1144 printf (" -h Generate the header (.h) file rather than the body (.c)\n");
1145 printf (" -c <output-file> output icache\n");
1146 printf (" -d <output-file> output idecode\n");
1147 printf (" -e <output-file> output engine\n");
1148 printf (" -f <output-file> output support functions\n");
1149 printf (" -m <output-file> output model\n");
1150 printf (" -r <output-file> output multi-sim run\n");
1151 printf (" -s <output-file> output schematic\n");
1152 printf (" -t <output-file> output itable\n");
1153 }
1154
1155 while ((ch = getopt(argc, argv,
1156 "B:D:F:G:H:I:M:N:P:T:W:o:k:i:n:hc:d:e:m:r:s:t:f:x"))
1157 != -1)
1158 {
1159 fprintf (stderr, " -%c ", ch);
1160 if (optarg)
1161 fprintf (stderr, "%s ", optarg);
1162 fprintf (stderr, "\\\n");
1163
1164 switch(ch)
1165 {
1166
1167 case 'M':
1168 filter_parse (&options.model_filter, optarg);
1169 break;
1170
1171 case 'D':
1172 if (strcmp (optarg, "processor-names"))
1173 {
1174 char *processor;
1175 for (processor = filter_next (options.model_filter, "");
1176 processor != NULL;
1177 processor = filter_next (options.model_filter, processor))
1178 lf_printf (standard_out, "%s\n", processor);
1179 }
1180 else
1181 error (NULL, "Unknown data structure %s, not dumped\n", optarg);
1182 break;
1183
1184 case 'F':
1185 filter_parse (&options.flags_filter, optarg);
1186 break;
1187
1188 case 'I':
1189 {
1190 table_include **dir = &options.include;
1191 while ((*dir) != NULL)
1192 dir = &(*dir)->next;
1193 (*dir) = ZALLOC (table_include);
1194 (*dir)->dir = strdup (optarg);
1195 }
1196 break;
1197
1198 case 'B':
1199 options.insn_bit_size = a2i (optarg);
1200 if (options.insn_bit_size <= 0
1201 || options.insn_bit_size > max_insn_bit_size)
1202 {
1203 error (NULL, "Instruction bitsize must be in range 1..%d\n",
1204 max_insn_bit_size);
1205 }
1206 if (options.hi_bit_nr != options.insn_bit_size - 1
1207 && options.hi_bit_nr != 0)
1208 {
1209 error (NULL, "Conflict betweem hi-bit-nr and insn-bit-size\n");
1210 }
1211 break;
1212
1213 case 'H':
1214 options.hi_bit_nr = a2i (optarg);
1215 if (options.hi_bit_nr != options.insn_bit_size - 1
1216 && options.hi_bit_nr != 0)
1217 {
1218 error (NULL, "Conflict between hi-bit-nr and insn-bit-size\n");
1219 }
1220 break;
1221
1222 case 'N':
1223 options.gen.smp = a2i (optarg);
1224 break;
1225
1226 case 'P':
1227 case 'S':
1228 {
1229 igen_module *names;
1230 igen_name *name;
1231 char *chp;
1232 chp = strchr (optarg, '=');
1233 if (chp == NULL)
1234 {
1235 names = &options.module.global;
1236 chp = optarg;
1237 }
1238 else
1239 {
1240 chp = chp + 1; /* skip `=' */
1241 names = NULL;
1242 if (strncmp (optarg, "global=", chp - optarg) == 0)
1243 {
1244 names = &options.module.global;
1245 }
1246 if (strncmp (optarg, "engine=", chp - optarg) == 0)
1247 {
1248 names = &options.module.engine;
1249 }
1250 if (strncmp (optarg, "icache=", chp - optarg) == 0)
1251 {
1252 names = &options.module.icache;
1253 }
1254 if (strncmp (optarg, "idecode=", chp - optarg) == 0)
1255 {
1256 names = &options.module.idecode;
1257 }
1258 if (strncmp (optarg, "itable=", chp - optarg) == 0)
1259 {
1260 names = &options.module.itable;
1261 }
1262 if (strncmp (optarg, "semantics=", chp - optarg) == 0)
1263 {
1264 names = &options.module.semantics;
1265 }
1266 if (strncmp (optarg, "support=", chp - optarg) == 0)
1267 {
1268 names = &options.module.support;
1269 }
1270 if (names == NULL)
1271 {
1272 error (NULL, "Prefix `%s' unreconized\n", optarg);
1273 }
1274 }
1275 switch (ch)
1276 {
1277 case 'P':
1278 name = &names->prefix;
1279 break;
1280 case 'S':
1281 name = &names->suffix;
1282 break;
1283 default:
1284 abort (); /* Bad switch. */
1285 }
1286 name->u = strdup (chp);
1287 name->l = strdup (chp);
1288 chp = name->u;
1289 while (*chp) {
1290 if (islower(*chp))
1291 *chp = toupper(*chp);
1292 chp++;
1293 }
1294 if (name == &options.module.global.prefix)
1295 {
1296 options.module.engine.prefix = options.module.global.prefix;
1297 options.module.icache.prefix = options.module.global.prefix;
1298 options.module.idecode.prefix = options.module.global.prefix;
1299 /* options.module.itable.prefix = options.module.global.prefix; */
1300 options.module.semantics.prefix = options.module.global.prefix;
1301 options.module.support.prefix = options.module.global.prefix;
1302 }
1303 if (name == &options.module.global.suffix)
1304 {
1305 options.module.engine.suffix = options.module.global.suffix;
1306 options.module.icache.suffix = options.module.global.suffix;
1307 options.module.idecode.suffix = options.module.global.suffix;
1308 /* options.module.itable.suffix = options.module.global.suffix; */
1309 options.module.semantics.suffix = options.module.global.suffix;
1310 options.module.support.suffix = options.module.global.suffix;
1311 }
1312 break;
1313 }
1314
1315 case 'W':
1316 {
1317 if (strcmp (optarg, "error") == 0)
1318 options.warning = error;
1319 else if (strcmp (optarg, "nodiscard") == 0)
1320 options.warn.discard = 0;
1321 else if (strcmp (optarg, "discard") == 0)
1322 options.warn.discard = 1;
1323 else if (strcmp (optarg, "nowidth") == 0)
1324 options.warn.width = 0;
1325 else if (strcmp (optarg, "width") == 0)
1326 options.warn.width = 1;
1327 else if (strcmp (optarg, "nounimplemented") == 0)
1328 options.warn.unimplemented = 0;
1329 else if (strcmp (optarg, "unimplemented") == 0)
1330 options.warn.unimplemented = 1;
1331 else
1332 error (NULL, "Unknown -W argument `%s'\n", optarg);
1333 break;
1334 }
1335
1336
1337 case 'G':
1338 {
1339 int enable_p;
1340 char *argp;
1341 if (strncmp (optarg, "no-", strlen ("no-")) == 0)
1342 {
1343 argp = optarg + strlen ("no-");
1344 enable_p = 0;
1345 }
1346 else if (strncmp (optarg, "!", strlen ("!")) == 0)
1347 {
1348 argp = optarg + strlen ("no-");
1349 enable_p = 0;
1350 }
1351 else
1352 {
1353 argp = optarg;
1354 enable_p = 1;
1355 }
1356 if (strcmp (argp, "decode-duplicate") == 0)
1357 {
1358 options.decode.duplicate = enable_p;
1359 }
1360 else if (strcmp (argp, "decode-combine") == 0)
1361 {
1362 options.decode.combine = enable_p;
1363 }
1364 else if (strcmp (argp, "decode-zero-reserved") == 0)
1365 {
1366 options.decode.zero_reserved = enable_p;
1367 }
1368
1369 else if (strcmp (argp, "gen-conditional-issue") == 0)
1370 {
1371 options.gen.conditional_issue = enable_p;
1372 }
1373 else if (strcmp (argp, "conditional-issue") == 0)
1374 {
1375 options.gen.conditional_issue = enable_p;
1376 options.warning (NULL, "Option conditional-issue replaced by gen-conditional-issue\n");
1377 }
1378 else if (strcmp (argp, "gen-delayed-branch") == 0)
1379 {
1380 options.gen.delayed_branch = enable_p;
1381 }
1382 else if (strcmp (argp, "delayed-branch") == 0)
1383 {
1384 options.gen.delayed_branch = enable_p;
1385 options.warning (NULL, "Option delayed-branch replaced by gen-delayed-branch\n");
1386 }
1387 else if (strcmp (argp, "gen-direct-access") == 0)
1388 {
1389 options.gen.direct_access = enable_p;
1390 }
1391 else if (strcmp (argp, "direct-access") == 0)
1392 {
1393 options.gen.direct_access = enable_p;
1394 options.warning (NULL, "Option direct-access replaced by gen-direct-access\n");
1395 }
1396 else if (strncmp (argp, "gen-zero-r", strlen ("gen-zero-r")) == 0)
1397 {
1398 options.gen.zero_reg = enable_p;
1399 options.gen.zero_reg_nr = atoi (argp + strlen ("gen-zero-r"));
1400 }
1401 else if (strncmp (argp, "zero-r", strlen ("zero-r")) == 0)
1402 {
1403 options.gen.zero_reg = enable_p;
1404 options.gen.zero_reg_nr = atoi (argp + strlen ("zero-r"));
1405 options.warning (NULL, "Option zero-r<N> replaced by gen-zero-r<N>\n");
1406 }
1407 else if (strncmp (argp, "gen-icache", strlen ("gen-icache")) == 0)
1408 {
1409 switch (argp[strlen ("gen-icache")])
1410 {
1411 case '=':
1412 options.gen.icache_size = atoi (argp + strlen ("gen-icache") + 1);
1413 options.gen.icache = enable_p;
1414 break;
1415 case '\0':
1416 options.gen.icache = enable_p;
1417 break;
1418 default:
1419 error (NULL, "Expecting -Ggen-icache or -Ggen-icache=<N>\n");
1420 }
1421 }
1422 else if (strcmp (argp, "gen-insn-in-icache") == 0)
1423 {
1424 options.gen.insn_in_icache = enable_p;
1425 }
1426 else if (strncmp (argp, "gen-multi-sim", strlen ("gen-multi-sim")) == 0)
1427 {
1428 char *arg = &argp[strlen ("gen-multi-sim")];
1429 switch (arg[0])
1430 {
1431 case '=':
1432 options.gen.multi_sim = enable_p;
1433 options.gen.default_model = arg + 1;
1434 if (! filter_is_member (options.model_filter, options.gen.default_model))
1435 error (NULL, "multi-sim model %s unknown\n", options.gen.default_model);
1436 break;
1437 case '\0':
1438 options.gen.multi_sim = enable_p;
1439 options.gen.default_model = NULL;
1440 break;
1441 default:
1442 error (NULL, "Expecting -Ggen-multi-sim or -Ggen-multi-sim=<MODEL>\n");
1443 break;
1444 }
1445 }
1446 else if (strcmp (argp, "gen-multi-word") == 0)
1447 {
1448 options.gen.multi_word = enable_p;
1449 }
1450 else if (strcmp (argp, "gen-semantic-icache") == 0)
1451 {
1452 options.gen.semantic_icache = enable_p;
1453 }
1454 else if (strcmp (argp, "gen-slot-verification") == 0)
1455 {
1456 options.gen.slot_verification = enable_p;
1457 }
1458 else if (strcmp (argp, "verify-slot") == 0)
1459 {
1460 options.gen.slot_verification = enable_p;
1461 options.warning (NULL, "Option verify-slot replaced by gen-slot-verification\n");
1462 }
1463 else if (strcmp (argp, "gen-nia-invalid") == 0)
1464 {
1465 options.gen.nia = nia_is_invalid;
1466 }
1467 else if (strcmp (argp, "default-nia-minus-one") == 0)
1468 {
1469 options.gen.nia = nia_is_invalid;
1470 options.warning (NULL, "Option default-nia-minus-one replaced by gen-nia-invalid\n");
1471 }
1472 else if (strcmp (argp, "gen-nia-void") == 0)
1473 {
1474 options.gen.nia = nia_is_void;
1475 }
1476 else if (strcmp (argp, "trace-all") == 0)
1477 {
1478 memset (&options.trace, enable_p, sizeof (options.trace));
1479 }
1480 else if (strcmp (argp, "trace-combine") == 0)
1481 {
1482 options.trace.combine = enable_p;
1483 }
1484 else if (strcmp (argp, "trace-entries") == 0)
1485 {
1486 options.trace.entries = enable_p;
1487 }
1488 else if (strcmp (argp, "trace-rule-rejection") == 0)
1489 {
1490 options.trace.rule_rejection = enable_p;
1491 }
1492 else if (strcmp (argp, "trace-rule-selection") == 0)
1493 {
1494 options.trace.rule_selection = enable_p;
1495 }
1496 else if (strcmp (argp, "trace-insn-insertion") == 0)
1497 {
1498 options.trace.insn_insertion = enable_p;
1499 }
1500 else if (strcmp (argp, "trace-insn-expansion") == 0)
1501 {
1502 options.trace.insn_expansion = enable_p;
1503 }
1504 else if (strcmp (argp, "jumps") == 0)
1505 {
1506 options.gen.code = generate_jumps;
1507 }
1508 else if (strcmp (argp, "field-widths") == 0)
1509 {
1510 options.insn_specifying_widths = enable_p;
1511 }
1512 else if (strcmp (argp, "omit-line-numbers") == 0)
1513 {
1514 file_references = lf_omit_references;
1515 }
1516 else
1517 {
1518 error (NULL, "Unknown option %s\n", optarg);
1519 }
1520 break;
1521 }
1522
1523 case 'i':
1524 isa = load_insn_table (optarg, cache_rules);
1525 if (isa->illegal_insn == NULL)
1526 error (NULL, "illegal-instruction missing from insn table\n");
1527 break;
1528
1529 case 'x':
1530 gen = do_gen (isa, decode_rules);
1531 break;
1532
1533 case 'o':
1534 decode_rules = load_decode_table (optarg);
1535 break;
1536
1537 case 'k':
1538 if (isa != NULL)
1539 error (NULL, "Cache file must appear before the insn file\n");
1540 cache_rules = load_cache_table (optarg);
1541 break;
1542
1543 case 'n':
1544 real_file_name = strdup(optarg);
1545 break;
1546
1547 case 'h':
1548 is_header = 1;
1549 break;
1550
1551 case 'c':
1552 case 'd':
1553 case 'e':
1554 case 'f':
1555 case 'm':
1556 case 'r':
1557 case 's':
1558 case 't':
1559 {
1560 lf *file = lf_open(optarg, real_file_name, file_references,
1561 (is_header ? lf_is_h : lf_is_c),
1562 argv[0]);
1563 if (gen == NULL && ch != 't' && ch != 'm' && ch != 'f')
1564 {
1565 options.warning (NULL, "Explicitly generate tables with -x option\n");
1566 gen = do_gen (isa, decode_rules);
1567 }
1568 lf_print__file_start(file);
1569 switch (ch)
1570 {
1571 case 'm':
1572 if (is_header)
1573 gen_model_h (file, isa);
1574 else
1575 gen_model_c (file, isa);
1576 break;
1577 case 't':
1578 if (is_header)
1579 gen_itable_h (file, isa);
1580 else
1581 gen_itable_c (file, isa);
1582 break;
1583 case 'f':
1584 if (is_header)
1585 gen_support_h (file, isa);
1586 else
1587 gen_support_c (file, isa);
1588 break;
1589 case 'r':
1590 if (is_header)
1591 options.warning (NULL, "-hr option ignored\n");
1592 else
1593 gen_run_c (file, gen);
1594 break;
1595 case 's':
1596 if(is_header)
1597 gen_semantics_h (file, gen->semantics, isa->max_nr_words);
1598 else
1599 gen_semantics_c (file, gen->semantics, isa->caches);
1600 break;
1601 case 'd':
1602 if (is_header)
1603 gen_idecode_h (file, gen, isa, cache_rules);
1604 else
1605 gen_idecode_c (file, gen, isa, cache_rules);
1606 break;
1607 case 'e':
1608 if (is_header)
1609 gen_engine_h (file, gen, isa, cache_rules);
1610 else
1611 gen_engine_c (file, gen, isa, cache_rules);
1612 break;
1613 case 'c':
1614 if (is_header)
1615 gen_icache_h (file,
1616 gen->semantics,
1617 isa->functions,
1618 isa->max_nr_words);
1619 else
1620 gen_icache_c (file,
1621 gen->semantics,
1622 isa->functions,
1623 cache_rules);
1624 break;
1625 }
1626 lf_print__file_finish(file);
1627 lf_close(file);
1628 is_header = 0;
1629 }
1630 real_file_name = NULL;
1631 break;
1632 default:
1633 ERROR ("Bad switch");
1634 }
1635 }
1636 return (0);
1637 }