|
|
1.1 root 1: /* Generate code from machine description to extract operands from insn as rtl.
2: Copyright (C) 1987 Free Software Foundation, Inc.
3:
4: This file is part of GNU CC.
5:
6: GNU CC is distributed in the hope that it will be useful,
7: but WITHOUT ANY WARRANTY. No author or distributor
8: accepts responsibility to anyone for the consequences of using it
9: or for whether it serves any particular purpose or works at all,
10: unless he says so in writing. Refer to the GNU CC General Public
11: License for full details.
12:
13: Everyone is granted permission to copy, modify and redistribute
14: GNU CC, but only under the conditions described in the
15: GNU CC General Public License. A copy of this license is
16: supposed to have been given to you along with GNU CC so you
17: can know your rights and responsibilities. It should be in a
18: file named COPYING. Among other things, the copyright notice
19: and this notice must be preserved on all copies. */
20:
21:
22: #include <stdio.h>
1.1.1.2 root 23: #include "config.h"
1.1 root 24: #include "rtl.h"
1.1.1.2 root 25: #include "obstack.h"
1.1 root 26:
27: struct obstack obstack;
1.1.1.2 root 28: struct obstack *rtl_obstack = &obstack;
1.1 root 29:
30: #define obstack_chunk_alloc xmalloc
31: #define obstack_chunk_free free
32: extern int xmalloc ();
33: extern void free ();
34:
1.1.1.2 root 35: void walk_rtx ();
36: void print_path ();
1.1 root 37: void fatal ();
38:
39: /* Number instruction patterns handled, starting at 0 for first one. */
40:
41: int insn_code_number;
42:
43: /* Number the occurrences of MATCH_DUP in each instruction,
44: starting at 0 for the first occurrence. */
45:
46: int dup_count;
47:
48: /* While tree-walking an instruction pattern, we keep a chain
49: of these `struct link's to record how to get down to the
1.1.1.2 root 50: current position. In each one, POS is the operand number,
51: and if the operand is a vector VEC is the element number.
52: VEC is -1 if the operand is not a vector. */
1.1 root 53:
54: struct link
55: {
56: struct link *next;
57: int pos;
1.1.1.2 root 58: int vecelt;
1.1 root 59: };
60:
61: void
62: gen_insn (insn)
63: rtx insn;
64: {
65: register int i;
66:
67: dup_count = 0;
68:
69: /* Output the function name and argument declaration. */
70: /* It would be cleaner to make `int' the return type
71: but 4.2 vax compiler doesn't accept that in the array
72: that these functions are supposed to go in. */
1.1.1.2 root 73: printf ("VOID\nextract_%d (insn)\n rtx insn;\n", insn_code_number);
1.1 root 74: printf ("{\n");
75:
76: /* Walk the insn's pattern, remembering at all times the path
77: down to the walking point. */
78:
79: if (XVECLEN (insn, 1) == 1)
80: walk_rtx (XVECEXP (insn, 1, 0), 0);
81: else
82: for (i = XVECLEN (insn, 1) - 1; i >= 0; i--)
83: {
84: struct link link;
85: link.next = 0;
1.1.1.2 root 86: link.pos = 0;
87: link.vecelt = i;
1.1 root 88: walk_rtx (XVECEXP (insn, 1, i), &link);
89: }
90: printf ("}\n\n");
91: }
92:
1.1.1.2 root 93: /* Like gen_insn but handles `define_peephole'. */
94:
95: void
96: gen_peephole (peep)
97: rtx peep;
98: {
99: /* Output the function name and argument declaration. */
100: printf ("VOID\nextract_%d (insn)\n rtx insn;\n", insn_code_number);
101: printf ("{\n");
102: /* The vector in the insn says how many operands it has.
103: And all it contains are operands. In fact, the vector was
104: created just for the sake of this function. */
105: printf ("\
106: bcopy (&XVECEXP (insn, 0, 0), recog_operand,\
107: UNITS_PER_WORD * XVECLEN (insn, 0));\n");
108: printf ("}\n\n");
109: }
110:
111: void
1.1 root 112: walk_rtx (x, path)
113: rtx x;
114: struct link *path;
115: {
1.1.1.2 root 116: register RTX_CODE code;
1.1 root 117: register int i;
118: register int len;
119: register char *fmt;
120: struct link link;
121:
1.1.1.2 root 122: if (x == 0)
123: return;
124:
125: code = GET_CODE (x);
126:
1.1 root 127: switch (code)
128: {
129: case PC:
130: case CC0:
131: case CONST_INT:
132: case SYMBOL_REF:
133: return;
134:
135: case MATCH_OPERAND:
136: printf (" recog_operand[%d] = *(recog_operand_loc[%d]\n = &",
137: XINT (x, 0), XINT (x, 0));
138: print_path (path);
139: printf (");\n");
140: break;
141:
142: case MATCH_DUP:
143: printf (" recog_dup_loc[%d] = &", dup_count);
144: print_path (path);
145: printf (";\n");
146: printf (" recog_dup_num[%d] = %d;\n", dup_count, XINT (x, 0));
147: dup_count++;
148: break;
149:
1.1.1.3 ! root 150: case MATCH_OPERATOR:
! 151: printf (" recog_operand[%d] = *(recog_operand_loc[%d]\n = &",
! 152: XINT (x, 0), XINT (x, 0));
! 153: print_path (path);
! 154: printf (");\n");
! 155: link.next = path;
! 156: link.vecelt = -1;
! 157: for (i = XVECLEN (x, 2) - 1; i >= 0; i--)
! 158: {
! 159: link.pos = i;
! 160: walk_rtx (XVECEXP (x, 2, i), &link);
! 161: }
! 162: return;
! 163:
1.1 root 164: case ADDRESS:
165: walk_rtx (XEXP (x, 0), path);
166: return;
167: }
168:
169: link.next = path;
1.1.1.2 root 170: link.vecelt = -1;
1.1 root 171: fmt = GET_RTX_FORMAT (code);
172: len = GET_RTX_LENGTH (code);
173: for (i = 0; i < len; i++)
1.1.1.2 root 174: {
175: link.pos = i;
176: if (fmt[i] == 'e' || fmt[i] == 'u')
177: {
178: walk_rtx (XEXP (x, i), &link);
179: }
180: else if (fmt[i] == 'E')
181: {
182: int j;
183: for (j = XVECLEN (x, i) - 1; j >= 0; j--)
184: {
185: link.vecelt = j;
186: walk_rtx (XVECEXP (x, i, j), &link);
187: }
188: }
189: }
1.1 root 190: }
191:
192: /* Given a PATH, representing a path down the instruction's
193: pattern from the root to a certain point, output code to
194: evaluate to the rtx at that point. */
195:
1.1.1.2 root 196: void
1.1 root 197: print_path (path)
198: struct link *path;
199: {
200: if (path == 0)
201: printf ("insn");
1.1.1.2 root 202: else if (path->vecelt >= 0)
1.1 root 203: {
204: printf ("XVECEXP (");
205: print_path (path->next);
1.1.1.2 root 206: printf (", %d, %d)", path->pos, path->vecelt);
1.1 root 207: }
208: else
209: {
210: printf ("XEXP (");
211: print_path (path->next);
212: printf (", %d)", path->pos);
213: }
214: }
215:
1.1.1.2 root 216: int
1.1 root 217: xmalloc (size)
218: {
219: register int val = malloc (size);
220:
221: if (val == 0)
1.1.1.2 root 222: fatal ("virtual memory exhausted");
1.1 root 223: return val;
224: }
225:
226: int
227: xrealloc (ptr, size)
228: char *ptr;
229: int size;
230: {
231: int result = realloc (ptr, size);
232: if (!result)
1.1.1.2 root 233: fatal ("virtual memory exhausted");
1.1 root 234: return result;
235: }
236:
237: void
238: fatal (s, a1, a2)
239: {
1.1.1.2 root 240: fprintf (stderr, "genextract: ");
1.1 root 241: fprintf (stderr, s, a1, a2);
242: fprintf (stderr, "\n");
1.1.1.2 root 243: exit (FATAL_EXIT_CODE);
1.1 root 244: }
245:
1.1.1.2 root 246: int
1.1 root 247: main (argc, argv)
248: int argc;
249: char **argv;
250: {
251: rtx desc;
252: FILE *infile;
253: extern rtx read_rtx ();
254: register int c, i;
255:
1.1.1.2 root 256: obstack_init (rtl_obstack);
1.1 root 257:
258: if (argc <= 1)
259: fatal ("No input file name.");
260:
261: infile = fopen (argv[1], "r");
262: if (infile == 0)
263: {
264: perror (argv[1]);
1.1.1.2 root 265: exit (FATAL_EXIT_CODE);
1.1 root 266: }
267:
268: init_rtl ();
269:
270: /* Assign sequential codes to all entries in the machine description
271: in parallel with the tables in insn-output.c. */
272:
273: insn_code_number = 0;
274:
275: printf ("/* Generated automatically by the program `genextract'\n\
276: from the machine description file `md'. */\n\n");
277:
1.1.1.2 root 278: printf ("#include \"config.h\"\n");
1.1 root 279: printf ("#include \"rtl.h\"\n\n");
280:
281: printf ("extern rtx recog_operand[];\n");
282: printf ("extern rtx *recog_operand_loc[];\n");
283: printf ("extern rtx *recog_dup_loc[];\n");
284: printf ("extern char recog_dup_num[];\n\n");
285:
1.1.1.2 root 286: /* The extractor functions really should return `void';
287: but old C compilers don't seem to be able to handle the array
288: definition if `void' is used. So use `int' in non-ANSI C compilers. */
289:
290: printf ("#ifdef __STDC__\n#define VOID void\n#else\n#define VOID int\n#endif\n\n");
291:
1.1 root 292: /* Read the machine description. */
293:
294: while (1)
295: {
296: c = read_skip_spaces (infile);
297: if (c == EOF)
298: break;
299: ungetc (c, infile);
300:
301: desc = read_rtx (infile);
1.1.1.2 root 302: if (GET_CODE (desc) == DEFINE_INSN)
303: {
304: gen_insn (desc);
305: ++insn_code_number;
306: }
307: if (GET_CODE (desc) == DEFINE_PEEPHOLE)
308: {
309: gen_peephole (desc);
310: ++insn_code_number;
311: }
312: if (GET_CODE (desc) == DEFINE_EXPAND)
313: {
314: printf ("VOID extract_%d () {}\n\n", insn_code_number);
315: ++insn_code_number;
316: }
1.1 root 317: }
318:
1.1.1.2 root 319: printf ("VOID (*insn_extract_fn[]) () =\n{ ");
1.1 root 320: for (i = 0; i < insn_code_number; i++)
321: {
322: if (i % 4 != 0)
323: printf (", ");
324: else if (i != 0)
325: printf (",\n ");
326: printf ("extract_%d", i);
327: }
328: printf ("\n};\n\n");
329:
330: printf ("void\ninsn_extract (insn)\n");
331: printf (" rtx insn;\n");
332: printf ("{\n if (INSN_CODE (insn) == -1) abort ();\n");
333: printf (" (*insn_extract_fn[INSN_CODE (insn)]) (PATTERN (insn));\n}\n");
1.1.1.2 root 334:
335: fflush (stdout);
336: exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
1.1 root 337: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.