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