1 /* Support routines for the various generation passes.
2 Copyright (C) 2000 Free Software Foundation, Inc.
4 This file is part of GNU CC.
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)
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.
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. */
26 #include "gensupport.h"
29 static struct obstack obstack;
30 struct obstack *rtl_obstack = &obstack;
32 #define obstack_chunk_alloc xmalloc
33 #define obstack_chunk_free free
35 static FILE *input_file;
37 static int sequence_num;
41 struct queue_elem *next;
44 static struct queue_elem *rtx_ready_queue;
46 static void remove_constraints PARAMS ((rtx));
47 static void process_rtx PARAMS ((rtx *));
50 message_with_line VPARAMS ((int lineno, const char *msg, ...))
52 #ifndef ANSI_PROTOTYPES
60 #ifndef ANSI_PROTOTYPES
61 lineno = va_arg (ap, int);
62 msg = va_arg (ap, const char *);
65 fprintf (stderr, "%s:%d: ", read_rtx_filename, lineno);
66 vfprintf (stderr, msg, ap);
72 /* Recursively remove constraints from an rtx. */
75 remove_constraints (part)
79 register const char *format_ptr;
84 if (GET_CODE (part) == MATCH_OPERAND)
86 else if (GET_CODE (part) == MATCH_SCRATCH)
89 format_ptr = GET_RTX_FORMAT (GET_CODE (part));
91 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (part)); i++)
92 switch (*format_ptr++)
96 remove_constraints (XEXP (part, i));
99 if (XVEC (part, i) != NULL)
100 for (j = 0; j < XVECLEN (part, i); j++)
101 remove_constraints (XVECEXP (part, i, j));
106 /* Handle any synthetic top level rtx, i.e. anything except:
114 DEFINE_ASM_ATTRIBUTES */
120 if (GET_CODE (*desc) == DEFINE_INSN_AND_SPLIT)
122 struct queue_elem* elem = xmalloc (sizeof (struct queue_elem));
123 const char *split_cond;
125 /* Create a split with values from the insn_and_split. */
126 rtx split = rtx_alloc (DEFINE_SPLIT);
127 XEXP (split, 0) = copy_rtx (XEXP (*desc, 1));
128 remove_constraints (XEXP (split, 0));
129 split_cond = XSTR (split, 1) = XSTR (*desc, 4);
131 /* If the split condition starts with "&&", append it to the
132 insn condition to create the new split condition. */
133 if (split_cond[0] == '&' && split_cond[1] == '&')
135 const char *insn_cond = XSTR (*desc, 2);
137 xmalloc (strlen (insn_cond) + strlen (split_cond) + 1);
138 strcpy (combined, insn_cond);
139 strcat (combined, split_cond);
140 XSTR (split, 1) = combined;
143 XVEC (split, 2) = XVEC (*desc, 5);
144 XSTR (split, 3) = XSTR (*desc, 6);
146 /* Fix up the DEFINE_INSN. */
147 PUT_CODE (*desc, DEFINE_INSN);
148 XVEC (*desc, 4) = XVEC (*desc, 7);
150 /* Return the DEFINE_INSN part, and put the DEFINE_SPLIT
152 elem->next = rtx_ready_queue;
154 rtx_ready_queue = elem;
158 /* The entry point for initializing the reader. */
161 init_md_reader (filename)
162 const char *filename;
164 read_rtx_filename = filename;
165 input_file = fopen (filename, "r");
169 return FATAL_EXIT_CODE;
172 obstack_init (rtl_obstack);
174 rtx_ready_queue = NULL;
176 return SUCCESS_EXIT_CODE;
180 /* The entry point for reading a single rtx from an md file. */
183 read_md_rtx (lineno, seqnr)
189 if (rtx_ready_queue != NULL)
191 desc = rtx_ready_queue->data;
192 rtx_ready_queue = rtx_ready_queue->next;
197 c = read_skip_spaces (input_file);
201 ungetc (c, input_file);
202 desc = read_rtx (input_file);
205 *lineno = read_rtx_lineno;
206 *seqnr = sequence_num;
207 switch (GET_CODE (desc))
212 case DEFINE_PEEPHOLE:
213 case DEFINE_PEEPHOLE2: