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