Import final gcc2 snapshot (990109)
[official-gcc.git] / gcc / gencodes.c
blobd2f4ece469dfb664f9511a18ef48819e89048806
1 /* Generate from machine description:
2 - some macros CODE_FOR_... giving the insn_code_number value
3 for each of the defined standard insn names.
4 Copyright (C) 1987, 1991, 1995, 1998 Free Software Foundation, Inc.
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #include "hconfig.h"
25 #include "system.h"
26 #include "rtl.h"
27 #include "obstack.h"
29 static struct obstack obstack;
30 struct obstack *rtl_obstack = &obstack;
32 #define obstack_chunk_alloc xmalloc
33 #define obstack_chunk_free free
36 char *xmalloc ();
38 #ifdef HAVE_VPRINTF
39 void fatal PVPROTO((char *, ...));
40 #else
41 /* We must not provide any prototype here, even if ANSI C. */
42 void fatal PROTO(());
43 #endif
45 void fancy_abort ();
47 static int insn_code_number;
49 static void
50 gen_insn (insn)
51 rtx insn;
53 /* Don't mention instructions whose names are the null string
54 or begin with '*'. They are in the machine description just
55 to be recognized. */
56 if (XSTR (insn, 0)[0] != 0 && XSTR (insn, 0)[0] != '*')
57 printf (" CODE_FOR_%s = %d,\n", XSTR (insn, 0),
58 insn_code_number);
61 char *
62 xmalloc (size)
63 unsigned size;
65 register char *val = (char *) malloc (size);
67 if (val == 0)
68 fatal ("virtual memory exhausted");
69 return val;
72 char *
73 xrealloc (ptr, size)
74 char *ptr;
75 unsigned size;
77 char *result = (char *) realloc (ptr, size);
78 if (!result)
79 fatal ("virtual memory exhausted");
80 return result;
83 #ifdef HAVE_VPRINTF
84 void
85 fatal VPROTO((char *s, ...))
87 #ifndef ANSI_PROTOTYPES
88 char *s;
89 #endif
90 va_list ap;
92 VA_START (ap, s);
94 #ifndef ANSI_PROTOTYPES
95 s = va_arg (ap, char *);
96 #endif
98 fprintf (stderr, "gencodes: ");
99 vfprintf (stderr, s, ap);
100 va_end (ap);
101 fprintf (stderr, "\n");
102 exit (FATAL_EXIT_CODE);
104 #else /* not HAVE_VPRINTF */
106 void
107 fatal (s, a1, a2)
108 char *s;
110 fprintf (stderr, "gencodes: ");
111 fprintf (stderr, s, a1, a2);
112 fprintf (stderr, "\n");
113 exit (FATAL_EXIT_CODE);
115 #endif /* not HAVE_VPRINTF */
117 /* More 'friendly' abort that prints the line and file.
118 config.h can #define abort fancy_abort if you like that sort of thing. */
120 void
121 fancy_abort ()
123 fatal ("Internal gcc abort.");
127 main (argc, argv)
128 int argc;
129 char **argv;
131 rtx desc;
132 FILE *infile;
133 register int c;
135 obstack_init (rtl_obstack);
137 if (argc <= 1)
138 fatal ("No input file name.");
140 infile = fopen (argv[1], "r");
141 if (infile == 0)
143 perror (argv[1]);
144 exit (FATAL_EXIT_CODE);
147 init_rtl ();
149 printf ("/* Generated automatically by the program `gencodes'\n\
150 from the machine description file `md'. */\n\n");
152 printf ("#ifndef MAX_INSN_CODE\n\n");
154 /* Read the machine description. */
156 insn_code_number = 0;
157 printf ("enum insn_code {\n");
159 while (1)
161 c = read_skip_spaces (infile);
162 if (c == EOF)
163 break;
164 ungetc (c, infile);
166 desc = read_rtx (infile);
167 if (GET_CODE (desc) == DEFINE_INSN || GET_CODE (desc) == DEFINE_EXPAND)
169 gen_insn (desc);
170 insn_code_number++;
172 if (GET_CODE (desc) == DEFINE_PEEPHOLE
173 || GET_CODE (desc) == DEFINE_SPLIT)
175 insn_code_number++;
179 printf (" CODE_FOR_nothing };\n");
181 printf ("\n#define MAX_INSN_CODE ((int) CODE_FOR_nothing)\n");
183 printf ("#endif /* MAX_INSN_CODE */\n");
185 fflush (stdout);
186 exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
187 /* NOTREACHED */
188 return 0;