1*38fd1498Szrj /* Generate from machine description:
2*38fd1498Szrj - some macros CODE_FOR_... giving the insn_code_number value
3*38fd1498Szrj for each of the defined standard insn names.
4*38fd1498Szrj Copyright (C) 1987-2018 Free Software Foundation, Inc.
5*38fd1498Szrj
6*38fd1498Szrj This file is part of GCC.
7*38fd1498Szrj
8*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
9*38fd1498Szrj the terms of the GNU General Public License as published by the Free
10*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later
11*38fd1498Szrj version.
12*38fd1498Szrj
13*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
15*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16*38fd1498Szrj for more details.
17*38fd1498Szrj
18*38fd1498Szrj You should have received a copy of the GNU General Public License
19*38fd1498Szrj along with GCC; see the file COPYING3. If not see
20*38fd1498Szrj <http://www.gnu.org/licenses/>. */
21*38fd1498Szrj
22*38fd1498Szrj
23*38fd1498Szrj #include "bconfig.h"
24*38fd1498Szrj #include "system.h"
25*38fd1498Szrj #include "coretypes.h"
26*38fd1498Szrj #include "tm.h"
27*38fd1498Szrj #include "rtl.h"
28*38fd1498Szrj #include "errors.h"
29*38fd1498Szrj #include "gensupport.h"
30*38fd1498Szrj
31*38fd1498Szrj static void
gen_insn(md_rtx_info * info)32*38fd1498Szrj gen_insn (md_rtx_info *info)
33*38fd1498Szrj {
34*38fd1498Szrj const char *name = XSTR (info->def, 0);
35*38fd1498Szrj int truth = maybe_eval_c_test (XSTR (info->def, 2));
36*38fd1498Szrj
37*38fd1498Szrj /* Don't mention instructions whose names are the null string
38*38fd1498Szrj or begin with '*'. They are in the machine description just
39*38fd1498Szrj to be recognized. */
40*38fd1498Szrj if (name[0] != 0 && name[0] != '*')
41*38fd1498Szrj {
42*38fd1498Szrj if (truth == 0)
43*38fd1498Szrj printf (",\n CODE_FOR_%s = CODE_FOR_nothing", name);
44*38fd1498Szrj else
45*38fd1498Szrj printf (",\n CODE_FOR_%s = %d", name, info->index);
46*38fd1498Szrj }
47*38fd1498Szrj }
48*38fd1498Szrj
49*38fd1498Szrj int
main(int argc,const char ** argv)50*38fd1498Szrj main (int argc, const char **argv)
51*38fd1498Szrj {
52*38fd1498Szrj progname = "gencodes";
53*38fd1498Szrj
54*38fd1498Szrj /* We need to see all the possibilities. Elided insns may have
55*38fd1498Szrj direct references to CODE_FOR_xxx in C code. */
56*38fd1498Szrj insn_elision = 0;
57*38fd1498Szrj
58*38fd1498Szrj if (!init_rtx_reader_args (argc, argv))
59*38fd1498Szrj return (FATAL_EXIT_CODE);
60*38fd1498Szrj
61*38fd1498Szrj printf ("\
62*38fd1498Szrj /* Generated automatically by the program `gencodes'\n\
63*38fd1498Szrj from the machine description file `md'. */\n\
64*38fd1498Szrj \n\
65*38fd1498Szrj #ifndef GCC_INSN_CODES_H\n\
66*38fd1498Szrj #define GCC_INSN_CODES_H\n\
67*38fd1498Szrj \n\
68*38fd1498Szrj enum insn_code {\n\
69*38fd1498Szrj CODE_FOR_nothing = 0");
70*38fd1498Szrj
71*38fd1498Szrj /* Read the machine description. */
72*38fd1498Szrj
73*38fd1498Szrj md_rtx_info info;
74*38fd1498Szrj while (read_md_rtx (&info))
75*38fd1498Szrj switch (GET_CODE (info.def))
76*38fd1498Szrj {
77*38fd1498Szrj case DEFINE_INSN:
78*38fd1498Szrj case DEFINE_EXPAND:
79*38fd1498Szrj gen_insn (&info);
80*38fd1498Szrj break;
81*38fd1498Szrj
82*38fd1498Szrj default:
83*38fd1498Szrj break;
84*38fd1498Szrj }
85*38fd1498Szrj
86*38fd1498Szrj printf ("\n};\n\
87*38fd1498Szrj \n\
88*38fd1498Szrj const unsigned int NUM_INSN_CODES = %d;\n\
89*38fd1498Szrj #endif /* GCC_INSN_CODES_H */\n", get_num_insn_codes ());
90*38fd1498Szrj
91*38fd1498Szrj if (ferror (stdout) || fflush (stdout) || fclose (stdout))
92*38fd1498Szrj return FATAL_EXIT_CODE;
93*38fd1498Szrj
94*38fd1498Szrj return SUCCESS_EXIT_CODE;
95*38fd1498Szrj }
96