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