]>
Commit | Line | Data |
---|---|---|
65963943 | 1 | /* Generate code from machine description to emit insns as rtl. |
5987a4f3 | 2 | Copyright (C) 1987, 88, 91, 94, 95, 97, 1998 Free Software Foundation, Inc. |
65963943 RK |
3 | |
4 | This file is part of GNU CC. | |
5 | ||
6 | GNU CC is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GNU CC is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU CC; see the file COPYING. If not, write to | |
a35311b0 RK |
18 | the Free Software Foundation, 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. */ | |
65963943 RK |
20 | |
21 | ||
0d64891c | 22 | #include "hconfig.h" |
0b93b64e | 23 | #include "system.h" |
65963943 RK |
24 | #include "rtl.h" |
25 | #include "obstack.h" | |
26 | ||
27 | static struct obstack obstack; | |
28 | struct obstack *rtl_obstack = &obstack; | |
29 | ||
30 | #define obstack_chunk_alloc xmalloc | |
31 | #define obstack_chunk_free free | |
32 | ||
0b93b64e | 33 | char *xmalloc PROTO((unsigned)); |
bf94d1ec KG |
34 | static void fatal PVPROTO ((char *, ...)) |
35 | ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN; | |
36 | void fancy_abort PROTO((void)) ATTRIBUTE_NORETURN; | |
65963943 | 37 | |
4db83042 MM |
38 | /* Define this so we can link with print-rtl.o to get debug_rtx function. */ |
39 | char **insn_name_ptr = 0; | |
40 | ||
65963943 RK |
41 | static int max_opno; |
42 | static int max_dup_opno; | |
43 | static int register_constraints; | |
44 | static int insn_code_number; | |
45 | static int insn_index_number; | |
46 | ||
47 | /* Data structure for recording the patterns of insns that have CLOBBERs. | |
48 | We use this to output a function that adds these CLOBBERs to a | |
49 | previously-allocated PARALLEL expression. */ | |
50 | ||
51 | struct clobber_pat | |
52 | { | |
e5f6a288 | 53 | struct clobber_ent *insns; |
65963943 RK |
54 | rtx pattern; |
55 | int first_clobber; | |
56 | struct clobber_pat *next; | |
57 | } *clobber_list; | |
58 | ||
e5f6a288 RK |
59 | /* Records one insn that uses the clobber list. */ |
60 | ||
61 | struct clobber_ent | |
62 | { | |
63 | int code_number; /* Counts only insns. */ | |
64 | struct clobber_ent *next; | |
65 | }; | |
66 | ||
e009aaf3 JL |
67 | static void max_operand_1 PROTO((rtx)); |
68 | static int max_operand_vec PROTO((rtx, int)); | |
69 | static void print_code PROTO((RTX_CODE)); | |
70 | static void gen_exp PROTO((rtx)); | |
71 | static void gen_insn PROTO((rtx)); | |
72 | static void gen_expand PROTO((rtx)); | |
73 | static void gen_split PROTO((rtx)); | |
74 | static void output_add_clobbers PROTO((void)); | |
75 | static void output_init_mov_optab PROTO((void)); | |
76 | ||
77 | \f | |
65963943 RK |
78 | static void |
79 | max_operand_1 (x) | |
80 | rtx x; | |
81 | { | |
82 | register RTX_CODE code; | |
83 | register int i; | |
84 | register int len; | |
85 | register char *fmt; | |
86 | ||
87 | if (x == 0) | |
88 | return; | |
89 | ||
90 | code = GET_CODE (x); | |
91 | ||
92 | if (code == MATCH_OPERAND && XSTR (x, 2) != 0 && *XSTR (x, 2) != '\0') | |
93 | register_constraints = 1; | |
94 | if (code == MATCH_SCRATCH && XSTR (x, 1) != 0 && *XSTR (x, 1) != '\0') | |
95 | register_constraints = 1; | |
96 | if (code == MATCH_OPERAND || code == MATCH_OPERATOR | |
97 | || code == MATCH_PARALLEL) | |
98 | max_opno = MAX (max_opno, XINT (x, 0)); | |
8fabbfe6 | 99 | if (code == MATCH_DUP || code == MATCH_OP_DUP || code == MATCH_PAR_DUP) |
65963943 RK |
100 | max_dup_opno = MAX (max_dup_opno, XINT (x, 0)); |
101 | ||
102 | fmt = GET_RTX_FORMAT (code); | |
103 | len = GET_RTX_LENGTH (code); | |
104 | for (i = 0; i < len; i++) | |
105 | { | |
106 | if (fmt[i] == 'e' || fmt[i] == 'u') | |
107 | max_operand_1 (XEXP (x, i)); | |
108 | else if (fmt[i] == 'E') | |
109 | { | |
110 | int j; | |
111 | for (j = 0; j < XVECLEN (x, i); j++) | |
112 | max_operand_1 (XVECEXP (x, i, j)); | |
113 | } | |
114 | } | |
115 | } | |
116 | ||
117 | static int | |
118 | max_operand_vec (insn, arg) | |
119 | rtx insn; | |
120 | int arg; | |
121 | { | |
122 | register int len = XVECLEN (insn, arg); | |
123 | register int i; | |
124 | ||
125 | max_opno = -1; | |
126 | max_dup_opno = -1; | |
127 | ||
128 | for (i = 0; i < len; i++) | |
129 | max_operand_1 (XVECEXP (insn, arg, i)); | |
130 | ||
131 | return max_opno + 1; | |
132 | } | |
133 | \f | |
134 | static void | |
135 | print_code (code) | |
136 | RTX_CODE code; | |
137 | { | |
138 | register char *p1; | |
139 | for (p1 = GET_RTX_NAME (code); *p1; p1++) | |
140 | { | |
141 | if (*p1 >= 'a' && *p1 <= 'z') | |
142 | putchar (*p1 + 'A' - 'a'); | |
143 | else | |
144 | putchar (*p1); | |
145 | } | |
146 | } | |
147 | ||
148 | /* Print a C expression to construct an RTX just like X, | |
149 | substituting any operand references appearing within. */ | |
150 | ||
151 | static void | |
152 | gen_exp (x) | |
153 | rtx x; | |
154 | { | |
155 | register RTX_CODE code; | |
156 | register int i; | |
157 | register int len; | |
158 | register char *fmt; | |
159 | ||
160 | if (x == 0) | |
161 | { | |
3d678dca | 162 | printf ("NULL_RTX"); |
65963943 RK |
163 | return; |
164 | } | |
165 | ||
166 | code = GET_CODE (x); | |
167 | ||
168 | switch (code) | |
169 | { | |
170 | case MATCH_OPERAND: | |
171 | case MATCH_DUP: | |
172 | printf ("operand%d", XINT (x, 0)); | |
173 | return; | |
174 | ||
175 | case MATCH_OP_DUP: | |
4ceb7595 JC |
176 | printf ("gen_rtx (GET_CODE (operand%d), ", XINT (x, 0)); |
177 | if (GET_MODE (x) == VOIDmode) | |
178 | printf ("GET_MODE (operand%d)", XINT (x, 0)); | |
179 | else | |
180 | printf ("%smode", GET_MODE_NAME (GET_MODE (x))); | |
65963943 RK |
181 | for (i = 0; i < XVECLEN (x, 1); i++) |
182 | { | |
183 | printf (",\n\t\t"); | |
184 | gen_exp (XVECEXP (x, 1, i)); | |
185 | } | |
186 | printf (")"); | |
187 | return; | |
188 | ||
189 | case MATCH_OPERATOR: | |
190 | printf ("gen_rtx (GET_CODE (operand%d)", XINT (x, 0)); | |
191 | printf (", %smode", GET_MODE_NAME (GET_MODE (x))); | |
192 | for (i = 0; i < XVECLEN (x, 2); i++) | |
193 | { | |
194 | printf (",\n\t\t"); | |
195 | gen_exp (XVECEXP (x, 2, i)); | |
196 | } | |
197 | printf (")"); | |
198 | return; | |
199 | ||
200 | case MATCH_PARALLEL: | |
8fabbfe6 | 201 | case MATCH_PAR_DUP: |
65963943 RK |
202 | printf ("operand%d", XINT (x, 0)); |
203 | return; | |
204 | ||
205 | case MATCH_SCRATCH: | |
3b80f6ca | 206 | printf ("gen_rtx_SCRATCH (%smode)", GET_MODE_NAME (GET_MODE (x))); |
65963943 RK |
207 | return; |
208 | ||
209 | case ADDRESS: | |
210 | fatal ("ADDRESS expression code used in named instruction pattern"); | |
211 | ||
212 | case PC: | |
213 | printf ("pc_rtx"); | |
214 | return; | |
215 | ||
216 | case CC0: | |
217 | printf ("cc0_rtx"); | |
218 | return; | |
219 | ||
220 | case CONST_INT: | |
221 | if (INTVAL (x) == 0) | |
3d678dca RS |
222 | printf ("const0_rtx"); |
223 | else if (INTVAL (x) == 1) | |
224 | printf ("const1_rtx"); | |
225 | else if (INTVAL (x) == -1) | |
226 | printf ("constm1_rtx"); | |
227 | else if (INTVAL (x) == STORE_FLAG_VALUE) | |
228 | printf ("const_true_rtx"); | |
229 | else | |
76d31c63 JL |
230 | { |
231 | printf ("GEN_INT ("); | |
232 | printf (HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); | |
233 | printf (")"); | |
234 | } | |
3d678dca RS |
235 | return; |
236 | ||
237 | case CONST_DOUBLE: | |
238 | /* These shouldn't be written in MD files. Instead, the appropriate | |
239 | routines in varasm.c should be called. */ | |
240 | abort (); | |
1d300e19 KG |
241 | |
242 | default: | |
243 | break; | |
65963943 RK |
244 | } |
245 | ||
3b80f6ca | 246 | printf ("gen_rtx_"); |
65963943 | 247 | print_code (code); |
3b80f6ca | 248 | printf (" (%smode", GET_MODE_NAME (GET_MODE (x))); |
65963943 RK |
249 | |
250 | fmt = GET_RTX_FORMAT (code); | |
251 | len = GET_RTX_LENGTH (code); | |
252 | for (i = 0; i < len; i++) | |
253 | { | |
254 | if (fmt[i] == '0') | |
255 | break; | |
a558d864 | 256 | printf (",\n\t"); |
65963943 RK |
257 | if (fmt[i] == 'e' || fmt[i] == 'u') |
258 | gen_exp (XEXP (x, i)); | |
259 | else if (fmt[i] == 'i') | |
3d678dca | 260 | printf ("%u", XINT (x, i)); |
65963943 RK |
261 | else if (fmt[i] == 's') |
262 | printf ("\"%s\"", XSTR (x, i)); | |
263 | else if (fmt[i] == 'E') | |
264 | { | |
265 | int j; | |
266 | printf ("gen_rtvec (%d", XVECLEN (x, i)); | |
267 | for (j = 0; j < XVECLEN (x, i); j++) | |
268 | { | |
269 | printf (",\n\t\t"); | |
270 | gen_exp (XVECEXP (x, i, j)); | |
271 | } | |
272 | printf (")"); | |
273 | } | |
274 | else | |
275 | abort (); | |
276 | } | |
277 | printf (")"); | |
278 | } | |
279 | \f | |
280 | /* Generate the `gen_...' function for a DEFINE_INSN. */ | |
281 | ||
282 | static void | |
283 | gen_insn (insn) | |
284 | rtx insn; | |
285 | { | |
286 | int operands; | |
287 | register int i; | |
288 | ||
289 | /* See if the pattern for this insn ends with a group of CLOBBERs of (hard) | |
290 | registers or MATCH_SCRATCHes. If so, store away the information for | |
0f41302f | 291 | later. */ |
65963943 RK |
292 | |
293 | if (XVEC (insn, 1)) | |
294 | { | |
295 | for (i = XVECLEN (insn, 1) - 1; i > 0; i--) | |
296 | if (GET_CODE (XVECEXP (insn, 1, i)) != CLOBBER | |
297 | || (GET_CODE (XEXP (XVECEXP (insn, 1, i), 0)) != REG | |
298 | && GET_CODE (XEXP (XVECEXP (insn, 1, i), 0)) != MATCH_SCRATCH)) | |
299 | break; | |
300 | ||
301 | if (i != XVECLEN (insn, 1) - 1) | |
302 | { | |
e5f6a288 RK |
303 | register struct clobber_pat *p; |
304 | register struct clobber_ent *link | |
305 | = (struct clobber_ent *) xmalloc (sizeof (struct clobber_ent)); | |
306 | register int j; | |
307 | ||
308 | link->code_number = insn_code_number; | |
309 | ||
310 | /* See if any previous CLOBBER_LIST entry is the same as this | |
311 | one. */ | |
312 | ||
313 | for (p = clobber_list; p; p = p->next) | |
314 | { | |
315 | if (p->first_clobber != i + 1 | |
316 | || XVECLEN (p->pattern, 1) != XVECLEN (insn, 1)) | |
317 | continue; | |
318 | ||
319 | for (j = i + 1; j < XVECLEN (insn, 1); j++) | |
320 | { | |
321 | rtx old = XEXP (XVECEXP (p->pattern, 1, j), 0); | |
322 | rtx new = XEXP (XVECEXP (insn, 1, j), 0); | |
323 | ||
324 | /* OLD and NEW are the same if both are to be a SCRATCH | |
f5f178e0 | 325 | of the same mode, |
e5f6a288 | 326 | or if both are registers of the same mode and number. */ |
f5f178e0 RS |
327 | if (! (GET_MODE (old) == GET_MODE (new) |
328 | && ((GET_CODE (old) == MATCH_SCRATCH | |
329 | && GET_CODE (new) == MATCH_SCRATCH) | |
330 | || (GET_CODE (old) == REG && GET_CODE (new) == REG | |
331 | && REGNO (old) == REGNO (new))))) | |
e5f6a288 RK |
332 | break; |
333 | } | |
334 | ||
335 | if (j == XVECLEN (insn, 1)) | |
336 | break; | |
337 | } | |
338 | ||
339 | if (p == 0) | |
340 | { | |
341 | p = (struct clobber_pat *) xmalloc (sizeof (struct clobber_pat)); | |
65963943 | 342 | |
e5f6a288 RK |
343 | p->insns = 0; |
344 | p->pattern = insn; | |
345 | p->first_clobber = i + 1; | |
346 | p->next = clobber_list; | |
347 | clobber_list = p; | |
348 | } | |
349 | ||
350 | link->next = p->insns; | |
351 | p->insns = link; | |
65963943 RK |
352 | } |
353 | } | |
354 | ||
6b6ca844 RK |
355 | /* Don't mention instructions whose names are the null string |
356 | or begin with '*'. They are in the machine description just | |
357 | to be recognized. */ | |
358 | if (XSTR (insn, 0)[0] == 0 || XSTR (insn, 0)[0] == '*') | |
65963943 RK |
359 | return; |
360 | ||
361 | /* Find out how many operands this function has, | |
362 | and also whether any of them have register constraints. */ | |
363 | register_constraints = 0; | |
364 | operands = max_operand_vec (insn, 1); | |
365 | if (max_dup_opno >= operands) | |
366 | fatal ("match_dup operand number has no match_operand"); | |
367 | ||
368 | /* Output the function name and argument declarations. */ | |
369 | printf ("rtx\ngen_%s (", XSTR (insn, 0)); | |
370 | for (i = 0; i < operands; i++) | |
371 | printf (i ? ", operand%d" : "operand%d", i); | |
372 | printf (")\n"); | |
373 | for (i = 0; i < operands; i++) | |
374 | printf (" rtx operand%d;\n", i); | |
375 | printf ("{\n"); | |
376 | ||
377 | /* Output code to construct and return the rtl for the instruction body */ | |
378 | ||
379 | if (XVECLEN (insn, 1) == 1) | |
380 | { | |
381 | printf (" return "); | |
382 | gen_exp (XVECEXP (insn, 1, 0)); | |
383 | printf (";\n}\n\n"); | |
384 | } | |
385 | else | |
386 | { | |
3b80f6ca | 387 | printf (" return gen_rtx_PARALLEL (VOIDmode, gen_rtvec (%d", XVECLEN (insn, 1)); |
65963943 RK |
388 | for (i = 0; i < XVECLEN (insn, 1); i++) |
389 | { | |
390 | printf (",\n\t\t"); | |
391 | gen_exp (XVECEXP (insn, 1, i)); | |
392 | } | |
393 | printf ("));\n}\n\n"); | |
394 | } | |
395 | } | |
396 | \f | |
397 | /* Generate the `gen_...' function for a DEFINE_EXPAND. */ | |
398 | ||
399 | static void | |
400 | gen_expand (expand) | |
401 | rtx expand; | |
402 | { | |
403 | int operands; | |
404 | register int i; | |
405 | ||
406 | if (strlen (XSTR (expand, 0)) == 0) | |
407 | fatal ("define_expand lacks a name"); | |
408 | if (XVEC (expand, 1) == 0) | |
409 | fatal ("define_expand for %s lacks a pattern", XSTR (expand, 0)); | |
410 | ||
411 | /* Find out how many operands this function has, | |
412 | and also whether any of them have register constraints. */ | |
413 | register_constraints = 0; | |
414 | ||
415 | operands = max_operand_vec (expand, 1); | |
416 | ||
417 | /* Output the function name and argument declarations. */ | |
418 | printf ("rtx\ngen_%s (", XSTR (expand, 0)); | |
419 | for (i = 0; i < operands; i++) | |
420 | printf (i ? ", operand%d" : "operand%d", i); | |
421 | printf (")\n"); | |
422 | for (i = 0; i < operands; i++) | |
423 | printf (" rtx operand%d;\n", i); | |
424 | printf ("{\n"); | |
425 | ||
426 | /* If we don't have any C code to write, only one insn is being written, | |
427 | and no MATCH_DUPs are present, we can just return the desired insn | |
428 | like we do for a DEFINE_INSN. This saves memory. */ | |
429 | if ((XSTR (expand, 3) == 0 || *XSTR (expand, 3) == '\0') | |
430 | && operands > max_dup_opno | |
431 | && XVECLEN (expand, 1) == 1) | |
432 | { | |
433 | printf (" return "); | |
434 | gen_exp (XVECEXP (expand, 1, 0)); | |
435 | printf (";\n}\n\n"); | |
436 | return; | |
437 | } | |
438 | ||
439 | /* For each operand referred to only with MATCH_DUPs, | |
440 | make a local variable. */ | |
441 | for (i = operands; i <= max_dup_opno; i++) | |
442 | printf (" rtx operand%d;\n", i); | |
443 | if (operands > 0 || max_dup_opno >= 0) | |
444 | printf (" rtx operands[%d];\n", MAX (operands, max_dup_opno + 1)); | |
445 | printf (" rtx _val = 0;\n"); | |
446 | printf (" start_sequence ();\n"); | |
447 | ||
448 | /* The fourth operand of DEFINE_EXPAND is some code to be executed | |
449 | before the actual construction. | |
450 | This code expects to refer to `operands' | |
451 | just as the output-code in a DEFINE_INSN does, | |
452 | but here `operands' is an automatic array. | |
453 | So copy the operand values there before executing it. */ | |
454 | if (XSTR (expand, 3) && *XSTR (expand, 3)) | |
455 | { | |
456 | /* Output code to copy the arguments into `operands'. */ | |
457 | for (i = 0; i < operands; i++) | |
458 | printf (" operands[%d] = operand%d;\n", i, i); | |
459 | ||
460 | /* Output the special code to be executed before the sequence | |
461 | is generated. */ | |
462 | printf ("%s\n", XSTR (expand, 3)); | |
463 | ||
464 | /* Output code to copy the arguments back out of `operands' | |
465 | (unless we aren't going to use them at all). */ | |
466 | if (XVEC (expand, 1) != 0) | |
467 | { | |
468 | for (i = 0; i < operands; i++) | |
469 | printf (" operand%d = operands[%d];\n", i, i); | |
470 | for (; i <= max_dup_opno; i++) | |
471 | printf (" operand%d = operands[%d];\n", i, i); | |
472 | } | |
473 | } | |
474 | ||
475 | /* Output code to construct the rtl for the instruction bodies. | |
476 | Use emit_insn to add them to the sequence being accumulated. | |
477 | But don't do this if the user's code has set `no_more' nonzero. */ | |
478 | ||
479 | for (i = 0; i < XVECLEN (expand, 1); i++) | |
480 | { | |
481 | rtx next = XVECEXP (expand, 1, i); | |
482 | if ((GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC) | |
483 | || (GET_CODE (next) == PARALLEL | |
484 | && GET_CODE (XVECEXP (next, 0, 0)) == SET | |
485 | && GET_CODE (SET_DEST (XVECEXP (next, 0, 0))) == PC) | |
486 | || GET_CODE (next) == RETURN) | |
487 | printf (" emit_jump_insn ("); | |
488 | else if ((GET_CODE (next) == SET && GET_CODE (SET_SRC (next)) == CALL) | |
489 | || GET_CODE (next) == CALL | |
490 | || (GET_CODE (next) == PARALLEL | |
491 | && GET_CODE (XVECEXP (next, 0, 0)) == SET | |
492 | && GET_CODE (SET_SRC (XVECEXP (next, 0, 0))) == CALL) | |
493 | || (GET_CODE (next) == PARALLEL | |
494 | && GET_CODE (XVECEXP (next, 0, 0)) == CALL)) | |
495 | printf (" emit_call_insn ("); | |
496 | else if (GET_CODE (next) == CODE_LABEL) | |
497 | printf (" emit_label ("); | |
498 | else if (GET_CODE (next) == MATCH_OPERAND | |
499 | || GET_CODE (next) == MATCH_OPERATOR | |
500 | || GET_CODE (next) == MATCH_PARALLEL | |
501 | || GET_CODE (next) == MATCH_OP_DUP | |
502 | || GET_CODE (next) == MATCH_DUP | |
503 | || GET_CODE (next) == PARALLEL) | |
504 | printf (" emit ("); | |
505 | else | |
506 | printf (" emit_insn ("); | |
507 | gen_exp (next); | |
508 | printf (");\n"); | |
509 | if (GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC | |
510 | && GET_CODE (SET_SRC (next)) == LABEL_REF) | |
511 | printf (" emit_barrier ();"); | |
512 | } | |
513 | ||
514 | /* Call `gen_sequence' to make a SEQUENCE out of all the | |
515 | insns emitted within this gen_... function. */ | |
516 | ||
65963943 | 517 | printf (" _val = gen_sequence ();\n"); |
65963943 RK |
518 | printf (" end_sequence ();\n"); |
519 | printf (" return _val;\n}\n\n"); | |
520 | } | |
521 | ||
522 | /* Like gen_expand, but generates a SEQUENCE. */ | |
0f41302f | 523 | |
65963943 RK |
524 | static void |
525 | gen_split (split) | |
526 | rtx split; | |
527 | { | |
528 | register int i; | |
529 | int operands; | |
530 | ||
531 | if (XVEC (split, 0) == 0) | |
3462dc45 | 532 | fatal ("define_split (definition %d) lacks a pattern", insn_index_number); |
65963943 | 533 | else if (XVEC (split, 2) == 0) |
3462dc45 RK |
534 | fatal ("define_split (definition %d) lacks a replacement pattern", |
535 | insn_index_number); | |
65963943 RK |
536 | |
537 | /* Find out how many operands this function has. */ | |
538 | ||
539 | max_operand_vec (split, 2); | |
540 | operands = MAX (max_opno, max_dup_opno) + 1; | |
541 | ||
542 | /* Output the function name and argument declarations. */ | |
543 | printf ("rtx\ngen_split_%d (operands)\n rtx *operands;\n", | |
544 | insn_code_number); | |
545 | printf ("{\n"); | |
546 | ||
547 | /* Declare all local variables. */ | |
548 | for (i = 0; i < operands; i++) | |
549 | printf (" rtx operand%d;\n", i); | |
91afd8f5 | 550 | printf (" rtx _val = 0;\n"); |
65963943 RK |
551 | printf (" start_sequence ();\n"); |
552 | ||
553 | /* The fourth operand of DEFINE_SPLIT is some code to be executed | |
554 | before the actual construction. */ | |
555 | ||
556 | if (XSTR (split, 3)) | |
557 | printf ("%s\n", XSTR (split, 3)); | |
558 | ||
559 | /* Output code to copy the arguments back out of `operands' */ | |
560 | for (i = 0; i < operands; i++) | |
561 | printf (" operand%d = operands[%d];\n", i, i); | |
562 | ||
563 | /* Output code to construct the rtl for the instruction bodies. | |
564 | Use emit_insn to add them to the sequence being accumulated. | |
565 | But don't do this if the user's code has set `no_more' nonzero. */ | |
566 | ||
567 | for (i = 0; i < XVECLEN (split, 2); i++) | |
568 | { | |
569 | rtx next = XVECEXP (split, 2, i); | |
570 | if ((GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC) | |
571 | || (GET_CODE (next) == PARALLEL | |
572 | && GET_CODE (XVECEXP (next, 0, 0)) == SET | |
573 | && GET_CODE (SET_DEST (XVECEXP (next, 0, 0))) == PC) | |
574 | || GET_CODE (next) == RETURN) | |
575 | printf (" emit_jump_insn ("); | |
576 | else if ((GET_CODE (next) == SET && GET_CODE (SET_SRC (next)) == CALL) | |
577 | || GET_CODE (next) == CALL | |
578 | || (GET_CODE (next) == PARALLEL | |
579 | && GET_CODE (XVECEXP (next, 0, 0)) == SET | |
580 | && GET_CODE (SET_SRC (XVECEXP (next, 0, 0))) == CALL) | |
581 | || (GET_CODE (next) == PARALLEL | |
582 | && GET_CODE (XVECEXP (next, 0, 0)) == CALL)) | |
583 | printf (" emit_call_insn ("); | |
584 | else if (GET_CODE (next) == CODE_LABEL) | |
585 | printf (" emit_label ("); | |
586 | else if (GET_CODE (next) == MATCH_OPERAND | |
587 | || GET_CODE (next) == MATCH_OPERATOR | |
588 | || GET_CODE (next) == MATCH_PARALLEL | |
589 | || GET_CODE (next) == MATCH_OP_DUP | |
590 | || GET_CODE (next) == MATCH_DUP | |
591 | || GET_CODE (next) == PARALLEL) | |
592 | printf (" emit ("); | |
593 | else | |
594 | printf (" emit_insn ("); | |
595 | gen_exp (next); | |
596 | printf (");\n"); | |
597 | if (GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC | |
598 | && GET_CODE (SET_SRC (next)) == LABEL_REF) | |
599 | printf (" emit_barrier ();"); | |
600 | } | |
601 | ||
602 | /* Call `gen_sequence' to make a SEQUENCE out of all the | |
603 | insns emitted within this gen_... function. */ | |
604 | ||
65963943 | 605 | printf (" _val = gen_sequence ();\n"); |
65963943 RK |
606 | printf (" end_sequence ();\n"); |
607 | printf (" return _val;\n}\n\n"); | |
608 | } | |
609 | \f | |
610 | /* Write a function, `add_clobbers', that is given a PARALLEL of sufficient | |
611 | size for the insn and an INSN_CODE, and inserts the required CLOBBERs at | |
612 | the end of the vector. */ | |
613 | ||
614 | static void | |
615 | output_add_clobbers () | |
616 | { | |
617 | struct clobber_pat *clobber; | |
e5f6a288 | 618 | struct clobber_ent *ent; |
65963943 RK |
619 | int i; |
620 | ||
621 | printf ("\n\nvoid\nadd_clobbers (pattern, insn_code_number)\n"); | |
622 | printf (" rtx pattern;\n int insn_code_number;\n"); | |
623 | printf ("{\n"); | |
65963943 RK |
624 | printf (" switch (insn_code_number)\n"); |
625 | printf (" {\n"); | |
626 | ||
627 | for (clobber = clobber_list; clobber; clobber = clobber->next) | |
628 | { | |
e5f6a288 RK |
629 | for (ent = clobber->insns; ent; ent = ent->next) |
630 | printf (" case %d:\n", ent->code_number); | |
65963943 RK |
631 | |
632 | for (i = clobber->first_clobber; i < XVECLEN (clobber->pattern, 1); i++) | |
633 | { | |
634 | printf (" XVECEXP (pattern, 0, %d) = ", i); | |
635 | gen_exp (XVECEXP (clobber->pattern, 1, i)); | |
636 | printf (";\n"); | |
637 | } | |
638 | ||
e5f6a288 | 639 | printf (" break;\n\n"); |
65963943 RK |
640 | } |
641 | ||
642 | printf (" default:\n"); | |
643 | printf (" abort ();\n"); | |
644 | printf (" }\n"); | |
645 | printf ("}\n"); | |
646 | } | |
647 | \f | |
648 | /* Write a function, init_mov_optab, that is called to set up entries | |
649 | in mov_optab for EXTRA_CC_MODES. */ | |
650 | ||
651 | static void | |
652 | output_init_mov_optab () | |
653 | { | |
654 | #ifdef EXTRA_CC_NAMES | |
655 | static char *cc_names[] = { EXTRA_CC_NAMES }; | |
656 | char *p; | |
85066503 | 657 | size_t i; |
65963943 RK |
658 | |
659 | printf ("\nvoid\ninit_mov_optab ()\n{\n"); | |
660 | ||
661 | for (i = 0; i < sizeof cc_names / sizeof cc_names[0]; i++) | |
662 | { | |
663 | printf ("#ifdef HAVE_mov"); | |
664 | for (p = cc_names[i]; *p; p++) | |
665 | printf ("%c", *p >= 'A' && *p <= 'Z' ? *p - 'A' + 'a' : *p); | |
666 | printf ("\n"); | |
667 | printf (" if (HAVE_mov"); | |
668 | for (p = cc_names[i]; *p; p++) | |
669 | printf ("%c", *p >= 'A' && *p <= 'Z' ? *p - 'A' + 'a' : *p); | |
670 | printf (")\n"); | |
671 | printf (" mov_optab->handlers[(int) %smode].insn_code = CODE_FOR_mov", | |
672 | cc_names[i]); | |
673 | for (p = cc_names[i]; *p; p++) | |
674 | printf ("%c", *p >= 'A' && *p <= 'Z' ? *p - 'A' + 'a' : *p); | |
675 | printf (";\n#endif\n"); | |
676 | } | |
677 | ||
678 | printf ("}\n"); | |
679 | #endif | |
680 | } | |
681 | \f | |
682 | char * | |
683 | xmalloc (size) | |
684 | unsigned size; | |
685 | { | |
686 | register char *val = (char *) malloc (size); | |
687 | ||
688 | if (val == 0) | |
689 | fatal ("virtual memory exhausted"); | |
690 | ||
691 | return val; | |
692 | } | |
693 | ||
694 | char * | |
695 | xrealloc (ptr, size) | |
696 | char *ptr; | |
697 | unsigned size; | |
698 | { | |
699 | char *result = (char *) realloc (ptr, size); | |
700 | if (!result) | |
701 | fatal ("virtual memory exhausted"); | |
702 | return result; | |
703 | } | |
704 | ||
705 | static void | |
320e7c40 | 706 | fatal VPROTO ((char *format, ...)) |
65963943 | 707 | { |
320e7c40 KG |
708 | #ifndef __STDC__ |
709 | char *format; | |
710 | #endif | |
711 | va_list ap; | |
712 | ||
713 | VA_START (ap, format); | |
714 | ||
715 | #ifndef __STDC__ | |
716 | format = va_arg (ap, char *); | |
717 | #endif | |
718 | ||
65963943 | 719 | fprintf (stderr, "genemit: "); |
320e7c40 KG |
720 | vfprintf (stderr, format, ap); |
721 | va_end (ap); | |
65963943 RK |
722 | fprintf (stderr, "\n"); |
723 | exit (FATAL_EXIT_CODE); | |
724 | } | |
725 | ||
726 | /* More 'friendly' abort that prints the line and file. | |
727 | config.h can #define abort fancy_abort if you like that sort of thing. */ | |
728 | ||
729 | void | |
730 | fancy_abort () | |
731 | { | |
732 | fatal ("Internal gcc abort."); | |
733 | } | |
734 | \f | |
735 | int | |
736 | main (argc, argv) | |
737 | int argc; | |
738 | char **argv; | |
739 | { | |
740 | rtx desc; | |
741 | FILE *infile; | |
65963943 RK |
742 | register int c; |
743 | ||
744 | obstack_init (rtl_obstack); | |
745 | ||
746 | if (argc <= 1) | |
747 | fatal ("No input file name."); | |
748 | ||
749 | infile = fopen (argv[1], "r"); | |
750 | if (infile == 0) | |
751 | { | |
752 | perror (argv[1]); | |
753 | exit (FATAL_EXIT_CODE); | |
754 | } | |
755 | ||
756 | init_rtl (); | |
757 | ||
758 | /* Assign sequential codes to all entries in the machine description | |
759 | in parallel with the tables in insn-output.c. */ | |
760 | ||
761 | insn_code_number = 0; | |
762 | insn_index_number = 0; | |
763 | ||
764 | printf ("/* Generated automatically by the program `genemit'\n\ | |
765 | from the machine description file `md'. */\n\n"); | |
766 | ||
767 | printf ("#include \"config.h\"\n"); | |
729da3f5 | 768 | printf ("#include \"system.h\"\n"); |
65963943 RK |
769 | printf ("#include \"rtl.h\"\n"); |
770 | printf ("#include \"expr.h\"\n"); | |
771 | printf ("#include \"real.h\"\n"); | |
1d300e19 | 772 | printf ("#include \"flags.h\"\n"); |
65963943 RK |
773 | printf ("#include \"output.h\"\n"); |
774 | printf ("#include \"insn-config.h\"\n\n"); | |
775 | printf ("#include \"insn-flags.h\"\n\n"); | |
776 | printf ("#include \"insn-codes.h\"\n\n"); | |
9ec36da5 | 777 | printf ("#include \"reload.h\"\n"); |
65963943 RK |
778 | printf ("extern char *insn_operand_constraint[][MAX_RECOG_OPERANDS];\n\n"); |
779 | printf ("extern rtx recog_operand[];\n"); | |
780 | printf ("#define operands emit_operand\n\n"); | |
53bfe9cd JC |
781 | printf ("#define FAIL return (end_sequence (), _val)\n"); |
782 | printf ("#define DONE return (_val = gen_sequence (), end_sequence (), _val)\n"); | |
65963943 RK |
783 | |
784 | /* Read the machine description. */ | |
785 | ||
786 | while (1) | |
787 | { | |
788 | c = read_skip_spaces (infile); | |
789 | if (c == EOF) | |
790 | break; | |
791 | ungetc (c, infile); | |
792 | ||
793 | desc = read_rtx (infile); | |
794 | if (GET_CODE (desc) == DEFINE_INSN) | |
795 | { | |
796 | gen_insn (desc); | |
797 | ++insn_code_number; | |
798 | } | |
799 | if (GET_CODE (desc) == DEFINE_EXPAND) | |
800 | { | |
801 | gen_expand (desc); | |
802 | ++insn_code_number; | |
803 | } | |
804 | if (GET_CODE (desc) == DEFINE_SPLIT) | |
805 | { | |
806 | gen_split (desc); | |
807 | ++insn_code_number; | |
808 | } | |
809 | if (GET_CODE (desc) == DEFINE_PEEPHOLE) | |
810 | { | |
811 | ++insn_code_number; | |
812 | } | |
813 | ++insn_index_number; | |
814 | } | |
815 | ||
816 | /* Write out the routine to add CLOBBERs to a pattern. */ | |
817 | output_add_clobbers (); | |
818 | ||
819 | /* Write the routine to initialize mov_optab for the EXTRA_CC_MODES. */ | |
820 | output_init_mov_optab (); | |
821 | ||
822 | fflush (stdout); | |
823 | exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE); | |
824 | /* NOTREACHED */ | |
825 | return 0; | |
826 | } |