* Test case for PR 18452.
[binutils-gdb.git] / sim / ppc / ld-cache.c
blob134339a083d1c2397e89ca5f9fd6f1b5effbd1b8
1 /* This file is part of the program psim.
3 Copyright (C) 1994,1995,1996, 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.
22 #include "misc.h"
23 #include "lf.h"
24 #include "table.h"
25 #include "ld-cache.h"
27 #ifndef NULL
28 #define NULL 0
29 #endif
32 enum {
33 ca_type,
34 ca_old_name,
35 ca_new_name,
36 ca_type_def,
37 ca_expression,
38 nr_cache_rule_fields,
41 static const name_map cache_type_map[] = {
42 { "cache", cache_value },
43 { "compute", compute_value },
44 { NULL, 0 },
48 cache_table *
49 load_cache_table(char *file_name,
50 int hi_bit_nr)
52 table *file = table_open(file_name, nr_cache_rule_fields, 0);
53 table_entry *entry;
54 cache_table *table = NULL;
55 cache_table **curr_rule = &table;
56 while ((entry = table_entry_read(file)) != NULL) {
57 cache_table *new_rule = ZALLOC(cache_table);
58 new_rule->type = name2i(entry->fields[ca_type], cache_type_map);
59 new_rule->old_name = entry->fields[ca_old_name];
60 new_rule->new_name = entry->fields[ca_new_name];
61 new_rule->type_def = (strlen(entry->fields[ca_type_def])
62 ? entry->fields[ca_type_def]
63 : NULL);
64 new_rule->expression = (strlen(entry->fields[ca_expression]) > 0
65 ? entry->fields[ca_expression]
66 : NULL);
67 new_rule->file_entry = entry;
68 *curr_rule = new_rule;
69 curr_rule = &new_rule->next;
71 return table;
76 #ifdef MAIN
78 static void
79 dump_cache_rule(cache_table* rule,
80 int indent)
82 dumpf(indent, "((cache_table*)0x%x\n", rule);
83 dumpf(indent, " (type %s)\n", i2name(rule->type, cache_type_map));
84 dumpf(indent, " (old_name \"%s\")\n", rule->old_name);
85 dumpf(indent, " (new_name \"%s\")\n", rule->new_name);
86 dumpf(indent, " (type-def \"%s\")\n", rule->type_def);
87 dumpf(indent, " (expression \"%s\")\n", rule->expression);
88 dumpf(indent, " (next 0x%x)\n", rule->next);
89 dumpf(indent, " )\n");
93 static void
94 dump_cache_rules(cache_table* rule,
95 int indent)
97 while (rule) {
98 dump_cache_rule(rule, indent);
99 rule = rule->next;
105 main(int argc, char **argv)
107 cache_table *rules;
108 if (argc != 3)
109 error("Usage: cache <cache-file> <hi-bit-nr>\n");
110 rules = load_cache_table(argv[1], a2i(argv[2]));
111 dump_cache_rules(rules, 0);
112 return 0;
114 #endif