]>
Commit | Line | Data |
---|---|---|
9db4e0ec | 1 | /* Generate code from to output assembler insns as recognized from rtl. |
23a5b65a | 2 | Copyright (C) 1987-2014 Free Software Foundation, Inc. |
9db4e0ec | 3 | |
1322177d | 4 | This file is part of GCC. |
9db4e0ec | 5 | |
1322177d LB |
6 | GCC is free software; you can redistribute it and/or modify it under |
7 | the terms of the GNU General Public License as published by the Free | |
9dcd6f09 | 8 | Software Foundation; either version 3, or (at your option) any later |
1322177d | 9 | version. |
9db4e0ec | 10 | |
1322177d LB |
11 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | for more details. | |
9db4e0ec RK |
15 | |
16 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
17 | along with GCC; see the file COPYING3. If not see |
18 | <http://www.gnu.org/licenses/>. */ | |
9db4e0ec RK |
19 | |
20 | ||
21 | /* This program reads the machine description for the compiler target machine | |
22 | and produces a file containing these things: | |
23 | ||
f12c802a | 24 | 1. An array of `struct insn_data_d', which is indexed by insn code number, |
a995e389 | 25 | which contains: |
9db4e0ec | 26 | |
a995e389 RH |
27 | a. `name' is the name for that pattern. Nameless patterns are |
28 | given a name. | |
29 | ||
4bbf910e RH |
30 | b. `output' hold either the output template, an array of output |
31 | templates, or an output function. | |
32 | ||
33 | c. `genfun' is the function to generate a body for that pattern, | |
a995e389 RH |
34 | given operands as arguments. |
35 | ||
4bbf910e | 36 | d. `n_operands' is the number of distinct operands in the pattern |
a995e389 | 37 | for that insn, |
9db4e0ec | 38 | |
4bbf910e | 39 | e. `n_dups' is the number of match_dup's that appear in the insn's |
a995e389 RH |
40 | pattern. This says how many elements of `recog_data.dup_loc' are |
41 | significant after an insn has been recognized. | |
9db4e0ec | 42 | |
4bbf910e | 43 | f. `n_alternatives' is the number of alternatives in the constraints |
a995e389 | 44 | of each pattern. |
9db4e0ec | 45 | |
4bbf910e RH |
46 | g. `output_format' tells what type of thing `output' is. |
47 | ||
a995e389 | 48 | h. `operand' is the base of an array of operand data for the insn. |
9db4e0ec | 49 | |
a995e389 | 50 | 2. An array of `struct insn_operand data', used by `operand' above. |
9db4e0ec | 51 | |
a995e389 RH |
52 | a. `predicate', an int-valued function, is the match_operand predicate |
53 | for this operand. | |
9db4e0ec | 54 | |
f38840db | 55 | b. `constraint' is the constraint for this operand. |
9db4e0ec | 56 | |
a995e389 | 57 | c. `address_p' indicates that the operand appears within ADDRESS |
f38840db | 58 | rtx's. |
9db4e0ec | 59 | |
a995e389 | 60 | d. `mode' is the machine mode that that operand is supposed to have. |
9db4e0ec | 61 | |
a995e389 | 62 | e. `strict_low', is nonzero for operands contained in a STRICT_LOW_PART. |
9db4e0ec | 63 | |
dfac187e BS |
64 | f. `eliminable', is nonzero for operands that are matched normally by |
65 | MATCH_OPERAND; it is zero for operands that should not be changed during | |
66 | register elimination such as MATCH_OPERATORs. | |
67 | ||
4fd3a105 RS |
68 | g. `allows_mem', is true for operands that accept MEM rtxes. |
69 | ||
a995e389 RH |
70 | The code number of an insn is simply its position in the machine |
71 | description; code numbers are assigned sequentially to entries in | |
72 | the description, starting with code number 0. | |
9db4e0ec | 73 | |
a995e389 | 74 | Thus, the following entry in the machine description |
9db4e0ec RK |
75 | |
76 | (define_insn "clrdf" | |
77 | [(set (match_operand:DF 0 "general_operand" "") | |
78 | (const_int 0))] | |
79 | "" | |
80 | "clrd %0") | |
81 | ||
a995e389 RH |
82 | assuming it is the 25th entry present, would cause |
83 | insn_data[24].template to be "clrd %0", and | |
84 | insn_data[24].n_operands to be 1. */ | |
9db4e0ec | 85 | \f |
4977bab6 | 86 | #include "bconfig.h" |
0b93b64e | 87 | #include "system.h" |
4977bab6 ZW |
88 | #include "coretypes.h" |
89 | #include "tm.h" | |
9db4e0ec | 90 | #include "rtl.h" |
d80eb1e1 | 91 | #include "errors.h" |
10692477 | 92 | #include "read-md.h" |
c88c0d42 | 93 | #include "gensupport.h" |
9db4e0ec | 94 | |
a995e389 RH |
95 | /* No instruction can have more operands than this. Sorry for this |
96 | arbitrary limit, but what machine will have an instruction with | |
97 | this many operands? */ | |
9db4e0ec RK |
98 | |
99 | #define MAX_MAX_OPERANDS 40 | |
100 | ||
8677664e RS |
101 | static char general_mem[] = { TARGET_MEM_CONSTRAINT, 0 }; |
102 | ||
3d7aafde AJ |
103 | static int n_occurrences (int, const char *); |
104 | static const char *strip_whitespace (const char *); | |
9db4e0ec RK |
105 | |
106 | /* insns in the machine description are assigned sequential code numbers | |
107 | that are used by insn-recog.c (produced by genrecog) to communicate | |
108 | to insn-output.c (produced by this program). */ | |
109 | ||
110 | static int next_code_number; | |
111 | ||
112 | /* This counts all definitions in the md file, | |
113 | for the sake of error messages. */ | |
114 | ||
115 | static int next_index_number; | |
116 | ||
a995e389 RH |
117 | /* This counts all operands used in the md file. The first is null. */ |
118 | ||
119 | static int next_operand_number = 1; | |
120 | ||
121 | /* Record in this chain all information about the operands we will output. */ | |
122 | ||
123 | struct operand_data | |
124 | { | |
125 | struct operand_data *next; | |
126 | int index; | |
c1b59dce KG |
127 | const char *predicate; |
128 | const char *constraint; | |
a995e389 RH |
129 | enum machine_mode mode; |
130 | unsigned char n_alternatives; | |
131 | char address_p; | |
132 | char strict_low; | |
dfac187e | 133 | char eliminable; |
a995e389 RH |
134 | char seen; |
135 | }; | |
136 | ||
137 | /* Begin with a null operand at index 0. */ | |
138 | ||
139 | static struct operand_data null_operand = | |
140 | { | |
f4e2ed09 | 141 | 0, 0, "", "", VOIDmode, 0, 0, 0, 0, 0 |
a995e389 RH |
142 | }; |
143 | ||
144 | static struct operand_data *odata = &null_operand; | |
145 | static struct operand_data **odata_end = &null_operand.next; | |
146 | ||
4bbf910e RH |
147 | /* Must match the constants in recog.h. */ |
148 | ||
149 | #define INSN_OUTPUT_FORMAT_NONE 0 /* abort */ | |
150 | #define INSN_OUTPUT_FORMAT_SINGLE 1 /* const char * */ | |
151 | #define INSN_OUTPUT_FORMAT_MULTI 2 /* const char * const * */ | |
152 | #define INSN_OUTPUT_FORMAT_FUNCTION 3 /* const char * (*)(...) */ | |
153 | ||
9db4e0ec RK |
154 | /* Record in this chain all information that we will output, |
155 | associated with the code number of the insn. */ | |
156 | ||
157 | struct data | |
158 | { | |
a995e389 | 159 | struct data *next; |
c1b59dce | 160 | const char *name; |
8ad97cfc | 161 | const char *template_code; |
a995e389 RH |
162 | int code_number; |
163 | int index_number; | |
1e9c8405 | 164 | const char *filename; |
d96a2fcd | 165 | int lineno; |
b29387ee | 166 | int n_generator_args; /* Number of arguments passed to generator */ |
9db4e0ec RK |
167 | int n_operands; /* Number of operands this insn recognizes */ |
168 | int n_dups; /* Number times match_dup appears in pattern */ | |
169 | int n_alternatives; /* Number of alternatives in each constraint */ | |
a995e389 | 170 | int operand_number; /* Operand index in the big array. */ |
4bbf910e | 171 | int output_format; /* INSN_OUTPUT_FORMAT_*. */ |
a995e389 | 172 | struct operand_data operand[MAX_MAX_OPERANDS]; |
9db4e0ec RK |
173 | }; |
174 | ||
e714561a SB |
175 | /* A dummy insn, for CODE_FOR_nothing. */ |
176 | static struct data nothing; | |
177 | ||
a995e389 | 178 | /* This variable points to the first link in the insn chain. */ |
e714561a SB |
179 | static struct data *idata = ¬hing; |
180 | ||
181 | /* This variable points to the end of the insn chain. This is where | |
182 | everything relevant from the machien description is appended to. */ | |
183 | static struct data **idata_end = ¬hing.next; | |
9db4e0ec | 184 | |
9db4e0ec | 185 | \f |
3d7aafde | 186 | static void output_prologue (void); |
3d7aafde AJ |
187 | static void output_operand_data (void); |
188 | static void output_insn_data (void); | |
189 | static void output_get_insn_name (void); | |
190 | static void scan_operands (struct data *, rtx, int, int); | |
191 | static int compare_operands (struct operand_data *, | |
192 | struct operand_data *); | |
193 | static void place_operands (struct data *); | |
194 | static void process_template (struct data *, const char *); | |
195 | static void validate_insn_alternatives (struct data *); | |
196 | static void validate_insn_operands (struct data *); | |
197 | static void gen_insn (rtx, int); | |
198 | static void gen_peephole (rtx, int); | |
199 | static void gen_expand (rtx, int); | |
200 | static void gen_split (rtx, int); | |
f38840db | 201 | |
f38840db ZW |
202 | struct constraint_data |
203 | { | |
204 | struct constraint_data *next_this_letter; | |
205 | int lineno; | |
206 | unsigned int namelen; | |
207 | const char name[1]; | |
208 | }; | |
209 | ||
8677664e RS |
210 | /* All machine-independent constraint characters (except digits) that |
211 | are handled outside the define*_constraint mechanism. */ | |
212 | static const char indep_constraints[] = ",=+%*?!#&g"; | |
f38840db ZW |
213 | |
214 | static struct constraint_data * | |
215 | constraints_by_letter_table[1 << CHAR_BIT]; | |
216 | ||
217 | static int mdep_constraint_len (const char *, int, int); | |
218 | static void note_constraint (rtx, int); | |
56c0e996 | 219 | \f |
9db4e0ec | 220 | static void |
3d7aafde | 221 | output_prologue (void) |
9db4e0ec | 222 | { |
9db4e0ec | 223 | printf ("/* Generated automatically by the program `genoutput'\n\ |
d96a2fcd | 224 | from the machine description file `md'. */\n\n"); |
9db4e0ec RK |
225 | |
226 | printf ("#include \"config.h\"\n"); | |
729da3f5 | 227 | printf ("#include \"system.h\"\n"); |
4977bab6 ZW |
228 | printf ("#include \"coretypes.h\"\n"); |
229 | printf ("#include \"tm.h\"\n"); | |
ccd043a9 | 230 | printf ("#include \"flags.h\"\n"); |
3bc9f12b | 231 | printf ("#include \"ggc.h\"\n"); |
4d648807 | 232 | printf ("#include \"tree.h\"\n"); |
d8a2d370 DN |
233 | printf ("#include \"varasm.h\"\n"); |
234 | printf ("#include \"stor-layout.h\"\n"); | |
235 | printf ("#include \"calls.h\"\n"); | |
9db4e0ec | 236 | printf ("#include \"rtl.h\"\n"); |
f3a8030a | 237 | printf ("#include \"expr.h\"\n"); |
e78d8e51 | 238 | printf ("#include \"insn-codes.h\"\n"); |
6baf1cc8 | 239 | printf ("#include \"tm_p.h\"\n"); |
49ad7cfa | 240 | printf ("#include \"function.h\"\n"); |
9db4e0ec RK |
241 | printf ("#include \"regs.h\"\n"); |
242 | printf ("#include \"hard-reg-set.h\"\n"); | |
9db4e0ec RK |
243 | printf ("#include \"insn-config.h\"\n\n"); |
244 | printf ("#include \"conditions.h\"\n"); | |
9db4e0ec | 245 | printf ("#include \"insn-attr.h\"\n\n"); |
9db4e0ec | 246 | printf ("#include \"recog.h\"\n\n"); |
79a3f089 | 247 | printf ("#include \"diagnostic-core.h\"\n"); |
9db4e0ec | 248 | printf ("#include \"output.h\"\n"); |
4977bab6 | 249 | printf ("#include \"target.h\"\n"); |
279bb624 | 250 | printf ("#include \"tm-constrs.h\"\n"); |
9db4e0ec RK |
251 | } |
252 | ||
a995e389 | 253 | static void |
3d7aafde | 254 | output_operand_data (void) |
a995e389 | 255 | { |
b3694847 | 256 | struct operand_data *d; |
a995e389 RH |
257 | |
258 | printf ("\nstatic const struct insn_operand_data operand_data[] = \n{\n"); | |
259 | ||
260 | for (d = odata; d; d = d->next) | |
9db4e0ec | 261 | { |
4fd3a105 RS |
262 | struct pred_data *pred; |
263 | ||
a995e389 RH |
264 | printf (" {\n"); |
265 | ||
266 | printf (" %s,\n", | |
267 | d->predicate && d->predicate[0] ? d->predicate : "0"); | |
268 | ||
19af6455 | 269 | printf (" \"%s\",\n", d->constraint ? d->constraint : ""); |
9db4e0ec | 270 | |
a995e389 RH |
271 | printf (" %smode,\n", GET_MODE_NAME (d->mode)); |
272 | ||
dfac187e BS |
273 | printf (" %d,\n", d->strict_low); |
274 | ||
6ddfdb0f BS |
275 | printf (" %d,\n", d->constraint == NULL ? 1 : 0); |
276 | ||
4fd3a105 RS |
277 | printf (" %d,\n", d->eliminable); |
278 | ||
279 | pred = NULL; | |
280 | if (d->predicate) | |
281 | pred = lookup_predicate (d->predicate); | |
282 | printf (" %d\n", pred && pred->codes[MEM]); | |
a995e389 | 283 | |
c3284718 | 284 | printf (" },\n"); |
a995e389 | 285 | } |
c3284718 | 286 | printf ("};\n\n\n"); |
a995e389 RH |
287 | } |
288 | ||
289 | static void | |
3d7aafde | 290 | output_insn_data (void) |
a995e389 | 291 | { |
b3694847 | 292 | struct data *d; |
a995e389 RH |
293 | int name_offset = 0; |
294 | int next_name_offset; | |
295 | const char * last_name = 0; | |
296 | const char * next_name = 0; | |
b3694847 | 297 | struct data *n; |
a995e389 RH |
298 | |
299 | for (n = idata, next_name_offset = 1; n; n = n->next, next_name_offset++) | |
300 | if (n->name) | |
9db4e0ec | 301 | { |
a995e389 RH |
302 | next_name = n->name; |
303 | break; | |
9db4e0ec | 304 | } |
9db4e0ec | 305 | |
3897f229 | 306 | printf ("#if GCC_VERSION >= 2007\n__extension__\n#endif\n"); |
f12c802a | 307 | printf ("\nconst struct insn_data_d insn_data[] = \n{\n"); |
9db4e0ec | 308 | |
a995e389 | 309 | for (d = idata; d; d = d->next) |
9db4e0ec | 310 | { |
1e9c8405 | 311 | printf (" /* %s:%d */\n", d->filename, d->lineno); |
a995e389 RH |
312 | printf (" {\n"); |
313 | ||
314 | if (d->name) | |
9db4e0ec | 315 | { |
a995e389 RH |
316 | printf (" \"%s\",\n", d->name); |
317 | name_offset = 0; | |
318 | last_name = d->name; | |
319 | next_name = 0; | |
320 | for (n = d->next, next_name_offset = 1; n; | |
321 | n = n->next, next_name_offset++) | |
9db4e0ec | 322 | { |
a995e389 RH |
323 | if (n->name) |
324 | { | |
325 | next_name = n->name; | |
326 | break; | |
327 | } | |
9db4e0ec | 328 | } |
9db4e0ec | 329 | } |
a995e389 | 330 | else |
9db4e0ec | 331 | { |
a995e389 RH |
332 | name_offset++; |
333 | if (next_name && (last_name == 0 | |
334 | || name_offset > next_name_offset / 2)) | |
335 | printf (" \"%s-%d\",\n", next_name, | |
336 | next_name_offset - name_offset); | |
337 | else | |
338 | printf (" \"%s+%d\",\n", last_name, name_offset); | |
9db4e0ec | 339 | } |
9db4e0ec | 340 | |
4bbf910e RH |
341 | switch (d->output_format) |
342 | { | |
343 | case INSN_OUTPUT_FORMAT_NONE: | |
9ca1483b | 344 | printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n"); |
3897f229 JM |
345 | printf (" { 0 },\n"); |
346 | printf ("#else\n"); | |
347 | printf (" { 0, 0, 0 },\n"); | |
348 | printf ("#endif\n"); | |
4bbf910e RH |
349 | break; |
350 | case INSN_OUTPUT_FORMAT_SINGLE: | |
212d447c | 351 | { |
8ad97cfc | 352 | const char *p = d->template_code; |
212d447c | 353 | char prev = 0; |
3d7aafde | 354 | |
9ca1483b | 355 | printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n"); |
3897f229 JM |
356 | printf (" { .single =\n"); |
357 | printf ("#else\n"); | |
358 | printf (" {\n"); | |
359 | printf ("#endif\n"); | |
212d447c DC |
360 | printf (" \""); |
361 | while (*p) | |
362 | { | |
6b8b9d7b CM |
363 | if (IS_VSPACE (*p) && prev != '\\') |
364 | { | |
365 | /* Preserve two consecutive \n's or \r's, but treat \r\n | |
366 | as a single newline. */ | |
367 | if (*p == '\n' && prev != '\r') | |
368 | printf ("\\n\\\n"); | |
369 | } | |
212d447c DC |
370 | else |
371 | putchar (*p); | |
372 | prev = *p; | |
373 | ++p; | |
374 | } | |
375 | printf ("\",\n"); | |
9ca1483b | 376 | printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n"); |
3897f229 JM |
377 | printf (" },\n"); |
378 | printf ("#else\n"); | |
379 | printf (" 0, 0 },\n"); | |
380 | printf ("#endif\n"); | |
212d447c | 381 | } |
4bbf910e RH |
382 | break; |
383 | case INSN_OUTPUT_FORMAT_MULTI: | |
9ca1483b | 384 | printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n"); |
3897f229 JM |
385 | printf (" { .multi = output_%d },\n", d->code_number); |
386 | printf ("#else\n"); | |
387 | printf (" { 0, output_%d, 0 },\n", d->code_number); | |
388 | printf ("#endif\n"); | |
389 | break; | |
4bbf910e | 390 | case INSN_OUTPUT_FORMAT_FUNCTION: |
9ca1483b | 391 | printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n"); |
3897f229 JM |
392 | printf (" { .function = output_%d },\n", d->code_number); |
393 | printf ("#else\n"); | |
394 | printf (" { 0, 0, output_%d },\n", d->code_number); | |
395 | printf ("#endif\n"); | |
4bbf910e RH |
396 | break; |
397 | default: | |
b2d59f6f | 398 | gcc_unreachable (); |
4bbf910e | 399 | } |
a995e389 RH |
400 | |
401 | if (d->name && d->name[0] != '*') | |
eb923e54 | 402 | printf (" { (insn_gen_fn::stored_funcptr) gen_%s },\n", d->name); |
a995e389 | 403 | else |
eb923e54 | 404 | printf (" { 0 },\n"); |
a995e389 RH |
405 | |
406 | printf (" &operand_data[%d],\n", d->operand_number); | |
b29387ee | 407 | printf (" %d,\n", d->n_generator_args); |
a995e389 RH |
408 | printf (" %d,\n", d->n_operands); |
409 | printf (" %d,\n", d->n_dups); | |
4bbf910e RH |
410 | printf (" %d,\n", d->n_alternatives); |
411 | printf (" %d\n", d->output_format); | |
a995e389 | 412 | |
c3284718 | 413 | printf (" },\n"); |
9db4e0ec | 414 | } |
a995e389 RH |
415 | printf ("};\n\n\n"); |
416 | } | |
9db4e0ec | 417 | |
a995e389 | 418 | static void |
3d7aafde | 419 | output_get_insn_name (void) |
a995e389 RH |
420 | { |
421 | printf ("const char *\n"); | |
6906ba40 | 422 | printf ("get_insn_name (int code)\n"); |
a995e389 | 423 | printf ("{\n"); |
a0f0e963 SB |
424 | printf (" if (code == NOOP_MOVE_INSN_CODE)\n"); |
425 | printf (" return \"NOOP_MOVE\";\n"); | |
426 | printf (" else\n"); | |
427 | printf (" return insn_data[code].name;\n"); | |
a995e389 | 428 | printf ("}\n"); |
9db4e0ec | 429 | } |
a995e389 | 430 | |
9db4e0ec | 431 | \f |
b29387ee | 432 | /* Stores the operand data into `d->operand[i]'. |
9db4e0ec RK |
433 | |
434 | THIS_ADDRESS_P is nonzero if the containing rtx was an ADDRESS. | |
435 | THIS_STRICT_LOW is nonzero if the containing rtx was a STRICT_LOW_PART. */ | |
436 | ||
9db4e0ec | 437 | static void |
3d7aafde AJ |
438 | scan_operands (struct data *d, rtx part, int this_address_p, |
439 | int this_strict_low) | |
9db4e0ec | 440 | { |
b3694847 SS |
441 | int i, j; |
442 | const char *format_ptr; | |
9db4e0ec RK |
443 | int opno; |
444 | ||
445 | if (part == 0) | |
446 | return; | |
447 | ||
448 | switch (GET_CODE (part)) | |
449 | { | |
450 | case MATCH_OPERAND: | |
451 | opno = XINT (part, 0); | |
b29387ee | 452 | if (opno >= MAX_MAX_OPERANDS) |
5a806d65 | 453 | { |
bb933490 | 454 | error_with_line (d->lineno, "maximum number of operands exceeded"); |
5a806d65 RK |
455 | return; |
456 | } | |
a995e389 | 457 | if (d->operand[opno].seen) |
bb933490 | 458 | error_with_line (d->lineno, "repeated operand number %d\n", opno); |
d96a2fcd | 459 | |
a995e389 RH |
460 | d->operand[opno].seen = 1; |
461 | d->operand[opno].mode = GET_MODE (part); | |
462 | d->operand[opno].strict_low = this_strict_low; | |
463 | d->operand[opno].predicate = XSTR (part, 1); | |
665f2503 RK |
464 | d->operand[opno].constraint = strip_whitespace (XSTR (part, 2)); |
465 | d->operand[opno].n_alternatives | |
466 | = n_occurrences (',', d->operand[opno].constraint) + 1; | |
a995e389 | 467 | d->operand[opno].address_p = this_address_p; |
dfac187e | 468 | d->operand[opno].eliminable = 1; |
9db4e0ec RK |
469 | return; |
470 | ||
471 | case MATCH_SCRATCH: | |
472 | opno = XINT (part, 0); | |
b29387ee | 473 | if (opno >= MAX_MAX_OPERANDS) |
5a806d65 | 474 | { |
bb933490 | 475 | error_with_line (d->lineno, "maximum number of operands exceeded"); |
5a806d65 RK |
476 | return; |
477 | } | |
a995e389 | 478 | if (d->operand[opno].seen) |
bb933490 | 479 | error_with_line (d->lineno, "repeated operand number %d\n", opno); |
d96a2fcd | 480 | |
a995e389 RH |
481 | d->operand[opno].seen = 1; |
482 | d->operand[opno].mode = GET_MODE (part); | |
483 | d->operand[opno].strict_low = 0; | |
484 | d->operand[opno].predicate = "scratch_operand"; | |
665f2503 RK |
485 | d->operand[opno].constraint = strip_whitespace (XSTR (part, 1)); |
486 | d->operand[opno].n_alternatives | |
487 | = n_occurrences (',', d->operand[opno].constraint) + 1; | |
a995e389 | 488 | d->operand[opno].address_p = 0; |
dfac187e | 489 | d->operand[opno].eliminable = 0; |
9db4e0ec RK |
490 | return; |
491 | ||
492 | case MATCH_OPERATOR: | |
493 | case MATCH_PARALLEL: | |
494 | opno = XINT (part, 0); | |
b29387ee | 495 | if (opno >= MAX_MAX_OPERANDS) |
5a806d65 | 496 | { |
bb933490 | 497 | error_with_line (d->lineno, "maximum number of operands exceeded"); |
5a806d65 RK |
498 | return; |
499 | } | |
a995e389 | 500 | if (d->operand[opno].seen) |
bb933490 | 501 | error_with_line (d->lineno, "repeated operand number %d\n", opno); |
d96a2fcd | 502 | |
a995e389 RH |
503 | d->operand[opno].seen = 1; |
504 | d->operand[opno].mode = GET_MODE (part); | |
505 | d->operand[opno].strict_low = 0; | |
506 | d->operand[opno].predicate = XSTR (part, 1); | |
507 | d->operand[opno].constraint = 0; | |
508 | d->operand[opno].address_p = 0; | |
dfac187e | 509 | d->operand[opno].eliminable = 0; |
9db4e0ec | 510 | for (i = 0; i < XVECLEN (part, 2); i++) |
a995e389 | 511 | scan_operands (d, XVECEXP (part, 2, i), 0, 0); |
9db4e0ec RK |
512 | return; |
513 | ||
9db4e0ec | 514 | case STRICT_LOW_PART: |
a995e389 | 515 | scan_operands (d, XEXP (part, 0), 0, 1); |
9db4e0ec | 516 | return; |
3d7aafde | 517 | |
ccd043a9 RL |
518 | default: |
519 | break; | |
9db4e0ec RK |
520 | } |
521 | ||
522 | format_ptr = GET_RTX_FORMAT (GET_CODE (part)); | |
523 | ||
524 | for (i = 0; i < GET_RTX_LENGTH (GET_CODE (part)); i++) | |
525 | switch (*format_ptr++) | |
526 | { | |
527 | case 'e': | |
ccd043a9 | 528 | case 'u': |
a995e389 | 529 | scan_operands (d, XEXP (part, i), 0, 0); |
9db4e0ec RK |
530 | break; |
531 | case 'E': | |
532 | if (XVEC (part, i) != NULL) | |
533 | for (j = 0; j < XVECLEN (part, i); j++) | |
a995e389 | 534 | scan_operands (d, XVECEXP (part, i, j), 0, 0); |
9db4e0ec RK |
535 | break; |
536 | } | |
537 | } | |
a995e389 RH |
538 | |
539 | /* Compare two operands for content equality. */ | |
540 | ||
541 | static int | |
3d7aafde | 542 | compare_operands (struct operand_data *d0, struct operand_data *d1) |
a995e389 | 543 | { |
c1b59dce | 544 | const char *p0, *p1; |
a995e389 RH |
545 | |
546 | p0 = d0->predicate; | |
547 | if (!p0) | |
548 | p0 = ""; | |
549 | p1 = d1->predicate; | |
550 | if (!p1) | |
551 | p1 = ""; | |
552 | if (strcmp (p0, p1) != 0) | |
553 | return 0; | |
554 | ||
19af6455 BS |
555 | p0 = d0->constraint; |
556 | if (!p0) | |
557 | p0 = ""; | |
558 | p1 = d1->constraint; | |
559 | if (!p1) | |
560 | p1 = ""; | |
561 | if (strcmp (p0, p1) != 0) | |
562 | return 0; | |
a995e389 RH |
563 | |
564 | if (d0->mode != d1->mode) | |
565 | return 0; | |
566 | ||
a995e389 RH |
567 | if (d0->strict_low != d1->strict_low) |
568 | return 0; | |
569 | ||
dfac187e BS |
570 | if (d0->eliminable != d1->eliminable) |
571 | return 0; | |
572 | ||
a995e389 RH |
573 | return 1; |
574 | } | |
575 | ||
576 | /* Scan the list of operands we've already committed to output and either | |
577 | find a subsequence that is the same, or allocate a new one at the end. */ | |
578 | ||
579 | static void | |
3d7aafde | 580 | place_operands (struct data *d) |
a995e389 RH |
581 | { |
582 | struct operand_data *od, *od2; | |
583 | int i; | |
584 | ||
585 | if (d->n_operands == 0) | |
586 | { | |
587 | d->operand_number = 0; | |
588 | return; | |
589 | } | |
590 | ||
591 | /* Brute force substring search. */ | |
592 | for (od = odata, i = 0; od; od = od->next, i = 0) | |
593 | if (compare_operands (od, &d->operand[0])) | |
594 | { | |
595 | od2 = od->next; | |
596 | i = 1; | |
597 | while (1) | |
598 | { | |
599 | if (i == d->n_operands) | |
600 | goto full_match; | |
601 | if (od2 == NULL) | |
602 | goto partial_match; | |
603 | if (! compare_operands (od2, &d->operand[i])) | |
604 | break; | |
605 | ++i, od2 = od2->next; | |
606 | } | |
607 | } | |
608 | ||
609 | /* Either partial match at the end of the list, or no match. In either | |
610 | case, we tack on what operands are remaining to the end of the list. */ | |
611 | partial_match: | |
612 | d->operand_number = next_operand_number - i; | |
613 | for (; i < d->n_operands; ++i) | |
614 | { | |
615 | od2 = &d->operand[i]; | |
616 | *odata_end = od2; | |
617 | odata_end = &od2->next; | |
618 | od2->index = next_operand_number++; | |
619 | } | |
620 | *odata_end = NULL; | |
621 | return; | |
622 | ||
623 | full_match: | |
624 | d->operand_number = od->index; | |
625 | return; | |
626 | } | |
627 | ||
9db4e0ec RK |
628 | \f |
629 | /* Process an assembler template from a define_insn or a define_peephole. | |
630 | It is either the assembler code template, a list of assembler code | |
631 | templates, or C code to generate the assembler code template. */ | |
632 | ||
633 | static void | |
8ad97cfc | 634 | process_template (struct data *d, const char *template_code) |
9db4e0ec | 635 | { |
b3694847 SS |
636 | const char *cp; |
637 | int i; | |
9db4e0ec | 638 | |
4bbf910e | 639 | /* Templates starting with * contain straight code to be run. */ |
8ad97cfc | 640 | if (template_code[0] == '*') |
9db4e0ec | 641 | { |
8ad97cfc | 642 | d->template_code = 0; |
4bbf910e | 643 | d->output_format = INSN_OUTPUT_FORMAT_FUNCTION; |
9db4e0ec | 644 | |
4bbf910e | 645 | puts ("\nstatic const char *"); |
95770ca3 | 646 | printf ("output_%d (rtx *operands ATTRIBUTE_UNUSED, rtx_insn *insn ATTRIBUTE_UNUSED)\n", |
6906ba40 | 647 | d->code_number); |
4bbf910e | 648 | puts ("{"); |
d2a3ce4e | 649 | print_md_ptr_loc (template_code); |
8ad97cfc | 650 | puts (template_code + 1); |
4bbf910e RH |
651 | puts ("}"); |
652 | } | |
9db4e0ec RK |
653 | |
654 | /* If the assembler code template starts with a @ it is a newline-separated | |
4bbf910e | 655 | list of assembler code templates, one for each alternative. */ |
8ad97cfc | 656 | else if (template_code[0] == '@') |
9db4e0ec | 657 | { |
94c765ab | 658 | int found_star = 0; |
9db4e0ec | 659 | |
94c765ab R |
660 | for (cp = &template_code[1]; *cp; ) |
661 | { | |
662 | while (ISSPACE (*cp)) | |
663 | cp++; | |
664 | if (*cp == '*') | |
665 | found_star = 1; | |
666 | while (!IS_VSPACE (*cp) && *cp != '\0') | |
667 | ++cp; | |
668 | } | |
669 | d->template_code = 0; | |
670 | if (found_star) | |
671 | { | |
672 | d->output_format = INSN_OUTPUT_FORMAT_FUNCTION; | |
673 | puts ("\nstatic const char *"); | |
674 | printf ("output_%d (rtx *operands ATTRIBUTE_UNUSED, " | |
95770ca3 | 675 | "rtx_insn *insn ATTRIBUTE_UNUSED)\n", d->code_number); |
94c765ab R |
676 | puts ("{"); |
677 | puts (" switch (which_alternative)\n {"); | |
678 | } | |
679 | else | |
680 | { | |
681 | d->output_format = INSN_OUTPUT_FORMAT_MULTI; | |
682 | printf ("\nstatic const char * const output_%d[] = {\n", | |
683 | d->code_number); | |
684 | } | |
9db4e0ec | 685 | |
8ad97cfc | 686 | for (i = 0, cp = &template_code[1]; *cp; ) |
9db4e0ec | 687 | { |
94c765ab | 688 | const char *ep, *sp, *bp; |
4112be4a | 689 | |
6b8b9d7b | 690 | while (ISSPACE (*cp)) |
9db4e0ec RK |
691 | cp++; |
692 | ||
94c765ab R |
693 | bp = cp; |
694 | if (found_star) | |
695 | { | |
696 | printf (" case %d:", i); | |
697 | if (*cp == '*') | |
698 | { | |
699 | printf ("\n "); | |
700 | cp++; | |
701 | } | |
702 | else | |
703 | printf (" return \""); | |
704 | } | |
705 | else | |
706 | printf (" \""); | |
4112be4a JJ |
707 | |
708 | for (ep = sp = cp; !IS_VSPACE (*ep) && *ep != '\0'; ++ep) | |
709 | if (!ISSPACE (*ep)) | |
710 | sp = ep + 1; | |
711 | ||
712 | if (sp != ep) | |
713 | message_with_line (d->lineno, | |
714 | "trailing whitespace in output template"); | |
715 | ||
716 | while (cp < sp) | |
2f013c71 RK |
717 | { |
718 | putchar (*cp); | |
719 | cp++; | |
720 | } | |
9db4e0ec | 721 | |
94c765ab R |
722 | if (!found_star) |
723 | puts ("\","); | |
724 | else if (*bp != '*') | |
725 | puts ("\";"); | |
726 | else | |
727 | { | |
728 | /* The usual action will end with a return. | |
729 | If there is neither break or return at the end, this is | |
730 | assumed to be intentional; this allows to have multiple | |
731 | consecutive alternatives share some code. */ | |
732 | puts (""); | |
733 | } | |
9db4e0ec RK |
734 | i++; |
735 | } | |
c6d79bee JH |
736 | if (i == 1) |
737 | message_with_line (d->lineno, | |
738 | "'@' is redundant for output template with single alternative"); | |
739 | if (i != d->n_alternatives) | |
bb933490 RS |
740 | error_with_line (d->lineno, |
741 | "wrong number of alternatives in the output template"); | |
9db4e0ec | 742 | |
94c765ab R |
743 | if (found_star) |
744 | puts (" default: gcc_unreachable ();\n }\n}"); | |
745 | else | |
746 | printf ("};\n"); | |
9db4e0ec RK |
747 | } |
748 | else | |
749 | { | |
8ad97cfc | 750 | d->template_code = template_code; |
4bbf910e | 751 | d->output_format = INSN_OUTPUT_FORMAT_SINGLE; |
9db4e0ec | 752 | } |
9db4e0ec RK |
753 | } |
754 | \f | |
755 | /* Check insn D for consistency in number of constraint alternatives. */ | |
756 | ||
757 | static void | |
3d7aafde | 758 | validate_insn_alternatives (struct data *d) |
9db4e0ec | 759 | { |
b3694847 | 760 | int n = 0, start; |
a995e389 RH |
761 | |
762 | /* Make sure all the operands have the same number of alternatives | |
763 | in their constraints. Let N be that number. */ | |
9db4e0ec | 764 | for (start = 0; start < d->n_operands; start++) |
a995e389 | 765 | if (d->operand[start].n_alternatives > 0) |
9db4e0ec | 766 | { |
97488870 R |
767 | int len, i; |
768 | const char *p; | |
769 | char c; | |
770 | int which_alternative = 0; | |
771 | int alternative_count_unsure = 0; | |
772 | ||
773 | for (p = d->operand[start].constraint; (c = *p); p += len) | |
774 | { | |
73f793e3 RS |
775 | if ((c == '%' || c == '=' || c == '+') |
776 | && p != d->operand[start].constraint) | |
777 | error_with_line (d->lineno, | |
778 | "character '%c' can only be used at the" | |
779 | " beginning of a constraint string", c); | |
f38840db ZW |
780 | if (ISSPACE (c) || strchr (indep_constraints, c)) |
781 | len = 1; | |
782 | else if (ISDIGIT (c)) | |
783 | { | |
784 | const char *q = p; | |
785 | do | |
786 | q++; | |
787 | while (ISDIGIT (*q)); | |
788 | len = q - p; | |
789 | } | |
790 | else | |
791 | len = mdep_constraint_len (p, d->lineno, start); | |
97488870 R |
792 | |
793 | if (c == ',') | |
794 | { | |
795 | which_alternative++; | |
796 | continue; | |
797 | } | |
798 | ||
799 | for (i = 1; i < len; i++) | |
800 | if (p[i] == '\0') | |
801 | { | |
bb933490 RS |
802 | error_with_line (d->lineno, |
803 | "NUL in alternative %d of operand %d", | |
804 | which_alternative, start); | |
97488870 R |
805 | alternative_count_unsure = 1; |
806 | break; | |
807 | } | |
808 | else if (strchr (",#*", p[i])) | |
809 | { | |
bb933490 RS |
810 | error_with_line (d->lineno, |
811 | "'%c' in alternative %d of operand %d", | |
812 | p[i], which_alternative, start); | |
97488870 R |
813 | alternative_count_unsure = 1; |
814 | } | |
815 | } | |
bb933490 | 816 | if (!alternative_count_unsure) |
d96a2fcd | 817 | { |
bb933490 RS |
818 | if (n == 0) |
819 | n = d->operand[start].n_alternatives; | |
820 | else if (n != d->operand[start].n_alternatives) | |
821 | error_with_line (d->lineno, | |
d96a2fcd RH |
822 | "wrong number of alternatives in operand %d", |
823 | start); | |
d96a2fcd | 824 | } |
9db4e0ec | 825 | } |
a995e389 | 826 | |
9db4e0ec RK |
827 | /* Record the insn's overall number of alternatives. */ |
828 | d->n_alternatives = n; | |
829 | } | |
c77e04ae RH |
830 | |
831 | /* Verify that there are no gaps in operand numbers for INSNs. */ | |
832 | ||
833 | static void | |
3d7aafde | 834 | validate_insn_operands (struct data *d) |
c77e04ae RH |
835 | { |
836 | int i; | |
837 | ||
838 | for (i = 0; i < d->n_operands; ++i) | |
839 | if (d->operand[i].seen == 0) | |
bb933490 | 840 | error_with_line (d->lineno, "missing operand %d", i); |
c77e04ae | 841 | } |
7ddf71e3 PB |
842 | |
843 | static void | |
844 | validate_optab_operands (struct data *d) | |
845 | { | |
846 | if (!d->name || d->name[0] == '\0' || d->name[0] == '*') | |
847 | return; | |
848 | ||
849 | /* Miscellaneous tests. */ | |
850 | if (strncmp (d->name, "cstore", 6) == 0 | |
851 | && d->name[strlen (d->name) - 1] == '4' | |
852 | && d->operand[0].mode == VOIDmode) | |
853 | { | |
854 | message_with_line (d->lineno, "missing mode for operand 0 of cstore"); | |
855 | have_error = 1; | |
856 | } | |
857 | } | |
9db4e0ec | 858 | \f |
a995e389 RH |
859 | /* Look at a define_insn just read. Assign its code number. Record |
860 | on idata the template and the number of arguments. If the insn has | |
861 | a hairy output action, output a function for now. */ | |
9db4e0ec RK |
862 | |
863 | static void | |
3d7aafde | 864 | gen_insn (rtx insn, int lineno) |
9db4e0ec | 865 | { |
b29387ee | 866 | struct pattern_stats stats; |
5ed6ace5 | 867 | struct data *d = XNEW (struct data); |
b3694847 | 868 | int i; |
9db4e0ec | 869 | |
c88c0d42 | 870 | d->code_number = next_code_number; |
9db4e0ec | 871 | d->index_number = next_index_number; |
d2a3ce4e | 872 | d->filename = read_md_filename; |
d96a2fcd | 873 | d->lineno = lineno; |
9db4e0ec RK |
874 | if (XSTR (insn, 0)[0]) |
875 | d->name = XSTR (insn, 0); | |
876 | else | |
877 | d->name = 0; | |
878 | ||
879 | /* Build up the list in the same order as the insns are seen | |
880 | in the machine description. */ | |
881 | d->next = 0; | |
a995e389 RH |
882 | *idata_end = d; |
883 | idata_end = &d->next; | |
9db4e0ec | 884 | |
a995e389 | 885 | memset (d->operand, 0, sizeof (d->operand)); |
9db4e0ec RK |
886 | |
887 | for (i = 0; i < XVECLEN (insn, 1); i++) | |
a995e389 | 888 | scan_operands (d, XVECEXP (insn, 1, i), 0, 0); |
9db4e0ec | 889 | |
b29387ee RS |
890 | get_pattern_stats (&stats, XVEC (insn, 1)); |
891 | d->n_generator_args = stats.num_generator_args; | |
892 | d->n_operands = stats.num_insn_operands; | |
893 | d->n_dups = stats.num_dups; | |
9db4e0ec | 894 | |
c77e04ae | 895 | validate_insn_operands (d); |
9db4e0ec | 896 | validate_insn_alternatives (d); |
7ddf71e3 | 897 | validate_optab_operands (d); |
a995e389 | 898 | place_operands (d); |
1f3b37a3 | 899 | process_template (d, XTMPL (insn, 3)); |
9db4e0ec RK |
900 | } |
901 | \f | |
902 | /* Look at a define_peephole just read. Assign its code number. | |
a995e389 | 903 | Record on idata the template and the number of arguments. |
9db4e0ec RK |
904 | If the insn has a hairy output action, output it now. */ |
905 | ||
906 | static void | |
3d7aafde | 907 | gen_peephole (rtx peep, int lineno) |
9db4e0ec | 908 | { |
b29387ee | 909 | struct pattern_stats stats; |
5ed6ace5 | 910 | struct data *d = XNEW (struct data); |
b3694847 | 911 | int i; |
9db4e0ec | 912 | |
c88c0d42 | 913 | d->code_number = next_code_number; |
9db4e0ec | 914 | d->index_number = next_index_number; |
d2a3ce4e | 915 | d->filename = read_md_filename; |
d96a2fcd | 916 | d->lineno = lineno; |
9db4e0ec RK |
917 | d->name = 0; |
918 | ||
919 | /* Build up the list in the same order as the insns are seen | |
920 | in the machine description. */ | |
921 | d->next = 0; | |
a995e389 RH |
922 | *idata_end = d; |
923 | idata_end = &d->next; | |
9db4e0ec | 924 | |
a995e389 RH |
925 | memset (d->operand, 0, sizeof (d->operand)); |
926 | ||
927 | /* Get the number of operands by scanning all the patterns of the | |
928 | peephole optimizer. But ignore all the rest of the information | |
929 | thus obtained. */ | |
9db4e0ec | 930 | for (i = 0; i < XVECLEN (peep, 0); i++) |
a995e389 | 931 | scan_operands (d, XVECEXP (peep, 0, i), 0, 0); |
9db4e0ec | 932 | |
b29387ee RS |
933 | get_pattern_stats (&stats, XVEC (peep, 0)); |
934 | d->n_generator_args = 0; | |
935 | d->n_operands = stats.num_insn_operands; | |
9db4e0ec RK |
936 | d->n_dups = 0; |
937 | ||
9db4e0ec | 938 | validate_insn_alternatives (d); |
a995e389 | 939 | place_operands (d); |
1f3b37a3 | 940 | process_template (d, XTMPL (peep, 2)); |
9db4e0ec RK |
941 | } |
942 | \f | |
943 | /* Process a define_expand just read. Assign its code number, | |
944 | only for the purposes of `insn_gen_function'. */ | |
945 | ||
946 | static void | |
3d7aafde | 947 | gen_expand (rtx insn, int lineno) |
9db4e0ec | 948 | { |
b29387ee | 949 | struct pattern_stats stats; |
5ed6ace5 | 950 | struct data *d = XNEW (struct data); |
b3694847 | 951 | int i; |
9db4e0ec | 952 | |
c88c0d42 | 953 | d->code_number = next_code_number; |
9db4e0ec | 954 | d->index_number = next_index_number; |
d2a3ce4e | 955 | d->filename = read_md_filename; |
d96a2fcd | 956 | d->lineno = lineno; |
9db4e0ec RK |
957 | if (XSTR (insn, 0)[0]) |
958 | d->name = XSTR (insn, 0); | |
959 | else | |
960 | d->name = 0; | |
961 | ||
962 | /* Build up the list in the same order as the insns are seen | |
963 | in the machine description. */ | |
964 | d->next = 0; | |
a995e389 RH |
965 | *idata_end = d; |
966 | idata_end = &d->next; | |
9db4e0ec | 967 | |
a995e389 | 968 | memset (d->operand, 0, sizeof (d->operand)); |
9db4e0ec RK |
969 | |
970 | /* Scan the operands to get the specified predicates and modes, | |
971 | since expand_binop needs to know them. */ | |
972 | ||
9db4e0ec RK |
973 | if (XVEC (insn, 1)) |
974 | for (i = 0; i < XVECLEN (insn, 1); i++) | |
a995e389 | 975 | scan_operands (d, XVECEXP (insn, 1, i), 0, 0); |
9db4e0ec | 976 | |
b29387ee RS |
977 | get_pattern_stats (&stats, XVEC (insn, 1)); |
978 | d->n_generator_args = stats.num_generator_args; | |
979 | d->n_operands = stats.num_insn_operands; | |
980 | d->n_dups = stats.num_dups; | |
8ad97cfc | 981 | d->template_code = 0; |
4bbf910e | 982 | d->output_format = INSN_OUTPUT_FORMAT_NONE; |
a995e389 | 983 | |
9db4e0ec | 984 | validate_insn_alternatives (d); |
7ddf71e3 | 985 | validate_optab_operands (d); |
a995e389 | 986 | place_operands (d); |
9db4e0ec RK |
987 | } |
988 | \f | |
989 | /* Process a define_split just read. Assign its code number, | |
990 | only for reasons of consistency and to simplify genrecog. */ | |
991 | ||
9db4e0ec | 992 | static void |
3d7aafde | 993 | gen_split (rtx split, int lineno) |
9db4e0ec | 994 | { |
b29387ee | 995 | struct pattern_stats stats; |
5ed6ace5 | 996 | struct data *d = XNEW (struct data); |
b3694847 | 997 | int i; |
9db4e0ec | 998 | |
c88c0d42 | 999 | d->code_number = next_code_number; |
9db4e0ec | 1000 | d->index_number = next_index_number; |
d2a3ce4e | 1001 | d->filename = read_md_filename; |
d96a2fcd | 1002 | d->lineno = lineno; |
9db4e0ec RK |
1003 | d->name = 0; |
1004 | ||
1005 | /* Build up the list in the same order as the insns are seen | |
1006 | in the machine description. */ | |
1007 | d->next = 0; | |
a995e389 RH |
1008 | *idata_end = d; |
1009 | idata_end = &d->next; | |
9db4e0ec | 1010 | |
a995e389 | 1011 | memset (d->operand, 0, sizeof (d->operand)); |
9db4e0ec | 1012 | |
a995e389 RH |
1013 | /* Get the number of operands by scanning all the patterns of the |
1014 | split patterns. But ignore all the rest of the information thus | |
1015 | obtained. */ | |
9db4e0ec | 1016 | for (i = 0; i < XVECLEN (split, 0); i++) |
a995e389 | 1017 | scan_operands (d, XVECEXP (split, 0, i), 0, 0); |
9db4e0ec | 1018 | |
b29387ee RS |
1019 | get_pattern_stats (&stats, XVEC (split, 0)); |
1020 | d->n_generator_args = 0; | |
1021 | d->n_operands = stats.num_insn_operands; | |
9db4e0ec | 1022 | d->n_dups = 0; |
42495ca0 | 1023 | d->n_alternatives = 0; |
8ad97cfc | 1024 | d->template_code = 0; |
4bbf910e | 1025 | d->output_format = INSN_OUTPUT_FORMAT_NONE; |
a995e389 RH |
1026 | |
1027 | place_operands (d); | |
9db4e0ec | 1028 | } |
9db4e0ec | 1029 | |
e714561a SB |
1030 | static void |
1031 | init_insn_for_nothing (void) | |
1032 | { | |
1033 | memset (¬hing, 0, sizeof (nothing)); | |
1034 | nothing.name = "*placeholder_for_nothing"; | |
1035 | nothing.filename = "<internal>"; | |
1036 | } | |
1037 | ||
3d7aafde | 1038 | extern int main (int, char **); |
c1b59dce | 1039 | |
9db4e0ec | 1040 | int |
3d7aafde | 1041 | main (int argc, char **argv) |
9db4e0ec RK |
1042 | { |
1043 | rtx desc; | |
9db4e0ec | 1044 | |
d80eb1e1 RH |
1045 | progname = "genoutput"; |
1046 | ||
e714561a SB |
1047 | init_insn_for_nothing (); |
1048 | ||
600ab3fc | 1049 | if (!init_rtx_reader_args (argc, argv)) |
c88c0d42 | 1050 | return (FATAL_EXIT_CODE); |
9db4e0ec | 1051 | |
9db4e0ec | 1052 | output_prologue (); |
9db4e0ec | 1053 | next_index_number = 0; |
9db4e0ec RK |
1054 | |
1055 | /* Read the machine description. */ | |
1056 | ||
1057 | while (1) | |
1058 | { | |
c88c0d42 CP |
1059 | int line_no; |
1060 | ||
1061 | desc = read_md_rtx (&line_no, &next_code_number); | |
1062 | if (desc == NULL) | |
9db4e0ec | 1063 | break; |
9db4e0ec | 1064 | |
f38840db ZW |
1065 | switch (GET_CODE (desc)) |
1066 | { | |
1067 | case DEFINE_INSN: | |
1068 | gen_insn (desc, line_no); | |
1069 | break; | |
1070 | ||
1071 | case DEFINE_PEEPHOLE: | |
1072 | gen_peephole (desc, line_no); | |
1073 | break; | |
1074 | ||
1075 | case DEFINE_EXPAND: | |
1076 | gen_expand (desc, line_no); | |
1077 | break; | |
1078 | ||
1079 | case DEFINE_SPLIT: | |
1080 | case DEFINE_PEEPHOLE2: | |
1081 | gen_split (desc, line_no); | |
1082 | break; | |
1083 | ||
f38840db ZW |
1084 | case DEFINE_CONSTRAINT: |
1085 | case DEFINE_REGISTER_CONSTRAINT: | |
1086 | case DEFINE_ADDRESS_CONSTRAINT: | |
1087 | case DEFINE_MEMORY_CONSTRAINT: | |
1088 | note_constraint (desc, line_no); | |
1089 | break; | |
f38840db ZW |
1090 | |
1091 | default: | |
1092 | break; | |
1093 | } | |
9db4e0ec RK |
1094 | next_index_number++; |
1095 | } | |
1096 | ||
c3284718 | 1097 | printf ("\n\n"); |
a995e389 RH |
1098 | output_operand_data (); |
1099 | output_insn_data (); | |
1100 | output_get_insn_name (); | |
9db4e0ec RK |
1101 | |
1102 | fflush (stdout); | |
c1b59dce | 1103 | return (ferror (stdout) != 0 || have_error |
6a270722 | 1104 | ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE); |
9db4e0ec RK |
1105 | } |
1106 | ||
665f2503 RK |
1107 | /* Return the number of occurrences of character C in string S or |
1108 | -1 if S is the null string. */ | |
1109 | ||
9db4e0ec | 1110 | static int |
3d7aafde | 1111 | n_occurrences (int c, const char *s) |
9db4e0ec RK |
1112 | { |
1113 | int n = 0; | |
665f2503 RK |
1114 | |
1115 | if (s == 0 || *s == '\0') | |
1116 | return -1; | |
1117 | ||
9db4e0ec RK |
1118 | while (*s) |
1119 | n += (*s++ == c); | |
665f2503 | 1120 | |
9db4e0ec RK |
1121 | return n; |
1122 | } | |
88a56c2e | 1123 | |
665f2503 RK |
1124 | /* Remove whitespace in `s' by moving up characters until the end. |
1125 | Return a new string. */ | |
1126 | ||
1127 | static const char * | |
3d7aafde | 1128 | strip_whitespace (const char *s) |
88a56c2e | 1129 | { |
665f2503 RK |
1130 | char *p, *q; |
1131 | char ch; | |
1132 | ||
1133 | if (s == 0) | |
1134 | return 0; | |
88a56c2e | 1135 | |
5ed6ace5 | 1136 | p = q = XNEWVEC (char, strlen (s) + 1); |
88a56c2e HPN |
1137 | while ((ch = *s++) != '\0') |
1138 | if (! ISSPACE (ch)) | |
1139 | *p++ = ch; | |
1140 | ||
1141 | *p = '\0'; | |
665f2503 | 1142 | return q; |
88a56c2e | 1143 | } |
97488870 | 1144 | |
f38840db ZW |
1145 | /* Record just enough information about a constraint to allow checking |
1146 | of operand constraint strings above, in validate_insn_alternatives. | |
1147 | Does not validate most properties of the constraint itself; does | |
1148 | enforce no duplicate names, no overlap with MI constraints, and no | |
1149 | prefixes. EXP is the define_*constraint form, LINENO the line number | |
1150 | reported by the reader. */ | |
1151 | static void | |
1152 | note_constraint (rtx exp, int lineno) | |
1153 | { | |
1154 | const char *name = XSTR (exp, 0); | |
8ad97cfc | 1155 | struct constraint_data **iter, **slot, *new_cdata; |
f38840db | 1156 | |
8677664e RS |
1157 | if (strcmp (name, "TARGET_MEM_CONSTRAINT") == 0) |
1158 | name = general_mem; | |
1159 | unsigned int namelen = strlen (name); | |
1160 | ||
1161 | if (strchr (indep_constraints, name[0])) | |
f38840db ZW |
1162 | { |
1163 | if (name[1] == '\0') | |
bb933490 RS |
1164 | error_with_line (lineno, "constraint letter '%s' cannot be " |
1165 | "redefined by the machine description", name); | |
f38840db | 1166 | else |
bb933490 RS |
1167 | error_with_line (lineno, "constraint name '%s' cannot be defined by " |
1168 | "the machine description, as it begins with '%c'", | |
1169 | name, name[0]); | |
f38840db ZW |
1170 | return; |
1171 | } | |
1172 | ||
1173 | slot = &constraints_by_letter_table[(unsigned int)name[0]]; | |
1174 | for (iter = slot; *iter; iter = &(*iter)->next_this_letter) | |
1175 | { | |
1176 | /* This causes slot to end up pointing to the | |
1177 | next_this_letter field of the last constraint with a name | |
1178 | of equal or greater length than the new constraint; hence | |
1179 | the new constraint will be inserted after all previous | |
1180 | constraints with names of the same length. */ | |
1181 | if ((*iter)->namelen >= namelen) | |
1182 | slot = iter; | |
1183 | ||
1184 | if (!strcmp ((*iter)->name, name)) | |
1185 | { | |
bb933490 | 1186 | error_with_line (lineno, "redefinition of constraint '%s'", name); |
f38840db | 1187 | message_with_line ((*iter)->lineno, "previous definition is here"); |
f38840db ZW |
1188 | return; |
1189 | } | |
1190 | else if (!strncmp ((*iter)->name, name, (*iter)->namelen)) | |
1191 | { | |
bb933490 | 1192 | error_with_line (lineno, "defining constraint '%s' here", name); |
f38840db ZW |
1193 | message_with_line ((*iter)->lineno, "renders constraint '%s' " |
1194 | "(defined here) a prefix", (*iter)->name); | |
f38840db ZW |
1195 | return; |
1196 | } | |
1197 | else if (!strncmp ((*iter)->name, name, namelen)) | |
1198 | { | |
bb933490 | 1199 | error_with_line (lineno, "constraint '%s' is a prefix", name); |
f38840db ZW |
1200 | message_with_line ((*iter)->lineno, "of constraint '%s' " |
1201 | "(defined here)", (*iter)->name); | |
f38840db ZW |
1202 | return; |
1203 | } | |
1204 | } | |
8ad97cfc | 1205 | new_cdata = XNEWVAR (struct constraint_data, sizeof (struct constraint_data) + namelen); |
c3284718 | 1206 | strcpy (CONST_CAST (char *, new_cdata->name), name); |
8ad97cfc KG |
1207 | new_cdata->namelen = namelen; |
1208 | new_cdata->lineno = lineno; | |
1209 | new_cdata->next_this_letter = *slot; | |
1210 | *slot = new_cdata; | |
f38840db ZW |
1211 | } |
1212 | ||
1213 | /* Return the length of the constraint name beginning at position S | |
1214 | of an operand constraint string, or issue an error message if there | |
1215 | is no such constraint. Does not expect to be called for generic | |
1216 | constraints. */ | |
1217 | static int | |
1218 | mdep_constraint_len (const char *s, int lineno, int opno) | |
1219 | { | |
1220 | struct constraint_data *p; | |
1221 | ||
1222 | p = constraints_by_letter_table[(unsigned int)s[0]]; | |
1223 | ||
1224 | if (p) | |
1225 | for (; p; p = p->next_this_letter) | |
1226 | if (!strncmp (s, p->name, p->namelen)) | |
1227 | return p->namelen; | |
1228 | ||
bb933490 RS |
1229 | error_with_line (lineno, |
1230 | "error: undefined machine-specific constraint " | |
1231 | "at this point: \"%s\"", s); | |
f38840db | 1232 | message_with_line (lineno, "note: in operand %d", opno); |
f38840db ZW |
1233 | return 1; /* safe */ |
1234 | } |