1 1.1 christos /* The IGEN simulator generator for GDB, the GNU Debugger. 2 1.1 christos 3 1.1.1.10 christos Copyright 2002-2024 Free Software Foundation, Inc. 4 1.1 christos 5 1.1 christos Contributed by Andrew Cagney. 6 1.1 christos 7 1.1 christos This file is part of GDB. 8 1.1 christos 9 1.1 christos This program is free software; you can redistribute it and/or modify 10 1.1 christos it under the terms of the GNU General Public License as published by 11 1.1 christos the Free Software Foundation; either version 3 of the License, or 12 1.1 christos (at your option) any later version. 13 1.1 christos 14 1.1 christos This program is distributed in the hope that it will be useful, 15 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 16 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 1.1 christos GNU General Public License for more details. 18 1.1 christos 19 1.1 christos You should have received a copy of the GNU General Public License 20 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 21 1.1 christos 22 1.1 christos 23 1.1 christos 24 1.1 christos #include "misc.h" 25 1.1 christos #include "lf.h" 26 1.1 christos #include "table.h" 27 1.1 christos #include "filter.h" 28 1.1 christos #include "igen.h" 29 1.1 christos 30 1.1 christos #include "ld-insn.h" 31 1.1 christos #include "ld-cache.h" 32 1.1 christos 33 1.1 christos 34 1.1 christos enum 35 1.1 christos { 36 1.1 christos ca_type, 37 1.1 christos ca_field_name, 38 1.1 christos ca_derived_name, 39 1.1 christos ca_type_def, 40 1.1 christos ca_expression, 41 1.1 christos nr_cache_rule_fields, 42 1.1 christos }; 43 1.1 christos 44 1.1 christos static const name_map cache_type_map[] = { 45 1.1 christos {"cache", cache_value}, 46 1.1 christos {"compute", compute_value}, 47 1.1 christos {"scratch", scratch_value}, 48 1.1 christos {NULL, 0}, 49 1.1 christos }; 50 1.1 christos 51 1.1 christos 52 1.1 christos cache_entry * 53 1.1.1.9 christos load_cache_table (const char *file_name) 54 1.1 christos { 55 1.1 christos cache_entry *cache = NULL; 56 1.1 christos cache_entry **last = &cache; 57 1.1 christos table *file = table_open (file_name); 58 1.1 christos table_entry *entry; 59 1.1 christos while ((entry = table_read (file)) != NULL) 60 1.1 christos { 61 1.1 christos cache_entry *new_rule = ZALLOC (cache_entry); 62 1.1 christos new_rule->line = entry->line; 63 1.1 christos new_rule->entry_type = name2i (entry->field[ca_type], cache_type_map); 64 1.1 christos new_rule->name = entry->field[ca_derived_name]; 65 1.1 christos filter_parse (&new_rule->original_fields, entry->field[ca_field_name]); 66 1.1 christos new_rule->type = entry->field[ca_type_def]; 67 1.1 christos /* expression is the concatenation of the remaining fields */ 68 1.1 christos if (entry->nr_fields > ca_expression) 69 1.1 christos { 70 1.1 christos int len = 0; 71 1.1 christos int chi; 72 1.1 christos for (chi = ca_expression; chi < entry->nr_fields; chi++) 73 1.1 christos { 74 1.1 christos len += strlen (" : ") + strlen (entry->field[chi]); 75 1.1 christos } 76 1.1 christos new_rule->expression = NZALLOC (char, len); 77 1.1 christos strcpy (new_rule->expression, entry->field[ca_expression]); 78 1.1 christos for (chi = ca_expression + 1; chi < entry->nr_fields; chi++) 79 1.1 christos { 80 1.1 christos strcat (new_rule->expression, " : "); 81 1.1 christos strcat (new_rule->expression, entry->field[chi]); 82 1.1 christos } 83 1.1 christos } 84 1.1 christos /* insert it */ 85 1.1 christos *last = new_rule; 86 1.1 christos last = &new_rule->next; 87 1.1 christos } 88 1.1 christos return cache; 89 1.1 christos } 90 1.1 christos 91 1.1 christos 92 1.1 christos 93 1.1 christos #ifdef MAIN 94 1.1 christos 95 1.1 christos igen_options options; 96 1.1 christos 97 1.1 christos int 98 1.1 christos main (int argc, char **argv) 99 1.1 christos { 100 1.1 christos cache_entry *rules = NULL; 101 1.1 christos lf *l; 102 1.1 christos 103 1.1 christos if (argc != 2) 104 1.1 christos error (NULL, "Usage: cache <cache-file>\n"); 105 1.1 christos 106 1.1 christos rules = load_cache_table (argv[1]); 107 1.1 christos l = lf_open ("-", "stdout", lf_omit_references, lf_is_text, "tmp-ld-insn"); 108 1.1 christos dump_cache_entries (l, "(", rules, ")\n"); 109 1.1 christos 110 1.1 christos return 0; 111 1.1 christos } 112 1.1 christos #endif 113