ld-cache.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #ifndef NULL
  19. #define NULL 0
  20. #endif
  21. enum {
  22. ca_type,
  23. ca_field_name,
  24. ca_derived_name,
  25. ca_type_def,
  26. ca_expression,
  27. nr_cache_rule_fields,
  28. };
  29. static const name_map cache_type_map[] = {
  30. { "cache", cache_value },
  31. { "compute", compute_value },
  32. { "scratch", scratch_value },
  33. { NULL, 0 },
  34. };
  35. void
  36. append_cache_rule (cache_table **table, char *type, char *field_name,
  37. char *derived_name, char *type_def,
  38. char *expression, table_entry *file_entry)
  39. {
  40. while ((*table) != NULL)
  41. table = &(*table)->next;
  42. (*table) = ZALLOC(cache_table);
  43. (*table)->type = name2i(type, cache_type_map);
  44. (*table)->field_name = field_name;
  45. (*table)->derived_name = derived_name;
  46. (*table)->type_def = (strlen(type_def) > 0 ? type_def : NULL);
  47. (*table)->expression = (strlen(expression) > 0 ? expression : NULL);
  48. (*table)->file_entry = file_entry;
  49. (*table)->next = NULL;
  50. }
  51. cache_table *
  52. load_cache_table(char *file_name,
  53. int hi_bit_nr)
  54. {
  55. table *file = table_open(file_name, nr_cache_rule_fields, 0);
  56. table_entry *entry;
  57. cache_table *table = NULL;
  58. cache_table **curr_rule = &table;
  59. while ((entry = table_entry_read(file)) != NULL) {
  60. append_cache_rule (curr_rule, entry->fields[ca_type],
  61. entry->fields[ca_field_name],
  62. entry->fields[ca_derived_name],
  63. entry->fields[ca_type_def],
  64. entry->fields[ca_expression],
  65. entry);
  66. curr_rule = &(*curr_rule)->next;
  67. }
  68. return table;
  69. }
  70. #ifdef MAIN
  71. static void
  72. dump_cache_rule(cache_table* rule,
  73. int indent)
  74. {
  75. dumpf(indent, "((cache_table*)0x%x\n", rule);
  76. dumpf(indent, " (type %s)\n", i2name(rule->type, cache_type_map));
  77. dumpf(indent, " (field_name \"%s\")\n", rule->field_name);
  78. dumpf(indent, " (derived_name \"%s\")\n", rule->derived_name);
  79. dumpf(indent, " (type-def \"%s\")\n", rule->type_def);
  80. dumpf(indent, " (expression \"%s\")\n", rule->expression);
  81. dumpf(indent, " (next 0x%x)\n", rule->next);
  82. dumpf(indent, " )\n");
  83. }
  84. static void
  85. dump_cache_rules(cache_table* rule,
  86. int indent)
  87. {
  88. while (rule) {
  89. dump_cache_rule(rule, indent);
  90. rule = rule->next;
  91. }
  92. }
  93. int
  94. main(int argc, char **argv)
  95. {
  96. cache_table *rules;
  97. if (argc != 3)
  98. error("Usage: cache <cache-file> <hi-bit-nr>\n");
  99. rules = load_cache_table(argv[1], a2i(argv[2]));
  100. dump_cache_rules(rules, 0);
  101. return 0;
  102. }
  103. #endif