Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* This file is part of the program psim. |
2 | ||
3 | Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au> | |
4 | ||
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 | |
3fd725ef | 7 | the Free Software Foundation; either version 3 of the License, or |
c906108c SS |
8 | (at your option) any later version. |
9 | ||
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. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
51b318de | 16 | along with this program; if not, see <http://www.gnu.org/licenses/>. |
c906108c SS |
17 | |
18 | */ | |
19 | ||
20 | /* load the opcode stat structure */ | |
21 | ||
22 | #include "misc.h" | |
23 | #include "lf.h" | |
24 | #include "table.h" | |
25 | #include "ld-decode.h" | |
26 | ||
27 | #ifndef NULL | |
28 | #define NULL 0 | |
29 | #endif | |
30 | ||
31 | enum { | |
32 | op_options, | |
33 | op_first, | |
34 | op_last, | |
35 | op_force_first, | |
36 | op_force_last, | |
37 | op_force_expansion, | |
38 | op_special_mask, | |
39 | op_special_value, | |
40 | op_special_constant, | |
41 | nr_decode_fields, | |
42 | }; | |
43 | ||
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 }, | |
49 | }; | |
50 | ||
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 }, | |
56 | { NULL, -1 }, | |
57 | }; | |
58 | ||
59 | static const name_map decode_slash_map[] = { | |
60 | { "variable-slash", 0 }, | |
61 | { "constant-slash", 1 }, | |
62 | { NULL }, | |
63 | }; | |
64 | ||
65 | ||
66 | static decode_gen_type overriding_gen_type = invalid_gen; | |
67 | ||
68 | void | |
69 | force_decode_gen_type(const char *type) | |
70 | { | |
71 | overriding_gen_type = name2i(type, decode_gen_map); | |
72 | } | |
73 | ||
74 | ||
75 | decode_table * | |
76 | load_decode_table(char *file_name, | |
77 | int hi_bit_nr) | |
78 | { | |
79 | table *file = table_open(file_name, nr_decode_fields, 0); | |
80 | table_entry *entry; | |
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 | |
87 | ? overriding_gen_type | |
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; | |
104 | } | |
105 | return table; | |
106 | } | |
107 | ||
108 | ||
109 | void | |
110 | dump_decode_rule(decode_table *rule, | |
111 | int indent) | |
112 | { | |
113 | dumpf(indent, "((decode_table*)%p\n", rule); | |
114 | if (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); | |
127 | } | |
128 | dumpf(indent, " )\n"); | |
129 | } | |
130 | ||
131 | ||
132 | #ifdef MAIN | |
133 | ||
134 | static void | |
135 | dump_decode_rules(decode_table *rule, | |
136 | int indent) | |
137 | { | |
138 | while (rule) { | |
139 | dump_decode_rule(rule, indent); | |
140 | rule = rule->next; | |
141 | } | |
142 | } | |
143 | ||
144 | int | |
145 | main(int argc, char **argv) | |
146 | { | |
147 | decode_table *rules; | |
148 | if (argc != 3) | |
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); | |
152 | return 0; | |
153 | } | |
154 | #endif |