Commit | Line | Data |
---|---|---|
15c16493 AC |
1 | /* This file is part of the program psim. |
2 | ||
3 | Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au> | |
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 | ||
687f3f1c AC |
26 | #include "igen.h" |
27 | ||
15c16493 | 28 | #include "ld-insn.h" |
687f3f1c | 29 | #include "ld-decode.h" |
15c16493 | 30 | |
687f3f1c | 31 | #include "gen.h" |
15c16493 AC |
32 | |
33 | #include "gen-semantics.h" | |
34 | #include "gen-support.h" | |
35 | ||
36 | static void | |
687f3f1c AC |
37 | print_support_function_name (lf *file, |
38 | function_entry *function, | |
39 | int is_function_definition) | |
15c16493 | 40 | { |
687f3f1c AC |
41 | if (function->is_internal) |
42 | { | |
43 | lf_print__function_type_function (file, print_semantic_function_type, | |
44 | "INLINE_SUPPORT", | |
45 | (is_function_definition ? "\n" : " ")); | |
46 | print_function_name (file, | |
47 | function->name, | |
48 | NULL, | |
49 | NULL, | |
50 | NULL, | |
51 | function_name_prefix_semantics); | |
52 | lf_printf (file, "\n("); | |
53 | lf_indent (file, +1); | |
54 | print_semantic_function_formal (file, 0); | |
55 | lf_indent (file, -1); | |
56 | lf_printf (file, ")"); | |
57 | if (!is_function_definition) | |
58 | lf_printf (file, ";"); | |
59 | lf_printf (file, "\n"); | |
60 | } | |
61 | else | |
62 | { | |
63 | /* map the name onto a globally valid name */ | |
64 | if (!is_function_definition | |
65 | && strcmp (options.prefix.global.name, "") != 0) | |
66 | { | |
67 | lf_indent_suppress (file); | |
68 | lf_printf (file, "#define %s %s%s\n", | |
69 | function->name, | |
70 | options.prefix.global.name, | |
71 | function->name); | |
72 | } | |
73 | lf_print__function_type (file, | |
74 | function->type, | |
75 | "INLINE_SUPPORT", | |
76 | (is_function_definition ? "\n" : " ")); | |
77 | lf_printf (file, "%s%s\n(", | |
78 | options.prefix.global.name, | |
79 | function->name); | |
80 | if (options.gen.smp) | |
81 | lf_printf (file, | |
82 | "sim_cpu *cpu, %sinstruction_address cia, int MY_INDEX", | |
83 | options.prefix.global.name); | |
84 | else | |
85 | lf_printf (file, | |
86 | "SIM_DESC sd, %sinstruction_address cia, int MY_INDEX", | |
87 | options.prefix.global.name); | |
88 | if (function->param != NULL | |
89 | && strlen (function->param) > 0) | |
90 | lf_printf (file, ", %s", function->param); | |
91 | lf_printf (file, ")%s", (is_function_definition ? "\n" : ";\n")); | |
15c16493 | 92 | } |
15c16493 AC |
93 | } |
94 | ||
95 | ||
96 | static void | |
687f3f1c AC |
97 | support_h_function (lf *file, |
98 | function_entry *function, | |
99 | void *data) | |
15c16493 | 100 | { |
687f3f1c AC |
101 | ASSERT (function->type != NULL); |
102 | print_support_function_name (file, | |
103 | function, | |
104 | 0/*!is_definition*/); | |
15c16493 AC |
105 | lf_printf(file, "\n"); |
106 | } | |
107 | ||
108 | ||
109 | extern void | |
687f3f1c AC |
110 | gen_support_h (lf *file, |
111 | insn_table *table) | |
15c16493 | 112 | { |
9ec6741b | 113 | /* output the definition of `SD_'*/ |
687f3f1c AC |
114 | if (options.gen.smp) |
115 | { | |
9ec6741b AC |
116 | lf_printf(file, "#define _SD cpu, cia, MY_INDEX /* depreciated */\n"); |
117 | lf_printf(file, "#define SD_ cpu, cia, MY_INDEX\n"); | |
687f3f1c AC |
118 | lf_printf(file, "#define SD CPU_STATE (cpu)\n"); |
119 | lf_printf(file, "#define CPU cpu\n"); | |
120 | } | |
121 | else | |
122 | { | |
9ec6741b AC |
123 | lf_printf(file, "#define _SD sd, cia, MY_INDEX /* depreciated */\n"); |
124 | lf_printf(file, "#define SD_ sd, cia, MY_INDEX\n"); | |
687f3f1c AC |
125 | lf_printf(file, "#define SD sd\n"); |
126 | lf_printf(file, "#define CPU (STATE_CPU (sd, 0))\n"); | |
127 | } | |
9ec6741b AC |
128 | if (options.gen.delayed_branch) |
129 | { | |
130 | lf_printf(file, "#define CIA cia.ip\n"); | |
131 | lf_printf(file, "/* #define NIA nia.dp -- do not define, ambigious */\n"); | |
132 | } | |
133 | else | |
134 | { | |
135 | lf_printf(file, "#define CIA cia\n"); | |
136 | lf_printf(file, "#define NIA nia\n"); | |
137 | } | |
15c16493 AC |
138 | lf_printf(file, "\n"); |
139 | /* output a declaration for all functions */ | |
687f3f1c AC |
140 | function_entry_traverse (file, table->functions, |
141 | support_h_function, | |
142 | NULL); | |
15c16493 AC |
143 | lf_printf(file, "\n"); |
144 | lf_printf(file, "#if defined(SUPPORT_INLINE)\n"); | |
145 | lf_printf(file, "# if ((SUPPORT_INLINE & INCLUDE_MODULE)\\\n"); | |
146 | lf_printf(file, " && (SUPPORT_INLINE & INCLUDED_BY_MODULE))\n"); | |
687f3f1c | 147 | lf_printf(file, "# include \"%ssupport.c\"\n", options.prefix.global.name); |
15c16493 AC |
148 | lf_printf(file, "# endif\n"); |
149 | lf_printf(file, "#endif\n"); | |
150 | } | |
151 | ||
152 | static void | |
687f3f1c AC |
153 | support_c_function (lf *file, |
154 | function_entry *function, | |
155 | void *data) | |
15c16493 | 156 | { |
687f3f1c | 157 | ASSERT (function->type != NULL); |
15c16493 AC |
158 | print_support_function_name (file, |
159 | function, | |
160 | 1/*!is_definition*/); | |
15c16493 AC |
161 | lf_printf (file, "{\n"); |
162 | lf_indent (file, +2); | |
687f3f1c AC |
163 | if (function->code == NULL) |
164 | error (function->line, | |
165 | "Function without body (or null statement)"); | |
166 | lf_print__line_ref (file, function->code->line); | |
167 | table_print_code (file, function->code); | |
168 | if (function->is_internal) | |
15c16493 | 169 | { |
9ec6741b | 170 | lf_printf (file, "sim_engine_abort (SD, CPU, cia, \"Internal function must longjump\\n\");\n"); |
15c16493 AC |
171 | lf_printf (file, "return cia;\n"); |
172 | } | |
173 | lf_indent (file, -2); | |
174 | lf_printf (file, "}\n"); | |
687f3f1c | 175 | lf_print__internal_ref (file); |
15c16493 AC |
176 | lf_printf (file, "\n"); |
177 | } | |
178 | ||
179 | ||
180 | void | |
687f3f1c AC |
181 | gen_support_c (lf *file, |
182 | insn_table *table) | |
15c16493 AC |
183 | { |
184 | lf_printf(file, "#include \"sim-main.h\"\n"); | |
687f3f1c AC |
185 | lf_printf(file, "#include \"%sidecode.h\"\n", options.prefix.idecode.name); |
186 | lf_printf(file, "#include \"%sitable.h\"\n", options.prefix.itable.name); | |
187 | lf_printf(file, "#include \"%ssupport.h\"\n", options.prefix.support.name); | |
15c16493 AC |
188 | lf_printf(file, "\n"); |
189 | ||
190 | /* output a definition (c-code) for all functions */ | |
687f3f1c AC |
191 | function_entry_traverse (file, table->functions, |
192 | support_c_function, | |
193 | NULL); | |
15c16493 | 194 | } |