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