Mercurial > hg > CbC > GCC_original
comparison gcc/genoutput.c @ 16:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | f6334be47118 |
children | 84e7813d76e9 |
comparison
equal
deleted
inserted
replaced
15:561a7518be6b | 16:04ced10e8804 |
---|---|
1 /* Generate code from to output assembler insns as recognized from rtl. | 1 /* Generate code from to output assembler insns as recognized from rtl. |
2 Copyright (C) 1987, 1988, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2002, | 2 Copyright (C) 1987-2017 Free Software Foundation, Inc. |
3 2003, 2004, 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. | |
4 | 3 |
5 This file is part of GCC. | 4 This file is part of GCC. |
6 | 5 |
7 GCC is free software; you can redistribute it and/or modify it under | 6 GCC is free software; you can redistribute it and/or modify it under |
8 the terms of the GNU General Public License as published by the Free | 7 the terms of the GNU General Public License as published by the Free |
63 e. `strict_low', is nonzero for operands contained in a STRICT_LOW_PART. | 62 e. `strict_low', is nonzero for operands contained in a STRICT_LOW_PART. |
64 | 63 |
65 f. `eliminable', is nonzero for operands that are matched normally by | 64 f. `eliminable', is nonzero for operands that are matched normally by |
66 MATCH_OPERAND; it is zero for operands that should not be changed during | 65 MATCH_OPERAND; it is zero for operands that should not be changed during |
67 register elimination such as MATCH_OPERATORs. | 66 register elimination such as MATCH_OPERATORs. |
67 | |
68 g. `allows_mem', is true for operands that accept MEM rtxes. | |
68 | 69 |
69 The code number of an insn is simply its position in the machine | 70 The code number of an insn is simply its position in the machine |
70 description; code numbers are assigned sequentially to entries in | 71 description; code numbers are assigned sequentially to entries in |
71 the description, starting with code number 0. | 72 the description, starting with code number 0. |
72 | 73 |
95 arbitrary limit, but what machine will have an instruction with | 96 arbitrary limit, but what machine will have an instruction with |
96 this many operands? */ | 97 this many operands? */ |
97 | 98 |
98 #define MAX_MAX_OPERANDS 40 | 99 #define MAX_MAX_OPERANDS 40 |
99 | 100 |
101 static char general_mem[] = { TARGET_MEM_CONSTRAINT, 0 }; | |
102 | |
100 static int n_occurrences (int, const char *); | 103 static int n_occurrences (int, const char *); |
101 static const char *strip_whitespace (const char *); | 104 static const char *strip_whitespace (const char *); |
102 | |
103 /* insns in the machine description are assigned sequential code numbers | |
104 that are used by insn-recog.c (produced by genrecog) to communicate | |
105 to insn-output.c (produced by this program). */ | |
106 | |
107 static int next_code_number; | |
108 | |
109 /* This counts all definitions in the md file, | |
110 for the sake of error messages. */ | |
111 | |
112 static int next_index_number; | |
113 | 105 |
114 /* This counts all operands used in the md file. The first is null. */ | 106 /* This counts all operands used in the md file. The first is null. */ |
115 | 107 |
116 static int next_operand_number = 1; | 108 static int next_operand_number = 1; |
117 | 109 |
121 { | 113 { |
122 struct operand_data *next; | 114 struct operand_data *next; |
123 int index; | 115 int index; |
124 const char *predicate; | 116 const char *predicate; |
125 const char *constraint; | 117 const char *constraint; |
126 enum machine_mode mode; | 118 machine_mode mode; |
127 unsigned char n_alternatives; | 119 unsigned char n_alternatives; |
128 char address_p; | 120 char address_p; |
129 char strict_low; | 121 char strict_low; |
130 char eliminable; | 122 char eliminable; |
131 char seen; | 123 char seen; |
133 | 125 |
134 /* Begin with a null operand at index 0. */ | 126 /* Begin with a null operand at index 0. */ |
135 | 127 |
136 static struct operand_data null_operand = | 128 static struct operand_data null_operand = |
137 { | 129 { |
138 0, 0, "", "", VOIDmode, 0, 0, 0, 0, 0 | 130 0, 0, "", "", E_VOIDmode, 0, 0, 0, 0, 0 |
139 }; | 131 }; |
140 | 132 |
141 static struct operand_data *odata = &null_operand; | 133 static struct operand_data *odata = &null_operand; |
142 static struct operand_data **odata_end = &null_operand.next; | 134 static struct operand_data **odata_end = &null_operand.next; |
143 | 135 |
154 struct data | 146 struct data |
155 { | 147 { |
156 struct data *next; | 148 struct data *next; |
157 const char *name; | 149 const char *name; |
158 const char *template_code; | 150 const char *template_code; |
151 file_location loc; | |
159 int code_number; | 152 int code_number; |
160 int index_number; | 153 int n_generator_args; /* Number of arguments passed to generator */ |
161 const char *filename; | |
162 int lineno; | |
163 int n_operands; /* Number of operands this insn recognizes */ | 154 int n_operands; /* Number of operands this insn recognizes */ |
164 int n_dups; /* Number times match_dup appears in pattern */ | 155 int n_dups; /* Number times match_dup appears in pattern */ |
165 int n_alternatives; /* Number of alternatives in each constraint */ | 156 int n_alternatives; /* Number of alternatives in each constraint */ |
166 int operand_number; /* Operand index in the big array. */ | 157 int operand_number; /* Operand index in the big array. */ |
167 int output_format; /* INSN_OUTPUT_FORMAT_*. */ | 158 int output_format; /* INSN_OUTPUT_FORMAT_*. */ |
168 struct operand_data operand[MAX_MAX_OPERANDS]; | 159 struct operand_data operand[MAX_MAX_OPERANDS]; |
169 }; | 160 }; |
170 | 161 |
171 /* This variable points to the first link in the insn chain. */ | 162 /* This variable points to the first link in the insn chain. */ |
172 | 163 static struct data *idata; |
173 static struct data *idata, **idata_end = &idata; | 164 |
165 /* This variable points to the end of the insn chain. This is where | |
166 everything relevant from the machien description is appended to. */ | |
167 static struct data **idata_end; | |
168 | |
174 | 169 |
175 static void output_prologue (void); | 170 static void output_prologue (void); |
176 static void output_operand_data (void); | 171 static void output_operand_data (void); |
177 static void output_insn_data (void); | 172 static void output_insn_data (void); |
178 static void output_get_insn_name (void); | 173 static void output_get_insn_name (void); |
181 struct operand_data *); | 176 struct operand_data *); |
182 static void place_operands (struct data *); | 177 static void place_operands (struct data *); |
183 static void process_template (struct data *, const char *); | 178 static void process_template (struct data *, const char *); |
184 static void validate_insn_alternatives (struct data *); | 179 static void validate_insn_alternatives (struct data *); |
185 static void validate_insn_operands (struct data *); | 180 static void validate_insn_operands (struct data *); |
186 static void gen_insn (rtx, int); | |
187 static void gen_peephole (rtx, int); | |
188 static void gen_expand (rtx, int); | |
189 static void gen_split (rtx, int); | |
190 | |
191 #ifdef USE_MD_CONSTRAINTS | |
192 | 181 |
193 struct constraint_data | 182 struct constraint_data |
194 { | 183 { |
195 struct constraint_data *next_this_letter; | 184 struct constraint_data *next_this_letter; |
196 int lineno; | 185 file_location loc; |
197 unsigned int namelen; | 186 unsigned int namelen; |
198 const char name[1]; | 187 char name[1]; |
199 }; | 188 }; |
200 | 189 |
201 /* This is a complete list (unlike the one in genpreds.c) of constraint | 190 /* All machine-independent constraint characters (except digits) that |
202 letters and modifiers with machine-independent meaning. The only | 191 are handled outside the define*_constraint mechanism. */ |
203 omission is digits, as these are handled specially. */ | 192 static const char indep_constraints[] = ",=+%*?!^$#&g"; |
204 static const char indep_constraints[] = ",=+%*?!#&<>EFVXgimnoprs"; | |
205 | 193 |
206 static struct constraint_data * | 194 static struct constraint_data * |
207 constraints_by_letter_table[1 << CHAR_BIT]; | 195 constraints_by_letter_table[1 << CHAR_BIT]; |
208 | 196 |
209 static int mdep_constraint_len (const char *, int, int); | 197 static int mdep_constraint_len (const char *, file_location, int); |
210 static void note_constraint (rtx, int); | 198 static void note_constraint (md_rtx_info *); |
211 | |
212 #else /* !USE_MD_CONSTRAINTS */ | |
213 | |
214 static void check_constraint_len (void); | |
215 static int constraint_len (const char *, int); | |
216 | |
217 #endif /* !USE_MD_CONSTRAINTS */ | |
218 | |
219 | 199 |
220 static void | 200 static void |
221 output_prologue (void) | 201 output_prologue (void) |
222 { | 202 { |
223 printf ("/* Generated automatically by the program `genoutput'\n\ | 203 printf ("/* Generated automatically by the program `genoutput'\n\ |
224 from the machine description file `md'. */\n\n"); | 204 from the machine description file `md'. */\n\n"); |
225 | 205 |
226 printf ("#include \"config.h\"\n"); | 206 printf ("#include \"config.h\"\n"); |
227 printf ("#include \"system.h\"\n"); | 207 printf ("#include \"system.h\"\n"); |
228 printf ("#include \"coretypes.h\"\n"); | 208 printf ("#include \"coretypes.h\"\n"); |
229 printf ("#include \"tm.h\"\n"); | 209 printf ("#include \"backend.h\"\n"); |
210 printf ("#include \"predict.h\"\n"); | |
211 printf ("#include \"tree.h\"\n"); | |
212 printf ("#include \"rtl.h\"\n"); | |
230 printf ("#include \"flags.h\"\n"); | 213 printf ("#include \"flags.h\"\n"); |
231 printf ("#include \"ggc.h\"\n"); | 214 printf ("#include \"alias.h\"\n"); |
232 printf ("#include \"rtl.h\"\n"); | 215 printf ("#include \"varasm.h\"\n"); |
216 printf ("#include \"stor-layout.h\"\n"); | |
217 printf ("#include \"calls.h\"\n"); | |
218 printf ("#include \"insn-config.h\"\n"); | |
219 printf ("#include \"expmed.h\"\n"); | |
220 printf ("#include \"dojump.h\"\n"); | |
221 printf ("#include \"explow.h\"\n"); | |
222 printf ("#include \"memmodel.h\"\n"); | |
223 printf ("#include \"emit-rtl.h\"\n"); | |
224 printf ("#include \"stmt.h\"\n"); | |
233 printf ("#include \"expr.h\"\n"); | 225 printf ("#include \"expr.h\"\n"); |
234 printf ("#include \"insn-codes.h\"\n"); | 226 printf ("#include \"insn-codes.h\"\n"); |
235 printf ("#include \"tm_p.h\"\n"); | 227 printf ("#include \"tm_p.h\"\n"); |
236 printf ("#include \"function.h\"\n"); | |
237 printf ("#include \"regs.h\"\n"); | 228 printf ("#include \"regs.h\"\n"); |
238 printf ("#include \"hard-reg-set.h\"\n"); | |
239 printf ("#include \"insn-config.h\"\n\n"); | |
240 printf ("#include \"conditions.h\"\n"); | 229 printf ("#include \"conditions.h\"\n"); |
241 printf ("#include \"insn-attr.h\"\n\n"); | 230 printf ("#include \"insn-attr.h\"\n\n"); |
242 printf ("#include \"recog.h\"\n\n"); | 231 printf ("#include \"recog.h\"\n\n"); |
243 printf ("#include \"diagnostic-core.h\"\n"); | 232 printf ("#include \"diagnostic-core.h\"\n"); |
244 printf ("#include \"output.h\"\n"); | 233 printf ("#include \"output.h\"\n"); |
253 | 242 |
254 printf ("\nstatic const struct insn_operand_data operand_data[] = \n{\n"); | 243 printf ("\nstatic const struct insn_operand_data operand_data[] = \n{\n"); |
255 | 244 |
256 for (d = odata; d; d = d->next) | 245 for (d = odata; d; d = d->next) |
257 { | 246 { |
247 struct pred_data *pred; | |
248 | |
258 printf (" {\n"); | 249 printf (" {\n"); |
259 | 250 |
260 printf (" %s,\n", | 251 printf (" %s,\n", |
261 d->predicate && d->predicate[0] ? d->predicate : "0"); | 252 d->predicate && d->predicate[0] ? d->predicate : "0"); |
262 | 253 |
263 printf (" \"%s\",\n", d->constraint ? d->constraint : ""); | 254 printf (" \"%s\",\n", d->constraint ? d->constraint : ""); |
264 | 255 |
265 printf (" %smode,\n", GET_MODE_NAME (d->mode)); | 256 printf (" E_%smode,\n", GET_MODE_NAME (d->mode)); |
266 | 257 |
267 printf (" %d,\n", d->strict_low); | 258 printf (" %d,\n", d->strict_low); |
268 | 259 |
269 printf (" %d,\n", d->constraint == NULL ? 1 : 0); | 260 printf (" %d,\n", d->constraint == NULL ? 1 : 0); |
270 | 261 |
271 printf (" %d\n", d->eliminable); | 262 printf (" %d,\n", d->eliminable); |
272 | 263 |
273 printf(" },\n"); | 264 pred = NULL; |
265 if (d->predicate) | |
266 pred = lookup_predicate (d->predicate); | |
267 printf (" %d\n", pred && pred->codes[MEM]); | |
268 | |
269 printf (" },\n"); | |
274 } | 270 } |
275 printf("};\n\n\n"); | 271 printf ("};\n\n\n"); |
276 } | 272 } |
277 | 273 |
278 static void | 274 static void |
279 output_insn_data (void) | 275 output_insn_data (void) |
280 { | 276 { |
295 printf ("#if GCC_VERSION >= 2007\n__extension__\n#endif\n"); | 291 printf ("#if GCC_VERSION >= 2007\n__extension__\n#endif\n"); |
296 printf ("\nconst struct insn_data_d insn_data[] = \n{\n"); | 292 printf ("\nconst struct insn_data_d insn_data[] = \n{\n"); |
297 | 293 |
298 for (d = idata; d; d = d->next) | 294 for (d = idata; d; d = d->next) |
299 { | 295 { |
300 printf (" /* %s:%d */\n", d->filename, d->lineno); | 296 printf (" /* %s:%d */\n", d->loc.filename, d->loc.lineno); |
301 printf (" {\n"); | 297 printf (" {\n"); |
302 | 298 |
303 if (d->name) | 299 if (d->name) |
304 { | 300 { |
305 printf (" \"%s\",\n", d->name); | 301 printf (" \"%s\",\n", d->name); |
328 } | 324 } |
329 | 325 |
330 switch (d->output_format) | 326 switch (d->output_format) |
331 { | 327 { |
332 case INSN_OUTPUT_FORMAT_NONE: | 328 case INSN_OUTPUT_FORMAT_NONE: |
333 printf ("#if HAVE_DESIGNATED_INITIALIZERS\n"); | 329 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n"); |
334 printf (" { 0 },\n"); | 330 printf (" { 0 },\n"); |
335 printf ("#else\n"); | 331 printf ("#else\n"); |
336 printf (" { 0, 0, 0 },\n"); | 332 printf (" { 0, 0, 0 },\n"); |
337 printf ("#endif\n"); | 333 printf ("#endif\n"); |
338 break; | 334 break; |
339 case INSN_OUTPUT_FORMAT_SINGLE: | 335 case INSN_OUTPUT_FORMAT_SINGLE: |
340 { | 336 { |
341 const char *p = d->template_code; | 337 const char *p = d->template_code; |
342 char prev = 0; | 338 char prev = 0; |
343 | 339 |
344 printf ("#if HAVE_DESIGNATED_INITIALIZERS\n"); | 340 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n"); |
345 printf (" { .single =\n"); | 341 printf (" { .single =\n"); |
346 printf ("#else\n"); | 342 printf ("#else\n"); |
347 printf (" {\n"); | 343 printf (" {\n"); |
348 printf ("#endif\n"); | 344 printf ("#endif\n"); |
349 printf (" \""); | 345 printf (" \""); |
360 putchar (*p); | 356 putchar (*p); |
361 prev = *p; | 357 prev = *p; |
362 ++p; | 358 ++p; |
363 } | 359 } |
364 printf ("\",\n"); | 360 printf ("\",\n"); |
365 printf ("#if HAVE_DESIGNATED_INITIALIZERS\n"); | 361 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n"); |
366 printf (" },\n"); | 362 printf (" },\n"); |
367 printf ("#else\n"); | 363 printf ("#else\n"); |
368 printf (" 0, 0 },\n"); | 364 printf (" 0, 0 },\n"); |
369 printf ("#endif\n"); | 365 printf ("#endif\n"); |
370 } | 366 } |
371 break; | 367 break; |
372 case INSN_OUTPUT_FORMAT_MULTI: | 368 case INSN_OUTPUT_FORMAT_MULTI: |
373 printf ("#if HAVE_DESIGNATED_INITIALIZERS\n"); | 369 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n"); |
374 printf (" { .multi = output_%d },\n", d->code_number); | 370 printf (" { .multi = output_%d },\n", d->code_number); |
375 printf ("#else\n"); | 371 printf ("#else\n"); |
376 printf (" { 0, output_%d, 0 },\n", d->code_number); | 372 printf (" { 0, output_%d, 0 },\n", d->code_number); |
377 printf ("#endif\n"); | 373 printf ("#endif\n"); |
378 break; | 374 break; |
379 case INSN_OUTPUT_FORMAT_FUNCTION: | 375 case INSN_OUTPUT_FORMAT_FUNCTION: |
380 printf ("#if HAVE_DESIGNATED_INITIALIZERS\n"); | 376 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n"); |
381 printf (" { .function = output_%d },\n", d->code_number); | 377 printf (" { .function = output_%d },\n", d->code_number); |
382 printf ("#else\n"); | 378 printf ("#else\n"); |
383 printf (" { 0, 0, output_%d },\n", d->code_number); | 379 printf (" { 0, 0, output_%d },\n", d->code_number); |
384 printf ("#endif\n"); | 380 printf ("#endif\n"); |
385 break; | 381 break; |
386 default: | 382 default: |
387 gcc_unreachable (); | 383 gcc_unreachable (); |
388 } | 384 } |
389 | 385 |
390 if (d->name && d->name[0] != '*') | 386 if (d->name && d->name[0] != '*') |
391 printf (" (insn_gen_fn) gen_%s,\n", d->name); | 387 printf (" { (insn_gen_fn::stored_funcptr) gen_%s },\n", d->name); |
392 else | 388 else |
393 printf (" 0,\n"); | 389 printf (" { 0 },\n"); |
394 | 390 |
395 printf (" &operand_data[%d],\n", d->operand_number); | 391 printf (" &operand_data[%d],\n", d->operand_number); |
392 printf (" %d,\n", d->n_generator_args); | |
396 printf (" %d,\n", d->n_operands); | 393 printf (" %d,\n", d->n_operands); |
397 printf (" %d,\n", d->n_dups); | 394 printf (" %d,\n", d->n_dups); |
398 printf (" %d,\n", d->n_alternatives); | 395 printf (" %d,\n", d->n_alternatives); |
399 printf (" %d\n", d->output_format); | 396 printf (" %d\n", d->output_format); |
400 | 397 |
401 printf(" },\n"); | 398 printf (" },\n"); |
402 } | 399 } |
403 printf ("};\n\n\n"); | 400 printf ("};\n\n\n"); |
404 } | 401 } |
405 | 402 |
406 static void | 403 static void |
415 printf (" return insn_data[code].name;\n"); | 412 printf (" return insn_data[code].name;\n"); |
416 printf ("}\n"); | 413 printf ("}\n"); |
417 } | 414 } |
418 | 415 |
419 | 416 |
420 /* Stores in max_opno the largest operand number present in `part', if | 417 /* Stores the operand data into `d->operand[i]'. |
421 that is larger than the previous value of max_opno, and the rest of | |
422 the operand data into `d->operand[i]'. | |
423 | 418 |
424 THIS_ADDRESS_P is nonzero if the containing rtx was an ADDRESS. | 419 THIS_ADDRESS_P is nonzero if the containing rtx was an ADDRESS. |
425 THIS_STRICT_LOW is nonzero if the containing rtx was a STRICT_LOW_PART. */ | 420 THIS_STRICT_LOW is nonzero if the containing rtx was a STRICT_LOW_PART. */ |
426 | |
427 static int max_opno; | |
428 static int num_dups; | |
429 | 421 |
430 static void | 422 static void |
431 scan_operands (struct data *d, rtx part, int this_address_p, | 423 scan_operands (struct data *d, rtx part, int this_address_p, |
432 int this_strict_low) | 424 int this_strict_low) |
433 { | 425 { |
440 | 432 |
441 switch (GET_CODE (part)) | 433 switch (GET_CODE (part)) |
442 { | 434 { |
443 case MATCH_OPERAND: | 435 case MATCH_OPERAND: |
444 opno = XINT (part, 0); | 436 opno = XINT (part, 0); |
445 if (opno > max_opno) | 437 if (opno >= MAX_MAX_OPERANDS) |
446 max_opno = opno; | 438 { |
447 if (max_opno >= MAX_MAX_OPERANDS) | 439 error_at (d->loc, "maximum number of operands exceeded"); |
448 { | |
449 error_with_line (d->lineno, "maximum number of operands exceeded"); | |
450 return; | 440 return; |
451 } | 441 } |
452 if (d->operand[opno].seen) | 442 if (d->operand[opno].seen) |
453 error_with_line (d->lineno, "repeated operand number %d\n", opno); | 443 error_at (d->loc, "repeated operand number %d\n", opno); |
454 | 444 |
455 d->operand[opno].seen = 1; | 445 d->operand[opno].seen = 1; |
456 d->operand[opno].mode = GET_MODE (part); | 446 d->operand[opno].mode = GET_MODE (part); |
457 d->operand[opno].strict_low = this_strict_low; | 447 d->operand[opno].strict_low = this_strict_low; |
458 d->operand[opno].predicate = XSTR (part, 1); | 448 d->operand[opno].predicate = XSTR (part, 1); |
463 d->operand[opno].eliminable = 1; | 453 d->operand[opno].eliminable = 1; |
464 return; | 454 return; |
465 | 455 |
466 case MATCH_SCRATCH: | 456 case MATCH_SCRATCH: |
467 opno = XINT (part, 0); | 457 opno = XINT (part, 0); |
468 if (opno > max_opno) | 458 if (opno >= MAX_MAX_OPERANDS) |
469 max_opno = opno; | 459 { |
470 if (max_opno >= MAX_MAX_OPERANDS) | 460 error_at (d->loc, "maximum number of operands exceeded"); |
471 { | |
472 error_with_line (d->lineno, "maximum number of operands exceeded"); | |
473 return; | 461 return; |
474 } | 462 } |
475 if (d->operand[opno].seen) | 463 if (d->operand[opno].seen) |
476 error_with_line (d->lineno, "repeated operand number %d\n", opno); | 464 error_at (d->loc, "repeated operand number %d\n", opno); |
477 | 465 |
478 d->operand[opno].seen = 1; | 466 d->operand[opno].seen = 1; |
479 d->operand[opno].mode = GET_MODE (part); | 467 d->operand[opno].mode = GET_MODE (part); |
480 d->operand[opno].strict_low = 0; | 468 d->operand[opno].strict_low = 0; |
481 d->operand[opno].predicate = "scratch_operand"; | 469 d->operand[opno].predicate = "scratch_operand"; |
487 return; | 475 return; |
488 | 476 |
489 case MATCH_OPERATOR: | 477 case MATCH_OPERATOR: |
490 case MATCH_PARALLEL: | 478 case MATCH_PARALLEL: |
491 opno = XINT (part, 0); | 479 opno = XINT (part, 0); |
492 if (opno > max_opno) | 480 if (opno >= MAX_MAX_OPERANDS) |
493 max_opno = opno; | 481 { |
494 if (max_opno >= MAX_MAX_OPERANDS) | 482 error_at (d->loc, "maximum number of operands exceeded"); |
495 { | |
496 error_with_line (d->lineno, "maximum number of operands exceeded"); | |
497 return; | 483 return; |
498 } | 484 } |
499 if (d->operand[opno].seen) | 485 if (d->operand[opno].seen) |
500 error_with_line (d->lineno, "repeated operand number %d\n", opno); | 486 error_at (d->loc, "repeated operand number %d\n", opno); |
501 | 487 |
502 d->operand[opno].seen = 1; | 488 d->operand[opno].seen = 1; |
503 d->operand[opno].mode = GET_MODE (part); | 489 d->operand[opno].mode = GET_MODE (part); |
504 d->operand[opno].strict_low = 0; | 490 d->operand[opno].strict_low = 0; |
505 d->operand[opno].predicate = XSTR (part, 1); | 491 d->operand[opno].predicate = XSTR (part, 1); |
506 d->operand[opno].constraint = 0; | 492 d->operand[opno].constraint = 0; |
507 d->operand[opno].address_p = 0; | 493 d->operand[opno].address_p = 0; |
508 d->operand[opno].eliminable = 0; | 494 d->operand[opno].eliminable = 0; |
509 for (i = 0; i < XVECLEN (part, 2); i++) | 495 for (i = 0; i < XVECLEN (part, 2); i++) |
510 scan_operands (d, XVECEXP (part, 2, i), 0, 0); | 496 scan_operands (d, XVECEXP (part, 2, i), 0, 0); |
511 return; | |
512 | |
513 case MATCH_DUP: | |
514 case MATCH_OP_DUP: | |
515 case MATCH_PAR_DUP: | |
516 ++num_dups; | |
517 break; | |
518 | |
519 case ADDRESS: | |
520 scan_operands (d, XEXP (part, 0), 1, 0); | |
521 return; | 497 return; |
522 | 498 |
523 case STRICT_LOW_PART: | 499 case STRICT_LOW_PART: |
524 scan_operands (d, XEXP (part, 0), 0, 1); | 500 scan_operands (d, XEXP (part, 0), 0, 1); |
525 return; | 501 return; |
650 { | 626 { |
651 d->template_code = 0; | 627 d->template_code = 0; |
652 d->output_format = INSN_OUTPUT_FORMAT_FUNCTION; | 628 d->output_format = INSN_OUTPUT_FORMAT_FUNCTION; |
653 | 629 |
654 puts ("\nstatic const char *"); | 630 puts ("\nstatic const char *"); |
655 printf ("output_%d (rtx *operands ATTRIBUTE_UNUSED, rtx insn ATTRIBUTE_UNUSED)\n", | 631 printf ("output_%d (rtx *operands ATTRIBUTE_UNUSED, rtx_insn *insn ATTRIBUTE_UNUSED)\n", |
656 d->code_number); | 632 d->code_number); |
657 puts ("{"); | 633 puts ("{"); |
658 print_md_ptr_loc (template_code); | 634 rtx_reader_ptr->print_md_ptr_loc (template_code); |
659 puts (template_code + 1); | 635 puts (template_code + 1); |
660 puts ("}"); | 636 puts ("}"); |
661 } | 637 } |
662 | 638 |
663 /* If the assembler code template starts with a @ it is a newline-separated | 639 /* If the assembler code template starts with a @ it is a newline-separated |
664 list of assembler code templates, one for each alternative. */ | 640 list of assembler code templates, one for each alternative. */ |
665 else if (template_code[0] == '@') | 641 else if (template_code[0] == '@') |
666 { | 642 { |
667 d->template_code = 0; | 643 int found_star = 0; |
668 d->output_format = INSN_OUTPUT_FORMAT_MULTI; | 644 |
669 | 645 for (cp = &template_code[1]; *cp; ) |
670 printf ("\nstatic const char * const output_%d[] = {\n", d->code_number); | 646 { |
671 | |
672 for (i = 0, cp = &template_code[1]; *cp; ) | |
673 { | |
674 const char *ep, *sp; | |
675 | |
676 while (ISSPACE (*cp)) | 647 while (ISSPACE (*cp)) |
677 cp++; | 648 cp++; |
678 | 649 if (*cp == '*') |
679 printf (" \""); | 650 found_star = 1; |
651 while (!IS_VSPACE (*cp) && *cp != '\0') | |
652 ++cp; | |
653 } | |
654 d->template_code = 0; | |
655 if (found_star) | |
656 { | |
657 d->output_format = INSN_OUTPUT_FORMAT_FUNCTION; | |
658 puts ("\nstatic const char *"); | |
659 printf ("output_%d (rtx *operands ATTRIBUTE_UNUSED, " | |
660 "rtx_insn *insn ATTRIBUTE_UNUSED)\n", d->code_number); | |
661 puts ("{"); | |
662 puts (" switch (which_alternative)\n {"); | |
663 } | |
664 else | |
665 { | |
666 d->output_format = INSN_OUTPUT_FORMAT_MULTI; | |
667 printf ("\nstatic const char * const output_%d[] = {\n", | |
668 d->code_number); | |
669 } | |
670 | |
671 for (i = 0, cp = &template_code[1]; *cp; ) | |
672 { | |
673 const char *ep, *sp, *bp; | |
674 | |
675 while (ISSPACE (*cp)) | |
676 cp++; | |
677 | |
678 bp = cp; | |
679 if (found_star) | |
680 { | |
681 printf (" case %d:", i); | |
682 if (*cp == '*') | |
683 { | |
684 printf ("\n "); | |
685 cp++; | |
686 } | |
687 else | |
688 printf (" return \""); | |
689 } | |
690 else | |
691 printf (" \""); | |
680 | 692 |
681 for (ep = sp = cp; !IS_VSPACE (*ep) && *ep != '\0'; ++ep) | 693 for (ep = sp = cp; !IS_VSPACE (*ep) && *ep != '\0'; ++ep) |
682 if (!ISSPACE (*ep)) | 694 if (!ISSPACE (*ep)) |
683 sp = ep + 1; | 695 sp = ep + 1; |
684 | 696 |
685 if (sp != ep) | 697 if (sp != ep) |
686 message_with_line (d->lineno, | 698 message_at (d->loc, "trailing whitespace in output template"); |
687 "trailing whitespace in output template"); | |
688 | 699 |
689 while (cp < sp) | 700 while (cp < sp) |
690 { | 701 { |
691 putchar (*cp); | 702 putchar (*cp); |
692 cp++; | 703 cp++; |
693 } | 704 } |
694 | 705 |
695 printf ("\",\n"); | 706 if (!found_star) |
707 puts ("\","); | |
708 else if (*bp != '*') | |
709 puts ("\";"); | |
710 else | |
711 { | |
712 /* The usual action will end with a return. | |
713 If there is neither break or return at the end, this is | |
714 assumed to be intentional; this allows to have multiple | |
715 consecutive alternatives share some code. */ | |
716 puts (""); | |
717 } | |
696 i++; | 718 i++; |
697 } | 719 } |
698 if (i == 1) | 720 if (i == 1) |
699 message_with_line (d->lineno, | 721 message_at (d->loc, "'@' is redundant for output template with" |
700 "'@' is redundant for output template with single alternative"); | 722 " single alternative"); |
701 if (i != d->n_alternatives) | 723 if (i != d->n_alternatives) |
702 error_with_line (d->lineno, | 724 error_at (d->loc, "wrong number of alternatives in the output" |
703 "wrong number of alternatives in the output template"); | 725 " template"); |
704 | 726 |
705 printf ("};\n"); | 727 if (found_star) |
728 puts (" default: gcc_unreachable ();\n }\n}"); | |
729 else | |
730 printf ("};\n"); | |
706 } | 731 } |
707 else | 732 else |
708 { | 733 { |
709 d->template_code = template_code; | 734 d->template_code = template_code; |
710 d->output_format = INSN_OUTPUT_FORMAT_SINGLE; | 735 d->output_format = INSN_OUTPUT_FORMAT_SINGLE; |
726 int len, i; | 751 int len, i; |
727 const char *p; | 752 const char *p; |
728 char c; | 753 char c; |
729 int which_alternative = 0; | 754 int which_alternative = 0; |
730 int alternative_count_unsure = 0; | 755 int alternative_count_unsure = 0; |
756 bool seen_write = false; | |
731 | 757 |
732 for (p = d->operand[start].constraint; (c = *p); p += len) | 758 for (p = d->operand[start].constraint; (c = *p); p += len) |
733 { | 759 { |
734 #ifdef USE_MD_CONSTRAINTS | 760 if ((c == '%' || c == '=' || c == '+') |
761 && p != d->operand[start].constraint) | |
762 error_at (d->loc, "character '%c' can only be used at the" | |
763 " beginning of a constraint string", c); | |
764 | |
765 if (c == '=' || c == '+') | |
766 seen_write = true; | |
767 | |
768 /* Earlyclobber operands must always be marked write-only | |
769 or read/write. */ | |
770 if (!seen_write && c == '&') | |
771 error_at (d->loc, "earlyclobber operands may not be" | |
772 " read-only in alternative %d", which_alternative); | |
773 | |
735 if (ISSPACE (c) || strchr (indep_constraints, c)) | 774 if (ISSPACE (c) || strchr (indep_constraints, c)) |
736 len = 1; | 775 len = 1; |
737 else if (ISDIGIT (c)) | 776 else if (ISDIGIT (c)) |
738 { | 777 { |
739 const char *q = p; | 778 const char *q = p; |
741 q++; | 780 q++; |
742 while (ISDIGIT (*q)); | 781 while (ISDIGIT (*q)); |
743 len = q - p; | 782 len = q - p; |
744 } | 783 } |
745 else | 784 else |
746 len = mdep_constraint_len (p, d->lineno, start); | 785 len = mdep_constraint_len (p, d->loc, start); |
747 #else | |
748 len = CONSTRAINT_LEN (c, p); | |
749 | |
750 if (len < 1 || (len > 1 && strchr (",#*+=&%!0123456789", c))) | |
751 { | |
752 error_with_line (d->lineno, | |
753 "invalid length %d for char '%c' in" | |
754 " alternative %d of operand %d", | |
755 len, c, which_alternative, start); | |
756 len = 1; | |
757 } | |
758 #endif | |
759 | 786 |
760 if (c == ',') | 787 if (c == ',') |
761 { | 788 { |
762 which_alternative++; | 789 which_alternative++; |
763 continue; | 790 continue; |
764 } | 791 } |
765 | 792 |
766 for (i = 1; i < len; i++) | 793 for (i = 1; i < len; i++) |
767 if (p[i] == '\0') | 794 if (p[i] == '\0') |
768 { | 795 { |
769 error_with_line (d->lineno, | 796 error_at (d->loc, "NUL in alternative %d of operand %d", |
770 "NUL in alternative %d of operand %d", | 797 which_alternative, start); |
771 which_alternative, start); | |
772 alternative_count_unsure = 1; | 798 alternative_count_unsure = 1; |
773 break; | 799 break; |
774 } | 800 } |
775 else if (strchr (",#*", p[i])) | 801 else if (strchr (",#*", p[i])) |
776 { | 802 { |
777 error_with_line (d->lineno, | 803 error_at (d->loc, "'%c' in alternative %d of operand %d", |
778 "'%c' in alternative %d of operand %d", | 804 p[i], which_alternative, start); |
779 p[i], which_alternative, start); | |
780 alternative_count_unsure = 1; | 805 alternative_count_unsure = 1; |
781 } | 806 } |
782 } | 807 } |
783 if (!alternative_count_unsure) | 808 if (!alternative_count_unsure) |
784 { | 809 { |
785 if (n == 0) | 810 if (n == 0) |
786 n = d->operand[start].n_alternatives; | 811 n = d->operand[start].n_alternatives; |
787 else if (n != d->operand[start].n_alternatives) | 812 else if (n != d->operand[start].n_alternatives) |
788 error_with_line (d->lineno, | 813 error_at (d->loc, "wrong number of alternatives in operand %d", |
789 "wrong number of alternatives in operand %d", | 814 start); |
790 start); | |
791 } | 815 } |
792 } | 816 } |
793 | 817 |
794 /* Record the insn's overall number of alternatives. */ | 818 /* Record the insn's overall number of alternatives. */ |
795 d->n_alternatives = n; | 819 d->n_alternatives = n; |
802 { | 826 { |
803 int i; | 827 int i; |
804 | 828 |
805 for (i = 0; i < d->n_operands; ++i) | 829 for (i = 0; i < d->n_operands; ++i) |
806 if (d->operand[i].seen == 0) | 830 if (d->operand[i].seen == 0) |
807 error_with_line (d->lineno, "missing operand %d", i); | 831 error_at (d->loc, "missing operand %d", i); |
808 } | 832 } |
809 | 833 |
810 static void | 834 static void |
811 validate_optab_operands (struct data *d) | 835 validate_optab_operands (struct data *d) |
812 { | 836 { |
816 /* Miscellaneous tests. */ | 840 /* Miscellaneous tests. */ |
817 if (strncmp (d->name, "cstore", 6) == 0 | 841 if (strncmp (d->name, "cstore", 6) == 0 |
818 && d->name[strlen (d->name) - 1] == '4' | 842 && d->name[strlen (d->name) - 1] == '4' |
819 && d->operand[0].mode == VOIDmode) | 843 && d->operand[0].mode == VOIDmode) |
820 { | 844 { |
821 message_with_line (d->lineno, "missing mode for operand 0 of cstore"); | 845 message_at (d->loc, "missing mode for operand 0 of cstore"); |
822 have_error = 1; | 846 have_error = 1; |
823 } | 847 } |
824 } | 848 } |
825 | 849 |
826 /* Look at a define_insn just read. Assign its code number. Record | 850 /* Look at a define_insn just read. Assign its code number. Record |
827 on idata the template and the number of arguments. If the insn has | 851 on idata the template and the number of arguments. If the insn has |
828 a hairy output action, output a function for now. */ | 852 a hairy output action, output a function for now. */ |
829 | 853 |
830 static void | 854 static void |
831 gen_insn (rtx insn, int lineno) | 855 gen_insn (md_rtx_info *info) |
832 { | 856 { |
833 struct data *d = XNEW (struct data); | 857 struct pattern_stats stats; |
858 rtx insn = info->def; | |
859 data *d = new data; | |
834 int i; | 860 int i; |
835 | 861 |
836 d->code_number = next_code_number; | 862 d->code_number = info->index; |
837 d->index_number = next_index_number; | 863 d->loc = info->loc; |
838 d->filename = read_md_filename; | |
839 d->lineno = lineno; | |
840 if (XSTR (insn, 0)[0]) | 864 if (XSTR (insn, 0)[0]) |
841 d->name = XSTR (insn, 0); | 865 d->name = XSTR (insn, 0); |
842 else | 866 else |
843 d->name = 0; | 867 d->name = 0; |
844 | 868 |
846 in the machine description. */ | 870 in the machine description. */ |
847 d->next = 0; | 871 d->next = 0; |
848 *idata_end = d; | 872 *idata_end = d; |
849 idata_end = &d->next; | 873 idata_end = &d->next; |
850 | 874 |
851 max_opno = -1; | |
852 num_dups = 0; | |
853 memset (d->operand, 0, sizeof (d->operand)); | 875 memset (d->operand, 0, sizeof (d->operand)); |
854 | 876 |
855 for (i = 0; i < XVECLEN (insn, 1); i++) | 877 for (i = 0; i < XVECLEN (insn, 1); i++) |
856 scan_operands (d, XVECEXP (insn, 1, i), 0, 0); | 878 scan_operands (d, XVECEXP (insn, 1, i), 0, 0); |
857 | 879 |
858 d->n_operands = max_opno + 1; | 880 get_pattern_stats (&stats, XVEC (insn, 1)); |
859 d->n_dups = num_dups; | 881 d->n_generator_args = stats.num_generator_args; |
860 | 882 d->n_operands = stats.num_insn_operands; |
861 #ifndef USE_MD_CONSTRAINTS | 883 d->n_dups = stats.num_dups; |
862 check_constraint_len (); | 884 |
863 #endif | |
864 validate_insn_operands (d); | 885 validate_insn_operands (d); |
865 validate_insn_alternatives (d); | 886 validate_insn_alternatives (d); |
866 validate_optab_operands (d); | 887 validate_optab_operands (d); |
867 place_operands (d); | 888 place_operands (d); |
868 process_template (d, XTMPL (insn, 3)); | 889 process_template (d, XTMPL (insn, 3)); |
871 /* Look at a define_peephole just read. Assign its code number. | 892 /* Look at a define_peephole just read. Assign its code number. |
872 Record on idata the template and the number of arguments. | 893 Record on idata the template and the number of arguments. |
873 If the insn has a hairy output action, output it now. */ | 894 If the insn has a hairy output action, output it now. */ |
874 | 895 |
875 static void | 896 static void |
876 gen_peephole (rtx peep, int lineno) | 897 gen_peephole (md_rtx_info *info) |
877 { | 898 { |
878 struct data *d = XNEW (struct data); | 899 struct pattern_stats stats; |
900 data *d = new data; | |
879 int i; | 901 int i; |
880 | 902 |
881 d->code_number = next_code_number; | 903 d->code_number = info->index; |
882 d->index_number = next_index_number; | 904 d->loc = info->loc; |
883 d->filename = read_md_filename; | |
884 d->lineno = lineno; | |
885 d->name = 0; | 905 d->name = 0; |
886 | 906 |
887 /* Build up the list in the same order as the insns are seen | 907 /* Build up the list in the same order as the insns are seen |
888 in the machine description. */ | 908 in the machine description. */ |
889 d->next = 0; | 909 d->next = 0; |
890 *idata_end = d; | 910 *idata_end = d; |
891 idata_end = &d->next; | 911 idata_end = &d->next; |
892 | 912 |
893 max_opno = -1; | |
894 num_dups = 0; | |
895 memset (d->operand, 0, sizeof (d->operand)); | 913 memset (d->operand, 0, sizeof (d->operand)); |
896 | 914 |
897 /* Get the number of operands by scanning all the patterns of the | 915 /* Get the number of operands by scanning all the patterns of the |
898 peephole optimizer. But ignore all the rest of the information | 916 peephole optimizer. But ignore all the rest of the information |
899 thus obtained. */ | 917 thus obtained. */ |
918 rtx peep = info->def; | |
900 for (i = 0; i < XVECLEN (peep, 0); i++) | 919 for (i = 0; i < XVECLEN (peep, 0); i++) |
901 scan_operands (d, XVECEXP (peep, 0, i), 0, 0); | 920 scan_operands (d, XVECEXP (peep, 0, i), 0, 0); |
902 | 921 |
903 d->n_operands = max_opno + 1; | 922 get_pattern_stats (&stats, XVEC (peep, 0)); |
923 d->n_generator_args = 0; | |
924 d->n_operands = stats.num_insn_operands; | |
904 d->n_dups = 0; | 925 d->n_dups = 0; |
905 | 926 |
906 validate_insn_alternatives (d); | 927 validate_insn_alternatives (d); |
907 place_operands (d); | 928 place_operands (d); |
908 process_template (d, XTMPL (peep, 2)); | 929 process_template (d, XTMPL (peep, 2)); |
910 | 931 |
911 /* Process a define_expand just read. Assign its code number, | 932 /* Process a define_expand just read. Assign its code number, |
912 only for the purposes of `insn_gen_function'. */ | 933 only for the purposes of `insn_gen_function'. */ |
913 | 934 |
914 static void | 935 static void |
915 gen_expand (rtx insn, int lineno) | 936 gen_expand (md_rtx_info *info) |
916 { | 937 { |
917 struct data *d = XNEW (struct data); | 938 struct pattern_stats stats; |
939 rtx insn = info->def; | |
940 data *d = new data; | |
918 int i; | 941 int i; |
919 | 942 |
920 d->code_number = next_code_number; | 943 d->code_number = info->index; |
921 d->index_number = next_index_number; | 944 d->loc = info->loc; |
922 d->filename = read_md_filename; | |
923 d->lineno = lineno; | |
924 if (XSTR (insn, 0)[0]) | 945 if (XSTR (insn, 0)[0]) |
925 d->name = XSTR (insn, 0); | 946 d->name = XSTR (insn, 0); |
926 else | 947 else |
927 d->name = 0; | 948 d->name = 0; |
928 | 949 |
930 in the machine description. */ | 951 in the machine description. */ |
931 d->next = 0; | 952 d->next = 0; |
932 *idata_end = d; | 953 *idata_end = d; |
933 idata_end = &d->next; | 954 idata_end = &d->next; |
934 | 955 |
935 max_opno = -1; | |
936 num_dups = 0; | |
937 memset (d->operand, 0, sizeof (d->operand)); | 956 memset (d->operand, 0, sizeof (d->operand)); |
938 | 957 |
939 /* Scan the operands to get the specified predicates and modes, | 958 /* Scan the operands to get the specified predicates and modes, |
940 since expand_binop needs to know them. */ | 959 since expand_binop needs to know them. */ |
941 | 960 |
942 if (XVEC (insn, 1)) | 961 if (XVEC (insn, 1)) |
943 for (i = 0; i < XVECLEN (insn, 1); i++) | 962 for (i = 0; i < XVECLEN (insn, 1); i++) |
944 scan_operands (d, XVECEXP (insn, 1, i), 0, 0); | 963 scan_operands (d, XVECEXP (insn, 1, i), 0, 0); |
945 | 964 |
946 d->n_operands = max_opno + 1; | 965 get_pattern_stats (&stats, XVEC (insn, 1)); |
947 d->n_dups = num_dups; | 966 d->n_generator_args = stats.num_generator_args; |
967 d->n_operands = stats.num_insn_operands; | |
968 d->n_dups = stats.num_dups; | |
948 d->template_code = 0; | 969 d->template_code = 0; |
949 d->output_format = INSN_OUTPUT_FORMAT_NONE; | 970 d->output_format = INSN_OUTPUT_FORMAT_NONE; |
950 | 971 |
951 validate_insn_alternatives (d); | 972 validate_insn_alternatives (d); |
952 validate_optab_operands (d); | 973 validate_optab_operands (d); |
953 place_operands (d); | 974 place_operands (d); |
954 } | 975 } |
955 | 976 |
956 /* Process a define_split just read. Assign its code number, | 977 static void |
957 only for reasons of consistency and to simplify genrecog. */ | 978 init_insn_for_nothing (void) |
958 | 979 { |
959 static void | 980 idata = XCNEW (struct data); |
960 gen_split (rtx split, int lineno) | 981 new (idata) data (); |
961 { | 982 idata->name = "*placeholder_for_nothing"; |
962 struct data *d = XNEW (struct data); | 983 idata->loc = file_location ("<internal>", 0, 0); |
963 int i; | 984 idata_end = &idata->next; |
964 | 985 } |
965 d->code_number = next_code_number; | 986 |
966 d->index_number = next_index_number; | 987 extern int main (int, const char **); |
967 d->filename = read_md_filename; | |
968 d->lineno = lineno; | |
969 d->name = 0; | |
970 | |
971 /* Build up the list in the same order as the insns are seen | |
972 in the machine description. */ | |
973 d->next = 0; | |
974 *idata_end = d; | |
975 idata_end = &d->next; | |
976 | |
977 max_opno = -1; | |
978 num_dups = 0; | |
979 memset (d->operand, 0, sizeof (d->operand)); | |
980 | |
981 /* Get the number of operands by scanning all the patterns of the | |
982 split patterns. But ignore all the rest of the information thus | |
983 obtained. */ | |
984 for (i = 0; i < XVECLEN (split, 0); i++) | |
985 scan_operands (d, XVECEXP (split, 0, i), 0, 0); | |
986 | |
987 d->n_operands = max_opno + 1; | |
988 d->n_dups = 0; | |
989 d->n_alternatives = 0; | |
990 d->template_code = 0; | |
991 d->output_format = INSN_OUTPUT_FORMAT_NONE; | |
992 | |
993 place_operands (d); | |
994 } | |
995 | |
996 extern int main (int, char **); | |
997 | 988 |
998 int | 989 int |
999 main (int argc, char **argv) | 990 main (int argc, const char **argv) |
1000 { | 991 { |
1001 rtx desc; | |
1002 | |
1003 progname = "genoutput"; | 992 progname = "genoutput"; |
993 | |
994 init_insn_for_nothing (); | |
1004 | 995 |
1005 if (!init_rtx_reader_args (argc, argv)) | 996 if (!init_rtx_reader_args (argc, argv)) |
1006 return (FATAL_EXIT_CODE); | 997 return (FATAL_EXIT_CODE); |
1007 | 998 |
1008 output_prologue (); | 999 output_prologue (); |
1009 next_code_number = 0; | |
1010 next_index_number = 0; | |
1011 | 1000 |
1012 /* Read the machine description. */ | 1001 /* Read the machine description. */ |
1013 | 1002 |
1014 while (1) | 1003 md_rtx_info info; |
1015 { | 1004 while (read_md_rtx (&info)) |
1016 int line_no; | 1005 switch (GET_CODE (info.def)) |
1017 | 1006 { |
1018 desc = read_md_rtx (&line_no, &next_code_number); | 1007 case DEFINE_INSN: |
1019 if (desc == NULL) | 1008 gen_insn (&info); |
1020 break; | 1009 break; |
1021 | 1010 |
1022 switch (GET_CODE (desc)) | 1011 case DEFINE_PEEPHOLE: |
1023 { | 1012 gen_peephole (&info); |
1024 case DEFINE_INSN: | 1013 break; |
1025 gen_insn (desc, line_no); | 1014 |
1026 break; | 1015 case DEFINE_EXPAND: |
1027 | 1016 gen_expand (&info); |
1028 case DEFINE_PEEPHOLE: | 1017 break; |
1029 gen_peephole (desc, line_no); | 1018 |
1030 break; | 1019 case DEFINE_CONSTRAINT: |
1031 | 1020 case DEFINE_REGISTER_CONSTRAINT: |
1032 case DEFINE_EXPAND: | 1021 case DEFINE_ADDRESS_CONSTRAINT: |
1033 gen_expand (desc, line_no); | 1022 case DEFINE_MEMORY_CONSTRAINT: |
1034 break; | 1023 case DEFINE_SPECIAL_MEMORY_CONSTRAINT: |
1035 | 1024 note_constraint (&info); |
1036 case DEFINE_SPLIT: | 1025 break; |
1037 case DEFINE_PEEPHOLE2: | 1026 |
1038 gen_split (desc, line_no); | 1027 default: |
1039 break; | 1028 break; |
1040 | 1029 } |
1041 #ifdef USE_MD_CONSTRAINTS | 1030 |
1042 case DEFINE_CONSTRAINT: | 1031 printf ("\n\n"); |
1043 case DEFINE_REGISTER_CONSTRAINT: | |
1044 case DEFINE_ADDRESS_CONSTRAINT: | |
1045 case DEFINE_MEMORY_CONSTRAINT: | |
1046 note_constraint (desc, line_no); | |
1047 break; | |
1048 #endif | |
1049 | |
1050 default: | |
1051 break; | |
1052 } | |
1053 next_index_number++; | |
1054 } | |
1055 | |
1056 printf("\n\n"); | |
1057 output_operand_data (); | 1032 output_operand_data (); |
1058 output_insn_data (); | 1033 output_insn_data (); |
1059 output_get_insn_name (); | 1034 output_get_insn_name (); |
1060 | 1035 |
1061 fflush (stdout); | 1036 fflush (stdout); |
1099 | 1074 |
1100 *p = '\0'; | 1075 *p = '\0'; |
1101 return q; | 1076 return q; |
1102 } | 1077 } |
1103 | 1078 |
1104 #ifdef USE_MD_CONSTRAINTS | 1079 /* Record just enough information about the constraint in *INFO to allow |
1105 | 1080 checking of operand constraint strings above, in validate_insn_alternatives. |
1106 /* Record just enough information about a constraint to allow checking | 1081 Does not validate most properties of the constraint itself; does enforce |
1107 of operand constraint strings above, in validate_insn_alternatives. | 1082 no duplicate names, no overlap with MI constraints, and no prefixes. */ |
1108 Does not validate most properties of the constraint itself; does | 1083 static void |
1109 enforce no duplicate names, no overlap with MI constraints, and no | 1084 note_constraint (md_rtx_info *info) |
1110 prefixes. EXP is the define_*constraint form, LINENO the line number | 1085 { |
1111 reported by the reader. */ | 1086 rtx exp = info->def; |
1112 static void | |
1113 note_constraint (rtx exp, int lineno) | |
1114 { | |
1115 const char *name = XSTR (exp, 0); | 1087 const char *name = XSTR (exp, 0); |
1088 struct constraint_data **iter, **slot, *new_cdata; | |
1089 | |
1090 if (strcmp (name, "TARGET_MEM_CONSTRAINT") == 0) | |
1091 name = general_mem; | |
1116 unsigned int namelen = strlen (name); | 1092 unsigned int namelen = strlen (name); |
1117 struct constraint_data **iter, **slot, *new_cdata; | 1093 |
1118 | 1094 if (strchr (indep_constraints, name[0])) |
1119 /* The 'm' constraint is special here since that constraint letter | |
1120 can be overridden by the back end by defining the | |
1121 TARGET_MEM_CONSTRAINT macro. */ | |
1122 if (strchr (indep_constraints, name[0]) && name[0] != 'm') | |
1123 { | 1095 { |
1124 if (name[1] == '\0') | 1096 if (name[1] == '\0') |
1125 error_with_line (lineno, "constraint letter '%s' cannot be " | 1097 error_at (info->loc, "constraint letter '%s' cannot be " |
1126 "redefined by the machine description", name); | 1098 "redefined by the machine description", name); |
1127 else | 1099 else |
1128 error_with_line (lineno, "constraint name '%s' cannot be defined by " | 1100 error_at (info->loc, "constraint name '%s' cannot be defined by " |
1129 "the machine description, as it begins with '%c'", | 1101 "the machine description, as it begins with '%c'", |
1130 name, name[0]); | 1102 name, name[0]); |
1131 return; | 1103 return; |
1132 } | 1104 } |
1133 | 1105 |
1134 slot = &constraints_by_letter_table[(unsigned int)name[0]]; | 1106 slot = &constraints_by_letter_table[(unsigned int)name[0]]; |
1135 for (iter = slot; *iter; iter = &(*iter)->next_this_letter) | 1107 for (iter = slot; *iter; iter = &(*iter)->next_this_letter) |
1142 if ((*iter)->namelen >= namelen) | 1114 if ((*iter)->namelen >= namelen) |
1143 slot = iter; | 1115 slot = iter; |
1144 | 1116 |
1145 if (!strcmp ((*iter)->name, name)) | 1117 if (!strcmp ((*iter)->name, name)) |
1146 { | 1118 { |
1147 error_with_line (lineno, "redefinition of constraint '%s'", name); | 1119 error_at (info->loc, "redefinition of constraint '%s'", name); |
1148 message_with_line ((*iter)->lineno, "previous definition is here"); | 1120 message_at ((*iter)->loc, "previous definition is here"); |
1149 return; | 1121 return; |
1150 } | 1122 } |
1151 else if (!strncmp ((*iter)->name, name, (*iter)->namelen)) | 1123 else if (!strncmp ((*iter)->name, name, (*iter)->namelen)) |
1152 { | 1124 { |
1153 error_with_line (lineno, "defining constraint '%s' here", name); | 1125 error_at (info->loc, "defining constraint '%s' here", name); |
1154 message_with_line ((*iter)->lineno, "renders constraint '%s' " | 1126 message_at ((*iter)->loc, "renders constraint '%s' " |
1155 "(defined here) a prefix", (*iter)->name); | 1127 "(defined here) a prefix", (*iter)->name); |
1156 return; | 1128 return; |
1157 } | 1129 } |
1158 else if (!strncmp ((*iter)->name, name, namelen)) | 1130 else if (!strncmp ((*iter)->name, name, namelen)) |
1159 { | 1131 { |
1160 error_with_line (lineno, "constraint '%s' is a prefix", name); | 1132 error_at (info->loc, "constraint '%s' is a prefix", name); |
1161 message_with_line ((*iter)->lineno, "of constraint '%s' " | 1133 message_at ((*iter)->loc, "of constraint '%s' " |
1162 "(defined here)", (*iter)->name); | 1134 "(defined here)", (*iter)->name); |
1163 return; | 1135 return; |
1164 } | 1136 } |
1165 } | 1137 } |
1166 new_cdata = XNEWVAR (struct constraint_data, sizeof (struct constraint_data) + namelen); | 1138 new_cdata = XNEWVAR (struct constraint_data, |
1167 strcpy ((char *)new_cdata + offsetof(struct constraint_data, name), name); | 1139 sizeof (struct constraint_data) + namelen); |
1140 new (new_cdata) constraint_data (); | |
1141 strcpy (CONST_CAST (char *, new_cdata->name), name); | |
1168 new_cdata->namelen = namelen; | 1142 new_cdata->namelen = namelen; |
1169 new_cdata->lineno = lineno; | 1143 new_cdata->loc = info->loc; |
1170 new_cdata->next_this_letter = *slot; | 1144 new_cdata->next_this_letter = *slot; |
1171 *slot = new_cdata; | 1145 *slot = new_cdata; |
1172 } | 1146 } |
1173 | 1147 |
1174 /* Return the length of the constraint name beginning at position S | 1148 /* Return the length of the constraint name beginning at position S |
1175 of an operand constraint string, or issue an error message if there | 1149 of an operand constraint string, or issue an error message if there |
1176 is no such constraint. Does not expect to be called for generic | 1150 is no such constraint. Does not expect to be called for generic |
1177 constraints. */ | 1151 constraints. */ |
1178 static int | 1152 static int |
1179 mdep_constraint_len (const char *s, int lineno, int opno) | 1153 mdep_constraint_len (const char *s, file_location loc, int opno) |
1180 { | 1154 { |
1181 struct constraint_data *p; | 1155 struct constraint_data *p; |
1182 | 1156 |
1183 p = constraints_by_letter_table[(unsigned int)s[0]]; | 1157 p = constraints_by_letter_table[(unsigned int)s[0]]; |
1184 | 1158 |
1185 if (p) | 1159 if (p) |
1186 for (; p; p = p->next_this_letter) | 1160 for (; p; p = p->next_this_letter) |
1187 if (!strncmp (s, p->name, p->namelen)) | 1161 if (!strncmp (s, p->name, p->namelen)) |
1188 return p->namelen; | 1162 return p->namelen; |
1189 | 1163 |
1190 error_with_line (lineno, | 1164 error_at (loc, "error: undefined machine-specific constraint " |
1191 "error: undefined machine-specific constraint " | 1165 "at this point: \"%s\"", s); |
1192 "at this point: \"%s\"", s); | 1166 message_at (loc, "note: in operand %d", opno); |
1193 message_with_line (lineno, "note: in operand %d", opno); | |
1194 return 1; /* safe */ | 1167 return 1; /* safe */ |
1195 } | 1168 } |
1196 | |
1197 #else | |
1198 /* Verify that DEFAULT_CONSTRAINT_LEN is used properly and not | |
1199 tampered with. This isn't bullet-proof, but it should catch | |
1200 most genuine mistakes. */ | |
1201 static void | |
1202 check_constraint_len (void) | |
1203 { | |
1204 const char *p; | |
1205 int d; | |
1206 | |
1207 for (p = ",#*+=&%!1234567890"; *p; p++) | |
1208 for (d = -9; d < 9; d++) | |
1209 gcc_assert (constraint_len (p, d) == d); | |
1210 } | |
1211 | |
1212 static int | |
1213 constraint_len (const char *p, int genoutput_default_constraint_len) | |
1214 { | |
1215 /* Check that we still match defaults.h . First we do a generation-time | |
1216 check that fails if the value is not the expected one... */ | |
1217 gcc_assert (DEFAULT_CONSTRAINT_LEN (*p, p) == 1); | |
1218 /* And now a compile-time check that should give a diagnostic if the | |
1219 definition doesn't exactly match. */ | |
1220 #define DEFAULT_CONSTRAINT_LEN(C,STR) 1 | |
1221 /* Now re-define DEFAULT_CONSTRAINT_LEN so that we can verify it is | |
1222 being used. */ | |
1223 #undef DEFAULT_CONSTRAINT_LEN | |
1224 #define DEFAULT_CONSTRAINT_LEN(C,STR) \ | |
1225 ((C) != *p || STR != p ? -1 : genoutput_default_constraint_len) | |
1226 return CONSTRAINT_LEN (*p, p); | |
1227 /* And set it back. */ | |
1228 #undef DEFAULT_CONSTRAINT_LEN | |
1229 #define DEFAULT_CONSTRAINT_LEN(C,STR) 1 | |
1230 } | |
1231 #endif |