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

source code of gcc/gencodes.cc