1 /* This file is part of the program psim.
3 Copyright (C) 1994-1998, 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> | <field-name> } */
122 while (*chp == '!' || *chp == '=')
127 insn_field_cond *new_cond = ZALLOC (insn_field_cond);
129 /* determine the conditional test */
133 new_cond->test = insn_field_cond_eq;
136 new_cond->test = insn_field_cond_ne;
144 chp = skip_spaces (chp);
146 chp = skip_to_separator (chp, "+,:!=");
147 end = back_spaces (start, chp);
150 error (line, "Missing or invalid conditional value\n");
151 new_cond->string = NZALLOC (char, len + 1);
152 strncpy (new_cond->string, start, len);
154 /* determine the conditional type */
155 if (isdigit (*start))
157 /* [ "!" | "=" ] <value> */
158 new_cond->type = insn_field_cond_value;
159 new_cond->value = a2i (new_cond->string);
163 /* [ "!" | "=" ] <field> - check field valid */
164 new_cond->type = insn_field_cond_field;
165 /* new_cond->field is determined in later */
168 /* Only a single `=' is permitted. */
169 if ((new_cond->test == insn_field_cond_eq
170 && new_field->conditions != NULL)
171 || (new_field->conditions != NULL
172 && new_field->conditions->test == insn_field_cond_eq))
173 error (line, "Only single conditional when `=' allowed\n");
177 insn_field_cond **last = &new_field->conditions;
178 while (*last != NULL)
179 last = &(*last)->next;
184 /* NOW verify that the field was finished */
187 chp = skip_spaces (chp + 1);
189 error (line, "empty field\n");
191 else if (*chp != '\0')
193 error (line, "Missing field separator\n");
197 new_field->val_string = NZALLOC (char, strlen_val+1);
198 strncpy (new_field->val_string, start_val, strlen_val);
199 if (isdigit (new_field->val_string[0]))
203 /* when the length/pos field is omited, an integer field
207 for (i = 0; i < strlen_val; i++)
209 if (new_field->val_string[i] != '0'
210 && new_field->val_string[i] != '1')
211 error (line, "invalid binary field %s\n",
212 new_field->val_string);
213 val = (val << 1) + (new_field->val_string[i] == '1');
215 new_field->val_int = val;
216 new_field->type = insn_field_int;
220 new_field->val_int = a2i (new_field->val_string);
221 new_field->type = insn_field_int;
224 else if (new_field->val_string[0] == '/')
226 new_field->type = insn_field_reserved;
228 else if (new_field->val_string[0] == '*')
230 new_field->type = insn_field_wild;
234 new_field->type = insn_field_string;
235 if (filter_is_member (word->field_names, new_field->val_string))
236 error (line, "Field name %s is duplicated\n", new_field->val_string);
237 filter_parse (&word->field_names, new_field->val_string);
239 if (new_field->type != insn_field_string
240 && new_field->conditions != NULL)
241 error (line, "Conditionals can only be applied to named fields\n");
243 /* the copy the position */
244 new_field->pos_string = NZALLOC (char, strlen_pos + 1);
245 strncpy (new_field->pos_string, start_pos, strlen_pos);
248 new_field->first = new_field->prev->last + 1;
249 if (new_field->first == 0 /* first field */
250 && *chp == '\0' /* no further fields */
251 && new_field->type == insn_field_string)
253 /* A single string without any position, assume that it
254 represents the entire instruction word */
255 new_field->width = options.insn_bit_size;
259 /* No explicit width/position, assume value implicitly
260 supplies the width */
261 new_field->width = strlen_val;
263 new_field->last = new_field->first + new_field->width - 1;
264 if (new_field->last >= options.insn_bit_size)
265 error (line, "Bit position %d exceed instruction bit size (%d)\n",
266 new_field->last, options.insn_bit_size);
268 else if (options.insn_specifying_widths)
270 new_field->first = new_field->prev->last + 1;
271 new_field->width = a2i(new_field->pos_string);
272 new_field->last = new_field->first + new_field->width - 1;
273 if (new_field->last >= options.insn_bit_size)
274 error (line, "Bit position %d exceed instruction bit size (%d)\n",
275 new_field->last, options.insn_bit_size);
279 new_field->first = target_a2i(options.hi_bit_nr,
280 new_field->pos_string);
281 new_field->last = new_field->next->first - 1; /* guess */
282 new_field->width = new_field->last - new_field->first + 1; /* guess */
283 new_field->prev->last = new_field->first - 1; /*fix*/
284 new_field->prev->width = new_field->first - new_field->prev->first; /*fix*/
288 /* fiddle first/last so that the sentinals disapear */
289 ASSERT(word->first->last < 0);
290 ASSERT(word->last->first >= options.insn_bit_size);
291 word->first = word->first->next;
292 word->last = word->last->prev;
294 /* check that the last field goes all the way to the last bit */
295 if (word->last->last != options.insn_bit_size - 1)
297 if (options.warn.width)
298 options.warning (line, "Instruction format is not %d bits wide\n",
299 options.insn_bit_size);
300 word->last->last = options.insn_bit_size - 1;
303 /* now go over this again, pointing each bit position at a field
306 insn_field_entry *field;
307 for (field = word->first;
308 field->last < options.insn_bit_size;
312 for (i = field->first; i <= field->last; i++)
314 word->bit[i] = ZALLOC (insn_bit_entry);
315 word->bit[i]->field = field;
318 case insn_field_invalid:
322 word->bit[i]->mask = 1;
323 word->bit[i]->value = ((field->val_int
324 & ((insn_uint)1 << (field->last - i)))
326 case insn_field_reserved:
327 case insn_field_wild:
328 case insn_field_string:
329 /* if we encounter a constant conditional, encode
331 if (field->conditions != NULL
332 && field->conditions->test == insn_field_cond_eq
333 && field->conditions->type == insn_field_cond_value)
335 word->bit[i]->mask = 1;
336 word->bit[i]->value = ((field->conditions->value
337 & ((insn_uint)1 << (field->last - i)))
351 parse_insn_words (insn_entry *insn,
354 insn_word_entry **last_word = &insn->words;
357 /* now work through the formats */
367 insn_word_entry *new_word;
369 /* skip leading spaces */
370 chp = skip_spaces (chp);
372 /* break out the format */
374 chp = skip_to_separator (chp, "+");
375 end_pos = back_spaces (start_pos, chp);
376 strlen_pos = end_pos - start_pos;
378 /* check that something was there */
380 error (insn->line, "missing or empty instruction format\n");
382 /* parse the field */
383 format = NZALLOC (char, strlen_pos + 1);
384 strncpy (format, start_pos, strlen_pos);
385 new_word = parse_insn_word (insn->line, format, insn->nr_words);
387 if (filter_is_common (insn->field_names, new_word->field_names))
388 error (insn->line, "Field name duplicated between two words\n");
389 filter_add (&insn->field_names, new_word->field_names);
392 *last_word = new_word;
393 last_word = &new_word->next;
398 ASSERT (*chp == '+');
402 /* create a quick access array (indexed by word) of the same structure */
405 insn_word_entry *word;
406 insn->word = NZALLOC (insn_word_entry *, insn->nr_words + 1);
407 for (i = 0, word = insn->words;
409 i++, word = word->next)
410 insn->word[i] = word;
413 /* Go over all fields that have conditionals refering to other
414 fields. Link the fields up. Verify that the two fields have the
415 same size. Verify that the two fields are different */
418 for (i = 0; i < insn->nr_words; i++)
420 insn_word_entry *word = insn->word[i];
422 for (f = word->first;
423 f->last < options.insn_bit_size;
426 insn_field_cond *cond;
427 for (cond = f->conditions;
431 if (cond->type == insn_field_cond_field)
434 if (strcmp (cond->string, f->val_string) == 0)
436 "Conditional `%s' of field `%s' refers to its self\n",
437 cond->string, f->val_string);
438 for (j = 0; j <= i && cond->field == NULL; j++)
440 insn_word_entry *refered_word = insn->word[j];
441 insn_field_entry *refered_field;
442 for (refered_field = refered_word->first;
443 refered_field != NULL && cond->field == NULL;
444 refered_field = refered_field->next)
446 if (refered_field->type == insn_field_string
447 && strcmp (refered_field->val_string, cond->string) == 0)
449 /* found field being refered to by conditonal */
450 cond->field = refered_field;
451 /* check refered to and this field are
453 if (f->width != refered_field->width)
455 "Conditional `%s' of field `%s' should be of size %s\n",
456 cond->string, f->val_string, refered_field->width);
460 if (cond->field == NULL)
462 "Conditional `%s' of field `%s' not yet defined\n",
463 cond->string, f->val_string);
474 insn_record, /* default */
480 string_function_record,
485 model_processor_record,
489 model_function_record,
490 model_internal_record,
493 static const name_map insn_type_map[] = {
494 { "option", option_record },
495 { "cache", cache_record },
496 { "compute", compute_record },
497 { "scratch", scratch_record },
498 { "define", define_record },
499 { "include", include_record },
500 { "%s", string_function_record },
501 { "function", function_record },
502 { "internal", internal_record },
503 { "model", model_processor_record },
504 { "model-macro", model_macro_record },
505 { "model-data", model_data_record },
506 { "model-static", model_static_record },
507 { "model-internal", model_internal_record },
508 { "model-function", model_function_record },
509 { NULL, insn_record },
514 record_is_old (table_entry *entry)
516 if (entry->nr_fields > record_type_field
517 && strlen (entry->field[record_type_field]) == 0)
522 static insn_record_type
523 record_type (table_entry *entry)
527 case table_code_entry:
530 case table_colon_entry:
531 if (record_is_old (entry))
534 if (entry->nr_fields > old_record_type_field)
536 int i = name2i (entry->field[old_record_type_field],
542 return unknown_record;
545 else if (entry->nr_fields > record_type_field
546 && entry->field[0][0] == '\0')
549 int i = name2i (entry->field[record_type_field],
554 return insn_record; /* default */
556 return unknown_record;
560 record_prefix_is (table_entry *entry,
564 if (entry->type != table_colon_entry)
566 if (entry->nr_fields < nr_fields)
568 if (entry->field[0][0] != ch && ch != '\0')
574 parse_model_data_record (insn_table *isa,
580 table_entry *model_record = record;
581 table_entry *code_record = NULL;
582 model_data *new_data;
583 if (record->nr_fields < nr_fields)
584 error (record->line, "Incorrect number of fields\n");
585 record = table_read (file);
586 if (record->type == table_code_entry)
588 code_record = record;
589 record = table_read (file);
591 /* create the new data record */
592 new_data = ZALLOC (model_data);
593 new_data->line = model_record->line;
594 filter_parse (&new_data->flags,
595 model_record->field[record_filter_flags_field]);
596 new_data->entry = model_record;
597 new_data->code = code_record;
598 /* append it if not filtered out */
599 if (!is_filtered_out (options.flags_filter,
600 model_record->field[record_filter_flags_field])
601 && !is_filtered_out (options.model_filter,
602 model_record->field[record_filter_models_field]))
604 while (*list != NULL)
605 list = &(*list)->next;
613 insn_bit_size_option = 1,
614 insn_specifying_widths_option,
624 static const name_map option_map[] = {
625 { "insn-bit-size", insn_bit_size_option },
626 { "insn-specifying-widths", insn_specifying_widths_option },
627 { "hi-bit-nr", hi_bit_nr_option },
628 { "flags-filter", flags_filter_option },
629 { "model-filter", model_filter_option },
630 { "multi-sim", multi_sim_option },
631 { "format-names", format_names_option },
632 { "gen-delayed-branch", gen_delayed_branch },
633 { NULL, unknown_option },
637 parse_include_record (table *file,
640 /* parse the include record */
641 if (record->nr_fields < nr_include_fields)
642 error (record->line, "Incorrect nr fields for include record\n");
644 if (!is_filtered_out (options.flags_filter,
645 record->field[record_filter_flags_field])
646 && !is_filtered_out (options.model_filter,
647 record->field[record_filter_models_field]))
649 table_push (file, record->line, options.include,
650 record->field[include_filename_field]);
652 /* nb: can't read next record until after the file has been pushed */
653 record = table_read (file);
659 parse_option_record (table *file,
662 table_entry *option_record;
663 /* parse the option record */
664 option_record = record;
665 if (record->nr_fields < nr_option_fields)
666 error (record->line, "Incorrect nr of fields for option record\n");
667 record = table_read (file);
669 if (!is_filtered_out (options.flags_filter,
670 option_record->field[record_filter_flags_field])
671 && !is_filtered_out (options.model_filter,
672 option_record->field[record_filter_models_field]))
674 char *name = option_record->field[option_name_field];
675 option_names option = name2i (name, option_map);
676 char *value = option_record->field[option_value_field];
679 case insn_bit_size_option:
681 options.insn_bit_size = a2i (value);
682 if (options.insn_bit_size < 0
683 || options.insn_bit_size > max_insn_bit_size)
684 error (option_record->line, "Instruction bit size out of range\n");
685 if (options.hi_bit_nr != options.insn_bit_size - 1
686 && options.hi_bit_nr != 0)
687 error (option_record->line, "insn-bit-size / hi-bit-nr conflict\n");
690 case insn_specifying_widths_option:
692 options.insn_specifying_widths = a2i (value);
695 case hi_bit_nr_option:
697 options.hi_bit_nr = a2i (value);
698 if (options.hi_bit_nr != 0
699 && options.hi_bit_nr != options.insn_bit_size - 1)
700 error (option_record->line, "hi-bit-nr / insn-bit-size conflict\n");
703 case flags_filter_option:
705 filter_parse (&options.flags_filter, value);
708 case model_filter_option:
710 filter_parse (&options.model_filter, value);
713 case multi_sim_option:
715 options.gen.multi_sim = a2i (value);
718 case format_names_option:
720 filter_parse (&options.format_name_filter, value);
723 case gen_delayed_branch:
725 options.gen.delayed_branch = a2i (value);
730 error (option_record->line, "Unknown option - %s\n", name);
740 parse_function_record (table *file,
742 function_entry **list,
743 function_entry **list_entry,
747 function_entry *new_function;
748 new_function = ZALLOC (function_entry);
749 new_function->line = record->line;
750 new_function->is_internal = is_internal;
751 /* parse the function header */
752 if (record_is_old (record))
754 if (record->nr_fields < nr_old_function_fields)
755 error (record->line, "Missing fields from (old) function record\n");
756 new_function->type = record->field[old_function_typedef_field];
757 new_function->type = record->field[old_function_typedef_field];
758 if (record->nr_fields > old_function_param_field)
759 new_function->param = record->field[old_function_param_field];
760 new_function->name = record->field[old_function_name_field];
764 if (record->nr_fields < nr_function_fields)
765 error (record->line, "Missing fields from function record\n");
766 filter_parse (&new_function->flags,
767 record->field[record_filter_flags_field]);
768 filter_parse (&new_function->models,
769 record->field[record_filter_models_field]);
770 new_function->type = record->field[function_typedef_field];
771 new_function->param = record->field[function_param_field];
772 new_function->name = record->field[function_name_field];
774 record = table_read (file);
775 /* parse any function-model records */
776 while (record != NULL
777 && record_prefix_is (record, '*', nr_function_model_fields))
779 char *model_name = record->field[function_model_name_field] + 1; /*skip `*'*/
780 filter_parse (&new_function->models, model_name);
781 if (!filter_is_subset (model->processors, new_function->models))
783 error (record->line, "machine model `%s' undefined\n", model_name);
785 record = table_read (file);
787 /* parse the function body */
788 if (record->type == table_code_entry)
790 new_function->code = record;
791 record = table_read (file);
794 if (!filter_is_subset (options.flags_filter, new_function->flags))
796 if (options.warn.discard)
797 notify (new_function->line, "Discarding function %s - filter flags\n",
800 else if (new_function->models != NULL
801 && !filter_is_common (options.model_filter, new_function->models))
803 if (options.warn.discard)
804 notify (new_function->line, "Discarding function %s - filter models\n",
809 while (*list != NULL)
810 list = &(*list)->next;
811 *list = new_function;
812 if (list_entry != NULL)
813 *list_entry = new_function;
820 parse_insn_model_record (table *file,
825 insn_model_entry **last_insn_model;
826 insn_model_entry *new_insn_model = ZALLOC (insn_model_entry);
828 new_insn_model->line = record->line;
829 if (record->nr_fields > insn_model_unit_data_field)
830 new_insn_model->unit_data = record->field[insn_model_unit_data_field];
831 new_insn_model->insn = insn;
832 /* parse the model names, verify that all were defined */
833 new_insn_model->names = NULL;
834 filter_parse (&new_insn_model->names,
835 record->field[insn_model_name_field] + 1 /*skip `*'*/);
836 if (new_insn_model->names == NULL)
838 /* No processor names - a generic model entry, enter it into all
839 the non-empty fields */
841 for (index = 0; index < model->nr_models; index++)
842 if (insn->model[index] == 0)
844 insn->model[index] = new_insn_model;
846 /* also add the complete processor set to this processor's set */
847 filter_add (&insn->processors, model->processors);
851 /* Find the corresponding master model record for each name so
852 that they can be linked in. */
857 name = filter_next (new_insn_model->names, name);
858 if (name == NULL) break;
859 index = filter_is_member (model->processors, name) - 1;
862 error (new_insn_model->line,
863 "machine model `%s' undefined\n", name);
865 /* store it in the corresponding model array entry */
866 if (insn->model[index] != NULL
867 && insn->model[index]->names != NULL)
869 warning (new_insn_model->line,
870 "machine model `%s' previously defined\n", name);
871 error (insn->model[index]->line, "earlier definition\n");
873 insn->model[index] = new_insn_model;
874 /* also add the name to the instructions processor set as an
875 alternative lookup mechanism */
876 filter_parse (&insn->processors, name);
880 /* for some reason record the max length of any
881 function unit field */
882 int len = strlen (insn_model_ptr->field[insn_model_fields]);
883 if (model->max_model_fields_len < len)
884 model->max_model_fields_len = len;
887 last_insn_model = &insn->models;
888 while ((*last_insn_model) != NULL)
889 last_insn_model = &(*last_insn_model)->next;
890 *last_insn_model = new_insn_model;
895 parse_insn_mnemonic_record (table *file,
899 insn_mnemonic_entry **last_insn_mnemonic;
900 insn_mnemonic_entry *new_insn_mnemonic = ZALLOC (insn_mnemonic_entry);
902 new_insn_mnemonic->line = record->line;
903 ASSERT (record->nr_fields > insn_mnemonic_format_field);
904 new_insn_mnemonic->format = record->field[insn_mnemonic_format_field];
905 ASSERT (new_insn_mnemonic->format[0] == '"');
906 if (new_insn_mnemonic->format[strlen (new_insn_mnemonic->format) - 1] != '"')
907 error (new_insn_mnemonic->line, "Missing closing double quote in mnemonic field\n");
908 if (record->nr_fields > insn_mnemonic_condition_field)
909 new_insn_mnemonic->condition = record->field[insn_mnemonic_condition_field];
910 new_insn_mnemonic->insn = insn;
912 last_insn_mnemonic = &insn->mnemonics;
913 while ((*last_insn_mnemonic) != NULL)
914 last_insn_mnemonic = &(*last_insn_mnemonic)->next;
915 insn->nr_mnemonics++;
916 *last_insn_mnemonic = new_insn_mnemonic;
921 parse_macro_record (table *file,
925 error (record->line, "Macros are not implemented");
927 /* parse the define record */
928 if (record->nr_fields < nr_define_fields)
929 error (record->line, "Incorrect nr fields for define record\n");
931 if (!is_filtered_out (options.flags_filter,
932 record->field[record_filter_flags_field])
933 && !is_filtered_out (options.model_filter,
934 record->field[record_filter_models_field]))
938 record->field[macro_name_field],
939 record->field[macro_args_field],
940 record->field[macro_expr_field]);
942 record = table_read (file);
949 load_insn_table (char *file_name,
952 table *file = table_open (file_name);
953 table_entry *record = table_read (file);
955 insn_table *isa = ZALLOC (insn_table);
956 model_table *model = ZALLOC (model_table);
961 while (record != NULL)
964 switch (record_type (record))
969 record = parse_include_record (file, record);
975 if (isa->insns != NULL)
976 error (record->line, "Option after first instruction\n");
977 record = parse_option_record (file, record);
981 case string_function_record:
983 function_entry *function = NULL;
984 record = parse_function_record (file, record,
989 /* convert a string function record into an internal function */
990 if (function != NULL)
992 char *name = NZALLOC (char,
994 + strlen (function->name)
996 strcat (name, "str_");
997 strcat (name, function->name);
998 function->name = name;
999 function->type = "const char *";
1004 case function_record: /* function record */
1006 record = parse_function_record (file, record,
1014 case internal_record:
1016 /* only insert it into the function list if it is unknown */
1017 function_entry *function = NULL;
1018 record = parse_function_record (file, record,
1023 /* check what was inserted to see if a pseudo-instruction
1024 entry also needs to be created */
1025 if (function != NULL)
1027 insn_entry **insn = NULL;
1028 if (strcmp (function->name, "illegal") == 0)
1030 /* illegal function save it away */
1031 if (isa->illegal_insn != NULL)
1033 warning (function->line,
1034 "Multiple illegal instruction definitions\n");
1035 error (isa->illegal_insn->line,
1036 "Location of first illegal instruction\n");
1039 insn = &isa->illegal_insn;
1043 *insn = ZALLOC (insn_entry);
1044 (*insn)->line = function->line;
1045 (*insn)->name = function->name;
1046 (*insn)->code = function->code;
1052 case scratch_record: /* cache macro records */
1054 case compute_record:
1056 cache_entry *new_cache;
1057 /* parse the cache record */
1058 if (record->nr_fields < nr_cache_fields)
1059 error (record->line,
1060 "Incorrect nr of fields for scratch/cache/compute record\n");
1062 new_cache = ZALLOC (cache_entry);
1063 new_cache->line = record->line;
1064 filter_parse (&new_cache->flags,
1065 record->field[record_filter_flags_field]);
1066 filter_parse (&new_cache->models,
1067 record->field[record_filter_models_field]);
1068 new_cache->type = record->field[cache_typedef_field];
1069 new_cache->name = record->field[cache_name_field];
1070 filter_parse (&new_cache->original_fields,
1071 record->field[cache_original_fields_field]);
1072 new_cache->expression = record->field[cache_expression_field];
1073 /* insert it but only if not filtered out */
1074 if (!filter_is_subset (options.flags_filter, new_cache->flags))
1076 notify (new_cache->line, "Discarding cache entry %s - filter flags\n",
1079 else if (is_filtered_out (options.model_filter,
1080 record->field[record_filter_models_field]))
1082 notify (new_cache->line, "Discarding cache entry %s - filter models\n",
1088 last = &isa->caches;
1089 while (*last != NULL)
1090 last = &(*last)->next;
1093 /* advance things */
1094 record = table_read (file);
1099 case model_processor_record:
1101 model_entry *new_model;
1102 /* parse the model */
1103 if (record->nr_fields < nr_model_processor_fields)
1104 error (record->line, "Incorrect nr of fields for model record\n");
1105 if (isa->insns != NULL)
1106 error (record->line, "Model appears after first instruction\n");
1107 new_model = ZALLOC (model_entry);
1108 filter_parse (&new_model->flags,
1109 record->field[record_filter_flags_field]);
1110 new_model->line = record->line;
1111 new_model->name = record->field[model_name_field];
1112 new_model->full_name = record->field[model_full_name_field];
1113 new_model->unit_data = record->field[model_unit_data_field];
1114 /* only insert it if not filtered out */
1115 if (!filter_is_subset (options.flags_filter, new_model->flags))
1117 notify (new_model->line, "Discarding processor model %s - filter flags\n",
1120 else if (is_filtered_out (options.model_filter,
1121 record->field[record_filter_models_field]))
1123 notify (new_model->line, "Discarding processor model %s - filter models\n",
1126 else if (filter_is_member (model->processors, new_model->name))
1128 error (new_model->line, "Duplicate processor model %s\n",
1134 last = &model->models;
1135 while (*last != NULL)
1136 last = &(*last)->next;
1139 model->nr_models ++;
1140 filter_parse (&model->processors, new_model->name);
1142 /* advance things */
1143 record = table_read (file);
1147 case model_macro_record:
1148 record = parse_model_data_record (isa, file, record,
1149 nr_model_macro_fields,
1153 case model_data_record:
1154 record = parse_model_data_record (isa, file, record,
1155 nr_model_data_fields,
1159 case model_static_record:
1160 record = parse_function_record (file, record,
1167 case model_internal_record:
1168 record = parse_function_record (file, record,
1175 case model_function_record:
1176 record = parse_function_record (file, record,
1183 case insn_record: /* instruction records */
1185 insn_entry *new_insn;
1187 /* parse the instruction */
1188 if (record->nr_fields < nr_insn_fields)
1189 error (record->line, "Incorrect nr of fields for insn record\n");
1190 new_insn = ZALLOC (insn_entry);
1191 new_insn->line = record->line;
1192 filter_parse (&new_insn->flags,
1193 record->field[record_filter_flags_field]);
1194 /* save the format field. Can't parse it until after the
1195 filter-out checks. Could be filtered out because the
1196 format is invalid */
1197 format = record->field[insn_word_field];
1198 new_insn->format_name = record->field[insn_format_name_field];
1199 if (options.format_name_filter != NULL
1200 && !filter_is_member (options.format_name_filter,
1201 new_insn->format_name))
1202 error (new_insn->line, "Unreconized instruction format name `%s'\n",
1203 new_insn->format_name);
1204 filter_parse (&new_insn->options,
1205 record->field[insn_options_field]);
1206 new_insn->name = record->field[insn_name_field];
1207 record = table_read (file);
1208 /* Parse any model/assember records */
1209 new_insn->nr_models = model->nr_models;
1210 new_insn->model = NZALLOC (insn_model_entry*, model->nr_models + 1);
1211 while (record != NULL)
1213 if (record_prefix_is (record, '*', nr_insn_model_fields))
1214 parse_insn_model_record (file, record, new_insn, model);
1215 else if (record_prefix_is (record, '"', nr_insn_mnemonic_fields))
1216 parse_insn_mnemonic_record (file, record, new_insn);
1220 record = table_read (file);
1222 /* Parse the code record */
1223 if (record != NULL && record->type == table_code_entry)
1225 new_insn->code = record;
1226 record = table_read (file);
1228 else if (options.warn.unimplemented)
1229 notify (new_insn->line, "unimplemented\n");
1231 if (!filter_is_subset (options.flags_filter, new_insn->flags))
1233 if (options.warn.discard)
1234 notify (new_insn->line,
1235 "Discarding instruction %s (flags-filter)\n",
1238 else if (new_insn->processors != NULL
1239 && options.model_filter != NULL
1240 && !filter_is_common (options.model_filter,
1241 new_insn->processors))
1243 /* only discard an instruction based in the processor
1244 model when both the instruction and the options are
1246 if (options.warn.discard)
1247 notify (new_insn->line,
1248 "Discarding instruction %s (processor-model)\n",
1254 /* finish the parsing */
1255 parse_insn_words (new_insn, format);
1259 last = &(*last)->next;
1261 /* update global isa counters */
1263 if (isa->max_nr_words < new_insn->nr_words)
1264 isa->max_nr_words = new_insn->nr_words;
1265 filter_add (&isa->flags, new_insn->flags);
1266 filter_add (&isa->options, new_insn->options);
1272 record = parse_macro_record (file, record);
1275 case unknown_record:
1277 error (record->line, "Unknown or unexpected entry\n");
1287 print_insn_words (lf *file,
1290 insn_word_entry *word = insn->words;
1295 insn_field_entry *field = word->first;
1298 if (options.insn_specifying_widths)
1299 lf_printf (file, "%d.", field->width);
1301 lf_printf (file, "%d.", i2target (options.hi_bit_nr, field->first));
1302 switch (field->type)
1304 case insn_field_invalid:
1307 case insn_field_int:
1308 lf_printf (file, "0x%lx", (long) field->val_int);
1310 case insn_field_reserved:
1311 lf_printf (file, "/");
1313 case insn_field_wild:
1314 lf_printf (file, "*");
1316 case insn_field_string:
1317 lf_printf (file, "%s", field->val_string);
1320 if (field == word->last)
1322 field = field->next;
1323 lf_printf (file, ",");
1328 lf_printf (file, "+");
1336 function_entry_traverse (lf *file,
1337 function_entry *functions,
1338 function_entry_handler *handler,
1341 function_entry *function;
1342 for (function = functions; function != NULL; function = function->next)
1344 handler (file, function, data);
1349 insn_table_traverse_insn (lf *file,
1351 insn_entry_handler *handler,
1355 for (insn = isa->insns; insn != NULL; insn = insn->next)
1357 handler (file, isa, insn, data);
1363 dump_function_entry (lf *file,
1365 function_entry *entry,
1368 lf_printf (file, "%s(function_entry *) 0x%lx", prefix, (long) entry);
1371 dump_line_ref (file, "\n(line ", entry->line, ")");
1372 dump_filter (file, "\n(flags ", entry->flags, ")");
1373 lf_printf (file, "\n(type \"%s\")", entry->type);
1374 lf_printf (file, "\n(name \"%s\")", entry->name);
1375 lf_printf (file, "\n(param \"%s\")", entry->param);
1376 dump_table_entry (file, "\n(code ", entry->code, ")");
1377 lf_printf (file, "\n(is_internal %d)", entry->is_internal);
1378 lf_printf (file, "\n(next 0x%lx)", (long) entry->next);
1380 lf_printf (file, "%s", suffix);
1384 dump_function_entries (lf *file,
1386 function_entry *entry,
1389 lf_printf (file, "%s", prefix);
1390 lf_indent (file, +1);
1391 while (entry != NULL)
1393 dump_function_entry (file, "\n(", entry, ")");
1394 entry = entry->next;
1396 lf_indent (file, -1);
1397 lf_printf (file, "%s", suffix);
1401 cache_entry_type_to_str (cache_entry_type type)
1405 case scratch_value: return "scratch";
1406 case cache_value: return "cache";
1407 case compute_value: return "compute";
1409 ERROR ("Bad switch");
1414 dump_cache_entry (lf *file,
1419 lf_printf (file, "%s(cache_entry *) 0x%lx", prefix, (long) entry);
1422 dump_line_ref (file, "\n(line ", entry->line, ")");
1423 dump_filter (file, "\n(flags ", entry->flags, ")");
1424 lf_printf (file, "\n(entry_type \"%s\")", cache_entry_type_to_str (entry->entry_type));
1425 lf_printf (file, "\n(name \"%s\")", entry->name);
1426 dump_filter (file, "\n(original_fields ", entry->original_fields, ")");
1427 lf_printf (file, "\n(type \"%s\")", entry->type);
1428 lf_printf (file, "\n(expression \"%s\")", entry->expression);
1429 lf_printf (file, "\n(next 0x%lx)", (long) entry->next);
1431 lf_printf (file, "%s", suffix);
1435 dump_cache_entries (lf *file,
1440 lf_printf (file, "%s", prefix);
1441 lf_indent (file, +1);
1442 while (entry != NULL)
1444 dump_cache_entry (file, "\n(", entry, ")");
1445 entry = entry->next;
1447 lf_indent (file, -1);
1448 lf_printf (file, "%s", suffix);
1452 dump_model_data (lf *file,
1457 lf_printf (file, "%s(model_data *) 0x%lx", prefix, (long) entry);
1460 lf_indent (file, +1);
1461 dump_line_ref (file, "\n(line ", entry->line, ")");
1462 dump_filter (file, "\n(flags ", entry->flags, ")");
1463 dump_table_entry (file, "\n(entry ", entry->entry, ")");
1464 dump_table_entry (file, "\n(code ", entry->code, ")");
1465 lf_printf (file, "\n(next 0x%lx)", (long) entry->next);
1466 lf_indent (file, -1);
1468 lf_printf (file, "%s", prefix);
1472 dump_model_datas (lf *file,
1477 lf_printf (file, "%s", prefix);
1478 lf_indent (file, +1);
1479 while (entry != NULL)
1481 dump_model_data (file, "\n(", entry, ")");
1482 entry = entry->next;
1484 lf_indent (file, -1);
1485 lf_printf (file, "%s", suffix);
1489 dump_model_entry (lf *file,
1494 lf_printf (file, "%s(model_entry *) 0x%lx", prefix, (long) entry);
1497 lf_indent (file, +1);
1498 dump_line_ref (file, "\n(line ", entry->line, ")");
1499 dump_filter (file, "\n(flags ", entry->flags, ")");
1500 lf_printf (file, "\n(name \"%s\")", entry->name);
1501 lf_printf (file, "\n(full_name \"%s\")", entry->full_name);
1502 lf_printf (file, "\n(unit_data \"%s\")", entry->unit_data);
1503 lf_printf (file, "\n(next 0x%lx)", (long) entry->next);
1504 lf_indent (file, -1);
1506 lf_printf (file, "%s", prefix);
1510 dump_model_entries (lf *file,
1515 lf_printf (file, "%s", prefix);
1516 lf_indent (file, +1);
1517 while (entry != NULL)
1519 dump_model_entry (file, "\n(", entry, ")");
1520 entry = entry->next;
1522 lf_indent (file, -1);
1523 lf_printf (file, "%s", suffix);
1528 dump_model_table (lf *file,
1533 lf_printf (file, "%s(model_table *) 0x%lx", prefix, (long) entry);
1536 lf_indent (file, +1);
1537 dump_filter (file, "\n(processors ", entry->processors, ")");
1538 lf_printf (file, "\n(nr_models %d)", entry->nr_models);
1539 dump_model_entries (file, "\n(models ", entry->models, ")");
1540 dump_model_datas (file, "\n(macros ", entry->macros, ")");
1541 dump_model_datas (file, "\n(data ", entry->data, ")");
1542 dump_function_entries (file, "\n(statics ", entry->statics, ")");
1543 dump_function_entries (file, "\n(internals ", entry->functions, ")");
1544 dump_function_entries (file, "\n(functions ", entry->functions, ")");
1545 lf_indent (file, -1);
1547 lf_printf (file, "%s", suffix);
1552 insn_field_type_to_str (insn_field_type type)
1556 case insn_field_invalid: ASSERT (0); return "(invalid)";
1557 case insn_field_int: return "int";
1558 case insn_field_reserved: return "reserved";
1559 case insn_field_wild: return "wild";
1560 case insn_field_string: return "string";
1562 ERROR ("bad switch");
1567 dump_insn_field (lf *file,
1569 insn_field_entry *field,
1573 lf_printf (file, "%s(insn_field_entry *) 0x%lx", prefix, (long) field);
1576 lf_indent (file, +1);
1577 lf_printf (file, "%s(first %d)", sep, field->first);
1578 lf_printf (file, "%s(last %d)", sep, field->last);
1579 lf_printf (file, "%s(width %d)", sep, field->width);
1580 lf_printf (file, "%s(type %s)", sep, insn_field_type_to_str (field->type));
1581 switch (field->type)
1583 case insn_field_invalid:
1586 case insn_field_int:
1587 lf_printf (file, "%s(val 0x%lx)", sep, (long) field->val_int);
1589 case insn_field_reserved:
1590 /* nothing output */
1592 case insn_field_wild:
1593 /* nothing output */
1595 case insn_field_string:
1596 lf_printf (file, "%s(val \"%s\")", sep, field->val_string);
1599 lf_printf (file, "%s(next 0x%lx)", sep, (long) field->next);
1600 lf_printf (file, "%s(prev 0x%lx)", sep, (long) field->prev);
1601 lf_indent (file, -1);
1603 lf_printf (file, "%s", suffix);
1607 dump_insn_word_entry (lf *file,
1609 insn_word_entry *word,
1612 lf_printf (file, "%s(insn_word_entry *) 0x%lx", prefix, (long) word);
1616 insn_field_entry *field;
1617 lf_indent (file, +1);
1618 lf_printf (file, "\n(first 0x%lx)", (long) word->first);
1619 lf_printf (file, "\n(last 0x%lx)", (long) word->last);
1620 lf_printf (file, "\n(bit");
1621 for (i = 0; i < options.insn_bit_size; i++)
1622 lf_printf (file, "\n ((value %d) (mask %d) (field 0x%lx))",
1623 word->bit[i]->value, word->bit[i]->mask, (long) word->bit[i]->field);
1624 lf_printf (file, ")");
1625 for (field = word->first; field != NULL; field = field->next)
1626 dump_insn_field (file, "\n(", field, ")");
1627 dump_filter (file, "\n(field_names ", word->field_names, ")");
1628 lf_printf (file, "\n(next 0x%lx)", (long) word->next);
1629 lf_indent (file, -1);
1631 lf_printf (file, "%s", suffix);
1635 dump_insn_word_entries (lf *file,
1637 insn_word_entry *word,
1640 lf_printf (file, "%s", prefix);
1641 while (word != NULL)
1643 dump_insn_word_entry (file, "\n(", word, ")");
1646 lf_printf (file, "%s", suffix);
1650 dump_insn_model_entry (lf *file,
1652 insn_model_entry *model,
1655 lf_printf (file, "%s(insn_model_entry *) 0x%lx", prefix, (long) model);
1658 lf_indent (file, +1);
1659 dump_line_ref (file, "\n(line ", model->line, ")");
1660 dump_filter (file, "\n(names ", model->names, ")");
1661 lf_printf (file, "\n(full_name \"%s\")", model->full_name);
1662 lf_printf (file, "\n(unit_data \"%s\")", model->unit_data);
1663 lf_printf (file, "\n(insn (insn_entry *) 0x%lx)", (long) model->insn);
1664 lf_printf (file, "\n(next (insn_model_entry *) 0x%lx)",
1665 (long) model->next);
1666 lf_indent (file, -1);
1668 lf_printf (file, "%s", suffix);
1672 dump_insn_model_entries (lf *file,
1674 insn_model_entry *model,
1677 lf_printf (file, "%s", prefix);
1678 while (model != NULL)
1680 dump_insn_model_entry (file, "\n", model, "");
1681 model = model->next;
1683 lf_printf (file, "%s", suffix);
1688 dump_insn_mnemonic_entry (lf *file,
1690 insn_mnemonic_entry *mnemonic,
1693 lf_printf (file, "%s(insn_mnemonic_entry *) 0x%lx", prefix, (long) mnemonic);
1694 if (mnemonic != NULL)
1696 lf_indent (file, +1);
1697 dump_line_ref (file, "\n(line ", mnemonic->line, ")");
1698 lf_printf (file, "\n(format \"%s\")", mnemonic->format);
1699 lf_printf (file, "\n(condition \"%s\")", mnemonic->condition);
1700 lf_printf (file, "\n(insn (insn_entry *) 0x%lx)",
1701 (long) mnemonic->insn);
1702 lf_printf (file, "\n(next (insn_mnemonic_entry *) 0x%lx)",
1703 (long) mnemonic->next);
1704 lf_indent (file, -1);
1706 lf_printf (file, "%s", suffix);
1710 dump_insn_mnemonic_entries (lf *file,
1712 insn_mnemonic_entry *mnemonic,
1715 lf_printf (file, "%s", prefix);
1716 while (mnemonic != NULL)
1718 dump_insn_mnemonic_entry (file, "\n", mnemonic, "");
1719 mnemonic = mnemonic->next;
1721 lf_printf (file, "%s", suffix);
1725 dump_insn_entry (lf *file,
1730 lf_printf (file, "%s(insn_entry *) 0x%lx", prefix, (long) entry);
1734 lf_indent (file, +1);
1735 dump_line_ref (file, "\n(line ", entry->line, ")");
1736 dump_filter (file, "\n(flags ", entry->flags, ")");
1737 lf_printf (file, "\n(nr_words %d)", entry->nr_words);
1738 dump_insn_word_entries (file, "\n(words ", entry->words, ")");
1739 lf_printf (file, "\n(word");
1740 for (i = 0; i < entry->nr_models; i++)
1741 lf_printf (file, " 0x%lx", (long) entry->word[i]);
1742 lf_printf (file, ")");
1743 dump_filter (file, "\n(field_names ", entry->field_names, ")");
1744 lf_printf (file, "\n(format_name \"%s\")", entry->format_name);
1745 dump_filter (file, "\n(options ", entry->options, ")");
1746 lf_printf (file, "\n(name \"%s\")", entry->name);
1747 lf_printf (file, "\n(nr_models %d)", entry->nr_models);
1748 dump_insn_model_entries (file, "\n(models ", entry->models, ")");
1749 lf_printf (file, "\n(model");
1750 for (i = 0; i < entry->nr_models; i++)
1751 lf_printf (file, " 0x%lx", (long) entry->model[i]);
1752 lf_printf (file, ")");
1753 dump_filter (file, "\n(processors ", entry->processors, ")");
1754 dump_insn_mnemonic_entries (file, "\n(mnemonics ", entry->mnemonics, ")");
1755 dump_table_entry (file, "\n(code ", entry->code, ")");
1756 lf_printf (file, "\n(next 0x%lx)", (long) entry->next);
1757 lf_indent (file, -1);
1759 lf_printf (file, "%s", suffix);
1763 dump_insn_entries (lf *file,
1768 lf_printf (file, "%s", prefix);
1769 lf_indent (file, +1);
1770 while (entry != NULL)
1772 dump_insn_entry (file, "\n(", entry, ")");
1773 entry = entry->next;
1775 lf_indent (file, -1);
1776 lf_printf (file, "%s", suffix);
1782 dump_insn_table (lf *file,
1787 lf_printf (file, "%s(insn_table *) 0x%lx", prefix, (long) isa);
1790 lf_indent (file, +1);
1791 dump_cache_entries (file, "\n(caches ", isa->caches, ")");
1792 lf_printf (file, "\n(nr_insns %d)", isa->nr_insns);
1793 lf_printf (file, "\n(max_nr_words %d)", isa->max_nr_words);
1794 dump_insn_entries (file, "\n(insns ", isa->insns, ")");
1795 dump_function_entries (file, "\n(functions ", isa->functions, ")");
1796 dump_insn_entry (file, "\n(illegal_insn ", isa->illegal_insn, ")");
1797 dump_model_table (file, "\n(model ", isa->model, ")");
1798 dump_filter (file, "\n(flags ", isa->flags, ")");
1799 dump_filter (file, "\n(options ", isa->options, ")");
1800 lf_indent (file, -1);
1802 lf_printf (file, "%s", suffix);
1807 igen_options options;
1810 main (int argc, char **argv)
1815 INIT_OPTIONS (options);
1818 filter_parse (&options.flags_filter, argv[2]);
1820 error (NULL, "Usage: insn <insn-table> [ <filter-in> ]\n");
1822 isa = load_insn_table (argv[1], NULL);
1823 l = lf_open ("-", "stdout", lf_omit_references, lf_is_text, "tmp-ld-insn");
1824 dump_insn_table (l, "(isa ", isa, ")\n");