1 /* This file is part of the program psim.
3 Copyright 1994, 1995, 1996, 2003 Andrew Cagney
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 3 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, see <http://www.gnu.org/licenses/>.
25 #include "filter-ppc.h"
26 #include "ld-decode.h"
33 static model
*last_model
;
35 static insn
*last_model_macro
;
36 static insn
*last_model_function
;
37 static insn
*last_model_internal
;
38 static insn
*last_model_static
;
39 static insn
*last_model_data
;
44 insn
*model_functions
;
49 int max_model_fields_len
;
52 update_depth(insn_table
*entry
,
58 int *max_depth
= (int*)data
;
59 if (*max_depth
< depth
)
65 insn_table_depth(insn_table
*table
)
68 insn_table_traverse_tree(table
,
81 parse_insn_format(table_entry
*entry
,
85 insn_fields
*fields
= ZALLOC(insn_fields
);
87 /* create a leading sentinal */
88 fields
->first
= ZALLOC(insn_field
);
89 fields
->first
->first
= -1;
90 fields
->first
->last
= -1;
91 fields
->first
->width
= 0;
93 /* and a trailing sentinal */
94 fields
->last
= ZALLOC(insn_field
);
95 fields
->last
->first
= insn_bit_size
;
96 fields
->last
->last
= insn_bit_size
;
97 fields
->last
->width
= 0;
99 /* link them together */
100 fields
->first
->next
= fields
->last
;
101 fields
->last
->prev
= fields
->first
;
103 /* now work through the formats */
106 while (*chp
!= '\0') {
107 const char *start_pos
;
108 const char *start_val
;
111 insn_field
*new_field
;
114 if (!isdigit(*chp
)) {
115 ERROR("%s:%d: missing position field at `%s'\n",
116 entry
->file_name
, entry
->line_nr
, chp
);
119 /* break out the bit position */
121 while (isdigit(*chp
))
123 strlen_pos
= chp
- start_pos
;
124 if (*chp
== '.' && strlen_pos
> 0)
127 ERROR("%s:%d: missing field value at %s\n",
128 entry
->file_name
, entry
->line_nr
, chp
);
132 /* break out the value */
134 while ((*start_val
== '/' && *chp
== '/')
135 || (isdigit(*start_val
) && isdigit(*chp
))
136 || (isalpha(*start_val
) && (isalnum(*chp
) || *chp
== '_')))
138 strlen_val
= chp
- start_val
;
141 else if (*chp
!= '\0' || strlen_val
== 0) {
142 ERROR("%s:%d: missing field terminator at %s\n",
143 entry
->file_name
, entry
->line_nr
, chp
);
147 /* create a new field and insert it */
148 new_field
= ZALLOC(insn_field
);
149 new_field
->next
= fields
->last
;
150 new_field
->prev
= fields
->last
->prev
;
151 new_field
->next
->prev
= new_field
;
152 new_field
->prev
->next
= new_field
;
155 new_field
->val_string
= (char*)zalloc(strlen_val
+1);
156 strncpy(new_field
->val_string
, start_val
, strlen_val
);
157 if (isdigit(*new_field
->val_string
)) {
158 new_field
->val_int
= a2i(new_field
->val_string
);
159 new_field
->is_int
= 1;
161 else if (new_field
->val_string
[0] == '/') {
162 new_field
->is_slash
= 1;
165 new_field
->is_string
= 1;
169 new_field
->pos_string
= (char*)zalloc(strlen_pos
+1);
170 strncpy(new_field
->pos_string
, start_pos
, strlen_pos
);
171 new_field
->first
= target_a2i(hi_bit_nr
, new_field
->pos_string
);
172 new_field
->last
= new_field
->next
->first
- 1; /* guess */
173 new_field
->width
= new_field
->last
- new_field
->first
+ 1; /* guess */
174 new_field
->prev
->last
= new_field
->first
-1; /*fix*/
175 new_field
->prev
->width
= new_field
->first
- new_field
->prev
->first
; /*fix*/
178 /* fiddle first/last so that the sentinals `disapear' */
179 ASSERT(fields
->first
->last
< 0);
180 ASSERT(fields
->last
->first
>= insn_bit_size
);
181 fields
->first
= fields
->first
->next
;
182 fields
->last
= fields
->last
->prev
;
184 /* now go over this again, pointing each bit position at a field
189 field
= fields
->first
;
190 for (i
= 0; i
< insn_bit_size
; i
++) {
191 while (field
->last
< i
)
193 fields
->bits
[i
] = field
;
197 /* go over each of the fields, and compute a `value' for the insn */
201 for (field
= fields
->first
;
202 field
->last
< insn_bit_size
;
203 field
= field
->next
) {
204 fields
->value
<<= field
->width
;
206 fields
->value
|= field
->val_int
;
214 parse_include_entry (table
*file
,
215 table_entry
*file_entry
,
217 table_include
*includes
)
219 /* parse the include file_entry */
220 if (file_entry
->nr_fields
< 4)
221 ERROR ("Incorrect nr fields for include record\n");
223 if (!is_filtered_out(filters
, file_entry
->fields
[include_flags
]))
225 table_push (file
, includes
,
226 file_entry
->fields
[include_path
],
227 file_entry
->nr_fields
, file_entry
->nr_fields
);
232 model_table_insert(insn_table
*table
,
233 table_entry
*file_entry
)
237 /* create a new model */
238 model
*new_model
= ZALLOC(model
);
240 new_model
->name
= file_entry
->fields
[model_identifer
];
241 new_model
->printable_name
= file_entry
->fields
[model_name
];
242 new_model
->insn_default
= file_entry
->fields
[model_default
];
244 while (*new_model
->insn_default
&& isspace(*new_model
->insn_default
))
245 new_model
->insn_default
++;
247 len
= strlen(new_model
->insn_default
);
248 if (max_model_fields_len
< len
)
249 max_model_fields_len
= len
;
251 /* append it to the end of the model list */
253 last_model
->next
= new_model
;
256 last_model
= new_model
;
260 model_table_insert_specific(insn_table
*table
,
261 table_entry
*file_entry
,
265 insn
*ptr
= ZALLOC(insn
);
266 ptr
->file_entry
= file_entry
;
268 (*end_ptr
)->next
= ptr
;
276 insn_table_insert_function(insn_table
*table
,
277 table_entry
*file_entry
)
279 /* create a new function */
280 insn
*new_function
= ZALLOC(insn
);
281 new_function
->file_entry
= file_entry
;
283 /* append it to the end of the function list */
284 if (table
->last_function
)
285 table
->last_function
->next
= new_function
;
287 table
->functions
= new_function
;
288 table
->last_function
= new_function
;
292 insn_table_insert_insn(insn_table
*table
,
293 table_entry
*file_entry
,
296 insn
**ptr_to_cur_insn
= &table
->insns
;
297 insn
*cur_insn
= *ptr_to_cur_insn
;
298 table_model_entry
*insn_model_ptr
;
301 /* create a new instruction */
302 insn
*new_insn
= ZALLOC(insn
);
303 new_insn
->file_entry
= file_entry
;
304 new_insn
->fields
= fields
;
306 /* Check out any model information returned to make sure the model
308 for(insn_model_ptr
= file_entry
->model_first
; insn_model_ptr
; insn_model_ptr
= insn_model_ptr
->next
) {
309 const char *name
= insn_model_ptr
->fields
[insn_model_name
];
310 int len
= strlen (insn_model_ptr
->fields
[insn_model_fields
]);
312 while (len
> 0 && isspace(*insn_model_ptr
->fields
[insn_model_fields
])) {
314 insn_model_ptr
->fields
[insn_model_fields
]++;
317 if (max_model_fields_len
< len
)
318 max_model_fields_len
= len
;
320 for(model_ptr
= models
; model_ptr
; model_ptr
= model_ptr
->next
) {
321 if (strcmp(name
, model_ptr
->printable_name
) == 0) {
323 /* Replace the name field with that of the global model, so that when we
324 want to print it out, we can just compare pointers. */
325 insn_model_ptr
->fields
[insn_model_name
] = model_ptr
->printable_name
;
331 ERROR("%s:%d: machine model `%s' was not known about\n",
332 file_entry
->file_name
, file_entry
->line_nr
, name
);
335 /* insert it according to the order of the fields */
336 while (cur_insn
!= NULL
337 && new_insn
->fields
->value
>= cur_insn
->fields
->value
) {
338 ptr_to_cur_insn
= &cur_insn
->next
;
339 cur_insn
= *ptr_to_cur_insn
;
342 new_insn
->next
= cur_insn
;
343 *ptr_to_cur_insn
= new_insn
;
351 load_insn_table(const char *file_name
,
352 decode_table
*decode_rules
,
354 table_include
*includes
,
355 cache_table
**cache_rules
)
357 table
*file
= table_open(file_name
, nr_insn_table_fields
, nr_insn_model_table_fields
);
358 insn_table
*table
= ZALLOC(insn_table
);
359 table_entry
*file_entry
;
360 table
->opcode_rule
= decode_rules
;
362 while ((file_entry
= table_entry_read(file
)) != NULL
) {
363 if (it_is("function", file_entry
->fields
[insn_flags
])
364 || it_is("internal", file_entry
->fields
[insn_flags
])) {
365 insn_table_insert_function(table
, file_entry
);
367 else if ((it_is("function", file_entry
->fields
[insn_form
])
368 || it_is("internal", file_entry
->fields
[insn_form
]))
369 && !is_filtered_out(filters
, file_entry
->fields
[insn_flags
])) {
370 /* Ok, this is evil. Need to convert a new style function into
371 an old style function. Construct an old style table and then
373 char *fields
[nr_insn_table_fields
];
374 memset (fields
, 0, sizeof fields
);
375 fields
[insn_flags
] = file_entry
->fields
[insn_form
];
376 fields
[function_type
] = file_entry
->fields
[insn_name
];
377 fields
[function_name
] = file_entry
->fields
[insn_comment
];
378 fields
[function_param
] = file_entry
->fields
[insn_field_6
];
379 memcpy (file_entry
->fields
, fields
,
380 sizeof (fields
[0]) * file_entry
->nr_fields
);
381 insn_table_insert_function(table
, file_entry
);
388 [ ":" <parameter
-list
> ]
394 else if (it_is("model", file_entry
->fields
[insn_flags
])) {
395 model_table_insert(table
, file_entry
);
397 else if (it_is("model-macro", file_entry
->fields
[insn_flags
])) {
398 model_table_insert_specific(table
, file_entry
, &model_macros
, &last_model_macro
);
400 else if (it_is("model-function", file_entry
->fields
[insn_flags
])) {
401 model_table_insert_specific(table
, file_entry
, &model_functions
, &last_model_function
);
403 else if (it_is("model-internal", file_entry
->fields
[insn_flags
])) {
404 model_table_insert_specific(table
, file_entry
, &model_internal
, &last_model_internal
);
406 else if (it_is("model-static", file_entry
->fields
[insn_flags
])) {
407 model_table_insert_specific(table
, file_entry
, &model_static
, &last_model_static
);
409 else if (it_is("model-data", file_entry
->fields
[insn_flags
])) {
410 model_table_insert_specific(table
, file_entry
, &model_data
, &last_model_data
);
412 else if (it_is("include", file_entry
->fields
[insn_form
])
413 && !is_filtered_out(filters
, file_entry
->fields
[insn_flags
])) {
414 parse_include_entry (file
, file_entry
, filters
, includes
);
416 else if ((it_is("cache", file_entry
->fields
[insn_form
])
417 || it_is("compute", file_entry
->fields
[insn_form
])
418 || it_is("scratch", file_entry
->fields
[insn_form
]))
419 && !is_filtered_out(filters
, file_entry
->fields
[insn_flags
])) {
420 append_cache_rule (cache_rules
,
421 file_entry
->fields
[insn_form
], /* type */
422 file_entry
->fields
[cache_name
],
423 file_entry
->fields
[cache_derived_name
],
424 file_entry
->fields
[cache_type_def
],
425 file_entry
->fields
[cache_expression
],
430 /* skip instructions that aren't relevant to the mode */
431 if (is_filtered_out(filters
, file_entry
->fields
[insn_flags
])) {
432 fprintf(stderr
, "Dropping %s - %s\n",
433 file_entry
->fields
[insn_name
],
434 file_entry
->fields
[insn_flags
]);
437 /* create/insert the new instruction */
438 fields
= parse_insn_format(file_entry
,
439 file_entry
->fields
[insn_format
]);
440 insn_table_insert_insn(table
, file_entry
, fields
);
449 insn_table_traverse_tree(insn_table
*table
,
456 padding_handler
*padding
)
462 && table
->opcode
!= NULL
463 && table
->nr_entries
> 0
464 && table
->entries
!= 0);
466 if (start
!= NULL
&& depth
>= 0)
467 start(table
, file
, data
, depth
);
469 for (entry_nr
= 0, entry
= table
->entries
;
470 entry_nr
< (table
->opcode
->is_boolean
472 : (1 << (table
->opcode
->last
- table
->opcode
->first
+ 1)));
475 || (!table
->opcode
->is_boolean
476 && entry_nr
< entry
->opcode_nr
)) {
477 if (padding
!= NULL
&& depth
>= 0)
478 padding(table
, file
, data
, depth
, entry_nr
);
481 ASSERT(entry
!= NULL
&& (entry
->opcode_nr
== entry_nr
482 || table
->opcode
->is_boolean
));
483 if (entry
->opcode
!= NULL
&& depth
!= 0) {
484 insn_table_traverse_tree(entry
, file
, data
, depth
+1,
485 start
, leaf
, end
, padding
);
487 else if (depth
>= 0) {
489 leaf(entry
, file
, data
, entry
->insns
, depth
);
491 entry
= entry
->sibling
;
494 if (end
!= NULL
&& depth
>= 0)
495 end(table
, file
, data
, depth
);
500 insn_table_traverse_function(insn_table
*table
,
503 function_handler
*leaf
)
506 for (function
= table
->functions
;
508 function
= function
->next
) {
509 leaf(table
, file
, data
, function
->file_entry
);
514 insn_table_traverse_insn(insn_table
*table
,
517 insn_handler
*handler
)
520 for (instruction
= table
->insns
;
522 instruction
= instruction
->next
) {
523 handler(table
, file
, data
, instruction
, 0);
528 /****************************************************************/
531 field_constant_int
= 1,
532 field_constant_slash
= 2,
533 field_constant_string
= 3
534 } constant_field_types
;
538 insn_field_is_constant(insn_field
*field
,
541 /* field is an integer */
543 return field_constant_int
;
544 /* field is `/' and treating that as a constant */
545 if (field
->is_slash
&& rule
->force_slash
)
546 return field_constant_slash
;
547 /* field, though variable is on the list */
548 if (field
->is_string
&& rule
->force_expansion
!= NULL
) {
549 const char *forced_fields
= rule
->force_expansion
;
550 while (*forced_fields
!= '\0') {
552 const char *end
= strchr(forced_fields
, ',');
554 field_len
= strlen(forced_fields
);
556 field_len
= end
-forced_fields
;
557 if (strncmp(forced_fields
, field
->val_string
, field_len
) == 0
558 && field
->val_string
[field_len
] == '\0')
559 return field_constant_string
;
560 forced_fields
+= field_len
;
561 if (*forced_fields
== ',')
569 static opcode_field
*
570 insn_table_find_opcode_field(insn
*insns
,
574 opcode_field
*curr_opcode
= ZALLOC(opcode_field
);
578 curr_opcode
->first
= insn_bit_size
;
579 curr_opcode
->last
= -1;
580 for (entry
= insns
; entry
!= NULL
; entry
= entry
->next
) {
581 insn_fields
*fields
= entry
->fields
;
582 opcode_field new_opcode
;
584 /* find a start point for the opcode field */
585 new_opcode
.first
= rule
->first
;
586 while (new_opcode
.first
<= rule
->last
588 || insn_field_is_constant(fields
->bits
[new_opcode
.first
],
589 rule
) != field_constant_string
)
591 || !insn_field_is_constant(fields
->bits
[new_opcode
.first
],
593 new_opcode
.first
= fields
->bits
[new_opcode
.first
]->last
+ 1;
594 ASSERT(new_opcode
.first
> rule
->last
596 && insn_field_is_constant(fields
->bits
[new_opcode
.first
],
597 rule
) == field_constant_string
)
599 && insn_field_is_constant(fields
->bits
[new_opcode
.first
],
602 /* find the end point for the opcode field */
603 new_opcode
.last
= rule
->last
;
604 while (new_opcode
.last
>= rule
->first
606 || insn_field_is_constant(fields
->bits
[new_opcode
.last
],
607 rule
) != field_constant_string
)
609 || !insn_field_is_constant(fields
->bits
[new_opcode
.last
],
611 new_opcode
.last
= fields
->bits
[new_opcode
.last
]->first
- 1;
612 ASSERT(new_opcode
.last
< rule
->first
614 && insn_field_is_constant(fields
->bits
[new_opcode
.last
],
615 rule
) == field_constant_string
)
617 && insn_field_is_constant(fields
->bits
[new_opcode
.last
],
620 /* now see if our current opcode needs expanding */
621 if (new_opcode
.first
<= rule
->last
622 && curr_opcode
->first
> new_opcode
.first
)
623 curr_opcode
->first
= new_opcode
.first
;
624 if (new_opcode
.last
>= rule
->first
625 && curr_opcode
->last
< new_opcode
.last
)
626 curr_opcode
->last
= new_opcode
.last
;
630 /* was any thing interesting found? */
631 if (curr_opcode
->first
> rule
->last
) {
632 ASSERT(curr_opcode
->last
< rule
->first
);
635 ASSERT(curr_opcode
->last
>= rule
->first
);
636 ASSERT(curr_opcode
->first
<= rule
->last
);
638 /* if something was found, check it includes the forced field range */
640 && curr_opcode
->first
> rule
->force_first
) {
641 curr_opcode
->first
= rule
->force_first
;
644 && curr_opcode
->last
< rule
->force_last
) {
645 curr_opcode
->last
= rule
->force_last
;
647 /* handle special case elminating any need to do shift after mask */
649 && rule
->force_last
== insn_bit_size
-1) {
650 curr_opcode
->last
= insn_bit_size
-1;
653 /* handle any special cases */
654 switch (rule
->type
) {
655 case normal_decode_rule
:
656 /* let the above apply */
658 case expand_forced_rule
:
659 /* expand a limited nr of bits, ignoring the rest */
660 curr_opcode
->first
= rule
->force_first
;
661 curr_opcode
->last
= rule
->force_last
;
664 curr_opcode
->is_boolean
= 1;
665 curr_opcode
->boolean_constant
= rule
->special_constant
;
668 ERROR("Something is going wrong\n");
676 insn_table_insert_expanded(insn_table
*table
,
681 insn_table
**ptr_to_cur_entry
= &table
->entries
;
682 insn_table
*cur_entry
= *ptr_to_cur_entry
;
684 /* find the new table for this entry */
685 while (cur_entry
!= NULL
686 && cur_entry
->opcode_nr
< new_opcode_nr
) {
687 ptr_to_cur_entry
= &cur_entry
->sibling
;
688 cur_entry
= *ptr_to_cur_entry
;
691 if (cur_entry
== NULL
|| cur_entry
->opcode_nr
!= new_opcode_nr
) {
692 insn_table
*new_entry
= ZALLOC(insn_table
);
693 new_entry
->opcode_nr
= new_opcode_nr
;
694 new_entry
->expanded_bits
= new_bits
;
695 new_entry
->opcode_rule
= table
->opcode_rule
->next
;
696 new_entry
->sibling
= cur_entry
;
697 new_entry
->parent
= table
;
698 *ptr_to_cur_entry
= new_entry
;
699 cur_entry
= new_entry
;
702 /* ASSERT new_bits == cur_entry bits */
703 ASSERT(cur_entry
!= NULL
&& cur_entry
->opcode_nr
== new_opcode_nr
);
704 insn_table_insert_insn(cur_entry
,
705 old_insn
->file_entry
,
710 insn_table_expand_opcode(insn_table
*table
,
717 if (field_nr
> table
->opcode
->last
) {
718 insn_table_insert_expanded(table
, instruction
, opcode_nr
, bits
);
721 insn_field
*field
= instruction
->fields
->bits
[field_nr
];
722 if (field
->is_int
|| field
->is_slash
) {
723 ASSERT(field
->first
>= table
->opcode
->first
724 && field
->last
<= table
->opcode
->last
);
725 insn_table_expand_opcode(table
, instruction
, field
->last
+1,
726 ((opcode_nr
<< field
->width
) + field
->val_int
),
731 int last_pos
= ((field
->last
< table
->opcode
->last
)
732 ? field
->last
: table
->opcode
->last
);
733 int first_pos
= ((field
->first
> table
->opcode
->first
)
734 ? field
->first
: table
->opcode
->first
);
735 int width
= last_pos
- first_pos
+ 1;
736 int last_val
= (table
->opcode
->is_boolean
738 for (val
= 0; val
< last_val
; val
++) {
739 insn_bits
*new_bits
= ZALLOC(insn_bits
);
740 new_bits
->field
= field
;
741 new_bits
->value
= val
;
742 new_bits
->last
= bits
;
743 new_bits
->opcode
= table
->opcode
;
744 insn_table_expand_opcode(table
, instruction
, last_pos
+1,
745 ((opcode_nr
<< width
) | val
),
753 insn_table_insert_expanding(insn_table
*table
,
756 insn_table_expand_opcode(table
,
758 table
->opcode
->first
,
760 table
->expanded_bits
);
765 insn_table_expand_insns(insn_table
*table
)
768 ASSERT(table
->nr_insn
>= 1);
770 /* determine a valid opcode */
771 while (table
->opcode_rule
) {
772 /* specials only for single instructions */
773 if ((table
->nr_insn
> 1
774 && table
->opcode_rule
->special_mask
== 0
775 && table
->opcode_rule
->type
== normal_decode_rule
)
776 || (table
->nr_insn
== 1
777 && table
->opcode_rule
->special_mask
!= 0
778 && ((table
->insns
->fields
->value
779 & table
->opcode_rule
->special_mask
)
780 == table
->opcode_rule
->special_value
))
781 || (generate_expanded_instructions
782 && table
->opcode_rule
->special_mask
== 0
783 && table
->opcode_rule
->type
== normal_decode_rule
))
785 insn_table_find_opcode_field(table
->insns
,
787 table
->nr_insn
== 1/*string*/
789 if (table
->opcode
!= NULL
)
791 table
->opcode_rule
= table
->opcode_rule
->next
;
794 /* did we find anything */
795 if (table
->opcode
== NULL
) {
798 ASSERT(table
->opcode
!= NULL
);
800 /* back link what we found to its parent */
801 if (table
->parent
!= NULL
) {
802 ASSERT(table
->parent
->opcode
!= NULL
);
803 table
->opcode
->parent
= table
->parent
->opcode
;
806 /* expand the raw instructions according to the opcode */
809 for (entry
= table
->insns
; entry
!= NULL
; entry
= entry
->next
) {
810 insn_table_insert_expanding(table
, entry
);
814 /* and do the same for the sub entries */
817 for (entry
= table
->entries
; entry
!= NULL
; entry
= entry
->sibling
) {
818 insn_table_expand_insns(entry
);
829 dump_insn_field(insn_field
*field
,
832 printf ("(insn_field*)%p\n", field
);
833 dumpf (indent
, "(first %d)\n", field
->first
);
834 dumpf (indent
, "(last %d)\n", field
->last
);
835 dumpf (indent
, "(width %d)\n", field
->width
);
837 dumpf (indent
, "(is_int %d)\n", field
->val_int
);
839 dumpf (indent
, "(is_slash)\n");
840 if (field
->is_string
)
841 dumpf (indent
, "(is_string `%s')\n", field
->val_string
);
842 dumpf (indent
, "(next %p)\n", field
->next
);
843 dumpf (indent
, "(prev %p)\n", field
->prev
);
847 dump_insn_fields(insn_fields
*fields
,
852 printf("(insn_fields*)%p\n", fields
);
854 dumpf(indent
, "(first %p)\n", fields
->first
);
855 dumpf(indent
, "(last %p)\n", fields
->last
);
857 dumpf(indent
, "(value 0x%x)\n", fields
->value
);
859 for (i
= 0; i
< insn_bit_size
; i
++) {
860 dumpf(indent
, "(bits[%d]", i
);
861 dump_insn_field(fields
->bits
[i
], indent
+1);
862 dumpf(indent
, " )\n");
869 dump_opcode_field(opcode_field
*field
, int indent
, int levels
)
871 printf("(opcode_field*)%p\n", field
);
872 if (levels
&& field
!= NULL
) {
873 dumpf(indent
, "(first %d)\n", field
->first
);
874 dumpf(indent
, "(last %d)\n", field
->last
);
875 dumpf(indent
, "(is_boolean %d)\n", field
->is_boolean
);
876 dumpf(indent
, "(parent ");
877 dump_opcode_field(field
->parent
, indent
, levels
-1);
883 dump_insn_bits(insn_bits
*bits
, int indent
, int levels
)
885 printf("(insn_bits*)%p\n", bits
);
887 if (levels
&& bits
!= NULL
) {
888 dumpf(indent
, "(value %d)\n", bits
->value
);
889 dumpf(indent
, "(opcode ");
890 dump_opcode_field(bits
->opcode
, indent
+1, 0);
891 dumpf(indent
, " )\n");
892 dumpf(indent
, "(field ");
893 dump_insn_field(bits
->field
, indent
+1);
894 dumpf(indent
, " )\n");
895 dumpf(indent
, "(last ");
896 dump_insn_bits(bits
->last
, indent
+1, levels
-1);
903 dump_insn(insn
*entry
, int indent
, int levels
)
905 printf("(insn*)%p\n", entry
);
907 if (levels
&& entry
!= NULL
) {
909 dumpf(indent
, "(file_entry ");
910 dump_table_entry(entry
->file_entry
, indent
+1);
911 dumpf(indent
, " )\n");
913 dumpf(indent
, "(fields ");
914 dump_insn_fields(entry
->fields
, indent
+1);
915 dumpf(indent
, " )\n");
917 dumpf(indent
, "(next ");
918 dump_insn(entry
->next
, indent
+1, levels
-1);
919 dumpf(indent
, " )\n");
927 dump_insn_table(insn_table
*table
,
928 int indent
, int levels
)
931 printf("(insn_table*)%p\n", table
);
933 if (levels
&& table
!= NULL
) {
935 dumpf(indent
, "(opcode_nr %d)\n", table
->opcode_nr
);
937 dumpf(indent
, "(expanded_bits ");
938 dump_insn_bits(table
->expanded_bits
, indent
+1, -1);
939 dumpf(indent
, " )\n");
941 dumpf(indent
, "(int nr_insn %d)\n", table
->nr_insn
);
943 dumpf(indent
, "(insns ");
944 dump_insn(table
->insns
, indent
+1, table
->nr_insn
);
945 dumpf(indent
, " )\n");
947 dumpf(indent
, "(opcode_rule ");
948 dump_decode_rule(table
->opcode_rule
, indent
+1);
949 dumpf(indent
, " )\n");
951 dumpf(indent
, "(opcode ");
952 dump_opcode_field(table
->opcode
, indent
+1, 1);
953 dumpf(indent
, " )\n");
955 dumpf(indent
, "(nr_entries %d)\n", table
->nr_entries
);
956 dumpf(indent
, "(entries ");
957 dump_insn_table(table
->entries
, indent
+1, table
->nr_entries
);
958 dumpf(indent
, " )\n");
960 dumpf(indent
, "(sibling ");
961 dump_insn_table(table
->sibling
, indent
+1, levels
-1);
962 dumpf(indent
, " )\n");
964 dumpf(indent
, "(parent ");
965 dump_insn_table(table
->parent
, indent
+1, 0);
966 dumpf(indent
, " )\n");
971 int insn_bit_size
= ppc_max_insn_bit_size
;
973 int generate_expanded_instructions
;
976 main(int argc
, char **argv
)
978 filter
*filters
= NULL
;
979 decode_table
*decode_rules
= NULL
;
980 insn_table
*instructions
= NULL
;
981 cache_table
*cache_rules
= NULL
;
984 ERROR("Usage: insn <filter> <hi-bit-nr> <decode-table> <insn-table>\n");
986 filter_parse(&filters
, argv
[1]);
987 hi_bit_nr
= a2i(argv
[2]);
988 ASSERT(hi_bit_nr
< insn_bit_size
);
989 decode_rules
= load_decode_table(argv
[3], hi_bit_nr
);
990 instructions
= load_insn_table(argv
[4], decode_rules
, filters
, NULL
,
992 insn_table_expand_insns(instructions
);
994 dump_insn_table(instructions
, 0, -1);