gen-itable.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* This file is part of the program psim.
  2. Copyright (C) 1994-1995, 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. #include "misc.h"
  15. #include "lf.h"
  16. #include "table.h"
  17. #include "filter.h"
  18. #include "ld-cache.h"
  19. #include "ld-decode.h"
  20. #include "ld-insn.h"
  21. #include "igen.h"
  22. #include "gen-itable.h"
  23. static void
  24. itable_h_insn(insn_table *entry,
  25. lf *file,
  26. void *data,
  27. insn *instruction,
  28. int depth)
  29. {
  30. lf_printf(file, " ");
  31. print_function_name(file,
  32. instruction->file_entry->fields[insn_name],
  33. NULL,
  34. function_name_prefix_itable);
  35. lf_printf(file, ",\n");
  36. }
  37. extern void
  38. gen_itable_h(insn_table *table, lf *file)
  39. {
  40. /* output an enumerated type for each instruction */
  41. lf_printf(file, "typedef enum {\n");
  42. insn_table_traverse_insn(table,
  43. file, NULL,
  44. itable_h_insn);
  45. lf_printf(file, " nr_itable_entries,\n");
  46. lf_printf(file, "} itable_index;\n");
  47. lf_printf(file, "\n");
  48. /* output the table that contains the actual instruction info */
  49. lf_printf(file, "typedef struct _itable_instruction_info {\n");
  50. lf_printf(file, " itable_index nr;\n");
  51. lf_printf(file, " const char *format;\n");
  52. lf_printf(file, " const char *form;\n");
  53. lf_printf(file, " const char *flags;\n");
  54. lf_printf(file, " const char *mnemonic;\n");
  55. lf_printf(file, " const char *name;\n");
  56. lf_printf(file, " const char *file;\n");
  57. lf_printf(file, " int line_nr;\n");
  58. lf_printf(file, "} itable_info;\n");
  59. lf_printf(file, "\n");
  60. lf_printf(file, "extern itable_info itable[nr_itable_entries];\n");
  61. }
  62. /****************************************************************/
  63. static void
  64. itable_c_insn(insn_table *entry,
  65. lf *file,
  66. void *data,
  67. insn *instruction,
  68. int depth)
  69. {
  70. char **fields = instruction->file_entry->fields;
  71. lf_printf(file, " { ");
  72. print_function_name(file,
  73. instruction->file_entry->fields[insn_name],
  74. NULL,
  75. function_name_prefix_itable);
  76. lf_printf(file, ",\n");
  77. lf_printf(file, " \"%s\",\n", fields[insn_format]);
  78. lf_printf(file, " \"%s\",\n", fields[insn_form]);
  79. lf_printf(file, " \"%s\",\n", fields[insn_flags]);
  80. lf_printf(file, " \"%s\",\n", fields[insn_mnemonic]);
  81. lf_printf(file, " \"%s\",\n", fields[insn_name]);
  82. lf_printf(file, " \"%s\",\n", filter_filename (instruction->file_entry->file_name));
  83. lf_printf(file, " %d,\n", instruction->file_entry->line_nr);
  84. lf_printf(file, " },\n");
  85. }
  86. extern void
  87. gen_itable_c(insn_table *table, lf *file)
  88. {
  89. /* output the table that contains the actual instruction info */
  90. lf_printf(file, "#include \"itable.h\"\n");
  91. lf_printf(file, "\n");
  92. lf_printf(file, "itable_info itable[nr_itable_entries] = {\n");
  93. insn_table_traverse_insn(table,
  94. file, NULL,
  95. itable_c_insn);
  96. lf_printf(file, "};\n");
  97. }