xref: /dflybsd-src/contrib/gcc-4.7/gcc/genenums.c (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino /* Generate from machine description the strings for each enum.
2*e4b17023SJohn Marino    Copyright (C) 2010  Free Software Foundation, Inc.
3*e4b17023SJohn Marino 
4*e4b17023SJohn Marino This file is part of GCC.
5*e4b17023SJohn Marino 
6*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify
7*e4b17023SJohn Marino it under the terms of the GNU General Public License as published by
8*e4b17023SJohn Marino the Free Software Foundation; either version 3, or (at your option)
9*e4b17023SJohn Marino any later version.
10*e4b17023SJohn Marino 
11*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful,
12*e4b17023SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of
13*e4b17023SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*e4b17023SJohn Marino GNU General Public License for more details.
15*e4b17023SJohn Marino 
16*e4b17023SJohn Marino You should have received a copy of the GNU General Public License
17*e4b17023SJohn Marino along with GCC; see the file COPYING3.  If not see
18*e4b17023SJohn Marino <http://www.gnu.org/licenses/>.  */
19*e4b17023SJohn Marino 
20*e4b17023SJohn Marino #include "bconfig.h"
21*e4b17023SJohn Marino #include "system.h"
22*e4b17023SJohn Marino #include "coretypes.h"
23*e4b17023SJohn Marino #include "errors.h"
24*e4b17023SJohn Marino #include "read-md.h"
25*e4b17023SJohn Marino 
26*e4b17023SJohn Marino /* Called via traverse_enum_types.  Emit an enum definition for
27*e4b17023SJohn Marino    enum_type *SLOT.  */
28*e4b17023SJohn Marino 
29*e4b17023SJohn Marino static int
print_enum_type(void ** slot,void * info ATTRIBUTE_UNUSED)30*e4b17023SJohn Marino print_enum_type (void **slot, void *info ATTRIBUTE_UNUSED)
31*e4b17023SJohn Marino {
32*e4b17023SJohn Marino   struct enum_type *def;
33*e4b17023SJohn Marino   struct enum_value *value;
34*e4b17023SJohn Marino 
35*e4b17023SJohn Marino   def = (struct enum_type *) *slot;
36*e4b17023SJohn Marino   printf ("\nconst char *const %s_strings[] = {", def->name);
37*e4b17023SJohn Marino   for (value = def->values; value; value = value->next)
38*e4b17023SJohn Marino     {
39*e4b17023SJohn Marino       printf ("\n  \"%s\"", value->def->name);
40*e4b17023SJohn Marino       if (value->next)
41*e4b17023SJohn Marino 	putc (',', stdout);
42*e4b17023SJohn Marino     }
43*e4b17023SJohn Marino   printf ("\n};\n");
44*e4b17023SJohn Marino   return 1;
45*e4b17023SJohn Marino }
46*e4b17023SJohn Marino 
47*e4b17023SJohn Marino int
main(int argc,char ** argv)48*e4b17023SJohn Marino main (int argc, char **argv)
49*e4b17023SJohn Marino {
50*e4b17023SJohn Marino   progname = "genenums";
51*e4b17023SJohn Marino 
52*e4b17023SJohn Marino   if (!read_md_files (argc, argv, NULL, NULL))
53*e4b17023SJohn Marino     return (FATAL_EXIT_CODE);
54*e4b17023SJohn Marino 
55*e4b17023SJohn Marino   puts ("/* Generated automatically by the program `genenums'");
56*e4b17023SJohn Marino   puts ("   from the machine description file.  */\n");
57*e4b17023SJohn Marino   puts ("#include \"config.h\"\n");
58*e4b17023SJohn Marino   puts ("#include \"system.h\"\n");
59*e4b17023SJohn Marino   puts ("#include \"insn-constants.h\"\n");
60*e4b17023SJohn Marino 
61*e4b17023SJohn Marino   traverse_enum_types (print_enum_type, 0);
62*e4b17023SJohn Marino 
63*e4b17023SJohn Marino   if (ferror (stdout) || fflush (stdout) || fclose (stdout))
64*e4b17023SJohn Marino     return FATAL_EXIT_CODE;
65*e4b17023SJohn Marino 
66*e4b17023SJohn Marino   return SUCCESS_EXIT_CODE;
67*e4b17023SJohn Marino }
68