]>
Commit | Line | Data |
---|---|---|
41299f41 | 1 | /* Generate from machine description: |
41299f41 TW |
2 | - some macros CODE_FOR_... giving the insn_code_number value |
3 | for each of the defined standard insn names. | |
34627ce6 | 4 | Copyright (C) 1987, 1991, 1995, 1998, 1999 Free Software Foundation, Inc. |
41299f41 TW |
5 | |
6 | This file is part of GNU CC. | |
7 | ||
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. | |
12 | ||
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. | |
17 | ||
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 | |
a35311b0 RK |
20 | the Free Software Foundation, 59 Temple Place - Suite 330, |
21 | Boston, MA 02111-1307, USA. */ | |
41299f41 TW |
22 | |
23 | ||
0d64891c | 24 | #include "hconfig.h" |
0b93b64e | 25 | #include "system.h" |
41299f41 TW |
26 | #include "rtl.h" |
27 | #include "obstack.h" | |
f8b6598e | 28 | #include "errors.h" |
41299f41 TW |
29 | |
30 | static struct obstack obstack; | |
31 | struct obstack *rtl_obstack = &obstack; | |
32 | ||
33 | #define obstack_chunk_alloc xmalloc | |
34 | #define obstack_chunk_free free | |
35 | ||
41299f41 TW |
36 | static int insn_code_number; |
37 | ||
56c0e996 BS |
38 | static void gen_insn PROTO((rtx)); |
39 | ||
41299f41 TW |
40 | static void |
41 | gen_insn (insn) | |
42 | rtx insn; | |
43 | { | |
6b6ca844 RK |
44 | /* Don't mention instructions whose names are the null string |
45 | or begin with '*'. They are in the machine description just | |
46 | to be recognized. */ | |
47 | if (XSTR (insn, 0)[0] != 0 && XSTR (insn, 0)[0] != '*') | |
41299f41 TW |
48 | printf (" CODE_FOR_%s = %d,\n", XSTR (insn, 0), |
49 | insn_code_number); | |
50 | } | |
51 | ||
2778b98d | 52 | PTR |
41299f41 | 53 | xmalloc (size) |
2778b98d | 54 | size_t size; |
41299f41 | 55 | { |
2778b98d | 56 | register PTR val = (PTR) malloc (size); |
41299f41 TW |
57 | |
58 | if (val == 0) | |
59 | fatal ("virtual memory exhausted"); | |
60 | return val; | |
61 | } | |
62 | ||
2778b98d | 63 | PTR |
470b68c0 RH |
64 | xrealloc (old, size) |
65 | PTR old; | |
2778b98d | 66 | size_t size; |
41299f41 | 67 | { |
470b68c0 | 68 | register PTR ptr; |
09d83d25 | 69 | if (old) |
470b68c0 RH |
70 | ptr = (PTR) realloc (old, size); |
71 | else | |
72 | ptr = (PTR) malloc (size); | |
73 | if (!ptr) | |
41299f41 | 74 | fatal ("virtual memory exhausted"); |
470b68c0 | 75 | return ptr; |
41299f41 TW |
76 | } |
77 | ||
41299f41 TW |
78 | int |
79 | main (argc, argv) | |
80 | int argc; | |
81 | char **argv; | |
82 | { | |
83 | rtx desc; | |
84 | FILE *infile; | |
41299f41 TW |
85 | register int c; |
86 | ||
f8b6598e | 87 | progname = "gencodes"; |
41299f41 TW |
88 | obstack_init (rtl_obstack); |
89 | ||
90 | if (argc <= 1) | |
91 | fatal ("No input file name."); | |
92 | ||
93 | infile = fopen (argv[1], "r"); | |
94 | if (infile == 0) | |
95 | { | |
96 | perror (argv[1]); | |
97 | exit (FATAL_EXIT_CODE); | |
98 | } | |
99 | ||
41299f41 TW |
100 | printf ("/* Generated automatically by the program `gencodes'\n\ |
101 | from the machine description file `md'. */\n\n"); | |
102 | ||
103 | printf ("#ifndef MAX_INSN_CODE\n\n"); | |
104 | ||
105 | /* Read the machine description. */ | |
106 | ||
107 | insn_code_number = 0; | |
108 | printf ("enum insn_code {\n"); | |
109 | ||
110 | while (1) | |
111 | { | |
112 | c = read_skip_spaces (infile); | |
113 | if (c == EOF) | |
114 | break; | |
115 | ungetc (c, infile); | |
116 | ||
117 | desc = read_rtx (infile); | |
118 | if (GET_CODE (desc) == DEFINE_INSN || GET_CODE (desc) == DEFINE_EXPAND) | |
119 | { | |
120 | gen_insn (desc); | |
121 | insn_code_number++; | |
122 | } | |
123 | if (GET_CODE (desc) == DEFINE_PEEPHOLE | |
ede7cd44 | 124 | || GET_CODE (desc) == DEFINE_PEEPHOLE2 |
41299f41 TW |
125 | || GET_CODE (desc) == DEFINE_SPLIT) |
126 | { | |
127 | insn_code_number++; | |
128 | } | |
129 | } | |
130 | ||
131 | printf (" CODE_FOR_nothing };\n"); | |
132 | ||
133 | printf ("\n#define MAX_INSN_CODE ((int) CODE_FOR_nothing)\n"); | |
134 | ||
135 | printf ("#endif /* MAX_INSN_CODE */\n"); | |
136 | ||
137 | fflush (stdout); | |
138 | exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE); | |
139 | /* NOTREACHED */ | |
140 | return 0; | |
141 | } | |
a995e389 RH |
142 | |
143 | /* Define this so we can link with print-rtl.o to get debug_rtx function. */ | |
144 | const char * | |
145 | get_insn_name (code) | |
146 | int code; | |
147 | { | |
148 | return NULL; | |
149 | } |