1 /* This file is part of the program psim.
3 Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 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/>.
20 /* load the opcode stat structure */
25 #include "ld-decode.h"
44 static const name_map decode_type_map
[] = {
45 { "normal", normal_decode_rule
},
46 { "expand-forced", expand_forced_rule
},
47 { "boolean", boolean_rule
},
48 { NULL
, normal_decode_rule
},
51 static const name_map decode_gen_map
[] = {
52 { "array", array_gen
},
53 { "switch", switch_gen
},
54 { "padded-switch", padded_switch_gen
},
55 { "goto-switch", goto_switch_gen
},
59 static const name_map decode_slash_map
[] = {
60 { "variable-slash", 0 },
61 { "constant-slash", 1 },
66 static decode_gen_type overriding_gen_type
= invalid_gen
;
69 force_decode_gen_type(const char *type
)
71 overriding_gen_type
= name2i(type
, decode_gen_map
);
76 load_decode_table(char *file_name
,
79 table
*file
= table_open(file_name
, nr_decode_fields
, 0);
81 decode_table
*table
= NULL
;
82 decode_table
**curr_rule
= &table
;
83 while ((entry
= table_entry_read(file
)) != NULL
) {
84 decode_table
*new_rule
= ZALLOC(decode_table
);
85 new_rule
->type
= name2i(entry
->fields
[op_options
], decode_type_map
);
86 new_rule
->gen
= (overriding_gen_type
!= invalid_gen
88 : name2i(entry
->fields
[op_options
], decode_gen_map
));
89 new_rule
->force_slash
= name2i(entry
->fields
[op_options
], decode_slash_map
);
90 new_rule
->first
= target_a2i(hi_bit_nr
, entry
->fields
[op_first
]);
91 new_rule
->last
= target_a2i(hi_bit_nr
, entry
->fields
[op_last
]);
92 new_rule
->force_first
= (strlen(entry
->fields
[op_force_first
])
93 ? target_a2i(hi_bit_nr
, entry
->fields
[op_force_first
])
94 : new_rule
->last
+ 1);
95 new_rule
->force_last
= (strlen(entry
->fields
[op_force_last
])
96 ? target_a2i(hi_bit_nr
, entry
->fields
[op_force_last
])
97 : new_rule
->first
- 1);
98 new_rule
->force_expansion
= entry
->fields
[op_force_expansion
];
99 new_rule
->special_mask
= a2i(entry
->fields
[op_special_mask
]);
100 new_rule
->special_value
= a2i(entry
->fields
[op_special_value
]);
101 new_rule
->special_constant
= a2i(entry
->fields
[op_special_constant
]);
102 *curr_rule
= new_rule
;
103 curr_rule
= &new_rule
->next
;
110 dump_decode_rule(decode_table
*rule
,
113 dumpf(indent
, "((decode_table*)%p\n", rule
);
115 dumpf(indent
, " (type %s)\n", i2name(rule
->type
, decode_type_map
));
116 dumpf(indent
, " (gen %s)\n", i2name(rule
->gen
, decode_gen_map
));
117 dumpf(indent
, " (force_slash %d)\n", rule
->force_slash
);
118 dumpf(indent
, " (first %d)\n", rule
->first
);
119 dumpf(indent
, " (last %d)\n", rule
->last
);
120 dumpf(indent
, " (force_first %d)\n", rule
->force_first
);
121 dumpf(indent
, " (force_last %d)\n", rule
->force_last
);
122 dumpf(indent
, " (force_expansion \"%s\")\n", rule
->force_expansion
);
123 dumpf(indent
, " (special_mask 0x%x)\n", rule
->special_mask
);
124 dumpf(indent
, " (special_value 0x%x)\n", rule
->special_value
);
125 dumpf(indent
, " (special_constant 0x%x)\n", rule
->special_constant
);
126 dumpf(indent
, " (next 0x%x)\n", rule
->next
);
128 dumpf(indent
, " )\n");
135 dump_decode_rules(decode_table
*rule
,
139 dump_decode_rule(rule
, indent
);
145 main(int argc
, char **argv
)
149 error("Usage: decode <decode-file> <hi-bit-nr>\n");
150 rules
= load_decode_table(argv
[1], a2i(argv
[2]));
151 dump_decode_rules(rules
, 0);