Makefile.in (BUILD_RTL): Move build/read-md.o to...
[gcc.git] / gcc / genconstants.c
1 /* Generate from machine description:
2 a series of #define statements, one for each constant named in
3 a (define_constants ...) pattern.
4
5 Copyright (C) 1987, 1991, 1995, 1998, 1999, 2000, 2001, 2003, 2004,
6 2007 Free Software Foundation, Inc.
7
8 This file is part of GCC.
9
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
12 the Free Software Foundation; either version 3, or (at your option)
13 any later version.
14
15 GCC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
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
28 #include "bconfig.h"
29 #include "system.h"
30 #include "coretypes.h"
31 #include "errors.h"
32 #include "read-md.h"
33
34 /* Called via traverse_md_constants; emit a #define for
35 the current constant definition. */
36
37 static int
38 print_md_constant (void **slot, void *info)
39 {
40 struct md_constant *def = (struct md_constant *) *slot;
41 FILE *file = (FILE *) info;
42
43 fprintf (file, "#define %s %s\n", def->name, def->value);
44 return 1;
45 }
46
47 int
48 main (int argc, char **argv)
49 {
50 progname = "genconstants";
51
52 if (!read_md_files (argc, argv, NULL, NULL))
53 return (FATAL_EXIT_CODE);
54
55 /* Initializing the MD reader has the side effect of loading up
56 the constants table that we wish to scan. */
57
58 puts ("/* Generated automatically by the program `genconstants'");
59 puts (" from the machine description file `md'. */\n");
60 puts ("#ifndef GCC_INSN_CONSTANTS_H");
61 puts ("#define GCC_INSN_CONSTANTS_H\n");
62
63 traverse_md_constants (print_md_constant, stdout);
64
65 puts ("\n#endif /* GCC_INSN_CONSTANTS_H */");
66
67 if (ferror (stdout) || fflush (stdout) || fclose (stdout))
68 return FATAL_EXIT_CODE;
69
70 return SUCCESS_EXIT_CODE;
71 }