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