gdb: remove newlines from some linux_nat_debug_printf calls
[binutils-gdb.git] / sim / ppc / ld-decode.c
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
7 the Free Software Foundation; either version 3 of the License, or
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
16 along with this program; if not, see <http://www.gnu.org/licenses/>.
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
28 enum {
29 op_options,
30 op_first,
31 op_last,
32 op_force_first,
33 op_force_last,
34 op_force_expansion,
35 op_special_mask,
36 op_special_value,
37 op_special_constant,
38 nr_decode_fields,
39 };
40
41 static const name_map decode_type_map[] = {
42 { "normal", normal_decode_rule },
43 { "expand-forced", expand_forced_rule },
44 { "boolean", boolean_rule },
45 { NULL, normal_decode_rule },
46 };
47
48 static const name_map decode_gen_map[] = {
49 { "array", array_gen },
50 { "switch", switch_gen },
51 { "padded-switch", padded_switch_gen },
52 { "goto-switch", goto_switch_gen },
53 { NULL, -1 },
54 };
55
56 static const name_map decode_slash_map[] = {
57 { "variable-slash", 0 },
58 { "constant-slash", 1 },
59 { NULL },
60 };
61
62
63 static decode_gen_type overriding_gen_type = invalid_gen;
64
65 void
66 force_decode_gen_type(const char *type)
67 {
68 overriding_gen_type = name2i(type, decode_gen_map);
69 }
70
71
72 decode_table *
73 load_decode_table(const char *file_name,
74 int hi_bit_nr)
75 {
76 table *file = table_open(file_name, nr_decode_fields, 0);
77 table_entry *entry;
78 decode_table *table = NULL;
79 decode_table **curr_rule = &table;
80 while ((entry = table_entry_read(file)) != NULL) {
81 decode_table *new_rule = ZALLOC(decode_table);
82 new_rule->type = name2i(entry->fields[op_options], decode_type_map);
83 new_rule->gen = (overriding_gen_type != invalid_gen
84 ? overriding_gen_type
85 : name2i(entry->fields[op_options], decode_gen_map));
86 new_rule->force_slash = name2i(entry->fields[op_options], decode_slash_map);
87 new_rule->first = target_a2i(hi_bit_nr, entry->fields[op_first]);
88 new_rule->last = target_a2i(hi_bit_nr, entry->fields[op_last]);
89 new_rule->force_first = (strlen(entry->fields[op_force_first])
90 ? target_a2i(hi_bit_nr, entry->fields[op_force_first])
91 : new_rule->last + 1);
92 new_rule->force_last = (strlen(entry->fields[op_force_last])
93 ? target_a2i(hi_bit_nr, entry->fields[op_force_last])
94 : new_rule->first - 1);
95 new_rule->force_expansion = entry->fields[op_force_expansion];
96 new_rule->special_mask = a2i(entry->fields[op_special_mask]);
97 new_rule->special_value = a2i(entry->fields[op_special_value]);
98 new_rule->special_constant = a2i(entry->fields[op_special_constant]);
99 *curr_rule = new_rule;
100 curr_rule = &new_rule->next;
101 }
102 return table;
103 }
104
105
106 void
107 dump_decode_rule(decode_table *rule,
108 int indent)
109 {
110 dumpf(indent, "((decode_table*)%p\n", rule);
111 if (rule) {
112 dumpf(indent, " (type %s)\n", i2name(rule->type, decode_type_map));
113 dumpf(indent, " (gen %s)\n", i2name(rule->gen, decode_gen_map));
114 dumpf(indent, " (force_slash %d)\n", rule->force_slash);
115 dumpf(indent, " (first %d)\n", rule->first);
116 dumpf(indent, " (last %d)\n", rule->last);
117 dumpf(indent, " (force_first %d)\n", rule->force_first);
118 dumpf(indent, " (force_last %d)\n", rule->force_last);
119 dumpf(indent, " (force_expansion \"%s\")\n", rule->force_expansion);
120 dumpf(indent, " (special_mask 0x%x)\n", rule->special_mask);
121 dumpf(indent, " (special_value 0x%x)\n", rule->special_value);
122 dumpf(indent, " (special_constant 0x%x)\n", rule->special_constant);
123 dumpf(indent, " (next 0x%x)\n", rule->next);
124 }
125 dumpf(indent, " )\n");
126 }
127
128
129 #ifdef MAIN
130
131 static void
132 dump_decode_rules(decode_table *rule,
133 int indent)
134 {
135 while (rule) {
136 dump_decode_rule(rule, indent);
137 rule = rule->next;
138 }
139 }
140
141 int
142 main(int argc, char **argv)
143 {
144 decode_table *rules;
145 if (argc != 3)
146 error("Usage: decode <decode-file> <hi-bit-nr>\n");
147 rules = load_decode_table(argv[1], a2i(argv[2]));
148 dump_decode_rules(rules, 0);
149 return 0;
150 }
151 #endif