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