| 1 | /* This file is part of the program psim. |
| 2 | |
| 3 | Copyright 1994, 1995, 2003 Andrew Cagney |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 3 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | */ |
| 19 | |
| 20 | #include "misc.h" |
| 21 | #include "lf.h" |
| 22 | #include "table.h" |
| 23 | #include "filter.h" |
| 24 | |
| 25 | #include "ld-decode.h" |
| 26 | #include "ld-cache.h" |
| 27 | #include "ld-insn.h" |
| 28 | |
| 29 | #include "igen.h" |
| 30 | |
| 31 | #include "gen-semantics.h" |
| 32 | #include "gen-support.h" |
| 33 | |
| 34 | static void |
| 35 | print_support_function_name(lf *file, |
| 36 | table_entry *function, |
| 37 | int is_function_definition) |
| 38 | { |
| 39 | if (it_is("internal", function->fields[insn_flags])) { |
| 40 | lf_print_function_type(file, SEMANTIC_FUNCTION_TYPE, "PSIM_INLINE_SUPPORT", |
| 41 | (is_function_definition ? "\n" : " ")); |
| 42 | print_function_name(file, |
| 43 | function->fields[function_name], |
| 44 | NULL, |
| 45 | function_name_prefix_semantics); |
| 46 | lf_printf(file, "\n(%s)", SEMANTIC_FUNCTION_FORMAL); |
| 47 | if (!is_function_definition) |
| 48 | lf_printf(file, ";"); |
| 49 | lf_printf(file, "\n"); |
| 50 | } |
| 51 | else { |
| 52 | lf_print_function_type(file, |
| 53 | function->fields[function_type], |
| 54 | "PSIM_INLINE_SUPPORT", |
| 55 | (is_function_definition ? "\n" : " ")); |
| 56 | lf_printf(file, "%s\n(%s)%s", |
| 57 | function->fields[function_name], |
| 58 | function->fields[function_param], |
| 59 | (is_function_definition ? "\n" : ";\n")); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | |
| 64 | static void |
| 65 | support_h_function(insn_table *entry, |
| 66 | lf *file, |
| 67 | void *data, |
| 68 | table_entry *function) |
| 69 | { |
| 70 | ASSERT(function->fields[function_type] != NULL); |
| 71 | ASSERT(function->fields[function_param] != NULL); |
| 72 | print_support_function_name(file, |
| 73 | function, |
| 74 | 0/*!is_definition*/); |
| 75 | lf_printf(file, "\n"); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | extern void |
| 80 | gen_support_h(insn_table *table, |
| 81 | lf *file) |
| 82 | { |
| 83 | /* output a declaration for all functions */ |
| 84 | insn_table_traverse_function(table, |
| 85 | file, NULL, |
| 86 | support_h_function); |
| 87 | lf_printf(file, "\n"); |
| 88 | lf_printf(file, "#if (SUPPORT_INLINE & INCLUDE_MODULE)\n"); |
| 89 | lf_printf(file, "# include \"support.c\"\n"); |
| 90 | lf_printf(file, "#endif\n"); |
| 91 | } |
| 92 | |
| 93 | static void |
| 94 | support_c_function(insn_table *table, |
| 95 | lf *file, |
| 96 | void *data, |
| 97 | table_entry *function) |
| 98 | { |
| 99 | ASSERT(function->fields[function_type] != NULL); |
| 100 | print_support_function_name(file, |
| 101 | function, |
| 102 | 1/*!is_definition*/); |
| 103 | table_entry_print_cpp_line_nr(file, function); |
| 104 | lf_printf(file, "{\n"); |
| 105 | lf_indent(file, +2); |
| 106 | lf_print__c_code(file, function->annex); |
| 107 | if (it_is("internal", function->fields[insn_flags])) { |
| 108 | lf_printf(file, "error(\"Internal function must longjump\\n\");\n"); |
| 109 | lf_printf(file, "return 0;\n"); |
| 110 | } |
| 111 | lf_indent(file, -2); |
| 112 | lf_printf(file, "}\n"); |
| 113 | lf_print__internal_reference(file); |
| 114 | lf_printf(file, "\n"); |
| 115 | } |
| 116 | |
| 117 | |
| 118 | void |
| 119 | gen_support_c(insn_table *table, |
| 120 | lf *file) |
| 121 | { |
| 122 | lf_printf(file, "#include \"cpu.h\"\n"); |
| 123 | lf_printf(file, "#include \"idecode.h\"\n"); |
| 124 | lf_printf(file, "#ifdef HAVE_COMMON_FPU\n"); |
| 125 | lf_printf(file, "#include \"sim-inline.h\"\n"); |
| 126 | lf_printf(file, "#include \"sim-fpu.h\"\n"); |
| 127 | lf_printf(file, "#endif\n"); |
| 128 | lf_printf(file, "#include \"support.h\"\n"); |
| 129 | lf_printf(file, "\n"); |
| 130 | |
| 131 | /* output a definition (c-code) for all functions */ |
| 132 | insn_table_traverse_function(table, |
| 133 | file, NULL, |
| 134 | support_c_function); |
| 135 | } |