1 /* This file is part of the program psim.
3 Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 /* load the opcode stat structure */
26 #include "ld-decode.h"
45 static const name_map decode_type_map[] = {
46 { "normal", normal_decode_rule },
47 { "expand-forced", expand_forced_rule },
48 { "boolean", boolean_rule },
49 { NULL, normal_decode_rule },
52 static const name_map decode_gen_map[] = {
53 { "array", array_gen },
54 { "switch", switch_gen },
55 { "padded-switch", padded_switch_gen },
56 { "goto-switch", goto_switch_gen },
60 static const name_map decode_slash_map[] = {
61 { "variable-slash", 0 },
62 { "constant-slash", 1 },
67 static decode_gen_type overriding_gen_type = invalid_gen;
70 force_decode_gen_type(const char *type)
72 overriding_gen_type = name2i(type, decode_gen_map);
77 load_decode_table(char *file_name,
80 table *file = table_open(file_name, nr_decode_fields, 0);
82 decode_table *table = NULL;
83 decode_table **curr_rule = &table;
84 while ((entry = table_entry_read(file)) != NULL) {
85 decode_table *new_rule = ZALLOC(decode_table);
86 new_rule->type = name2i(entry->fields[op_options], decode_type_map);
87 new_rule->gen = (overriding_gen_type != invalid_gen
89 : name2i(entry->fields[op_options], decode_gen_map));
90 new_rule->force_slash = name2i(entry->fields[op_options], decode_slash_map);
91 new_rule->first = target_a2i(hi_bit_nr, entry->fields[op_first]);
92 new_rule->last = target_a2i(hi_bit_nr, entry->fields[op_last]);
93 new_rule->force_first = (strlen(entry->fields[op_force_first])
94 ? target_a2i(hi_bit_nr, entry->fields[op_force_first])
95 : new_rule->last + 1);
96 new_rule->force_last = (strlen(entry->fields[op_force_last])
97 ? target_a2i(hi_bit_nr, entry->fields[op_force_last])
98 : new_rule->first - 1);
99 new_rule->force_expansion = entry->fields[op_force_expansion];
100 new_rule->special_mask = a2i(entry->fields[op_special_mask]);
101 new_rule->special_value = a2i(entry->fields[op_special_value]);
102 new_rule->special_constant = a2i(entry->fields[op_special_constant]);
103 *curr_rule = new_rule;
104 curr_rule = &new_rule->next;
111 dump_decode_rule(decode_table *rule,
114 dumpf(indent, "((decode_table*)%p\n", rule);
116 dumpf(indent, " (type %s)\n", i2name(rule->type, decode_type_map));
117 dumpf(indent, " (gen %s)\n", i2name(rule->gen, decode_gen_map));
118 dumpf(indent, " (force_slash %d)\n", rule->force_slash);
119 dumpf(indent, " (first %d)\n", rule->first);
120 dumpf(indent, " (last %d)\n", rule->last);
121 dumpf(indent, " (force_first %d)\n", rule->force_first);
122 dumpf(indent, " (force_last %d)\n", rule->force_last);
123 dumpf(indent, " (force_expansion \"%s\")\n", rule->force_expansion);
124 dumpf(indent, " (special_mask 0x%x)\n", rule->special_mask);
125 dumpf(indent, " (special_value 0x%x)\n", rule->special_value);
126 dumpf(indent, " (special_constant 0x%x)\n", rule->special_constant);
127 dumpf(indent, " (next 0x%x)\n", rule->next);
129 dumpf(indent, " )\n");
136 dump_decode_rules(decode_table *rule,
140 dump_decode_rule(rule, indent);
146 main(int argc, char **argv)
150 error("Usage: decode <decode-file> <hi-bit-nr>\n");
151 rules = load_decode_table(argv[1], a2i(argv[2]));
152 dump_decode_rules(rules, 0);