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