14e98e3e1Schristos /* The IGEN simulator generator for GDB, the GNU Debugger. 24e98e3e1Schristos 3*71f62182Schristos Copyright 2002-2024 Free Software Foundation, Inc. 44e98e3e1Schristos 54e98e3e1Schristos Contributed by Andrew Cagney. 64e98e3e1Schristos 74e98e3e1Schristos This file is part of GDB. 84e98e3e1Schristos 94e98e3e1Schristos This program is free software; you can redistribute it and/or modify 104e98e3e1Schristos it under the terms of the GNU General Public License as published by 114e98e3e1Schristos the Free Software Foundation; either version 3 of the License, or 124e98e3e1Schristos (at your option) any later version. 134e98e3e1Schristos 144e98e3e1Schristos This program is distributed in the hope that it will be useful, 154e98e3e1Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 164e98e3e1Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 174e98e3e1Schristos GNU General Public License for more details. 184e98e3e1Schristos 194e98e3e1Schristos You should have received a copy of the GNU General Public License 204e98e3e1Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 214e98e3e1Schristos 224e98e3e1Schristos 234e98e3e1Schristos 244e98e3e1Schristos #include "misc.h" 254e98e3e1Schristos #include "lf.h" 264e98e3e1Schristos #include "table.h" 274e98e3e1Schristos #include "filter.h" 284e98e3e1Schristos #include "igen.h" 294e98e3e1Schristos 304e98e3e1Schristos #include "ld-insn.h" 314e98e3e1Schristos #include "ld-cache.h" 324e98e3e1Schristos 334e98e3e1Schristos 344e98e3e1Schristos enum 354e98e3e1Schristos { 364e98e3e1Schristos ca_type, 374e98e3e1Schristos ca_field_name, 384e98e3e1Schristos ca_derived_name, 394e98e3e1Schristos ca_type_def, 404e98e3e1Schristos ca_expression, 414e98e3e1Schristos nr_cache_rule_fields, 424e98e3e1Schristos }; 434e98e3e1Schristos 444e98e3e1Schristos static const name_map cache_type_map[] = { 454e98e3e1Schristos {"cache", cache_value}, 464e98e3e1Schristos {"compute", compute_value}, 474e98e3e1Schristos {"scratch", scratch_value}, 484e98e3e1Schristos {NULL, 0}, 494e98e3e1Schristos }; 504e98e3e1Schristos 514e98e3e1Schristos 524e98e3e1Schristos cache_entry * 534b169a6bSchristos load_cache_table (const char *file_name) 544e98e3e1Schristos { 554e98e3e1Schristos cache_entry *cache = NULL; 564e98e3e1Schristos cache_entry **last = &cache; 574e98e3e1Schristos table *file = table_open (file_name); 584e98e3e1Schristos table_entry *entry; 594e98e3e1Schristos while ((entry = table_read (file)) != NULL) 604e98e3e1Schristos { 614e98e3e1Schristos cache_entry *new_rule = ZALLOC (cache_entry); 624e98e3e1Schristos new_rule->line = entry->line; 634e98e3e1Schristos new_rule->entry_type = name2i (entry->field[ca_type], cache_type_map); 644e98e3e1Schristos new_rule->name = entry->field[ca_derived_name]; 654e98e3e1Schristos filter_parse (&new_rule->original_fields, entry->field[ca_field_name]); 664e98e3e1Schristos new_rule->type = entry->field[ca_type_def]; 674e98e3e1Schristos /* expression is the concatenation of the remaining fields */ 684e98e3e1Schristos if (entry->nr_fields > ca_expression) 694e98e3e1Schristos { 704e98e3e1Schristos int len = 0; 714e98e3e1Schristos int chi; 724e98e3e1Schristos for (chi = ca_expression; chi < entry->nr_fields; chi++) 734e98e3e1Schristos { 744e98e3e1Schristos len += strlen (" : ") + strlen (entry->field[chi]); 754e98e3e1Schristos } 764e98e3e1Schristos new_rule->expression = NZALLOC (char, len); 774e98e3e1Schristos strcpy (new_rule->expression, entry->field[ca_expression]); 784e98e3e1Schristos for (chi = ca_expression + 1; chi < entry->nr_fields; chi++) 794e98e3e1Schristos { 804e98e3e1Schristos strcat (new_rule->expression, " : "); 814e98e3e1Schristos strcat (new_rule->expression, entry->field[chi]); 824e98e3e1Schristos } 834e98e3e1Schristos } 844e98e3e1Schristos /* insert it */ 854e98e3e1Schristos *last = new_rule; 864e98e3e1Schristos last = &new_rule->next; 874e98e3e1Schristos } 884e98e3e1Schristos return cache; 894e98e3e1Schristos } 904e98e3e1Schristos 914e98e3e1Schristos 924e98e3e1Schristos 934e98e3e1Schristos #ifdef MAIN 944e98e3e1Schristos 954e98e3e1Schristos igen_options options; 964e98e3e1Schristos 974e98e3e1Schristos int 984e98e3e1Schristos main (int argc, char **argv) 994e98e3e1Schristos { 1004e98e3e1Schristos cache_entry *rules = NULL; 1014e98e3e1Schristos lf *l; 1024e98e3e1Schristos 1034e98e3e1Schristos if (argc != 2) 1044e98e3e1Schristos error (NULL, "Usage: cache <cache-file>\n"); 1054e98e3e1Schristos 1064e98e3e1Schristos rules = load_cache_table (argv[1]); 1074e98e3e1Schristos l = lf_open ("-", "stdout", lf_omit_references, lf_is_text, "tmp-ld-insn"); 1084e98e3e1Schristos dump_cache_entries (l, "(", rules, ")\n"); 1094e98e3e1Schristos 1104e98e3e1Schristos return 0; 1114e98e3e1Schristos } 1124e98e3e1Schristos #endif 113