comparison gcc/genconstants.c @ 67:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents a06113de4d67
children 04ced10e8804
comparison
equal deleted inserted replaced
65:65488c3d617d 67:f6334be47118
1 /* Generate from machine description: 1 /* Generate from machine description:
2 a series of #define statements, one for each constant named in 2 a series of #define statements, one for each constant named in
3 a (define_constants ...) pattern. 3 a (define_constants ...) pattern.
4 4
5 Copyright (C) 1987, 1991, 1995, 1998, 1999, 2000, 2001, 2003, 2004, 5 Copyright (C) 1987, 1991, 1995, 1998, 1999, 2000, 2001, 2003, 2004,
6 2007 Free Software Foundation, Inc. 6 2007, 2010 Free Software Foundation, Inc.
7 7
8 This file is part of GCC. 8 This file is part of GCC.
9 9
10 GCC is free software; you can redistribute it and/or modify 10 GCC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by 11 it under the terms of the GNU General Public License as published by
26 minimize dependencies. */ 26 minimize dependencies. */
27 27
28 #include "bconfig.h" 28 #include "bconfig.h"
29 #include "system.h" 29 #include "system.h"
30 #include "coretypes.h" 30 #include "coretypes.h"
31 #include "tm.h"
32 #include "rtl.h"
33 #include "errors.h" 31 #include "errors.h"
34 #include "gensupport.h" 32 #include "read-md.h"
35 33
36 /* Called via traverse_md_constants; emit a #define for 34 /* Called via traverse_md_constants; emit a #define for
37 the current constant definition. */ 35 the current constant definition. */
38 36
39 static int 37 static int
40 print_md_constant (void **slot, void *info) 38 print_md_constant (void **slot, void *info ATTRIBUTE_UNUSED)
41 { 39 {
42 struct md_constant *def = (struct md_constant *) *slot; 40 struct md_constant *def = (struct md_constant *) *slot;
43 FILE *file = (FILE *) info;
44 41
45 fprintf (file, "#define %s %s\n", def->name, def->value); 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
50 static int
51 print_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
72 /* Declare the array that is generated by genenum. */
73 printf ("extern const char *const %s_strings[];\n", def->name);
74
46 return 1; 75 return 1;
47 } 76 }
48 77
49 int 78 int
50 main (int argc, char **argv) 79 main (int argc, char **argv)
51 { 80 {
52 progname = "genconstants"; 81 progname = "genconstants";
53 82
54 if (init_md_reader_args (argc, argv) != SUCCESS_EXIT_CODE) 83 if (!read_md_files (argc, argv, NULL, NULL))
55 return (FATAL_EXIT_CODE); 84 return (FATAL_EXIT_CODE);
56 85
57 /* Initializing the MD reader has the side effect of loading up 86 /* Initializing the MD reader has the side effect of loading up
58 the constants table that we wish to scan. */ 87 the constants table that we wish to scan. */
59 88
60 puts ("/* Generated automatically by the program `genconstants'"); 89 puts ("/* Generated automatically by the program `genconstants'");
61 puts (" from the machine description file `md'. */\n"); 90 puts (" from the machine description file `md'. */\n");
62 puts ("#ifndef GCC_INSN_CONSTANTS_H"); 91 puts ("#ifndef GCC_INSN_CONSTANTS_H");
63 puts ("#define GCC_INSN_CONSTANTS_H\n"); 92 puts ("#define GCC_INSN_CONSTANTS_H\n");
64 93
65 traverse_md_constants (print_md_constant, stdout); 94 traverse_md_constants (print_md_constant, 0);
95 traverse_enum_types (print_enum_type, 0);
66 96
67 puts ("\n#endif /* GCC_INSN_CONSTANTS_H */"); 97 puts ("\n#endif /* GCC_INSN_CONSTANTS_H */");
68 98
69 if (ferror (stdout) || fflush (stdout) || fclose (stdout)) 99 if (ferror (stdout) || fflush (stdout) || fclose (stdout))
70 return FATAL_EXIT_CODE; 100 return FATAL_EXIT_CODE;