1 /* This file is part of the program psim.
3 Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
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.
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.
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.
29 static insn_word_entry *
30 parse_insn_word (line_ref *line,
35 insn_word_entry *word = ZALLOC (insn_word_entry);
37 /* create a leading sentinal */
38 word->first = ZALLOC (insn_field_entry);
39 word->first->first = -1;
40 word->first->last = -1;
41 word->first->width = 0;
43 /* and a trailing sentinal */
44 word->last = ZALLOC (insn_field_entry);
45 word->last->first = options.insn_bit_size;
46 word->last->last = options.insn_bit_size;
47 word->last->width = 0;
49 /* link them together */
50 word->first->next = word->last;
51 word->last->prev = word->first;
53 /* now work through the formats */
54 chp = skip_spaces (string);
56 while (*chp != '\0') {
61 insn_field_entry *new_field;
63 /* create / link in the new field */
64 new_field = ZALLOC (insn_field_entry);
65 new_field->next = word->last;
66 new_field->prev = word->last->prev;
67 new_field->next->prev = new_field;
68 new_field->prev->next = new_field;
69 new_field->word_nr = word_nr;
71 /* break out the first field (if present) */
73 chp = skip_to_separator (chp, ".,!");
74 strlen_pos = back_spaces (start_pos, chp) - start_pos;
76 /* break out the second field (if present) */
79 /* assume what was specified was the value (and not the start
80 position). Assume the value length implicitly specifies
82 start_val = start_pos;
83 strlen_val = strlen_pos;
90 chp = skip_spaces (chp);
92 if (*chp == '/' || *chp == '*')
98 while (*chp == '/' || *chp == '*');
100 else if (isalpha(*start_val))
106 while (isalnum(*chp) || *chp == '_');
108 else if (isdigit(*start_val))
113 while (isalnum(*chp));
115 strlen_val = chp - start_val;
116 chp = skip_spaces (chp);
119 error (line, "Empty value field\n");
121 /* break out any conditional fields - { "!" <value> } */
126 insn_field_exclusion *new_exclusion = ZALLOC (insn_field_exclusion);
127 insn_field_exclusion **last;
129 /* what type of conditional field */
131 chp = skip_spaces (chp);
134 chp = skip_digits (chp);
137 error (line, "Missing or invalid conditional value\n");
138 /* fill in the entry */
139 new_exclusion->string = NZALLOC (char, len + 1);
140 strncpy (new_exclusion->string, start, len);
141 new_exclusion->value = a2i (new_exclusion->string);
143 last = &new_field->exclusions;
144 while (*last != NULL)
145 last = &(*last)->next;
146 *last = new_exclusion;
147 chp = skip_spaces (chp);
150 /* NOW verify that the field ws finished */
153 chp = skip_spaces (chp + 1);
155 error (line, "empty field\n");
157 else if (*chp != '\0')
159 error (line, "Missing field separator");
163 new_field->val_string = NZALLOC (char, strlen_val+1);
164 strncpy (new_field->val_string, start_val, strlen_val);
165 if (isdigit (new_field->val_string[0]))
169 /* when the length/pos field is omited, an integer field
173 for (i = 0; i < strlen_val; i++)
175 if (new_field->val_string[i] != '0'
176 && new_field->val_string[i] != '1')
177 error (line, "invalid binary field %s\n",
178 new_field->val_string);
179 val = (val << 1) + (new_field->val_string[i] == '1');
181 new_field->val_int = val;
182 new_field->type = insn_field_int;
186 new_field->val_int = a2i (new_field->val_string);
187 new_field->type = insn_field_int;
190 else if (new_field->val_string[0] == '/')
192 new_field->type = insn_field_reserved;
194 else if (new_field->val_string[0] == '*')
196 new_field->type = insn_field_wild;
200 new_field->type = insn_field_string;
201 if (filter_is_member (word->field_names, new_field->val_string))
202 error (line, "Field name %s is duplicated\n", new_field->val_string);
203 filter_parse (&word->field_names, new_field->val_string);
205 if (new_field->type != insn_field_string
206 && new_field->exclusions != NULL)
207 error (line, "Exclusions only apply to name fields\n");
209 /* the copy the position */
210 new_field->pos_string = NZALLOC (char, strlen_pos + 1);
211 strncpy (new_field->pos_string, start_pos, strlen_pos);
214 new_field->first = new_field->prev->last + 1;
215 if (new_field->first == 0 /* first field */
216 && *chp == '\0' /* no further fields */
217 && new_field->type == insn_field_string)
219 /* A single string without any position, assume that it
220 represents the entire instruction word */
221 new_field->width = options.insn_bit_size;
225 /* No explicit width/position, assume value implicitly
226 supplies the width */
227 new_field->width = strlen_val;
229 new_field->last = new_field->first + new_field->width - 1;
230 if (new_field->last >= options.insn_bit_size)
231 error (line, "Bit position %d exceed instruction bit size (%d)\n",
232 new_field->last, options.insn_bit_size);
234 else if (options.insn_specifying_widths)
236 new_field->first = new_field->prev->last + 1;
237 new_field->width = a2i(new_field->pos_string);
238 new_field->last = new_field->first + new_field->width - 1;
239 if (new_field->last >= options.insn_bit_size)
240 error (line, "Bit position %d exceed instruction bit size (%d)\n",
241 new_field->last, options.insn_bit_size);
245 new_field->first = target_a2i(options.hi_bit_nr,
246 new_field->pos_string);
247 new_field->last = new_field->next->first - 1; /* guess */
248 new_field->width = new_field->last - new_field->first + 1; /* guess */
249 new_field->prev->last = new_field->first - 1; /*fix*/
250 new_field->prev->width = new_field->first - new_field->prev->first; /*fix*/
254 /* fiddle first/last so that the sentinals disapear */
255 ASSERT(word->first->last < 0);
256 ASSERT(word->last->first >= options.insn_bit_size);
257 word->first = word->first->next;
258 word->last = word->last->prev;
260 /* check that the last field goes all the way to the last bit */
261 if (word->last->last != options.insn_bit_size - 1)
263 options.warning (line, "Instruction format is not %d bits wide\n",
264 options.insn_bit_size);
265 word->last->last = options.insn_bit_size - 1;
268 /* now go over this again, pointing each bit position at a field
271 insn_field_entry *field;
272 for (field = word->first;
273 field->last < options.insn_bit_size;
277 for (i = field->first; i <= field->last; i++)
279 word->bit[i] = ZALLOC (insn_bit_entry);
280 word->bit[i]->field = field;
284 word->bit[i]->mask = 1;
285 word->bit[i]->value = ((field->val_int
286 & ((insn_uint)1 << (field->last - i)))
288 case insn_field_reserved:
289 case insn_field_wild:
290 case insn_field_string:
302 parse_insn_words (insn_entry *insn,
305 insn_word_entry **last_word = &insn->words;
308 /* now work through the formats */
318 insn_word_entry *new_word;
320 /* skip leading spaces */
321 chp = skip_spaces (chp);
323 /* break out the format */
325 chp = skip_to_separator (chp, "+");
326 end_pos = back_spaces (start_pos, chp);
327 strlen_pos = end_pos - start_pos;
329 /* check that something was there */
331 error (insn->line, "missing or empty instruction format\n");
333 /* parse the field */
334 format = NZALLOC (char, strlen_pos + 1);
335 strncpy (format, start_pos, strlen_pos);
336 new_word = parse_insn_word (insn->line, format, insn->nr_words);
338 if (filter_is_common (insn->field_names, new_word->field_names))
339 error (insn->line, "Field name duplicated between two words\n");
340 filter_add (&insn->field_names, new_word->field_names);
343 *last_word = new_word;
344 last_word = &new_word->next;
349 ASSERT (*chp == '+');
353 /* now create a quick access array of the same structure */
356 insn_word_entry *word;
357 insn->word = NZALLOC (insn_word_entry *, insn->nr_words + 1);
358 for (i = 0, word = insn->words;
360 i++, word = word->next)
361 insn->word[i] = word;
367 insn_record, /* default */
373 string_function_record,
378 model_processor_record,
382 model_function_record,
383 model_internal_record,
386 static const name_map insn_type_map[] = {
387 { "option", option_record },
388 { "cache", cache_record },
389 { "compute", compute_record },
390 { "scratch", scratch_record },
391 { "define", define_record },
392 { "include", include_record },
393 { "%s", string_function_record },
394 { "function", function_record },
395 { "internal", internal_record },
396 { "model", model_processor_record },
397 { "model-macro", model_macro_record },
398 { "model-data", model_data_record },
399 { "model-static", model_static_record },
400 { "model-internal", model_internal_record },
401 { "model-function", model_function_record },
402 { NULL, insn_record },
407 record_is_old (table_entry *entry)
409 if (entry->nr_fields > record_type_field
410 && strlen (entry->field[record_type_field]) == 0)
415 static insn_record_type
416 record_type (table_entry *entry)
420 case table_code_entry:
423 case table_colon_entry:
424 if (record_is_old (entry))
427 if (entry->nr_fields > old_record_type_field)
429 int i = name2i (entry->field[old_record_type_field],
435 return unknown_record;
438 else if (entry->nr_fields > record_type_field
439 && entry->field[0][0] == '\0')
442 int i = name2i (entry->field[record_type_field],
447 return insn_record; /* default */
449 return unknown_record;
453 record_prefix_is (table_entry *entry,
457 if (entry->type != table_colon_entry)
459 if (entry->nr_fields < nr_fields)
461 if (entry->field[0][0] != ch && ch != '\0')
467 parse_model_data_record (insn_table *isa,
473 table_entry *model_record = record;
474 table_entry *code_record = NULL;
475 model_data *new_data;
476 if (record->nr_fields < nr_fields)
477 error (record->line, "Incorrect number of fields\n");
478 record = table_read (file);
479 if (record->type == table_code_entry)
481 code_record = record;
482 record = table_read (file);
484 /* create the new data record */
485 new_data = ZALLOC (model_data);
486 new_data->line = model_record->line;
487 filter_parse (&new_data->flags,
488 model_record->field[record_filter_flags_field]);
489 new_data->entry = model_record;
490 new_data->code = code_record;
492 while (*list != NULL)
493 list = &(*list)->next;
500 insn_bit_size_option = 1,
501 insn_specifying_widths_option,
511 static const name_map option_map[] = {
512 { "insn-bit-size", insn_bit_size_option },
513 { "insn-specifying-widths", insn_specifying_widths_option },
514 { "hi-bit-nr", hi_bit_nr_option },
515 { "flags-filter", flags_filter_option },
516 { "model-filter", model_filter_option },
517 { "multi-sim", multi_sim_option },
518 { "format-names", format_names_option },
519 { "gen-delayed-branch", gen_delayed_branch },
520 { NULL, unknown_option },
524 parse_option_record (table *file,
527 table_entry *option_record;
528 /* parse the option record */
529 option_record = record;
530 if (record->nr_fields < nr_option_fields)
531 error (record->line, "Incorrect nr of fields for option record\n");
532 record = table_read (file);
534 if (!is_filtered_out (options.flags_filter,
535 option_record->field[record_filter_flags_field]))
537 char *name = option_record->field[option_name_field];
538 option_names option = name2i (name, option_map);
539 char *value = option_record->field[option_value_field];
542 case insn_bit_size_option:
544 options.insn_bit_size = a2i (value);
545 if (options.insn_bit_size < 0
546 || options.insn_bit_size > max_insn_bit_size)
547 error (option_record->line, "Instruction bit size out of range\n");
548 if (options.hi_bit_nr != options.insn_bit_size - 1
549 && options.hi_bit_nr != 0)
550 error (option_record->line, "insn-bit-size / hi-bit-nr conflict\n");
553 case insn_specifying_widths_option:
555 options.insn_specifying_widths = a2i (value);
558 case hi_bit_nr_option:
560 options.hi_bit_nr = a2i (value);
561 if (options.hi_bit_nr != 0
562 && options.hi_bit_nr != options.insn_bit_size - 1)
563 error (option_record->line, "hi-bit-nr / insn-bit-size conflict\n");
566 case flags_filter_option:
568 filter_parse (&options.flags_filter, value);
571 case model_filter_option:
573 filter_parse (&options.model_filter, value);
576 case multi_sim_option:
578 options.gen.multi_sim = a2i (value);
581 case format_names_option:
583 filter_parse (&options.format_name_filter, value);
586 case gen_delayed_branch:
588 options.gen.delayed_branch = a2i (value);
593 error (option_record->line, "Unknown option - %s\n", name);
602 parse_function_record (table *file,
604 function_entry **list,
605 function_entry **list_entry,
608 function_entry *new_function;
609 if (record->nr_fields < nr_function_fields)
610 error (record->line, "Missing fields from function record\n");
611 /* look for a body to the function */
612 new_function = ZALLOC (function_entry);
613 /* parse the function header */
614 new_function->line = record->line;
615 filter_parse (&new_function->flags,
616 record->field[record_filter_flags_field]);
617 if (record_is_old (record))
618 new_function->type = record->field[old_function_typedef_field];
620 new_function->type = record->field[function_typedef_field];
621 new_function->name = record->field[function_name_field];
622 if (record->nr_fields > function_param_field)
623 new_function->param = record->field[function_param_field];
624 new_function->is_internal = is_internal;
625 /* parse the function body */
626 record = table_read (file);
627 if (record->type == table_code_entry)
629 new_function->code = record;
630 record = table_read (file);
633 while (*list != NULL)
634 list = &(*list)->next;
635 *list = new_function;
636 if (list_entry != NULL)
637 *list_entry = new_function;
643 parse_insn_model_record (table *file,
648 insn_model_entry **last_insn_model;
649 insn_model_entry *new_insn_model = ZALLOC (insn_model_entry);
651 new_insn_model->line = record->line;
652 if (record->nr_fields > insn_model_name_field)
653 new_insn_model->name = record->field[insn_model_name_field];
654 if (record->nr_fields > insn_model_unit_data_field)
655 new_insn_model->unit_data = record->field[insn_model_unit_data_field];
656 new_insn_model->insn = insn;
657 /* strip "\*[ ]*" from name */
658 new_insn_model->name = skip_spaces (new_insn_model->name + 1);
659 if (strlen (new_insn_model->name) == 0)
661 /* No processor name - a generic model entry, enter it into all
662 the non-empty fields */
664 for (index = 0; index < model->nr_models; index++)
665 if (insn->model[index] == 0)
667 insn->model[index] = new_insn_model;
669 /* also add the complete processor set to this processor's set */
670 filter_add (&insn->processors, model->processors);
674 /* Find the corresponding master model record so it can be
675 linked in correctly */
677 index = filter_is_member (model->processors, new_insn_model->name) - 1;
680 error (record->line, "machine model `%s' undefined\n",
681 new_insn_model->name);
683 /* store it in the corresponding model array entry */
684 insn->model[index] = new_insn_model;
685 /* also add the name to the instructions processor set as an
686 alternative lookup mechanism */
687 filter_parse (&insn->processors, new_insn_model->name);
690 /* for some reason record the max length of any
691 function unit field */
692 int len = strlen (insn_model_ptr->field[insn_model_fields]);
693 if (model->max_model_fields_len < len)
694 model->max_model_fields_len = len;
697 last_insn_model = &insn->models;
698 while ((*last_insn_model) != NULL)
699 last_insn_model = &(*last_insn_model)->next;
700 *last_insn_model = new_insn_model;
705 parse_insn_mnemonic_record (table *file,
709 insn_mnemonic_entry **last_insn_mnemonic;
710 insn_mnemonic_entry *new_insn_mnemonic = ZALLOC (insn_mnemonic_entry);
712 new_insn_mnemonic->line = record->line;
713 ASSERT (record->nr_fields > insn_mnemonic_format_field);
714 new_insn_mnemonic->format = record->field[insn_mnemonic_format_field];
715 ASSERT (new_insn_mnemonic->format[0] == '"');
716 if (new_insn_mnemonic->format[strlen (new_insn_mnemonic->format) - 1] != '"')
717 error (new_insn_mnemonic->line, "Missing closing double quote in mnemonic field\n");
718 if (record->nr_fields > insn_mnemonic_condition_field)
719 new_insn_mnemonic->condition = record->field[insn_mnemonic_condition_field];
720 new_insn_mnemonic->insn = insn;
722 last_insn_mnemonic = &insn->mnemonics;
723 while ((*last_insn_mnemonic) != NULL)
724 last_insn_mnemonic = &(*last_insn_mnemonic)->next;
725 insn->nr_mnemonics++;
726 *last_insn_mnemonic = new_insn_mnemonic;
731 load_insn_table (char *file_name,
734 table *file = table_open (file_name);
735 table_entry *record = table_read (file);
737 insn_table *isa = ZALLOC (insn_table);
738 model_table *model = ZALLOC (model_table);
743 while (record != NULL)
746 switch (record_type (record))
751 if (record->nr_fields < nr_include_record_fields)
753 "Incorrect nr of fields for include record\n");
754 table_push (file, record->line, options.include,
755 record->field[include_record_filename_field]);
756 record = table_read (file);
762 if (isa->insns != NULL)
763 error (record->line, "Option after first instruction\n");
764 record = parse_option_record (file, record);
768 case string_function_record:
770 /* convert a string function field into an internal function field */
772 if (record->nr_fields < nr_function_fields)
773 error (record->line, "Incorrect nr of fields for %%s record\n");
774 name = NZALLOC (char,
776 + strlen (record->field[function_name_field])
778 strcat (name, "str_");
779 strcat (name, record->field[function_name_field]);
780 record->field[record_type_field] = "function";
781 record->field[function_typedef_field] = "const char *";
782 record->field[function_name_field] = name;
783 /* HACK - comes round back as a function/internal record */
787 case function_record: /* function record */
789 record = parse_function_record (file, record,
796 case internal_record:
798 /* only insert it into the function list if it is unknown */
799 function_entry *function = NULL;
800 record = parse_function_record (file, record,
804 /* check what was inserted to see if a pseudo-instruction
805 entry also needs to be created */
806 if (function != NULL)
808 insn_entry **insn = NULL;
809 if (strcmp (function->name, "illegal") == 0)
811 /* illegal function save it away */
812 if (isa->illegal_insn != NULL)
814 warning (function->line,
815 "Multiple illegal instruction definitions\n");
816 error (isa->illegal_insn->line,
817 "Location of first illegal instruction\n");
820 insn = &isa->illegal_insn;
824 *insn = ZALLOC (insn_entry);
825 (*insn)->line = function->line;
826 (*insn)->name = function->name;
827 (*insn)->code = function->code;
833 case scratch_record: /* cache macro records */
837 cache_entry *new_cache;
838 /* parse the cache record */
839 if (record->nr_fields < nr_cache_fields)
841 "Incorrect nr of fields for scratch/cache/compute record\n");
843 new_cache = ZALLOC (cache_entry);
844 new_cache->line = record->line;
845 filter_parse (&new_cache->flags,
846 record->field[record_filter_flags_field]);
847 new_cache->type = record->field[cache_type_field];
848 new_cache->name = record->field[cache_name_field];
849 filter_parse (&new_cache->original_fields,
850 record->field[cache_original_fields_field]);
851 new_cache->expression = record->field[cache_expression_field];
852 /* insert it but only if not filtered out */
853 if (!filter_is_subset (options.flags_filter, new_cache->flags))
855 notify (new_cache->line, "Discarding cache entry %s\n",
862 while (*last != NULL)
863 last = &(*last)->next;
867 record = table_read (file);
872 case model_processor_record:
874 model_entry *new_model;
875 /* parse the model */
876 if (record->nr_fields < nr_model_processor_fields)
877 error (record->line, "Incorrect nr of fields for model record\n");
878 if (isa->insns != NULL)
879 error (record->line, "Model appears after first instruction\n");
880 new_model = ZALLOC (model_entry);
881 filter_parse (&new_model->flags,
882 record->field[record_filter_flags_field]);
883 new_model->line = record->line;
884 new_model->name = record->field[model_name_field];
885 new_model->full_name = record->field[model_full_name_field];
886 new_model->unit_data = record->field[model_unit_data_field];
887 /* only insert it if not filtered out */
888 if (!filter_is_subset (options.flags_filter, new_model->flags))
890 notify (new_model->line, "Discarding processor model %s\n",
893 else if (filter_is_member (model->processors, new_model->name))
895 error (new_model->line, "Duplicate processor model %s\n",
901 last = &model->models;
902 while (*last != NULL)
903 last = &(*last)->next;
907 filter_parse (&model->processors, new_model->name);
910 record = table_read (file);
914 case model_macro_record:
915 record = parse_model_data_record (isa, file, record,
916 nr_model_macro_fields,
920 case model_data_record:
921 record = parse_model_data_record (isa, file, record,
922 nr_model_data_fields,
926 case model_static_record:
927 record = parse_function_record (file, record,
933 case model_internal_record:
934 record = parse_function_record (file, record,
940 case model_function_record:
941 record = parse_function_record (file, record,
947 case insn_record: /* instruction records */
949 insn_entry *new_insn;
951 /* parse the instruction */
952 if (record->nr_fields < nr_insn_fields)
953 error (record->line, "Incorrect nr of fields for insn record\n");
954 new_insn = ZALLOC (insn_entry);
955 new_insn->line = record->line;
956 filter_parse (&new_insn->flags,
957 record->field[record_filter_flags_field]);
958 /* save the format field. Can't parse it until after the
959 filter-out checks. Could be filtered out because the
961 format = record->field[insn_word_field];
962 new_insn->format_name = record->field[insn_format_name_field];
963 if (options.format_name_filter != NULL
964 && !filter_is_member (options.format_name_filter,
965 new_insn->format_name))
966 error (new_insn->line, "Unreconized instruction format name `%s'\n",
967 new_insn->format_name);
968 filter_parse (&new_insn->options,
969 record->field[insn_options_field]);
970 new_insn->name = record->field[insn_name_field];
971 record = table_read (file);
972 /* Parse any model/assember records */
973 new_insn->nr_models = model->nr_models;
974 new_insn->model = NZALLOC (insn_model_entry*, model->nr_models + 1);
975 while (record != NULL)
977 if (record_prefix_is (record, '*', nr_insn_model_fields))
978 parse_insn_model_record (file, record, new_insn, model);
979 else if (record_prefix_is (record, '"', nr_insn_mnemonic_fields))
980 parse_insn_mnemonic_record (file, record, new_insn);
984 record = table_read (file);
986 /* Parse the code record */
987 if (record != NULL && record->type == table_code_entry)
989 new_insn->code = record;
990 record = table_read (file);
993 if (!filter_is_subset (options.flags_filter, new_insn->flags))
995 if (options.warn.discard)
996 notify (new_insn->line,
997 "Discarding instruction %s (flags-filter)\n",
1000 else if (new_insn->processors != NULL
1001 && options.model_filter != NULL
1002 && !filter_is_common (options.model_filter,
1003 new_insn->processors))
1005 /* only discard an instruction based in the processor
1006 model when both the instruction and the options are
1008 if (options.warn.discard)
1009 notify (new_insn->line,
1010 "Discarding instruction %s (processor-model)\n",
1016 /* finish the parsing */
1017 parse_insn_words (new_insn, format);
1021 last = &(*last)->next;
1023 /* update global isa counters */
1025 if (isa->max_nr_words < new_insn->nr_words)
1026 isa->max_nr_words = new_insn->nr_words;
1027 filter_add (&isa->flags, new_insn->flags);
1028 filter_add (&isa->options, new_insn->options);
1033 case unknown_record:
1036 error (record->line, "Unknown or unexpected entry\n");
1046 print_insn_words (lf *file,
1049 insn_word_entry *word = insn->words;
1054 insn_field_entry *field = word->first;
1057 if (options.insn_specifying_widths)
1058 lf_printf (file, "%d.", field->width);
1060 lf_printf (file, "%d.", i2target (options.hi_bit_nr, field->first));
1061 switch (field->type)
1063 case insn_field_int:
1064 lf_printf (file, "0x%lx", (long) field->val_int);
1066 case insn_field_reserved:
1067 lf_printf (file, "/");
1069 case insn_field_wild:
1070 lf_printf (file, "*");
1072 case insn_field_string:
1073 lf_printf (file, "%s", field->val_string);
1076 if (field == word->last)
1078 field = field->next;
1079 lf_printf (file, ",");
1084 lf_printf (file, "+");
1092 function_entry_traverse (lf *file,
1093 function_entry *functions,
1094 function_entry_handler *handler,
1097 function_entry *function;
1098 for (function = functions; function != NULL; function = function->next)
1100 handler (file, function, data);
1105 insn_table_traverse_insn (lf *file,
1107 insn_entry_handler *handler,
1111 for (insn = isa->insns; insn != NULL; insn = insn->next)
1113 handler (file, isa, insn, data);
1119 dump_function_entry (lf *file,
1121 function_entry *entry,
1124 lf_printf (file, "%s(function_entry *) 0x%lx", prefix, (long) entry);
1127 dump_line_ref (file, "\n(line ", entry->line, ")");
1128 dump_filter (file, "\n(flags ", entry->flags, ")");
1129 lf_printf (file, "\n(type \"%s\")", entry->type);
1130 lf_printf (file, "\n(name \"%s\")", entry->name);
1131 lf_printf (file, "\n(param \"%s\")", entry->param);
1132 dump_table_entry (file, "\n(code ", entry->code, ")");
1133 lf_printf (file, "\n(is_internal %d)", entry->is_internal);
1134 lf_printf (file, "\n(next 0x%lx)", (long) entry->next);
1136 lf_printf (file, "%s", suffix);
1140 dump_function_entries (lf *file,
1142 function_entry *entry,
1145 lf_printf (file, "%s", prefix);
1146 lf_indent (file, +1);
1147 while (entry != NULL)
1149 dump_function_entry (file, "\n(", entry, ")");
1150 entry = entry->next;
1152 lf_indent (file, -1);
1153 lf_printf (file, "%s", suffix);
1157 cache_entry_type_to_str (cache_entry_type type)
1161 case scratch_value: return "scratch";
1162 case cache_value: return "cache";
1163 case compute_value: return "compute";
1165 ERROR ("Bad switch");
1170 dump_cache_entry (lf *file,
1175 lf_printf (file, "%s(cache_entry *) 0x%lx", prefix, (long) entry);
1178 dump_line_ref (file, "\n(line ", entry->line, ")");
1179 dump_filter (file, "\n(flags ", entry->flags, ")");
1180 lf_printf (file, "\n(entry_type \"%s\")", cache_entry_type_to_str (entry->entry_type));
1181 lf_printf (file, "\n(name \"%s\")", entry->name);
1182 dump_filter (file, "\n(original_fields ", entry->original_fields, ")");
1183 lf_printf (file, "\n(type \"%s\")", entry->type);
1184 lf_printf (file, "\n(expression \"%s\")", entry->expression);
1185 lf_printf (file, "\n(next 0x%lx)", (long) entry->next);
1187 lf_printf (file, "%s", suffix);
1191 dump_cache_entries (lf *file,
1196 lf_printf (file, "%s", prefix);
1197 lf_indent (file, +1);
1198 while (entry != NULL)
1200 dump_cache_entry (file, "\n(", entry, ")");
1201 entry = entry->next;
1203 lf_indent (file, -1);
1204 lf_printf (file, "%s", suffix);
1208 dump_model_data (lf *file,
1213 lf_printf (file, "%s(model_data *) 0x%lx", prefix, (long) entry);
1216 lf_indent (file, +1);
1217 dump_line_ref (file, "\n(line ", entry->line, ")");
1218 dump_filter (file, "\n(flags ", entry->flags, ")");
1219 dump_table_entry (file, "\n(entry ", entry->entry, ")");
1220 dump_table_entry (file, "\n(code ", entry->code, ")");
1221 lf_printf (file, "\n(next 0x%lx)", (long) entry->next);
1222 lf_indent (file, -1);
1224 lf_printf (file, "%s", prefix);
1228 dump_model_datas (lf *file,
1233 lf_printf (file, "%s", prefix);
1234 lf_indent (file, +1);
1235 while (entry != NULL)
1237 dump_model_data (file, "\n(", entry, ")");
1238 entry = entry->next;
1240 lf_indent (file, -1);
1241 lf_printf (file, "%s", suffix);
1245 dump_model_entry (lf *file,
1250 lf_printf (file, "%s(model_entry *) 0x%lx", prefix, (long) entry);
1253 lf_indent (file, +1);
1254 dump_line_ref (file, "\n(line ", entry->line, ")");
1255 dump_filter (file, "\n(flags ", entry->flags, ")");
1256 lf_printf (file, "\n(name \"%s\")", entry->name);
1257 lf_printf (file, "\n(full_name \"%s\")", entry->full_name);
1258 lf_printf (file, "\n(unit_data \"%s\")", entry->unit_data);
1259 lf_printf (file, "\n(next 0x%lx)", (long) entry->next);
1260 lf_indent (file, -1);
1262 lf_printf (file, "%s", prefix);
1266 dump_model_entries (lf *file,
1271 lf_printf (file, "%s", prefix);
1272 lf_indent (file, +1);
1273 while (entry != NULL)
1275 dump_model_entry (file, "\n(", entry, ")");
1276 entry = entry->next;
1278 lf_indent (file, -1);
1279 lf_printf (file, "%s", suffix);
1284 dump_model_table (lf *file,
1289 lf_printf (file, "%s(model_table *) 0x%lx", prefix, (long) entry);
1292 lf_indent (file, +1);
1293 dump_filter (file, "\n(processors ", entry->processors, ")");
1294 lf_printf (file, "\n(nr_models %d)", entry->nr_models);
1295 dump_model_entries (file, "\n(models ", entry->models, ")");
1296 dump_model_datas (file, "\n(macros ", entry->macros, ")");
1297 dump_model_datas (file, "\n(data ", entry->data, ")");
1298 dump_function_entries (file, "\n(statics ", entry->statics, ")");
1299 dump_function_entries (file, "\n(internals ", entry->functions, ")");
1300 dump_function_entries (file, "\n(functions ", entry->functions, ")");
1301 lf_indent (file, -1);
1303 lf_printf (file, "%s", suffix);
1308 insn_field_type_to_str (insn_field_type type)
1312 case insn_field_int: return "int";
1313 case insn_field_reserved: return "reserved";
1314 case insn_field_wild: return "wild";
1315 case insn_field_string: return "string";
1317 ERROR ("bad switch");
1322 dump_insn_field (lf *file,
1324 insn_field_entry *field,
1328 lf_printf (file, "%s(insn_field_entry *) 0x%lx", prefix, (long) field);
1331 lf_indent (file, +1);
1332 lf_printf (file, "%s(first %d)", sep, field->first);
1333 lf_printf (file, "%s(last %d)", sep, field->last);
1334 lf_printf (file, "%s(width %d)", sep, field->width);
1335 lf_printf (file, "%s(type %s)", sep, insn_field_type_to_str (field->type));
1336 switch (field->type)
1338 case insn_field_int:
1339 lf_printf (file, "%s(val 0x%lx)", sep, (long) field->val_int);
1341 case insn_field_reserved:
1342 /* nothing output */
1344 case insn_field_wild:
1345 /* nothing output */
1347 case insn_field_string:
1348 lf_printf (file, "%s(val \"%s\")", sep, field->val_string);
1351 lf_printf (file, "%s(next 0x%lx)", sep, (long) field->next);
1352 lf_printf (file, "%s(prev 0x%lx)", sep, (long) field->prev);
1353 lf_indent (file, -1);
1355 lf_printf (file, "%s", suffix);
1359 dump_insn_word_entry (lf *file,
1361 insn_word_entry *word,
1364 lf_printf (file, "%s(insn_word_entry *) 0x%lx", prefix, (long) word);
1368 insn_field_entry *field;
1369 lf_indent (file, +1);
1370 lf_printf (file, "\n(first 0x%lx)", (long) word->first);
1371 lf_printf (file, "\n(last 0x%lx)", (long) word->last);
1372 lf_printf (file, "\n(bit");
1373 for (i = 0; i < options.insn_bit_size; i++)
1374 lf_printf (file, "\n ((value %d) (mask %d) (field 0x%lx))",
1375 word->bit[i]->value, word->bit[i]->mask, (long) word->bit[i]->field);
1376 lf_printf (file, ")");
1377 for (field = word->first; field != NULL; field = field->next)
1378 dump_insn_field (file, "\n(", field, ")");
1379 dump_filter (file, "\n(field_names ", word->field_names, ")");
1380 lf_printf (file, "\n(next 0x%lx)", (long) word->next);
1381 lf_indent (file, -1);
1383 lf_printf (file, "%s", suffix);
1387 dump_insn_word_entries (lf *file,
1389 insn_word_entry *word,
1392 lf_printf (file, "%s", prefix);
1393 while (word != NULL)
1395 dump_insn_word_entry (file, "\n(", word, ")");
1398 lf_printf (file, "%s", suffix);
1402 dump_insn_model_entry (lf *file,
1404 insn_model_entry *model,
1407 lf_printf (file, "%s(insn_model_entry *) 0x%lx", prefix, (long) model);
1410 lf_indent (file, +1);
1411 dump_line_ref (file, "\n(line ", model->line, ")");
1412 lf_printf (file, "\n(name \"%s\")", model->name);
1413 lf_printf (file, "\n(full_name \"%s\")", model->full_name);
1414 lf_printf (file, "\n(unit_data \"%s\")", model->unit_data);
1415 lf_printf (file, "\n(insn (insn_entry *) 0x%lx)", (long) model->insn);
1416 lf_printf (file, "\n(next (insn_model_entry *) 0x%lx)",
1417 (long) model->next);
1418 lf_indent (file, -1);
1420 lf_printf (file, "%s", suffix);
1424 dump_insn_model_entries (lf *file,
1426 insn_model_entry *model,
1429 lf_printf (file, "%s", prefix);
1430 while (model != NULL)
1432 dump_insn_model_entry (file, "\n", model, "");
1433 model = model->next;
1435 lf_printf (file, "%s", suffix);
1440 dump_insn_mnemonic_entry (lf *file,
1442 insn_mnemonic_entry *mnemonic,
1445 lf_printf (file, "%s(insn_mnemonic_entry *) 0x%lx", prefix, (long) mnemonic);
1446 if (mnemonic != NULL)
1448 lf_indent (file, +1);
1449 dump_line_ref (file, "\n(line ", mnemonic->line, ")");
1450 lf_printf (file, "\n(format \"%s\")", mnemonic->format);
1451 lf_printf (file, "\n(condition \"%s\")", mnemonic->condition);
1452 lf_printf (file, "\n(insn (insn_entry *) 0x%lx)",
1453 (long) mnemonic->insn);
1454 lf_printf (file, "\n(next (insn_mnemonic_entry *) 0x%lx)",
1455 (long) mnemonic->next);
1456 lf_indent (file, -1);
1458 lf_printf (file, "%s", suffix);
1462 dump_insn_mnemonic_entries (lf *file,
1464 insn_mnemonic_entry *mnemonic,
1467 lf_printf (file, "%s", prefix);
1468 while (mnemonic != NULL)
1470 dump_insn_mnemonic_entry (file, "\n", mnemonic, "");
1471 mnemonic = mnemonic->next;
1473 lf_printf (file, "%s", suffix);
1477 dump_insn_entry (lf *file,
1482 lf_printf (file, "%s(insn_entry *) 0x%lx", prefix, (long) entry);
1486 lf_indent (file, +1);
1487 dump_line_ref (file, "\n(line ", entry->line, ")");
1488 dump_filter (file, "\n(flags ", entry->flags, ")");
1489 lf_printf (file, "\n(nr_words %d)", entry->nr_words);
1490 dump_insn_word_entries (file, "\n(words ", entry->words, ")");
1491 lf_printf (file, "\n(word");
1492 for (i = 0; i < entry->nr_models; i++)
1493 lf_printf (file, " 0x%lx", (long) entry->word[i]);
1494 lf_printf (file, ")");
1495 dump_filter (file, "\n(field_names ", entry->field_names, ")");
1496 lf_printf (file, "\n(format_name \"%s\")", entry->format_name);
1497 dump_filter (file, "\n(options ", entry->options, ")");
1498 lf_printf (file, "\n(name \"%s\")", entry->name);
1499 lf_printf (file, "\n(nr_models %d)", entry->nr_models);
1500 dump_insn_model_entries (file, "\n(models ", entry->models, ")");
1501 lf_printf (file, "\n(model");
1502 for (i = 0; i < entry->nr_models; i++)
1503 lf_printf (file, " 0x%lx", (long) entry->model[i]);
1504 lf_printf (file, ")");
1505 dump_filter (file, "\n(processors ", entry->processors, ")");
1506 dump_insn_mnemonic_entries (file, "\n(mnemonics ", entry->mnemonics, ")");
1507 dump_table_entry (file, "\n(code ", entry->code, ")");
1508 lf_printf (file, "\n(next 0x%lx)", (long) entry->next);
1509 lf_indent (file, -1);
1511 lf_printf (file, "%s", suffix);
1515 dump_insn_entries (lf *file,
1520 lf_printf (file, "%s", prefix);
1521 lf_indent (file, +1);
1522 while (entry != NULL)
1524 dump_insn_entry (file, "\n(", entry, ")");
1525 entry = entry->next;
1527 lf_indent (file, -1);
1528 lf_printf (file, "%s", suffix);
1534 dump_insn_table (lf *file,
1539 lf_printf (file, "%s(insn_table *) 0x%lx", prefix, (long) isa);
1542 lf_indent (file, +1);
1543 dump_cache_entries (file, "\n(caches ", isa->caches, ")");
1544 lf_printf (file, "\n(nr_insns %d)", isa->nr_insns);
1545 lf_printf (file, "\n(max_nr_words %d)", isa->max_nr_words);
1546 dump_insn_entries (file, "\n(insns ", isa->insns, ")");
1547 dump_function_entries (file, "\n(functions ", isa->functions, ")");
1548 dump_insn_entry (file, "\n(illegal_insn ", isa->illegal_insn, ")");
1549 dump_model_table (file, "\n(model ", isa->model, ")");
1550 dump_filter (file, "\n(flags ", isa->flags, ")");
1551 dump_filter (file, "\n(options ", isa->options, ")");
1552 lf_indent (file, -1);
1554 lf_printf (file, "%s", suffix);
1559 igen_options options;
1562 main (int argc, char **argv)
1567 INIT_OPTIONS (options);
1570 filter_parse (&options.flags_filter, argv[2]);
1572 error (NULL, "Usage: insn <insn-table> [ <filter-in> ]\n");
1574 isa = load_insn_table (argv[1], NULL);
1575 l = lf_open ("-", "stdout", lf_omit_references, lf_is_text, "tmp-ld-insn");
1576 dump_insn_table (l, "(isa ", isa, ")\n");