sim: ppc: constify strings in igen tooling
[binutils-gdb.git] / sim / ppc / ld-cache.c
1 /* This file is part of the program psim.
2
3 Copyright 1994, 1995, 1996, 1997, 2003 Andrew Cagney
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
21 #include "misc.h"
22 #include "lf.h"
23 #include "table.h"
24 #include "ld-cache.h"
25
26
27 enum {
28 ca_type,
29 ca_field_name,
30 ca_derived_name,
31 ca_type_def,
32 ca_expression,
33 nr_cache_rule_fields,
34 };
35
36 static const name_map cache_type_map[] = {
37 { "cache", cache_value },
38 { "compute", compute_value },
39 { "scratch", scratch_value },
40 { NULL, 0 },
41 };
42
43
44 void
45 append_cache_rule (cache_table **table, const char *type,
46 const char *field_name, const char *derived_name,
47 const char *type_def, const char *expression,
48 table_entry *file_entry)
49 {
50 while ((*table) != NULL)
51 table = &(*table)->next;
52 (*table) = ZALLOC(cache_table);
53 (*table)->type = name2i(type, cache_type_map);
54 (*table)->field_name = field_name;
55 (*table)->derived_name = derived_name;
56 (*table)->type_def = (strlen(type_def) > 0 ? type_def : NULL);
57 (*table)->expression = (strlen(expression) > 0 ? expression : NULL);
58 (*table)->file_entry = file_entry;
59 (*table)->next = NULL;
60 }
61
62
63 cache_table *
64 load_cache_table(const char *file_name,
65 int hi_bit_nr)
66 {
67 table *file = table_open(file_name, nr_cache_rule_fields, 0);
68 table_entry *entry;
69 cache_table *table = NULL;
70 cache_table **curr_rule = &table;
71 while ((entry = table_entry_read(file)) != NULL) {
72 append_cache_rule (curr_rule, entry->fields[ca_type],
73 entry->fields[ca_field_name],
74 entry->fields[ca_derived_name],
75 entry->fields[ca_type_def],
76 entry->fields[ca_expression],
77 entry);
78 curr_rule = &(*curr_rule)->next;
79 }
80 return table;
81 }
82
83
84
85 #ifdef MAIN
86
87 static void
88 dump_cache_rule(cache_table* rule,
89 int indent)
90 {
91 dumpf(indent, "((cache_table*)0x%x\n", rule);
92 dumpf(indent, " (type %s)\n", i2name(rule->type, cache_type_map));
93 dumpf(indent, " (field_name \"%s\")\n", rule->field_name);
94 dumpf(indent, " (derived_name \"%s\")\n", rule->derived_name);
95 dumpf(indent, " (type-def \"%s\")\n", rule->type_def);
96 dumpf(indent, " (expression \"%s\")\n", rule->expression);
97 dumpf(indent, " (next 0x%x)\n", rule->next);
98 dumpf(indent, " )\n");
99 }
100
101
102 static void
103 dump_cache_rules(cache_table* rule,
104 int indent)
105 {
106 while (rule) {
107 dump_cache_rule(rule, indent);
108 rule = rule->next;
109 }
110 }
111
112
113 int
114 main(int argc, char **argv)
115 {
116 cache_table *rules;
117 if (argc != 3)
118 error("Usage: cache <cache-file> <hi-bit-nr>\n");
119 rules = load_cache_table(argv[1], a2i(argv[2]));
120 dump_cache_rules(rules, 0);
121 return 0;
122 }
123 #endif