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);
128 insn_field_cond **last;
130 /* determine the conditional test */
134 new_cond->test = insn_field_cond_eq;
137 new_cond->test = insn_field_cond_ne;
145 chp = skip_spaces (chp);
147 chp = skip_to_separator (chp, "+,:");
148 end = back_spaces (start, chp);
151 error (line, "Missing or invalid conditional value\n");
152 new_cond->string = NZALLOC (char, len + 1);
153 strncpy (new_cond->string, start, len);
155 /* determine the conditional type */
156 if (isdigit (*start))
158 /* [ "!" | "=" ] <value> */
159 new_cond->type = insn_field_cond_value;
160 new_cond->value = a2i (new_cond->string);
164 /* [ "!" | "=" ] <field> - check field valid */
165 new_cond->type = insn_field_cond_field;
166 /* new_cond->field is determined in later */
169 /* Only a single `=' is permitted. */
170 if ((new_cond->test == insn_field_cond_eq
171 && new_field->conditions != NULL)
172 || (new_field->conditions != NULL
173 && new_field->conditions->test == insn_field_cond_eq))
174 error (line, "Only single conditional when `=' allowed\n");
177 last = &new_field->conditions;
178 while (*last != NULL)
179 last = &(*last)->next;
183 /* NOW verify that the field was finished */
186 chp = skip_spaces (chp + 1);
188 error (line, "empty field\n");
190 else if (*chp != '\0')
192 error (line, "Missing field separator\n");
196 new_field->val_string = NZALLOC (char, strlen_val+1);
197 strncpy (new_field->val_string, start_val, strlen_val);
198 if (isdigit (new_field->val_string[0]))
202 /* when the length/pos field is omited, an integer field
206 for (i = 0; i < strlen_val; i++)
208 if (new_field->val_string[i] != '0'
209 && new_field->val_string[i] != '1')
210 error (line, "invalid binary field %s\n",
211 new_field->val_string);
212 val = (val << 1) + (new_field->val_string[i] == '1');
214 new_field->val_int = val;
215 new_field->type = insn_field_int;
219 new_field->val_int = a2i (new_field->val_string);
220 new_field->type = insn_field_int;
223 else if (new_field->val_string[0] == '/')
225 new_field->type = insn_field_reserved;
227 else if (new_field->val_string[0] == '*')
229 new_field->type = insn_field_wild;
233 new_field->type = insn_field_string;
234 if (filter_is_member (word->field_names, new_field->val_string))
235 error (line, "Field name %s is duplicated\n", new_field->val_string);
236 filter_parse (&word->field_names, new_field->val_string);
238 if (new_field->type != insn_field_string
239 && new_field->conditions != NULL)
240 error (line, "Conditionals can only be applied to named fields\n");
242 /* the copy the position */
243 new_field->pos_string = NZALLOC (char, strlen_pos + 1);
244 strncpy (new_field->pos_string, start_pos, strlen_pos);
247 new_field->first = new_field->prev->last + 1;
248 if (new_field->first == 0 /* first field */
249 && *chp == '\0' /* no further fields */
250 && new_field->type == insn_field_string)
252 /* A single string without any position, assume that it
253 represents the entire instruction word */
254 new_field->width = options.insn_bit_size;
258 /* No explicit width/position, assume value implicitly
259 supplies the width */
260 new_field->width = strlen_val;
262 new_field->last = new_field->first + new_field->width - 1;
263 if (new_field->last >= options.insn_bit_size)
264 error (line, "Bit position %d exceed instruction bit size (%d)\n",
265 new_field->last, options.insn_bit_size);
267 else if (options.insn_specifying_widths)
269 new_field->first = new_field->prev->last + 1;
270 new_field->width = a2i(new_field->pos_string);
271 new_field->last = new_field->first + new_field->width - 1;
272 if (new_field->last >= options.insn_bit_size)
273 error (line, "Bit position %d exceed instruction bit size (%d)\n",
274 new_field->last, options.insn_bit_size);
278 new_field->first = target_a2i(options.hi_bit_nr,
279 new_field->pos_string);
280 new_field->last = new_field->next->first - 1; /* guess */
281 new_field->width = new_field->last - new_field->first + 1; /* guess */
282 new_field->prev->last = new_field->first - 1; /*fix*/
283 new_field->prev->width = new_field->first - new_field->prev->first; /*fix*/
287 /* fiddle first/last so that the sentinals disapear */
288 ASSERT(word->first->last < 0);
289 ASSERT(word->last->first >= options.insn_bit_size);
290 word->first = word->first->next;
291 word->last = word->last->prev;
293 /* check that the last field goes all the way to the last bit */
294 if (word->last->last != options.insn_bit_size - 1)
296 if (options.warn.width)
297 options.warning (line, "Instruction format is not %d bits wide\n",
298 options.insn_bit_size);
299 word->last->last = options.insn_bit_size - 1;
302 /* now go over this again, pointing each bit position at a field
305 insn_field_entry *field;
306 for (field = word->first;
307 field->last < options.insn_bit_size;
311 for (i = field->first; i <= field->last; i++)
313 word->bit[i] = ZALLOC (insn_bit_entry);
314 word->bit[i]->field = field;
317 case insn_field_invalid:
321 word->bit[i]->mask = 1;
322 word->bit[i]->value = ((field->val_int
323 & ((insn_uint)1 << (field->last - i)))
325 case insn_field_reserved:
326 case insn_field_wild:
327 case insn_field_string:
334 /* go over all fields that have conditionals refering to other
335 fields. Link the fields up. Verify that the two fields have the
336 same size. Verify that the two fields are different */
339 for (f = word->first;
340 f->last < options.insn_bit_size;
343 insn_field_cond *cond;
344 for (cond = f->conditions;
348 if (cond->type == insn_field_cond_field)
350 insn_field_entry *field;
351 if (strcmp (cond->string, f->val_string) == 0)
352 error (line, "Conditional of field `%s' refers to its self\n",
354 for (field = word->first;
358 if (field->type == insn_field_string
359 && strcmp (field->val_string, cond->string) == 0)
361 /* found field being refered to by conditonal */
363 /* check refered to and this field are the
365 if (f->width != field->width)
366 error (line, "Conditional `%s' of field `%s' has different size\n",
367 field->width, f->width);
371 if (cond->field == NULL)
372 error (line, "Condition field refers to non-existant field `%s'\n",
384 parse_insn_words (insn_entry *insn,
387 insn_word_entry **last_word = &insn->words;
390 /* now work through the formats */
400 insn_word_entry *new_word;
402 /* skip leading spaces */
403 chp = skip_spaces (chp);
405 /* break out the format */
407 chp = skip_to_separator (chp, "+");
408 end_pos = back_spaces (start_pos, chp);
409 strlen_pos = end_pos - start_pos;
411 /* check that something was there */
413 error (insn->line, "missing or empty instruction format\n");
415 /* parse the field */
416 format = NZALLOC (char, strlen_pos + 1);
417 strncpy (format, start_pos, strlen_pos);
418 new_word = parse_insn_word (insn->line, format, insn->nr_words);
420 if (filter_is_common (insn->field_names, new_word->field_names))
421 error (insn->line, "Field name duplicated between two words\n");
422 filter_add (&insn->field_names, new_word->field_names);
425 *last_word = new_word;
426 last_word = &new_word->next;
431 ASSERT (*chp == '+');
435 /* now create a quick access array of the same structure */
438 insn_word_entry *word;
439 insn->word = NZALLOC (insn_word_entry *, insn->nr_words + 1);
440 for (i = 0, word = insn->words;
442 i++, word = word->next)
443 insn->word[i] = word;
449 insn_record, /* default */
455 string_function_record,
460 model_processor_record,
464 model_function_record,
465 model_internal_record,
468 static const name_map insn_type_map[] = {
469 { "option", option_record },
470 { "cache", cache_record },
471 { "compute", compute_record },
472 { "scratch", scratch_record },
473 { "define", define_record },
474 { "include", include_record },
475 { "%s", string_function_record },
476 { "function", function_record },
477 { "internal", internal_record },
478 { "model", model_processor_record },
479 { "model-macro", model_macro_record },
480 { "model-data", model_data_record },
481 { "model-static", model_static_record },
482 { "model-internal", model_internal_record },
483 { "model-function", model_function_record },
484 { NULL, insn_record },
489 record_is_old (table_entry *entry)
491 if (entry->nr_fields > record_type_field
492 && strlen (entry->field[record_type_field]) == 0)
497 static insn_record_type
498 record_type (table_entry *entry)
502 case table_code_entry:
505 case table_colon_entry:
506 if (record_is_old (entry))
509 if (entry->nr_fields > old_record_type_field)
511 int i = name2i (entry->field[old_record_type_field],
517 return unknown_record;
520 else if (entry->nr_fields > record_type_field
521 && entry->field[0][0] == '\0')
524 int i = name2i (entry->field[record_type_field],
529 return insn_record; /* default */
531 return unknown_record;
535 record_prefix_is (table_entry *entry,
539 if (entry->type != table_colon_entry)
541 if (entry->nr_fields < nr_fields)
543 if (entry->field[0][0] != ch && ch != '\0')
549 parse_model_data_record (insn_table *isa,
555 table_entry *model_record = record;
556 table_entry *code_record = NULL;
557 model_data *new_data;
558 if (record->nr_fields < nr_fields)
559 error (record->line, "Incorrect number of fields\n");
560 record = table_read (file);
561 if (record->type == table_code_entry)
563 code_record = record;
564 record = table_read (file);
566 /* create the new data record */
567 new_data = ZALLOC (model_data);
568 new_data->line = model_record->line;
569 filter_parse (&new_data->flags,
570 model_record->field[record_filter_flags_field]);
571 new_data->entry = model_record;
572 new_data->code = code_record;
573 /* append it if not filtered out */
574 if (!is_filtered_out (options.flags_filter,
575 model_record->field[record_filter_flags_field])
576 && !is_filtered_out (options.model_filter,
577 model_record->field[record_filter_models_field]))
579 while (*list != NULL)
580 list = &(*list)->next;
588 insn_bit_size_option = 1,
589 insn_specifying_widths_option,
599 static const name_map option_map[] = {
600 { "insn-bit-size", insn_bit_size_option },
601 { "insn-specifying-widths", insn_specifying_widths_option },
602 { "hi-bit-nr", hi_bit_nr_option },
603 { "flags-filter", flags_filter_option },
604 { "model-filter", model_filter_option },
605 { "multi-sim", multi_sim_option },
606 { "format-names", format_names_option },
607 { "gen-delayed-branch", gen_delayed_branch },
608 { NULL, unknown_option },
612 parse_include_record (table *file,
615 /* parse the include record */
616 if (record->nr_fields < nr_include_fields)
617 error (record->line, "Incorrect nr fields for include record\n");
619 if (!is_filtered_out (options.flags_filter,
620 record->field[record_filter_flags_field])
621 && !is_filtered_out (options.model_filter,
622 record->field[record_filter_models_field]))
624 table_push (file, record->line, options.include,
625 record->field[include_filename_field]);
627 /* nb: can't read next record until after the file has been pushed */
628 record = table_read (file);
634 parse_option_record (table *file,
637 table_entry *option_record;
638 /* parse the option record */
639 option_record = record;
640 if (record->nr_fields < nr_option_fields)
641 error (record->line, "Incorrect nr of fields for option record\n");
642 record = table_read (file);
644 if (!is_filtered_out (options.flags_filter,
645 option_record->field[record_filter_flags_field])
646 && !is_filtered_out (options.model_filter,
647 option_record->field[record_filter_models_field]))
649 char *name = option_record->field[option_name_field];
650 option_names option = name2i (name, option_map);
651 char *value = option_record->field[option_value_field];
654 case insn_bit_size_option:
656 options.insn_bit_size = a2i (value);
657 if (options.insn_bit_size < 0
658 || options.insn_bit_size > max_insn_bit_size)
659 error (option_record->line, "Instruction bit size out of range\n");
660 if (options.hi_bit_nr != options.insn_bit_size - 1
661 && options.hi_bit_nr != 0)
662 error (option_record->line, "insn-bit-size / hi-bit-nr conflict\n");
665 case insn_specifying_widths_option:
667 options.insn_specifying_widths = a2i (value);
670 case hi_bit_nr_option:
672 options.hi_bit_nr = a2i (value);
673 if (options.hi_bit_nr != 0
674 && options.hi_bit_nr != options.insn_bit_size - 1)
675 error (option_record->line, "hi-bit-nr / insn-bit-size conflict\n");
678 case flags_filter_option:
680 filter_parse (&options.flags_filter, value);
683 case model_filter_option:
685 filter_parse (&options.model_filter, value);
688 case multi_sim_option:
690 options.gen.multi_sim = a2i (value);
693 case format_names_option:
695 filter_parse (&options.format_name_filter, value);
698 case gen_delayed_branch:
700 options.gen.delayed_branch = a2i (value);
705 error (option_record->line, "Unknown option - %s\n", name);
715 parse_function_record (table *file,
717 function_entry **list,
718 function_entry **list_entry,
722 function_entry *new_function;
723 new_function = ZALLOC (function_entry);
724 new_function->line = record->line;
725 new_function->is_internal = is_internal;
726 /* parse the function header */
727 if (record_is_old (record))
729 if (record->nr_fields < nr_old_function_fields)
730 error (record->line, "Missing fields from (old) function record\n");
731 new_function->type = record->field[old_function_typedef_field];
732 new_function->type = record->field[old_function_typedef_field];
733 if (record->nr_fields > old_function_param_field)
734 new_function->param = record->field[old_function_param_field];
735 new_function->name = record->field[old_function_name_field];
739 if (record->nr_fields < nr_function_fields)
740 error (record->line, "Missing fields from function record\n");
741 filter_parse (&new_function->flags,
742 record->field[record_filter_flags_field]);
743 filter_parse (&new_function->models,
744 record->field[record_filter_models_field]);
745 new_function->type = record->field[function_typedef_field];
746 new_function->param = record->field[function_param_field];
747 new_function->name = record->field[function_name_field];
749 record = table_read (file);
750 /* parse any function-model records */
751 while (record != NULL
752 && record_prefix_is (record, '*', nr_function_model_fields))
754 char *model_name = record->field[function_model_name_field] + 1; /*skip `*'*/
755 filter_parse (&new_function->models, model_name);
756 if (!filter_is_subset (model->processors, new_function->models))
758 error (record->line, "machine model `%s' undefined\n", model_name);
760 record = table_read (file);
762 /* parse the function body */
763 if (record->type == table_code_entry)
765 new_function->code = record;
766 record = table_read (file);
769 if (!filter_is_subset (options.flags_filter, new_function->flags))
771 if (options.warn.discard)
772 notify (new_function->line, "Discarding function %s - filter flags\n",
775 else if (new_function->models != NULL
776 && !filter_is_common (options.model_filter, new_function->models))
778 if (options.warn.discard)
779 notify (new_function->line, "Discarding function %s - filter models\n",
784 while (*list != NULL)
785 list = &(*list)->next;
786 *list = new_function;
787 if (list_entry != NULL)
788 *list_entry = new_function;
795 parse_insn_model_record (table *file,
800 insn_model_entry **last_insn_model;
801 insn_model_entry *new_insn_model = ZALLOC (insn_model_entry);
803 new_insn_model->line = record->line;
804 if (record->nr_fields > insn_model_unit_data_field)
805 new_insn_model->unit_data = record->field[insn_model_unit_data_field];
806 new_insn_model->insn = insn;
807 /* parse the model names, verify that all were defined */
808 new_insn_model->names = NULL;
809 filter_parse (&new_insn_model->names,
810 record->field[insn_model_name_field] + 1 /*skip `*'*/);
811 if (new_insn_model->names == NULL)
813 /* No processor names - a generic model entry, enter it into all
814 the non-empty fields */
816 for (index = 0; index < model->nr_models; index++)
817 if (insn->model[index] == 0)
819 insn->model[index] = new_insn_model;
821 /* also add the complete processor set to this processor's set */
822 filter_add (&insn->processors, model->processors);
826 /* Find the corresponding master model record for each name so
827 that they can be linked in. */
832 name = filter_next (new_insn_model->names, name);
833 if (name == NULL) break;
834 index = filter_is_member (model->processors, name) - 1;
837 error (new_insn_model->line,
838 "machine model `%s' undefined\n", name);
840 /* store it in the corresponding model array entry */
841 if (insn->model[index] != NULL
842 && insn->model[index]->names != NULL)
844 warning (new_insn_model->line,
845 "machine model `%s' previously defined\n", name);
846 error (insn->model[index]->line, "earlier definition\n");
848 insn->model[index] = new_insn_model;
849 /* also add the name to the instructions processor set as an
850 alternative lookup mechanism */
851 filter_parse (&insn->processors, name);
855 /* for some reason record the max length of any
856 function unit field */
857 int len = strlen (insn_model_ptr->field[insn_model_fields]);
858 if (model->max_model_fields_len < len)
859 model->max_model_fields_len = len;
862 last_insn_model = &insn->models;
863 while ((*last_insn_model) != NULL)
864 last_insn_model = &(*last_insn_model)->next;
865 *last_insn_model = new_insn_model;
870 parse_insn_mnemonic_record (table *file,
874 insn_mnemonic_entry **last_insn_mnemonic;
875 insn_mnemonic_entry *new_insn_mnemonic = ZALLOC (insn_mnemonic_entry);
877 new_insn_mnemonic->line = record->line;
878 ASSERT (record->nr_fields > insn_mnemonic_format_field);
879 new_insn_mnemonic->format = record->field[insn_mnemonic_format_field];
880 ASSERT (new_insn_mnemonic->format[0] == '"');
881 if (new_insn_mnemonic->format[strlen (new_insn_mnemonic->format) - 1] != '"')
882 error (new_insn_mnemonic->line, "Missing closing double quote in mnemonic field\n");
883 if (record->nr_fields > insn_mnemonic_condition_field)
884 new_insn_mnemonic->condition = record->field[insn_mnemonic_condition_field];
885 new_insn_mnemonic->insn = insn;
887 last_insn_mnemonic = &insn->mnemonics;
888 while ((*last_insn_mnemonic) != NULL)
889 last_insn_mnemonic = &(*last_insn_mnemonic)->next;
890 insn->nr_mnemonics++;
891 *last_insn_mnemonic = new_insn_mnemonic;
896 parse_macro_record (table *file,
900 error (record->line, "Macros are not implemented");
902 /* parse the define record */
903 if (record->nr_fields < nr_define_fields)
904 error (record->line, "Incorrect nr fields for define record\n");
906 if (!is_filtered_out (options.flags_filter,
907 record->field[record_filter_flags_field])
908 && !is_filtered_out (options.model_filter,
909 record->field[record_filter_models_field]))
913 record->field[macro_name_field],
914 record->field[macro_args_field],
915 record->field[macro_expr_field]);
917 record = table_read (file);
924 load_insn_table (char *file_name,
927 table *file = table_open (file_name);
928 table_entry *record = table_read (file);
930 insn_table *isa = ZALLOC (insn_table);
931 model_table *model = ZALLOC (model_table);
936 while (record != NULL)
939 switch (record_type (record))
944 record = parse_include_record (file, record);
950 if (isa->insns != NULL)
951 error (record->line, "Option after first instruction\n");
952 record = parse_option_record (file, record);
956 case string_function_record:
958 function_entry *function = NULL;
959 record = parse_function_record (file, record,
964 /* convert a string function record into an internal function */
965 if (function != NULL)
967 char *name = NZALLOC (char,
969 + strlen (function->name)
971 strcat (name, "str_");
972 strcat (name, function->name);
973 function->name = name;
974 function->type = "const char *";
979 case function_record: /* function record */
981 record = parse_function_record (file, record,
989 case internal_record:
991 /* only insert it into the function list if it is unknown */
992 function_entry *function = NULL;
993 record = parse_function_record (file, record,
998 /* check what was inserted to see if a pseudo-instruction
999 entry also needs to be created */
1000 if (function != NULL)
1002 insn_entry **insn = NULL;
1003 if (strcmp (function->name, "illegal") == 0)
1005 /* illegal function save it away */
1006 if (isa->illegal_insn != NULL)
1008 warning (function->line,
1009 "Multiple illegal instruction definitions\n");
1010 error (isa->illegal_insn->line,
1011 "Location of first illegal instruction\n");
1014 insn = &isa->illegal_insn;
1018 *insn = ZALLOC (insn_entry);
1019 (*insn)->line = function->line;
1020 (*insn)->name = function->name;
1021 (*insn)->code = function->code;
1027 case scratch_record: /* cache macro records */
1029 case compute_record:
1031 cache_entry *new_cache;
1032 /* parse the cache record */
1033 if (record->nr_fields < nr_cache_fields)
1034 error (record->line,
1035 "Incorrect nr of fields for scratch/cache/compute record\n");
1037 new_cache = ZALLOC (cache_entry);
1038 new_cache->line = record->line;
1039 filter_parse (&new_cache->flags,
1040 record->field[record_filter_flags_field]);
1041 filter_parse (&new_cache->models,
1042 record->field[record_filter_models_field]);
1043 new_cache->type = record->field[cache_typedef_field];
1044 new_cache->name = record->field[cache_name_field];
1045 filter_parse (&new_cache->original_fields,
1046 record->field[cache_original_fields_field]);
1047 new_cache->expression = record->field[cache_expression_field];
1048 /* insert it but only if not filtered out */
1049 if (!filter_is_subset (options.flags_filter, new_cache->flags))
1051 notify (new_cache->line, "Discarding cache entry %s - filter flags\n",
1054 else if (is_filtered_out (options.model_filter,
1055 record->field[record_filter_models_field]))
1057 notify (new_cache->line, "Discarding cache entry %s - filter models\n",
1063 last = &isa->caches;
1064 while (*last != NULL)
1065 last = &(*last)->next;
1068 /* advance things */
1069 record = table_read (file);
1074 case model_processor_record:
1076 model_entry *new_model;
1077 /* parse the model */
1078 if (record->nr_fields < nr_model_processor_fields)
1079 error (record->line, "Incorrect nr of fields for model record\n");
1080 if (isa->insns != NULL)
1081 error (record->line, "Model appears after first instruction\n");
1082 new_model = ZALLOC (model_entry);
1083 filter_parse (&new_model->flags,
1084 record->field[record_filter_flags_field]);
1085 new_model->line = record->line;
1086 new_model->name = record->field[model_name_field];
1087 new_model->full_name = record->field[model_full_name_field];
1088 new_model->unit_data = record->field[model_unit_data_field];
1089 /* only insert it if not filtered out */
1090 if (!filter_is_subset (options.flags_filter, new_model->flags))
1092 notify (new_model->line, "Discarding processor model %s - filter flags\n",
1095 else if (is_filtered_out (options.model_filter,
1096 record->field[record_filter_models_field]))
1098 notify (new_model->line, "Discarding processor model %s - filter models\n",
1101 else if (filter_is_member (model->processors, new_model->name))
1103 error (new_model->line, "Duplicate processor model %s\n",
1109 last = &model->models;
1110 while (*last != NULL)
1111 last = &(*last)->next;
1114 model->nr_models ++;
1115 filter_parse (&model->processors, new_model->name);
1117 /* advance things */
1118 record = table_read (file);
1122 case model_macro_record:
1123 record = parse_model_data_record (isa, file, record,
1124 nr_model_macro_fields,
1128 case model_data_record:
1129 record = parse_model_data_record (isa, file, record,
1130 nr_model_data_fields,
1134 case model_static_record:
1135 record = parse_function_record (file, record,
1142 case model_internal_record:
1143 record = parse_function_record (file, record,
1150 case model_function_record:
1151 record = parse_function_record (file, record,
1158 case insn_record: /* instruction records */
1160 insn_entry *new_insn;
1162 /* parse the instruction */
1163 if (record->nr_fields < nr_insn_fields)
1164 error (record->line, "Incorrect nr of fields for insn record\n");
1165 new_insn = ZALLOC (insn_entry);
1166 new_insn->line = record->line;
1167 filter_parse (&new_insn->flags,
1168 record->field[record_filter_flags_field]);
1169 /* save the format field. Can't parse it until after the
1170 filter-out checks. Could be filtered out because the
1171 format is invalid */
1172 format = record->field[insn_word_field];
1173 new_insn->format_name = record->field[insn_format_name_field];
1174 if (options.format_name_filter != NULL
1175 && !filter_is_member (options.format_name_filter,
1176 new_insn->format_name))
1177 error (new_insn->line, "Unreconized instruction format name `%s'\n",
1178 new_insn->format_name);
1179 filter_parse (&new_insn->options,
1180 record->field[insn_options_field]);
1181 new_insn->name = record->field[insn_name_field];
1182 record = table_read (file);
1183 /* Parse any model/assember records */
1184 new_insn->nr_models = model->nr_models;
1185 new_insn->model = NZALLOC (insn_model_entry*, model->nr_models + 1);
1186 while (record != NULL)
1188 if (record_prefix_is (record, '*', nr_insn_model_fields))
1189 parse_insn_model_record (file, record, new_insn, model);
1190 else if (record_prefix_is (record, '"', nr_insn_mnemonic_fields))
1191 parse_insn_mnemonic_record (file, record, new_insn);
1195 record = table_read (file);
1197 /* Parse the code record */
1198 if (record != NULL && record->type == table_code_entry)
1200 new_insn->code = record;
1201 record = table_read (file);
1204 if (!filter_is_subset (options.flags_filter, new_insn->flags))
1206 if (options.warn.discard)
1207 notify (new_insn->line,
1208 "Discarding instruction %s (flags-filter)\n",
1211 else if (new_insn->processors != NULL
1212 && options.model_filter != NULL
1213 && !filter_is_common (options.model_filter,
1214 new_insn->processors))
1216 /* only discard an instruction based in the processor
1217 model when both the instruction and the options are
1219 if (options.warn.discard)
1220 notify (new_insn->line,
1221 "Discarding instruction %s (processor-model)\n",
1227 /* finish the parsing */
1228 parse_insn_words (new_insn, format);
1232 last = &(*last)->next;
1234 /* update global isa counters */
1236 if (isa->max_nr_words < new_insn->nr_words)
1237 isa->max_nr_words = new_insn->nr_words;
1238 filter_add (&isa->flags, new_insn->flags);
1239 filter_add (&isa->options, new_insn->options);
1245 record = parse_macro_record (file, record);
1248 case unknown_record:
1250 error (record->line, "Unknown or unexpected entry\n");
1260 print_insn_words (lf *file,
1263 insn_word_entry *word = insn->words;
1268 insn_field_entry *field = word->first;
1271 if (options.insn_specifying_widths)
1272 lf_printf (file, "%d.", field->width);
1274 lf_printf (file, "%d.", i2target (options.hi_bit_nr, field->first));
1275 switch (field->type)
1277 case insn_field_invalid:
1280 case insn_field_int:
1281 lf_printf (file, "0x%lx", (long) field->val_int);
1283 case insn_field_reserved:
1284 lf_printf (file, "/");
1286 case insn_field_wild:
1287 lf_printf (file, "*");
1289 case insn_field_string:
1290 lf_printf (file, "%s", field->val_string);
1293 if (field == word->last)
1295 field = field->next;
1296 lf_printf (file, ",");
1301 lf_printf (file, "+");
1309 function_entry_traverse (lf *file,
1310 function_entry *functions,
1311 function_entry_handler *handler,
1314 function_entry *function;
1315 for (function = functions; function != NULL; function = function->next)
1317 handler (file, function, data);
1322 insn_table_traverse_insn (lf *file,
1324 insn_entry_handler *handler,
1328 for (insn = isa->insns; insn != NULL; insn = insn->next)
1330 handler (file, isa, insn, data);
1336 dump_function_entry (lf *file,
1338 function_entry *entry,
1341 lf_printf (file, "%s(function_entry *) 0x%lx", prefix, (long) entry);
1344 dump_line_ref (file, "\n(line ", entry->line, ")");
1345 dump_filter (file, "\n(flags ", entry->flags, ")");
1346 lf_printf (file, "\n(type \"%s\")", entry->type);
1347 lf_printf (file, "\n(name \"%s\")", entry->name);
1348 lf_printf (file, "\n(param \"%s\")", entry->param);
1349 dump_table_entry (file, "\n(code ", entry->code, ")");
1350 lf_printf (file, "\n(is_internal %d)", entry->is_internal);
1351 lf_printf (file, "\n(next 0x%lx)", (long) entry->next);
1353 lf_printf (file, "%s", suffix);
1357 dump_function_entries (lf *file,
1359 function_entry *entry,
1362 lf_printf (file, "%s", prefix);
1363 lf_indent (file, +1);
1364 while (entry != NULL)
1366 dump_function_entry (file, "\n(", entry, ")");
1367 entry = entry->next;
1369 lf_indent (file, -1);
1370 lf_printf (file, "%s", suffix);
1374 cache_entry_type_to_str (cache_entry_type type)
1378 case scratch_value: return "scratch";
1379 case cache_value: return "cache";
1380 case compute_value: return "compute";
1382 ERROR ("Bad switch");
1387 dump_cache_entry (lf *file,
1392 lf_printf (file, "%s(cache_entry *) 0x%lx", prefix, (long) entry);
1395 dump_line_ref (file, "\n(line ", entry->line, ")");
1396 dump_filter (file, "\n(flags ", entry->flags, ")");
1397 lf_printf (file, "\n(entry_type \"%s\")", cache_entry_type_to_str (entry->entry_type));
1398 lf_printf (file, "\n(name \"%s\")", entry->name);
1399 dump_filter (file, "\n(original_fields ", entry->original_fields, ")");
1400 lf_printf (file, "\n(type \"%s\")", entry->type);
1401 lf_printf (file, "\n(expression \"%s\")", entry->expression);
1402 lf_printf (file, "\n(next 0x%lx)", (long) entry->next);
1404 lf_printf (file, "%s", suffix);
1408 dump_cache_entries (lf *file,
1413 lf_printf (file, "%s", prefix);
1414 lf_indent (file, +1);
1415 while (entry != NULL)
1417 dump_cache_entry (file, "\n(", entry, ")");
1418 entry = entry->next;
1420 lf_indent (file, -1);
1421 lf_printf (file, "%s", suffix);
1425 dump_model_data (lf *file,
1430 lf_printf (file, "%s(model_data *) 0x%lx", prefix, (long) entry);
1433 lf_indent (file, +1);
1434 dump_line_ref (file, "\n(line ", entry->line, ")");
1435 dump_filter (file, "\n(flags ", entry->flags, ")");
1436 dump_table_entry (file, "\n(entry ", entry->entry, ")");
1437 dump_table_entry (file, "\n(code ", entry->code, ")");
1438 lf_printf (file, "\n(next 0x%lx)", (long) entry->next);
1439 lf_indent (file, -1);
1441 lf_printf (file, "%s", prefix);
1445 dump_model_datas (lf *file,
1450 lf_printf (file, "%s", prefix);
1451 lf_indent (file, +1);
1452 while (entry != NULL)
1454 dump_model_data (file, "\n(", entry, ")");
1455 entry = entry->next;
1457 lf_indent (file, -1);
1458 lf_printf (file, "%s", suffix);
1462 dump_model_entry (lf *file,
1467 lf_printf (file, "%s(model_entry *) 0x%lx", prefix, (long) entry);
1470 lf_indent (file, +1);
1471 dump_line_ref (file, "\n(line ", entry->line, ")");
1472 dump_filter (file, "\n(flags ", entry->flags, ")");
1473 lf_printf (file, "\n(name \"%s\")", entry->name);
1474 lf_printf (file, "\n(full_name \"%s\")", entry->full_name);
1475 lf_printf (file, "\n(unit_data \"%s\")", entry->unit_data);
1476 lf_printf (file, "\n(next 0x%lx)", (long) entry->next);
1477 lf_indent (file, -1);
1479 lf_printf (file, "%s", prefix);
1483 dump_model_entries (lf *file,
1488 lf_printf (file, "%s", prefix);
1489 lf_indent (file, +1);
1490 while (entry != NULL)
1492 dump_model_entry (file, "\n(", entry, ")");
1493 entry = entry->next;
1495 lf_indent (file, -1);
1496 lf_printf (file, "%s", suffix);
1501 dump_model_table (lf *file,
1506 lf_printf (file, "%s(model_table *) 0x%lx", prefix, (long) entry);
1509 lf_indent (file, +1);
1510 dump_filter (file, "\n(processors ", entry->processors, ")");
1511 lf_printf (file, "\n(nr_models %d)", entry->nr_models);
1512 dump_model_entries (file, "\n(models ", entry->models, ")");
1513 dump_model_datas (file, "\n(macros ", entry->macros, ")");
1514 dump_model_datas (file, "\n(data ", entry->data, ")");
1515 dump_function_entries (file, "\n(statics ", entry->statics, ")");
1516 dump_function_entries (file, "\n(internals ", entry->functions, ")");
1517 dump_function_entries (file, "\n(functions ", entry->functions, ")");
1518 lf_indent (file, -1);
1520 lf_printf (file, "%s", suffix);
1525 insn_field_type_to_str (insn_field_type type)
1529 case insn_field_invalid: ASSERT (0); return "(invalid)";
1530 case insn_field_int: return "int";
1531 case insn_field_reserved: return "reserved";
1532 case insn_field_wild: return "wild";
1533 case insn_field_string: return "string";
1535 ERROR ("bad switch");
1540 dump_insn_field (lf *file,
1542 insn_field_entry *field,
1546 lf_printf (file, "%s(insn_field_entry *) 0x%lx", prefix, (long) field);
1549 lf_indent (file, +1);
1550 lf_printf (file, "%s(first %d)", sep, field->first);
1551 lf_printf (file, "%s(last %d)", sep, field->last);
1552 lf_printf (file, "%s(width %d)", sep, field->width);
1553 lf_printf (file, "%s(type %s)", sep, insn_field_type_to_str (field->type));
1554 switch (field->type)
1556 case insn_field_invalid:
1559 case insn_field_int:
1560 lf_printf (file, "%s(val 0x%lx)", sep, (long) field->val_int);
1562 case insn_field_reserved:
1563 /* nothing output */
1565 case insn_field_wild:
1566 /* nothing output */
1568 case insn_field_string:
1569 lf_printf (file, "%s(val \"%s\")", sep, field->val_string);
1572 lf_printf (file, "%s(next 0x%lx)", sep, (long) field->next);
1573 lf_printf (file, "%s(prev 0x%lx)", sep, (long) field->prev);
1574 lf_indent (file, -1);
1576 lf_printf (file, "%s", suffix);
1580 dump_insn_word_entry (lf *file,
1582 insn_word_entry *word,
1585 lf_printf (file, "%s(insn_word_entry *) 0x%lx", prefix, (long) word);
1589 insn_field_entry *field;
1590 lf_indent (file, +1);
1591 lf_printf (file, "\n(first 0x%lx)", (long) word->first);
1592 lf_printf (file, "\n(last 0x%lx)", (long) word->last);
1593 lf_printf (file, "\n(bit");
1594 for (i = 0; i < options.insn_bit_size; i++)
1595 lf_printf (file, "\n ((value %d) (mask %d) (field 0x%lx))",
1596 word->bit[i]->value, word->bit[i]->mask, (long) word->bit[i]->field);
1597 lf_printf (file, ")");
1598 for (field = word->first; field != NULL; field = field->next)
1599 dump_insn_field (file, "\n(", field, ")");
1600 dump_filter (file, "\n(field_names ", word->field_names, ")");
1601 lf_printf (file, "\n(next 0x%lx)", (long) word->next);
1602 lf_indent (file, -1);
1604 lf_printf (file, "%s", suffix);
1608 dump_insn_word_entries (lf *file,
1610 insn_word_entry *word,
1613 lf_printf (file, "%s", prefix);
1614 while (word != NULL)
1616 dump_insn_word_entry (file, "\n(", word, ")");
1619 lf_printf (file, "%s", suffix);
1623 dump_insn_model_entry (lf *file,
1625 insn_model_entry *model,
1628 lf_printf (file, "%s(insn_model_entry *) 0x%lx", prefix, (long) model);
1631 lf_indent (file, +1);
1632 dump_line_ref (file, "\n(line ", model->line, ")");
1633 dump_filter (file, "\n(names ", model->names, ")");
1634 lf_printf (file, "\n(full_name \"%s\")", model->full_name);
1635 lf_printf (file, "\n(unit_data \"%s\")", model->unit_data);
1636 lf_printf (file, "\n(insn (insn_entry *) 0x%lx)", (long) model->insn);
1637 lf_printf (file, "\n(next (insn_model_entry *) 0x%lx)",
1638 (long) model->next);
1639 lf_indent (file, -1);
1641 lf_printf (file, "%s", suffix);
1645 dump_insn_model_entries (lf *file,
1647 insn_model_entry *model,
1650 lf_printf (file, "%s", prefix);
1651 while (model != NULL)
1653 dump_insn_model_entry (file, "\n", model, "");
1654 model = model->next;
1656 lf_printf (file, "%s", suffix);
1661 dump_insn_mnemonic_entry (lf *file,
1663 insn_mnemonic_entry *mnemonic,
1666 lf_printf (file, "%s(insn_mnemonic_entry *) 0x%lx", prefix, (long) mnemonic);
1667 if (mnemonic != NULL)
1669 lf_indent (file, +1);
1670 dump_line_ref (file, "\n(line ", mnemonic->line, ")");
1671 lf_printf (file, "\n(format \"%s\")", mnemonic->format);
1672 lf_printf (file, "\n(condition \"%s\")", mnemonic->condition);
1673 lf_printf (file, "\n(insn (insn_entry *) 0x%lx)",
1674 (long) mnemonic->insn);
1675 lf_printf (file, "\n(next (insn_mnemonic_entry *) 0x%lx)",
1676 (long) mnemonic->next);
1677 lf_indent (file, -1);
1679 lf_printf (file, "%s", suffix);
1683 dump_insn_mnemonic_entries (lf *file,
1685 insn_mnemonic_entry *mnemonic,
1688 lf_printf (file, "%s", prefix);
1689 while (mnemonic != NULL)
1691 dump_insn_mnemonic_entry (file, "\n", mnemonic, "");
1692 mnemonic = mnemonic->next;
1694 lf_printf (file, "%s", suffix);
1698 dump_insn_entry (lf *file,
1703 lf_printf (file, "%s(insn_entry *) 0x%lx", prefix, (long) entry);
1707 lf_indent (file, +1);
1708 dump_line_ref (file, "\n(line ", entry->line, ")");
1709 dump_filter (file, "\n(flags ", entry->flags, ")");
1710 lf_printf (file, "\n(nr_words %d)", entry->nr_words);
1711 dump_insn_word_entries (file, "\n(words ", entry->words, ")");
1712 lf_printf (file, "\n(word");
1713 for (i = 0; i < entry->nr_models; i++)
1714 lf_printf (file, " 0x%lx", (long) entry->word[i]);
1715 lf_printf (file, ")");
1716 dump_filter (file, "\n(field_names ", entry->field_names, ")");
1717 lf_printf (file, "\n(format_name \"%s\")", entry->format_name);
1718 dump_filter (file, "\n(options ", entry->options, ")");
1719 lf_printf (file, "\n(name \"%s\")", entry->name);
1720 lf_printf (file, "\n(nr_models %d)", entry->nr_models);
1721 dump_insn_model_entries (file, "\n(models ", entry->models, ")");
1722 lf_printf (file, "\n(model");
1723 for (i = 0; i < entry->nr_models; i++)
1724 lf_printf (file, " 0x%lx", (long) entry->model[i]);
1725 lf_printf (file, ")");
1726 dump_filter (file, "\n(processors ", entry->processors, ")");
1727 dump_insn_mnemonic_entries (file, "\n(mnemonics ", entry->mnemonics, ")");
1728 dump_table_entry (file, "\n(code ", entry->code, ")");
1729 lf_printf (file, "\n(next 0x%lx)", (long) entry->next);
1730 lf_indent (file, -1);
1732 lf_printf (file, "%s", suffix);
1736 dump_insn_entries (lf *file,
1741 lf_printf (file, "%s", prefix);
1742 lf_indent (file, +1);
1743 while (entry != NULL)
1745 dump_insn_entry (file, "\n(", entry, ")");
1746 entry = entry->next;
1748 lf_indent (file, -1);
1749 lf_printf (file, "%s", suffix);
1755 dump_insn_table (lf *file,
1760 lf_printf (file, "%s(insn_table *) 0x%lx", prefix, (long) isa);
1763 lf_indent (file, +1);
1764 dump_cache_entries (file, "\n(caches ", isa->caches, ")");
1765 lf_printf (file, "\n(nr_insns %d)", isa->nr_insns);
1766 lf_printf (file, "\n(max_nr_words %d)", isa->max_nr_words);
1767 dump_insn_entries (file, "\n(insns ", isa->insns, ")");
1768 dump_function_entries (file, "\n(functions ", isa->functions, ")");
1769 dump_insn_entry (file, "\n(illegal_insn ", isa->illegal_insn, ")");
1770 dump_model_table (file, "\n(model ", isa->model, ")");
1771 dump_filter (file, "\n(flags ", isa->flags, ")");
1772 dump_filter (file, "\n(options ", isa->options, ")");
1773 lf_indent (file, -1);
1775 lf_printf (file, "%s", suffix);
1780 igen_options options;
1783 main (int argc, char **argv)
1788 INIT_OPTIONS (options);
1791 filter_parse (&options.flags_filter, argv[2]);
1793 error (NULL, "Usage: insn <insn-table> [ <filter-in> ]\n");
1795 isa = load_insn_table (argv[1], NULL);
1796 l = lf_open ("-", "stdout", lf_omit_references, lf_is_text, "tmp-ld-insn");
1797 dump_insn_table (l, "(isa ", isa, ")\n");