]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/genconstants.c
backport: As described in http://gcc.gnu.org/ml/gcc/2012-08/msg00015.html...
[thirdparty/gcc.git] / gcc / genconstants.c
CommitLineData
1b0c37d7
ZW
1/* Generate from machine description:
2 a series of #define statements, one for each constant named in
3 a (define_constants ...) pattern.
4
9dcd6f09 5 Copyright (C) 1987, 1991, 1995, 1998, 1999, 2000, 2001, 2003, 2004,
d652f226 6 2007, 2010 Free Software Foundation, Inc.
1b0c37d7 7
40803cd5 8This file is part of GCC.
1b0c37d7 9
40803cd5 10GCC is free software; you can redistribute it and/or modify
1b0c37d7 11it under the terms of the GNU General Public License as published by
9dcd6f09 12the Free Software Foundation; either version 3, or (at your option)
1b0c37d7
ZW
13any later version.
14
40803cd5 15GCC is distributed in the hope that it will be useful,
1b0c37d7
ZW
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
9dcd6f09
NC
21along with GCC; see the file COPYING3. If not see
22<http://www.gnu.org/licenses/>. */
1b0c37d7
ZW
23
24/* This program does not use gensupport.c because it does not need to
25 look at insn patterns, only (define_constants), and we want to
26 minimize dependencies. */
27
4977bab6 28#include "bconfig.h"
1b0c37d7 29#include "system.h"
4977bab6 30#include "coretypes.h"
1b0c37d7 31#include "errors.h"
9f418533 32#include "read-md.h"
1b0c37d7 33
1b0c37d7
ZW
34/* Called via traverse_md_constants; emit a #define for
35 the current constant definition. */
36
37static int
24609606 38print_md_constant (void **slot, void *info ATTRIBUTE_UNUSED)
1b0c37d7 39{
28dab132 40 struct md_constant *def = (struct md_constant *) *slot;
1b0c37d7 41
24609606
RS
42 if (!def->parent_enum)
43 printf ("#define %s %s\n", def->name, def->value);
44 return 1;
45}
46
47/* Called via traverse_enums. Emit an enum definition for
48 enum_type *SLOT. */
49
50static int
51print_enum_type (void **slot, void *info ATTRIBUTE_UNUSED)
52{
53 struct enum_type *def;
54 struct enum_value *value;
55 char *value_name;
56
57 def = (struct enum_type *) *slot;
58 printf ("\nenum %s {", def->name);
59 for (value = def->values; value; value = value->next)
60 {
61 printf ("\n %s = %s", value->def->name, value->def->value);
62 if (value->next)
63 putc (',', stdout);
64 }
65 printf ("\n};\n");
66
67 /* Define NUM_<enum>_VALUES to be the largest enum value + 1. */
68 value_name = ACONCAT (("num_", def->name, "_values", NULL));
69 upcase_string (value_name);
70 printf ("#define %s %d\n", value_name, def->num_values);
71
0fe60a1b
RS
72 /* Declare the array that is generated by genenum. */
73 printf ("extern const char *const %s_strings[];\n", def->name);
74
1b0c37d7
ZW
75 return 1;
76}
77
78int
3d7aafde 79main (int argc, char **argv)
1b0c37d7 80{
1b0c37d7
ZW
81 progname = "genconstants";
82
9b68b6ea 83 if (!read_md_files (argc, argv, NULL, NULL))
1b0c37d7
ZW
84 return (FATAL_EXIT_CODE);
85
f9942f4e
ZW
86 /* Initializing the MD reader has the side effect of loading up
87 the constants table that we wish to scan. */
1b0c37d7
ZW
88
89 puts ("/* Generated automatically by the program `genconstants'");
90 puts (" from the machine description file `md'. */\n");
91 puts ("#ifndef GCC_INSN_CONSTANTS_H");
92 puts ("#define GCC_INSN_CONSTANTS_H\n");
93
24609606
RS
94 traverse_md_constants (print_md_constant, 0);
95 traverse_enum_types (print_enum_type, 0);
1b0c37d7
ZW
96
97 puts ("\n#endif /* GCC_INSN_CONSTANTS_H */");
98
99 if (ferror (stdout) || fflush (stdout) || fclose (stdout))
100 return FATAL_EXIT_CODE;
101
102 return SUCCESS_EXIT_CODE;
103}