gen-support.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* This file is part of the program psim.
  2. Copyright 1994, 1995, 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 "filter.h"
  18. #include "ld-decode.h"
  19. #include "ld-cache.h"
  20. #include "ld-insn.h"
  21. #include "igen.h"
  22. #include "gen-semantics.h"
  23. #include "gen-support.h"
  24. static void
  25. print_support_function_name(lf *file,
  26. table_entry *function,
  27. int is_function_definition)
  28. {
  29. if (it_is("internal", function->fields[insn_flags])) {
  30. lf_print_function_type(file, SEMANTIC_FUNCTION_TYPE, "PSIM_INLINE_SUPPORT",
  31. (is_function_definition ? "\n" : " "));
  32. print_function_name(file,
  33. function->fields[function_name],
  34. NULL,
  35. function_name_prefix_semantics);
  36. lf_printf(file, "\n(%s)", SEMANTIC_FUNCTION_FORMAL);
  37. if (!is_function_definition)
  38. lf_printf(file, ";");
  39. lf_printf(file, "\n");
  40. }
  41. else {
  42. lf_print_function_type(file,
  43. function->fields[function_type],
  44. "PSIM_INLINE_SUPPORT",
  45. (is_function_definition ? "\n" : " "));
  46. lf_printf(file, "%s\n(%s)%s",
  47. function->fields[function_name],
  48. function->fields[function_param],
  49. (is_function_definition ? "\n" : ";\n"));
  50. }
  51. }
  52. static void
  53. support_h_function(insn_table *entry,
  54. lf *file,
  55. void *data,
  56. table_entry *function)
  57. {
  58. ASSERT(function->fields[function_type] != NULL);
  59. ASSERT(function->fields[function_param] != NULL);
  60. print_support_function_name(file,
  61. function,
  62. 0/*!is_definition*/);
  63. lf_printf(file, "\n");
  64. }
  65. extern void
  66. gen_support_h(insn_table *table,
  67. lf *file)
  68. {
  69. /* output a declaration for all functions */
  70. insn_table_traverse_function(table,
  71. file, NULL,
  72. support_h_function);
  73. lf_printf(file, "\n");
  74. lf_printf(file, "#if (SUPPORT_INLINE & INCLUDE_MODULE)\n");
  75. lf_printf(file, "# include \"support.c\"\n");
  76. lf_printf(file, "#endif\n");
  77. }
  78. static void
  79. support_c_function(insn_table *table,
  80. lf *file,
  81. void *data,
  82. table_entry *function)
  83. {
  84. ASSERT(function->fields[function_type] != NULL);
  85. print_support_function_name(file,
  86. function,
  87. 1/*!is_definition*/);
  88. table_entry_print_cpp_line_nr(file, function);
  89. lf_printf(file, "{\n");
  90. lf_indent(file, +2);
  91. lf_print__c_code(file, function->annex);
  92. if (it_is("internal", function->fields[insn_flags])) {
  93. lf_printf(file, "error(\"Internal function must longjump\\n\");\n");
  94. lf_printf(file, "return 0;\n");
  95. }
  96. lf_indent(file, -2);
  97. lf_printf(file, "}\n");
  98. lf_print__internal_reference(file);
  99. lf_printf(file, "\n");
  100. }
  101. void
  102. gen_support_c(insn_table *table,
  103. lf *file)
  104. {
  105. lf_printf(file, "#include \"cpu.h\"\n");
  106. lf_printf(file, "#include \"idecode.h\"\n");
  107. lf_printf(file, "#ifdef HAVE_COMMON_FPU\n");
  108. lf_printf(file, "#include \"sim-inline.h\"\n");
  109. lf_printf(file, "#include \"sim-fpu.h\"\n");
  110. lf_printf(file, "#endif\n");
  111. lf_printf(file, "#include \"support.h\"\n");
  112. lf_printf(file, "\n");
  113. /* output a definition (c-code) for all functions */
  114. insn_table_traverse_function(table,
  115. file, NULL,
  116. support_c_function);
  117. }