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