ld-cache.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* This file is part of the program psim.
  2. Copyright 1994, 1995, 1996, 1997, 2003 Andrew Cagney
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "misc.h"
  15. #include "lf.h"
  16. #include "table.h"
  17. #include "ld-cache.h"
  18. enum {
  19. ca_type,
  20. ca_field_name,
  21. ca_derived_name,
  22. ca_type_def,
  23. ca_expression,
  24. nr_cache_rule_fields,
  25. };
  26. static const name_map cache_type_map[] = {
  27. { "cache", cache_value },
  28. { "compute", compute_value },
  29. { "scratch", scratch_value },
  30. { NULL, 0 },
  31. };
  32. void
  33. append_cache_rule (cache_table **table, const char *type,
  34. const char *field_name, const char *derived_name,
  35. const char *type_def, const char *expression,
  36. table_entry *file_entry)
  37. {
  38. while ((*table) != NULL)
  39. table = &(*table)->next;
  40. (*table) = ZALLOC(cache_table);
  41. (*table)->type = name2i(type, cache_type_map);
  42. (*table)->field_name = field_name;
  43. (*table)->derived_name = derived_name;
  44. (*table)->type_def = (strlen(type_def) > 0 ? type_def : NULL);
  45. (*table)->expression = (strlen(expression) > 0 ? expression : NULL);
  46. (*table)->file_entry = file_entry;
  47. (*table)->next = NULL;
  48. }
  49. cache_table *
  50. load_cache_table(const 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. append_cache_rule (curr_rule, entry->fields[ca_type],
  59. entry->fields[ca_field_name],
  60. entry->fields[ca_derived_name],
  61. entry->fields[ca_type_def],
  62. entry->fields[ca_expression],
  63. entry);
  64. curr_rule = &(*curr_rule)->next;
  65. }
  66. return table;
  67. }
  68. #ifdef MAIN
  69. static void
  70. dump_cache_rule(cache_table* rule,
  71. int indent)
  72. {
  73. dumpf(indent, "((cache_table*)0x%x\n", rule);
  74. dumpf(indent, " (type %s)\n", i2name(rule->type, cache_type_map));
  75. dumpf(indent, " (field_name \"%s\")\n", rule->field_name);
  76. dumpf(indent, " (derived_name \"%s\")\n", rule->derived_name);
  77. dumpf(indent, " (type-def \"%s\")\n", rule->type_def);
  78. dumpf(indent, " (expression \"%s\")\n", rule->expression);
  79. dumpf(indent, " (next 0x%x)\n", rule->next);
  80. dumpf(indent, " )\n");
  81. }
  82. static void
  83. dump_cache_rules(cache_table* rule,
  84. int indent)
  85. {
  86. while (rule) {
  87. dump_cache_rule(rule, indent);
  88. rule = rule->next;
  89. }
  90. }
  91. int
  92. main(int argc, char **argv)
  93. {
  94. cache_table *rules;
  95. if (argc != 3)
  96. error("Usage: cache <cache-file> <hi-bit-nr>\n");
  97. rules = load_cache_table(argv[1], a2i(argv[2]));
  98. dump_cache_rules(rules, 0);
  99. return 0;
  100. }
  101. #endif