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