]>
Commit | Line | Data |
---|---|---|
3b80f6ca | 1 | /* Generate code to allocate RTL structures. |
d652f226 | 2 | Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2007, 2010 |
3d7aafde | 3 | Free Software Foundation, Inc. |
3b80f6ca | 4 | |
1322177d | 5 | This file is part of GCC. |
3b80f6ca | 6 | |
1322177d LB |
7 | GCC is free software; you can redistribute it and/or modify it under |
8 | the terms of the GNU General Public License as published by the Free | |
9dcd6f09 | 9 | Software Foundation; either version 3, or (at your option) any later |
1322177d | 10 | version. |
3b80f6ca | 11 | |
1322177d LB |
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
3b80f6ca RH |
16 | |
17 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
3b80f6ca RH |
20 | |
21 | ||
4977bab6 | 22 | #include "bconfig.h" |
b04cd507 | 23 | #include "system.h" |
aa0b4465 | 24 | |
8f9eb495 | 25 | struct rtx_definition |
3b80f6ca | 26 | { |
8b60264b | 27 | const char *const enumname, *const name, *const format; |
3b80f6ca RH |
28 | }; |
29 | ||
0974c7d7 ZW |
30 | /* rtl.def needs CONST_DOUBLE_FORMAT, but we don't care what |
31 | CONST_DOUBLE_FORMAT is because we're not going to be generating | |
32 | anything for CONST_DOUBLE anyway. */ | |
33 | #define CONST_DOUBLE_FORMAT "" | |
34 | ||
9a238586 | 35 | #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) { #ENUM, NAME, FORMAT }, |
3b80f6ca | 36 | |
8f9eb495 AJ |
37 | static const struct rtx_definition defs[] = |
38 | { | |
3b80f6ca RH |
39 | #include "rtl.def" /* rtl expressions are documented here */ |
40 | }; | |
0974c7d7 | 41 | #define NUM_RTX_CODE ARRAY_SIZE(defs) |
3b80f6ca | 42 | |
0b5826ac | 43 | static const char *formats[NUM_RTX_CODE]; |
c5c76735 | 44 | \f |
0133b7d9 RH |
45 | /* Decode a format letter into a C type string. */ |
46 | ||
3b80f6ca | 47 | static const char * |
3d7aafde | 48 | type_from_format (int c) |
3b80f6ca RH |
49 | { |
50 | switch (c) | |
51 | { | |
52 | case 'i': | |
c5c76735 JL |
53 | return "int "; |
54 | ||
3b80f6ca | 55 | case 'w': |
c5c76735 JL |
56 | return "HOST_WIDE_INT "; |
57 | ||
3b80f6ca | 58 | case 's': |
3cce094d | 59 | return "const char *"; |
c5c76735 JL |
60 | |
61 | case 'e': case 'u': | |
62 | return "rtx "; | |
63 | ||
3b80f6ca | 64 | case 'E': |
c5c76735 | 65 | return "rtvec "; |
0dfa1860 | 66 | case 't': |
8f985ec4 | 67 | return "union tree_node *"; /* tree - typedef not available */ |
c8ea9a0f JH |
68 | case 'B': |
69 | return "struct basic_block_def *"; /* basic block - typedef not available */ | |
3b80f6ca | 70 | default: |
b2d59f6f | 71 | gcc_unreachable (); |
3b80f6ca RH |
72 | } |
73 | } | |
74 | ||
0133b7d9 RH |
75 | /* Decode a format letter into the proper accessor function. */ |
76 | ||
3b80f6ca | 77 | static const char * |
3d7aafde | 78 | accessor_from_format (int c) |
3b80f6ca RH |
79 | { |
80 | switch (c) | |
81 | { | |
82 | case 'i': | |
83 | return "XINT"; | |
c5c76735 | 84 | |
3b80f6ca RH |
85 | case 'w': |
86 | return "XWINT"; | |
c5c76735 | 87 | |
3b80f6ca RH |
88 | case 's': |
89 | return "XSTR"; | |
c5c76735 JL |
90 | |
91 | case 'e': case 'u': | |
3b80f6ca | 92 | return "XEXP"; |
c5c76735 | 93 | |
3b80f6ca RH |
94 | case 'E': |
95 | return "XVEC"; | |
c5c76735 | 96 | |
0dfa1860 MM |
97 | case 't': |
98 | return "XTREE"; | |
c5c76735 | 99 | |
c8ea9a0f JH |
100 | case 'B': |
101 | return "XBBDEF"; | |
10d1bb36 JH |
102 | |
103 | default: | |
b2d59f6f | 104 | gcc_unreachable (); |
3b80f6ca RH |
105 | } |
106 | } | |
107 | ||
c5c76735 JL |
108 | /* Return nonzero if we should ignore FMT, an RTL format, when making |
109 | the list of formats we write routines to create. */ | |
0133b7d9 | 110 | |
3b80f6ca | 111 | static int |
3d7aafde | 112 | special_format (const char *fmt) |
3b80f6ca RH |
113 | { |
114 | return (strchr (fmt, '*') != 0 | |
115 | || strchr (fmt, 'V') != 0 | |
116 | || strchr (fmt, 'S') != 0 | |
117 | || strchr (fmt, 'n') != 0); | |
118 | } | |
119 | ||
5692c7bc ZW |
120 | /* Return nonzero if the RTL code given by index IDX is one that we should |
121 | generate a gen_rtx_raw_FOO macro for, not gen_rtx_FOO (because gen_rtx_FOO | |
122 | is a wrapper in emit-rtl.c). */ | |
0133b7d9 | 123 | |
3b80f6ca | 124 | static int |
3d7aafde | 125 | special_rtx (int idx) |
3b80f6ca RH |
126 | { |
127 | return (strcmp (defs[idx].enumname, "CONST_INT") == 0 | |
41472af8 | 128 | || strcmp (defs[idx].enumname, "REG") == 0 |
ddef6bc7 | 129 | || strcmp (defs[idx].enumname, "SUBREG") == 0 |
a06e3c40 | 130 | || strcmp (defs[idx].enumname, "MEM") == 0 |
3810076b BS |
131 | || strcmp (defs[idx].enumname, "PC") == 0 |
132 | || strcmp (defs[idx].enumname, "CC0") == 0 | |
133 | || strcmp (defs[idx].enumname, "RETURN") == 0 | |
a06e3c40 | 134 | || strcmp (defs[idx].enumname, "CONST_VECTOR") == 0); |
3b80f6ca RH |
135 | } |
136 | ||
5692c7bc ZW |
137 | /* Return nonzero if the RTL code given by index IDX is one that we should |
138 | generate no macro for at all (because gen_rtx_FOO is never used or | |
139 | cannot have the obvious interface). */ | |
140 | ||
141 | static int | |
3d7aafde | 142 | excluded_rtx (int idx) |
5692c7bc | 143 | { |
091a3ac7 CF |
144 | return ((strcmp (defs[idx].enumname, "CONST_DOUBLE") == 0) |
145 | || (strcmp (defs[idx].enumname, "CONST_FIXED") == 0)); | |
5692c7bc ZW |
146 | } |
147 | ||
dc297297 | 148 | /* Place a list of all format specifiers we use into the array FORMAT. */ |
0133b7d9 | 149 | |
3b80f6ca | 150 | static void |
3d7aafde | 151 | find_formats (void) |
3b80f6ca | 152 | { |
3ef996b0 | 153 | unsigned int i; |
3b80f6ca | 154 | |
3ef996b0 | 155 | for (i = 0; i < NUM_RTX_CODE; i++) |
3b80f6ca RH |
156 | { |
157 | const char **f; | |
158 | ||
159 | if (special_format (defs[i].format)) | |
160 | continue; | |
161 | ||
c5c76735 | 162 | for (f = formats; *f; f++) |
0133b7d9 | 163 | if (! strcmp (*f, defs[i].format)) |
3b80f6ca RH |
164 | break; |
165 | ||
c5c76735 | 166 | if (*f == 0) |
3b80f6ca RH |
167 | *f = defs[i].format; |
168 | } | |
169 | } | |
170 | ||
3b80f6ca | 171 | |
c5c76735 JL |
172 | /* Generate macros to generate RTL of code IDX using the functions we |
173 | write. */ | |
0133b7d9 | 174 | |
8f9eb495 | 175 | static void |
3d7aafde | 176 | genmacro (int idx) |
3b80f6ca RH |
177 | { |
178 | const char *p; | |
179 | int i; | |
180 | ||
c5c76735 JL |
181 | /* We write a macro that defines gen_rtx_RTLCODE to be an equivalent to |
182 | gen_rtx_fmt_FORMAT where FORMAT is the RTX_FORMAT of RTLCODE. */ | |
3b80f6ca | 183 | |
5692c7bc ZW |
184 | if (excluded_rtx (idx)) |
185 | /* Don't define a macro for this code. */ | |
186 | return; | |
187 | ||
c5c76735 JL |
188 | printf ("#define gen_rtx_%s%s(MODE", |
189 | special_rtx (idx) ? "raw_" : "", defs[idx].enumname); | |
190 | ||
191 | for (p = defs[idx].format, i = 0; *p != 0; p++) | |
3b80f6ca | 192 | if (*p != '0') |
c5c76735 JL |
193 | printf (", ARG%d", i++); |
194 | ||
195 | printf (") \\\n gen_rtx_fmt_%s (%s, (MODE)", | |
196 | defs[idx].format, defs[idx].enumname); | |
3b80f6ca | 197 | |
c5c76735 | 198 | for (p = defs[idx].format, i = 0; *p != 0; p++) |
3b80f6ca | 199 | if (*p != '0') |
c5c76735 JL |
200 | printf (", (ARG%d)", i++); |
201 | ||
f8a83ee3 | 202 | puts (")"); |
3b80f6ca RH |
203 | } |
204 | ||
c5c76735 JL |
205 | /* Generate the code for the function to generate RTL whose |
206 | format is FORMAT. */ | |
0133b7d9 | 207 | |
3b80f6ca | 208 | static void |
3d7aafde | 209 | gendef (const char *format) |
3b80f6ca RH |
210 | { |
211 | const char *p; | |
212 | int i, j; | |
8f9eb495 | 213 | |
c5c76735 JL |
214 | /* Start by writing the definition of the function name and the types |
215 | of the arguments. */ | |
3b80f6ca | 216 | |
6ac9d3a3 | 217 | printf ("static inline rtx\ngen_rtx_fmt_%s_stat (RTX_CODE code, enum machine_mode mode", format); |
c5c76735 | 218 | for (p = format, i = 0; *p != 0; p++) |
3b80f6ca | 219 | if (*p != '0') |
6906ba40 | 220 | printf (",\n\t%sarg%d", type_from_format (*p), i++); |
3b80f6ca | 221 | |
9dbe7947 | 222 | puts (" MEM_STAT_DECL)"); |
c5c76735 JL |
223 | |
224 | /* Now write out the body of the function itself, which allocates | |
225 | the memory and initializes it. */ | |
f8a83ee3 ZW |
226 | puts ("{"); |
227 | puts (" rtx rt;"); | |
9dbe7947 | 228 | puts (" rt = rtx_alloc_stat (code PASS_MEM_STAT);\n"); |
f8a83ee3 | 229 | |
f8a83ee3 | 230 | puts (" PUT_MODE (rt, mode);"); |
3b80f6ca RH |
231 | |
232 | for (p = format, i = j = 0; *p ; ++p, ++i) | |
233 | if (*p != '0') | |
c5c76735 | 234 | printf (" %s (rt, %d) = arg%d;\n", accessor_from_format (*p), i, j++); |
f8a83ee3 ZW |
235 | else |
236 | printf (" X0EXP (rt, %d) = NULL_RTX;\n", i); | |
3b80f6ca | 237 | |
f8a83ee3 | 238 | puts ("\n return rt;\n}\n"); |
6ac9d3a3 JH |
239 | printf ("#define gen_rtx_fmt_%s(c, m", format); |
240 | for (p = format, i = 0; *p != 0; p++) | |
241 | if (*p != '0') | |
242 | printf (", p%i",i++); | |
243 | printf (")\\\n gen_rtx_fmt_%s_stat (c, m", format); | |
244 | for (p = format, i = 0; *p != 0; p++) | |
245 | if (*p != '0') | |
246 | printf (", p%i",i++); | |
247 | printf (" MEM_STAT_INFO)\n\n"); | |
3b80f6ca RH |
248 | } |
249 | ||
c5c76735 | 250 | /* Generate the documentation header for files we write. */ |
0133b7d9 | 251 | |
3b80f6ca | 252 | static void |
3d7aafde | 253 | genlegend (void) |
3b80f6ca | 254 | { |
f8a83ee3 | 255 | puts ("/* Generated automatically by gengenrtl from rtl.def. */\n"); |
3b80f6ca RH |
256 | } |
257 | ||
c5c76735 | 258 | /* Generate the text of the header file we make, genrtl.h. */ |
0133b7d9 | 259 | |
3b80f6ca | 260 | static void |
3d7aafde | 261 | genheader (void) |
3b80f6ca | 262 | { |
3ef996b0 | 263 | unsigned int i; |
3b80f6ca | 264 | const char **fmt; |
0313e85b ZW |
265 | |
266 | puts ("#ifndef GCC_GENRTL_H"); | |
267 | puts ("#define GCC_GENRTL_H\n"); | |
9dbe7947 | 268 | puts ("#include \"statistics.h\"\n"); |
0313e85b | 269 | |
3b80f6ca | 270 | for (fmt = formats; *fmt; ++fmt) |
6ac9d3a3 | 271 | gendef (*fmt); |
3b80f6ca | 272 | |
f8a83ee3 | 273 | putchar ('\n'); |
3b80f6ca | 274 | |
3ef996b0 | 275 | for (i = 0; i < NUM_RTX_CODE; i++) |
c5c76735 JL |
276 | if (! special_format (defs[i].format)) |
277 | genmacro (i); | |
0313e85b ZW |
278 | |
279 | puts ("\n#endif /* GCC_GENRTL_H */"); | |
3b80f6ca RH |
280 | } |
281 | ||
6ac9d3a3 | 282 | /* This is the main program. */ |
c5c76735 | 283 | |
3b80f6ca | 284 | int |
6ac9d3a3 | 285 | main (void) |
3b80f6ca | 286 | { |
3b80f6ca | 287 | find_formats (); |
c5c76735 | 288 | genlegend (); |
3b80f6ca | 289 | |
6ac9d3a3 | 290 | genheader (); |
3b80f6ca | 291 | |
0313e85b ZW |
292 | if (ferror (stdout) || fflush (stdout) || fclose (stdout)) |
293 | return FATAL_EXIT_CODE; | |
294 | ||
295 | return SUCCESS_EXIT_CODE; | |
3b80f6ca | 296 | } |