ld-decode.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* This file is part of the program psim.
  2. Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
  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. /* load the opcode stat structure */
  15. #include "misc.h"
  16. #include "lf.h"
  17. #include "table.h"
  18. #include "ld-decode.h"
  19. enum {
  20. op_options,
  21. op_first,
  22. op_last,
  23. op_force_first,
  24. op_force_last,
  25. op_force_expansion,
  26. op_special_mask,
  27. op_special_value,
  28. op_special_constant,
  29. nr_decode_fields,
  30. };
  31. static const name_map decode_type_map[] = {
  32. { "normal", normal_decode_rule },
  33. { "expand-forced", expand_forced_rule },
  34. { "boolean", boolean_rule },
  35. { NULL, normal_decode_rule },
  36. };
  37. static const name_map decode_gen_map[] = {
  38. { "array", array_gen },
  39. { "switch", switch_gen },
  40. { "padded-switch", padded_switch_gen },
  41. { "goto-switch", goto_switch_gen },
  42. { NULL, -1 },
  43. };
  44. static const name_map decode_slash_map[] = {
  45. { "variable-slash", 0 },
  46. { "constant-slash", 1 },
  47. { NULL },
  48. };
  49. static decode_gen_type overriding_gen_type = invalid_gen;
  50. void
  51. force_decode_gen_type(const char *type)
  52. {
  53. overriding_gen_type = name2i(type, decode_gen_map);
  54. }
  55. decode_table *
  56. load_decode_table(const char *file_name,
  57. int hi_bit_nr)
  58. {
  59. table *file = table_open(file_name, nr_decode_fields, 0);
  60. table_entry *entry;
  61. decode_table *table = NULL;
  62. decode_table **curr_rule = &table;
  63. while ((entry = table_entry_read(file)) != NULL) {
  64. decode_table *new_rule = ZALLOC(decode_table);
  65. new_rule->type = name2i(entry->fields[op_options], decode_type_map);
  66. new_rule->gen = (overriding_gen_type != invalid_gen
  67. ? overriding_gen_type
  68. : name2i(entry->fields[op_options], decode_gen_map));
  69. new_rule->force_slash = name2i(entry->fields[op_options], decode_slash_map);
  70. new_rule->first = target_a2i(hi_bit_nr, entry->fields[op_first]);
  71. new_rule->last = target_a2i(hi_bit_nr, entry->fields[op_last]);
  72. new_rule->force_first = (strlen(entry->fields[op_force_first])
  73. ? target_a2i(hi_bit_nr, entry->fields[op_force_first])
  74. : new_rule->last + 1);
  75. new_rule->force_last = (strlen(entry->fields[op_force_last])
  76. ? target_a2i(hi_bit_nr, entry->fields[op_force_last])
  77. : new_rule->first - 1);
  78. new_rule->force_expansion = entry->fields[op_force_expansion];
  79. new_rule->special_mask = a2i(entry->fields[op_special_mask]);
  80. new_rule->special_value = a2i(entry->fields[op_special_value]);
  81. new_rule->special_constant = a2i(entry->fields[op_special_constant]);
  82. *curr_rule = new_rule;
  83. curr_rule = &new_rule->next;
  84. }
  85. return table;
  86. }
  87. void
  88. dump_decode_rule(decode_table *rule,
  89. int indent)
  90. {
  91. dumpf(indent, "((decode_table*)%p\n", rule);
  92. if (rule) {
  93. dumpf(indent, " (type %s)\n", i2name(rule->type, decode_type_map));
  94. dumpf(indent, " (gen %s)\n", i2name(rule->gen, decode_gen_map));
  95. dumpf(indent, " (force_slash %d)\n", rule->force_slash);
  96. dumpf(indent, " (first %d)\n", rule->first);
  97. dumpf(indent, " (last %d)\n", rule->last);
  98. dumpf(indent, " (force_first %d)\n", rule->force_first);
  99. dumpf(indent, " (force_last %d)\n", rule->force_last);
  100. dumpf(indent, " (force_expansion \"%s\")\n", rule->force_expansion);
  101. dumpf(indent, " (special_mask 0x%x)\n", rule->special_mask);
  102. dumpf(indent, " (special_value 0x%x)\n", rule->special_value);
  103. dumpf(indent, " (special_constant 0x%x)\n", rule->special_constant);
  104. dumpf(indent, " (next 0x%x)\n", rule->next);
  105. }
  106. dumpf(indent, " )\n");
  107. }
  108. #ifdef MAIN
  109. static void
  110. dump_decode_rules(decode_table *rule,
  111. int indent)
  112. {
  113. while (rule) {
  114. dump_decode_rule(rule, indent);
  115. rule = rule->next;
  116. }
  117. }
  118. int
  119. main(int argc, char **argv)
  120. {
  121. decode_table *rules;
  122. if (argc != 3)
  123. error("Usage: decode <decode-file> <hi-bit-nr>\n");
  124. rules = load_decode_table(argv[1], a2i(argv[2]));
  125. dump_decode_rules(rules, 0);
  126. return 0;
  127. }
  128. #endif