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