|
|
1.1 root 1: /* Generate from machine description:
2:
3: - some macros CODE_FOR_... giving the insn_code_number value
4: for each of the defined standard insn names.
5: Copyright (C) 1987 Free Software Foundation, Inc.
6:
7: This file is part of GNU CC.
8:
9: GNU CC is distributed in the hope that it will be useful,
10: but WITHOUT ANY WARRANTY. No author or distributor
11: accepts responsibility to anyone for the consequences of using it
12: or for whether it serves any particular purpose or works at all,
13: unless he says so in writing. Refer to the GNU CC General Public
14: License for full details.
15:
16: Everyone is granted permission to copy, modify and redistribute
17: GNU CC, but only under the conditions described in the
18: GNU CC General Public License. A copy of this license is
19: supposed to have been given to you along with GNU CC so you
20: can know your rights and responsibilities. It should be in a
21: file named COPYING. Among other things, the copyright notice
22: and this notice must be preserved on all copies. */
23:
24:
25: #include <stdio.h>
26: #include "config.h"
27: #include "rtl.h"
28: #include "obstack.h"
29:
30: struct obstack obstack;
31: struct obstack *rtl_obstack = &obstack;
32:
33: #define obstack_chunk_alloc xmalloc
34: #define obstack_chunk_free free
35: extern int xmalloc ();
36: extern void free ();
37:
38: void fatal ();
39:
40: int insn_code_number;
41:
42: void
43: gen_insn (insn)
44: rtx insn;
45: {
46: /* Don't mention instructions whose names are the null string.
47: They are in the machine description just to be recognized. */
48: if (strlen (XSTR (insn, 0)) != 0)
49: printf (" CODE_FOR_%s = %d,\n", XSTR (insn, 0),
50: insn_code_number);
51: }
52:
53: int
54: xmalloc (size)
55: {
56: register int val = malloc (size);
57:
58: if (val == 0)
59: fatal ("virtual memory exhausted");
60: return val;
61: }
62:
63: int
64: xrealloc (ptr, size)
65: char *ptr;
66: int size;
67: {
68: int result = realloc (ptr, size);
69: if (!result)
70: fatal ("virtual memory exhausted");
71: return result;
72: }
73:
74: void
75: fatal (s, a1, a2)
76: {
77: fprintf (stderr, "gencodes: ");
78: fprintf (stderr, s, a1, a2);
79: fprintf (stderr, "\n");
80: exit (FATAL_EXIT_CODE);
81: }
82:
83: int
84: main (argc, argv)
85: int argc;
86: char **argv;
87: {
88: rtx desc;
89: FILE *infile;
90: extern rtx read_rtx ();
91: register int c;
92:
93: obstack_init (rtl_obstack);
94:
95: if (argc <= 1)
96: fatal ("No input file name.");
97:
98: infile = fopen (argv[1], "r");
99: if (infile == 0)
100: {
101: perror (argv[1]);
102: exit (FATAL_EXIT_CODE);
103: }
104:
105: init_rtl ();
106:
107: printf ("/* Generated automatically by the program `gencodes'\n\
108: from the machine description file `md'. */\n\n");
109:
110: printf ("#ifndef MAX_INSN_CODE\n\n");
111:
112: /* Read the machine description. */
113:
114: insn_code_number = 0;
115: printf ("enum insn_code {\n");
116:
117: while (1)
118: {
119: c = read_skip_spaces (infile);
120: if (c == EOF)
121: break;
122: ungetc (c, infile);
123:
124: desc = read_rtx (infile);
125: if (GET_CODE (desc) == DEFINE_INSN || GET_CODE (desc) == DEFINE_EXPAND)
126: {
127: gen_insn (desc);
128: insn_code_number++;
129: }
130: if (GET_CODE (desc) == DEFINE_PEEPHOLE)
131: {
132: insn_code_number++;
133: }
134: }
135:
136: printf (" CODE_FOR_nothing };\n");
137:
138: printf ("\n#define MAX_INSN_CODE ((int) CODE_FOR_nothing)\n");
139:
140: printf ("#endif /* MAX_INSN_CODE */\n");
141:
142: fflush (stdout);
143: exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
144: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.