2013-08-02 Paolo Carlini <paolo.carlini@oracle.com>
[official-gcc.git] / gcc / gencodes.c
blob1b08dc5bb78ef1ca732b8c5223de9fc2f712d4d3
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-2013 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
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"
31 static void
32 gen_insn (rtx insn, int code)
34 const char *name = XSTR (insn, 0);
35 int truth = maybe_eval_c_test (XSTR (insn, 2));
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] != '*')
42 if (truth == 0)
43 printf ("#define CODE_FOR_%s CODE_FOR_nothing\n", name);
44 else
45 printf (" CODE_FOR_%s = %d,\n", name, code);
49 int
50 main (int argc, char **argv)
52 rtx desc;
54 progname = "gencodes";
56 /* We need to see all the possibilities. Elided insns may have
57 direct references to CODE_FOR_xxx in C code. */
58 insn_elision = 0;
60 if (!init_rtx_reader_args (argc, argv))
61 return (FATAL_EXIT_CODE);
63 puts ("\
64 /* Generated automatically by the program `gencodes'\n\
65 from the machine description file `md'. */\n\
66 \n\
67 #ifndef GCC_INSN_CODES_H\n\
68 #define GCC_INSN_CODES_H\n\
69 \n\
70 enum insn_code {\n\
71 CODE_FOR_nothing = 0,\n");
73 /* Read the machine description. */
75 while (1)
77 int line_no;
78 int insn_code_number;
80 desc = read_md_rtx (&line_no, &insn_code_number);
81 if (desc == NULL)
82 break;
84 if (GET_CODE (desc) == DEFINE_INSN || GET_CODE (desc) == DEFINE_EXPAND)
85 gen_insn (desc, insn_code_number);
88 puts (" LAST_INSN_CODE\n\
89 };\n\
90 \n\
91 #endif /* GCC_INSN_CODES_H */");
93 if (ferror (stdout) || fflush (stdout) || fclose (stdout))
94 return FATAL_EXIT_CODE;
96 return SUCCESS_EXIT_CODE;