]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/gensupport.c
gcc.c: Fix comment formatting.
[thirdparty/gcc.git] / gcc / gensupport.c
1 /* Support routines for the various generation passes.
2 Copyright (C) 2000, 2001 Free Software Foundation, Inc.
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
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 #include "hconfig.h"
22 #include "system.h"
23 #include "rtl.h"
24 #include "obstack.h"
25 #include "errors.h"
26 #include "gensupport.h"
27
28
29 static struct obstack obstack;
30 struct obstack *rtl_obstack = &obstack;
31
32 #define obstack_chunk_alloc xmalloc
33 #define obstack_chunk_free free
34
35 static int sequence_num;
36 static int errors;
37
38 static int predicable_default;
39 static const char *predicable_true;
40 static const char *predicable_false;
41
42 /* We initially queue all patterns, process the define_insn and
43 define_cond_exec patterns, then return them one at a time. */
44
45 struct queue_elem
46 {
47 rtx data;
48 int lineno;
49 struct queue_elem *next;
50 };
51
52 static struct queue_elem *define_attr_queue;
53 static struct queue_elem **define_attr_tail = &define_attr_queue;
54 static struct queue_elem *define_insn_queue;
55 static struct queue_elem **define_insn_tail = &define_insn_queue;
56 static struct queue_elem *define_cond_exec_queue;
57 static struct queue_elem **define_cond_exec_tail = &define_cond_exec_queue;
58 static struct queue_elem *other_queue;
59 static struct queue_elem **other_tail = &other_queue;
60
61 static void queue_pattern PARAMS ((rtx, struct queue_elem ***, int));
62 static void remove_constraints PARAMS ((rtx));
63 static void process_rtx PARAMS ((rtx, int));
64
65 static int is_predicable PARAMS ((struct queue_elem *));
66 static void identify_predicable_attribute PARAMS ((void));
67 static int n_alternatives PARAMS ((const char *));
68 static void collect_insn_data PARAMS ((rtx, int *, int *));
69 static rtx alter_predicate_for_insn PARAMS ((rtx, int, int, int));
70 static const char *alter_test_for_insn PARAMS ((struct queue_elem *,
71 struct queue_elem *));
72 static char *shift_output_template PARAMS ((char *, const char *, int));
73 static const char *alter_output_for_insn PARAMS ((struct queue_elem *,
74 struct queue_elem *,
75 int, int));
76 static void process_one_cond_exec PARAMS ((struct queue_elem *));
77 static void process_define_cond_exec PARAMS ((void));
78 \f
79 void
80 message_with_line VPARAMS ((int lineno, const char *msg, ...))
81 {
82 #ifndef ANSI_PROTOTYPES
83 int lineno;
84 const char *msg;
85 #endif
86 va_list ap;
87
88 VA_START (ap, msg);
89
90 #ifndef ANSI_PROTOTYPES
91 lineno = va_arg (ap, int);
92 msg = va_arg (ap, const char *);
93 #endif
94
95 fprintf (stderr, "%s:%d: ", read_rtx_filename, lineno);
96 vfprintf (stderr, msg, ap);
97 fputc ('\n', stderr);
98
99 va_end (ap);
100 }
101 \f
102 /* Queue PATTERN on LIST_TAIL. */
103
104 static void
105 queue_pattern (pattern, list_tail, lineno)
106 rtx pattern;
107 struct queue_elem ***list_tail;
108 int lineno;
109 {
110 struct queue_elem *e = (struct queue_elem *) xmalloc (sizeof (*e));
111 e->data = pattern;
112 e->lineno = lineno;
113 e->next = NULL;
114 **list_tail = e;
115 *list_tail = &e->next;
116 }
117
118 /* Recursively remove constraints from an rtx. */
119
120 static void
121 remove_constraints (part)
122 rtx part;
123 {
124 register int i, j;
125 register const char *format_ptr;
126
127 if (part == 0)
128 return;
129
130 if (GET_CODE (part) == MATCH_OPERAND)
131 XSTR (part, 2) = "";
132 else if (GET_CODE (part) == MATCH_SCRATCH)
133 XSTR (part, 1) = "";
134
135 format_ptr = GET_RTX_FORMAT (GET_CODE (part));
136
137 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (part)); i++)
138 switch (*format_ptr++)
139 {
140 case 'e':
141 case 'u':
142 remove_constraints (XEXP (part, i));
143 break;
144 case 'E':
145 if (XVEC (part, i) != NULL)
146 for (j = 0; j < XVECLEN (part, i); j++)
147 remove_constraints (XVECEXP (part, i, j));
148 break;
149 }
150 }
151
152 /* Process a top level rtx in some way, queueing as appropriate. */
153
154 static void
155 process_rtx (desc, lineno)
156 rtx desc;
157 int lineno;
158 {
159 switch (GET_CODE (desc))
160 {
161 case DEFINE_INSN:
162 queue_pattern (desc, &define_insn_tail, lineno);
163 break;
164
165 case DEFINE_COND_EXEC:
166 queue_pattern (desc, &define_cond_exec_tail, lineno);
167 break;
168
169 case DEFINE_ATTR:
170 queue_pattern (desc, &define_attr_tail, lineno);
171 break;
172
173 case DEFINE_INSN_AND_SPLIT:
174 {
175 const char *split_cond;
176 rtx split;
177 rtvec attr;
178 int i;
179
180 /* Create a split with values from the insn_and_split. */
181 split = rtx_alloc (DEFINE_SPLIT);
182
183 i = XVECLEN (desc, 1);
184 XVEC (split, 0) = rtvec_alloc (i);
185 while (--i >= 0)
186 {
187 XVECEXP (split, 0, i) = copy_rtx (XVECEXP (desc, 1, i));
188 remove_constraints (XVECEXP (split, 0, i));
189 }
190
191 /* If the split condition starts with "&&", append it to the
192 insn condition to create the new split condition. */
193 split_cond = XSTR (desc, 4);
194 if (split_cond[0] == '&' && split_cond[1] == '&')
195 {
196 const char *insn_cond = XSTR (desc, 2);
197 size_t insn_cond_len = strlen (insn_cond);
198 size_t split_cond_len = strlen (split_cond);
199 char *combined;
200
201 combined = (char *) xmalloc (insn_cond_len + split_cond_len + 1);
202 memcpy (combined, insn_cond, insn_cond_len);
203 memcpy (combined + insn_cond_len, split_cond, split_cond_len + 1);
204
205 split_cond = combined;
206 }
207 XSTR (split, 1) = split_cond;
208 XVEC (split, 2) = XVEC (desc, 5);
209 XSTR (split, 3) = XSTR (desc, 6);
210
211 /* Fix up the DEFINE_INSN. */
212 attr = XVEC (desc, 7);
213 PUT_CODE (desc, DEFINE_INSN);
214 XVEC (desc, 4) = attr;
215
216 /* Queue them. */
217 queue_pattern (desc, &define_insn_tail, lineno);
218 queue_pattern (split, &other_tail, lineno);
219 break;
220 }
221
222 default:
223 queue_pattern (desc, &other_tail, lineno);
224 break;
225 }
226 }
227 \f
228 /* Return true if attribute PREDICABLE is true for ELEM, which holds
229 a DEFINE_INSN. */
230
231 static int
232 is_predicable (elem)
233 struct queue_elem *elem;
234 {
235 rtvec vec = XVEC (elem->data, 4);
236 const char *value;
237 int i;
238
239 if (! vec)
240 return predicable_default;
241
242 for (i = GET_NUM_ELEM (vec) - 1; i >= 0; --i)
243 {
244 rtx sub = RTVEC_ELT (vec, i);
245 switch (GET_CODE (sub))
246 {
247 case SET_ATTR:
248 if (strcmp (XSTR (sub, 0), "predicable") == 0)
249 {
250 value = XSTR (sub, 1);
251 goto found;
252 }
253 break;
254
255 case SET_ATTR_ALTERNATIVE:
256 if (strcmp (XSTR (sub, 0), "predicable") == 0)
257 {
258 message_with_line (elem->lineno,
259 "multiple alternatives for `predicable'");
260 errors = 1;
261 return 0;
262 }
263 break;
264
265 case SET:
266 if (GET_CODE (SET_DEST (sub)) != ATTR
267 || strcmp (XSTR (SET_DEST (sub), 0), "predicable") != 0)
268 break;
269 sub = SET_SRC (sub);
270 if (GET_CODE (sub) == CONST_STRING)
271 {
272 value = XSTR (sub, 0);
273 goto found;
274 }
275
276 /* ??? It would be possible to handle this if we really tried.
277 It's not easy though, and I'm not going to bother until it
278 really proves necessary. */
279 message_with_line (elem->lineno,
280 "non-constant value for `predicable'");
281 errors = 1;
282 return 0;
283
284 default:
285 abort ();
286 }
287 }
288
289 return predicable_default;
290
291 found:
292 /* Verify that predicability does not vary on the alternative. */
293 /* ??? It should be possible to handle this by simply eliminating
294 the non-predicable alternatives from the insn. FRV would like
295 to do this. Delay this until we've got the basics solid. */
296 if (strchr (value, ',') != NULL)
297 {
298 message_with_line (elem->lineno,
299 "multiple alternatives for `predicable'");
300 errors = 1;
301 return 0;
302 }
303
304 /* Find out which value we're looking at. */
305 if (strcmp (value, predicable_true) == 0)
306 return 1;
307 if (strcmp (value, predicable_false) == 0)
308 return 0;
309
310 message_with_line (elem->lineno,
311 "Unknown value `%s' for `predicable' attribute",
312 value);
313 errors = 1;
314 return 0;
315 }
316
317 /* Examine the attribute "predicable"; discover its boolean values
318 and its default. */
319
320 static void
321 identify_predicable_attribute ()
322 {
323 struct queue_elem *elem;
324 char *p_true, *p_false;
325 const char *value;
326 size_t len;
327
328 /* Look for the DEFINE_ATTR for `predicable', which must exist. */
329 for (elem = define_attr_queue; elem ; elem = elem->next)
330 if (strcmp (XSTR (elem->data, 0), "predicable") == 0)
331 goto found;
332
333 message_with_line (define_cond_exec_queue->lineno,
334 "Attribute `predicable' not defined");
335 errors = 1;
336 return;
337
338 found:
339 value = XSTR (elem->data, 1);
340 len = strlen (value);
341 p_false = (char *) xmalloc (len + 1);
342 memcpy (p_false, value, len + 1);
343
344 p_true = strchr (p_false, ',');
345 if (p_true == NULL || strchr (++p_true, ',') != NULL)
346 {
347 message_with_line (elem->lineno,
348 "Attribute `predicable' is not a boolean");
349 errors = 1;
350 return;
351 }
352 p_true[-1] = '\0';
353
354 predicable_true = p_true;
355 predicable_false = p_false;
356
357 switch (GET_CODE (XEXP (elem->data, 2)))
358 {
359 case CONST_STRING:
360 value = XSTR (XEXP (elem->data, 2), 0);
361 break;
362
363 case CONST:
364 message_with_line (elem->lineno,
365 "Attribute `predicable' cannot be const");
366 errors = 1;
367 return;
368
369 default:
370 message_with_line (elem->lineno,
371 "Attribute `predicable' must have a constant default");
372 errors = 1;
373 return;
374 }
375
376 if (strcmp (value, p_true) == 0)
377 predicable_default = 1;
378 else if (strcmp (value, p_false) == 0)
379 predicable_default = 0;
380 else
381 {
382 message_with_line (elem->lineno,
383 "Unknown value `%s' for `predicable' attribute",
384 value);
385 errors = 1;
386 }
387 }
388
389 /* Return the number of alternatives in constraint S. */
390
391 static int
392 n_alternatives (s)
393 const char *s;
394 {
395 int n = 1;
396
397 if (s)
398 while (*s)
399 n += (*s++ == ',');
400
401 return n;
402 }
403
404 /* Determine how many alternatives there are in INSN, and how many
405 operands. */
406
407 static void
408 collect_insn_data (pattern, palt, pmax)
409 rtx pattern;
410 int *palt, *pmax;
411 {
412 const char *fmt;
413 enum rtx_code code;
414 int i, j, len;
415
416 code = GET_CODE (pattern);
417 switch (code)
418 {
419 case MATCH_OPERAND:
420 i = n_alternatives (XSTR (pattern, 2));
421 *palt = (i > *palt ? i : *palt);
422 /* FALLTHRU */
423
424 case MATCH_OPERATOR:
425 case MATCH_SCRATCH:
426 case MATCH_PARALLEL:
427 case MATCH_INSN:
428 i = XINT (pattern, 0);
429 if (i > *pmax)
430 *pmax = i;
431 break;
432
433 default:
434 break;
435 }
436
437 fmt = GET_RTX_FORMAT (code);
438 len = GET_RTX_LENGTH (code);
439 for (i = 0; i < len; i++)
440 {
441 switch (fmt[i])
442 {
443 case 'e': case 'u':
444 collect_insn_data (XEXP (pattern, i), palt, pmax);
445 break;
446
447 case 'V':
448 if (XVEC (pattern, i) == NULL)
449 break;
450 /* FALLTHRU */
451 case 'E':
452 for (j = XVECLEN (pattern, i) - 1; j >= 0; --j)
453 collect_insn_data (XVECEXP (pattern, i, j), palt, pmax);
454 break;
455
456 case 'i': case 'w': case '0': case 's': case 'S': case 'T':
457 break;
458
459 default:
460 abort ();
461 }
462 }
463 }
464
465 static rtx
466 alter_predicate_for_insn (pattern, alt, max_op, lineno)
467 rtx pattern;
468 int alt, max_op, lineno;
469 {
470 const char *fmt;
471 enum rtx_code code;
472 int i, j, len;
473
474 code = GET_CODE (pattern);
475 switch (code)
476 {
477 case MATCH_OPERAND:
478 {
479 const char *c = XSTR (pattern, 2);
480
481 if (n_alternatives (c) != 1)
482 {
483 message_with_line (lineno,
484 "Too many alternatives for operand %d",
485 XINT (pattern, 0));
486 errors = 1;
487 return NULL;
488 }
489
490 /* Replicate C as needed to fill out ALT alternatives. */
491 if (c && *c && alt > 1)
492 {
493 size_t c_len = strlen (c);
494 size_t len = alt * (c_len + 1);
495 char *new_c = (char *) xmalloc (len);
496
497 memcpy (new_c, c, c_len);
498 for (i = 1; i < alt; ++i)
499 {
500 new_c[i * (c_len + 1) - 1] = ',';
501 memcpy (&new_c[i * (c_len + 1)], c, c_len);
502 }
503 new_c[len - 1] = '\0';
504 XSTR (pattern, 2) = new_c;
505 }
506 }
507 /* FALLTHRU */
508
509 case MATCH_OPERATOR:
510 case MATCH_SCRATCH:
511 case MATCH_PARALLEL:
512 case MATCH_INSN:
513 XINT (pattern, 0) += max_op;
514 break;
515
516 default:
517 break;
518 }
519
520 fmt = GET_RTX_FORMAT (code);
521 len = GET_RTX_LENGTH (code);
522 for (i = 0; i < len; i++)
523 {
524 rtx r;
525
526 switch (fmt[i])
527 {
528 case 'e': case 'u':
529 r = alter_predicate_for_insn (XEXP (pattern, i), alt,
530 max_op, lineno);
531 if (r == NULL)
532 return r;
533 break;
534
535 case 'E':
536 for (j = XVECLEN (pattern, i) - 1; j >= 0; --j)
537 {
538 r = alter_predicate_for_insn (XVECEXP (pattern, i, j),
539 alt, max_op, lineno);
540 if (r == NULL)
541 return r;
542 }
543 break;
544
545 case 'i': case 'w': case '0': case 's':
546 break;
547
548 default:
549 abort ();
550 }
551 }
552
553 return pattern;
554 }
555
556 static const char *
557 alter_test_for_insn (ce_elem, insn_elem)
558 struct queue_elem *ce_elem, *insn_elem;
559 {
560 const char *ce_test, *insn_test;
561 char *new_test;
562 size_t len, ce_len, insn_len;
563
564 ce_test = XSTR (ce_elem->data, 1);
565 insn_test = XSTR (insn_elem->data, 2);
566 if (!ce_test || *ce_test == '\0')
567 return insn_test;
568 if (!insn_test || *insn_test == '\0')
569 return ce_test;
570
571 ce_len = strlen (ce_test);
572 insn_len = strlen (insn_test);
573 len = 1 + ce_len + 1 + 4 + 1 + insn_len + 1 + 1;
574 new_test = (char *) xmalloc (len);
575
576 sprintf (new_test, "(%s) && (%s)", ce_test, insn_test);
577
578 return new_test;
579 }
580
581 /* Adjust all of the operand numbers in OLD to match the shift they'll
582 get from an operand displacement of DISP. Return a pointer after the
583 adjusted string. */
584
585 static char *
586 shift_output_template (new, old, disp)
587 char *new;
588 const char *old;
589 int disp;
590 {
591 while (*old)
592 {
593 char c = *old++;
594 *new++ = c;
595 if (c == '%')
596 {
597 c = *old++;
598 if (ISDIGIT ((unsigned char) c))
599 c += disp;
600 else if (ISUPPER ((unsigned char) c)
601 || ISLOWER ((unsigned char) c))
602 {
603 *new++ = c;
604 c = *old++ + disp;
605 }
606 *new++ = c;
607 }
608 }
609
610 return new;
611 }
612
613 static const char *
614 alter_output_for_insn (ce_elem, insn_elem, alt, max_op)
615 struct queue_elem *ce_elem, *insn_elem;
616 int alt, max_op;
617 {
618 const char *ce_out, *insn_out;
619 char *new, *p;
620 size_t len, ce_len, insn_len;
621
622 /* ??? Could coordinate with genoutput to not duplicate code here. */
623
624 ce_out = XSTR (ce_elem->data, 2);
625 insn_out = XTMPL (insn_elem->data, 3);
626 if (!ce_out || *ce_out == '\0')
627 return insn_out;
628
629 ce_len = strlen (ce_out);
630 insn_len = strlen (insn_out);
631
632 if (*insn_out == '*')
633 /* You must take care of the predicate yourself. */
634 return insn_out;
635
636 if (*insn_out == '@')
637 {
638 len = (ce_len + 1) * alt + insn_len + 1;
639 p = new = xmalloc (len);
640
641 do
642 {
643 do
644 *p++ = *insn_out++;
645 while (ISSPACE ((unsigned char) *insn_out));
646
647 if (*insn_out != '#')
648 {
649 p = shift_output_template (p, ce_out, max_op);
650 *p++ = ' ';
651 }
652
653 do
654 *p++ = *insn_out++;
655 while (*insn_out && *insn_out != '\n');
656 }
657 while (*insn_out);
658 *p = '\0';
659 }
660 else
661 {
662 len = ce_len + 1 + insn_len + 1;
663 new = xmalloc (len);
664
665 p = shift_output_template (new, ce_out, max_op);
666 *p++ = ' ';
667 memcpy (p, insn_out, insn_len + 1);
668 }
669
670 return new;
671 }
672
673 /* Replicate insns as appropriate for the given DEFINE_COND_EXEC. */
674
675 static void
676 process_one_cond_exec (ce_elem)
677 struct queue_elem *ce_elem;
678 {
679 struct queue_elem *insn_elem;
680 for (insn_elem = define_insn_queue; insn_elem ; insn_elem = insn_elem->next)
681 {
682 int alternatives, max_operand;
683 rtx pred, insn, pattern;
684
685 if (! is_predicable (insn_elem))
686 continue;
687
688 alternatives = 1;
689 max_operand = -1;
690 collect_insn_data (insn_elem->data, &alternatives, &max_operand);
691 max_operand += 1;
692
693 if (XVECLEN (ce_elem->data, 0) != 1)
694 {
695 message_with_line (ce_elem->lineno,
696 "too many patterns in predicate");
697 errors = 1;
698 return;
699 }
700
701 pred = copy_rtx (XVECEXP (ce_elem->data, 0, 0));
702 pred = alter_predicate_for_insn (pred, alternatives, max_operand,
703 ce_elem->lineno);
704 if (pred == NULL)
705 return;
706
707 /* Construct a new pattern for the new insn. */
708 insn = copy_rtx (insn_elem->data);
709 XSTR (insn, 0) = "";
710 pattern = rtx_alloc (COND_EXEC);
711 XEXP (pattern, 0) = pred;
712 if (XVECLEN (insn, 1) == 1)
713 {
714 XEXP (pattern, 1) = XVECEXP (insn, 1, 0);
715 XVECEXP (insn, 1, 0) = pattern;
716 PUT_NUM_ELEM (XVEC (insn, 1), 1);
717 }
718 else
719 {
720 XEXP (pattern, 1) = rtx_alloc (PARALLEL);
721 XVEC (XEXP (pattern, 1), 0) = XVEC (insn, 1);
722 XVEC (insn, 1) = rtvec_alloc (1);
723 XVECEXP (insn, 1, 0) = pattern;
724 }
725
726 XSTR (insn, 2) = alter_test_for_insn (ce_elem, insn_elem);
727 XTMPL (insn, 3) = alter_output_for_insn (ce_elem, insn_elem,
728 alternatives, max_operand);
729
730 /* ??? Set `predicable' to false. Not crucial since it's really
731 only used here, and we won't reprocess this new pattern. */
732
733 /* Put the new pattern on the `other' list so that it
734 (a) is not reprocessed by other define_cond_exec patterns
735 (b) appears after all normal define_insn patterns.
736
737 ??? B is debatable. If one has normal insns that match
738 cond_exec patterns, they will be preferred over these
739 generated patterns. Whether this matters in practice, or if
740 it's a good thing, or whether we should thread these new
741 patterns into the define_insn chain just after their generator
742 is something we'll have to experiment with. */
743
744 queue_pattern (insn, &other_tail, insn_elem->lineno);
745 }
746 }
747
748 /* If we have any DEFINE_COND_EXEC patterns, expand the DEFINE_INSN
749 patterns appropriately. */
750
751 static void
752 process_define_cond_exec ()
753 {
754 struct queue_elem *elem;
755
756 identify_predicable_attribute ();
757 if (errors)
758 return;
759
760 for (elem = define_cond_exec_queue; elem ; elem = elem->next)
761 process_one_cond_exec (elem);
762 }
763 \f
764 /* The entry point for initializing the reader. */
765
766 int
767 init_md_reader (filename)
768 const char *filename;
769 {
770 FILE *input_file;
771 int c;
772
773 read_rtx_filename = filename;
774 input_file = fopen (filename, "r");
775 if (input_file == 0)
776 {
777 perror (filename);
778 return FATAL_EXIT_CODE;
779 }
780
781 obstack_init (rtl_obstack);
782 errors = 0;
783 sequence_num = 0;
784
785 /* Read the entire file. */
786 while (1)
787 {
788 rtx desc;
789 int lineno;
790
791 c = read_skip_spaces (input_file);
792 if (c == EOF)
793 break;
794
795 ungetc (c, input_file);
796 lineno = read_rtx_lineno;
797 desc = read_rtx (input_file);
798 process_rtx (desc, lineno);
799 }
800 fclose (input_file);
801
802 /* Process define_cond_exec patterns. */
803 if (define_cond_exec_queue != NULL)
804 process_define_cond_exec ();
805
806 return errors ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE;
807 }
808
809 /* The entry point for reading a single rtx from an md file. */
810
811 rtx
812 read_md_rtx (lineno, seqnr)
813 int *lineno;
814 int *seqnr;
815 {
816 struct queue_elem **queue, *elem;
817 rtx desc;
818
819 /* Read all patterns from a given queue before moving on to the next. */
820 if (define_attr_queue != NULL)
821 queue = &define_attr_queue;
822 else if (define_insn_queue != NULL)
823 queue = &define_insn_queue;
824 else if (other_queue != NULL)
825 queue = &other_queue;
826 else
827 return NULL_RTX;
828
829 elem = *queue;
830 *queue = elem->next;
831 desc = elem->data;
832 *lineno = elem->lineno;
833 *seqnr = sequence_num;
834
835 free (elem);
836
837 switch (GET_CODE (desc))
838 {
839 case DEFINE_INSN:
840 case DEFINE_EXPAND:
841 case DEFINE_SPLIT:
842 case DEFINE_PEEPHOLE:
843 case DEFINE_PEEPHOLE2:
844 sequence_num++;
845 break;
846
847 default:
848 break;
849 }
850
851 return desc;
852 }
853
854 /* Until we can use the versions in libiberty. */
855 char *
856 xstrdup (input)
857 const char *input;
858 {
859 register size_t len = strlen (input) + 1;
860 register char *output = xmalloc (len);
861 memcpy (output, input, len);
862 return output;
863 }
864
865 PTR
866 xcalloc (nelem, elsize)
867 size_t nelem, elsize;
868 {
869 PTR newmem;
870
871 if (nelem == 0 || elsize == 0)
872 nelem = elsize = 1;
873
874 newmem = really_call_calloc (nelem, elsize);
875 if (!newmem)
876 fatal ("virtual memory exhausted");
877 return (newmem);
878 }
879
880 PTR
881 xrealloc (old, size)
882 PTR old;
883 size_t size;
884 {
885 register PTR ptr;
886 if (old)
887 ptr = (PTR) really_call_realloc (old, size);
888 else
889 ptr = (PTR) really_call_malloc (size);
890 if (!ptr)
891 fatal ("virtual memory exhausted");
892 return ptr;
893 }
894
895 PTR
896 xmalloc (size)
897 size_t size;
898 {
899 register PTR val = (PTR) really_call_malloc (size);
900
901 if (val == 0)
902 fatal ("virtual memory exhausted");
903 return val;
904 }