]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/genconstants.c
Merge basic-improvements-branch to trunk
[thirdparty/gcc.git] / gcc / genconstants.c
CommitLineData
e23a6527 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,
6 1999, 2000, 2001 Free Software Foundation, Inc.
7
049df704 8This file is part of GCC.
e23a6527 9
049df704 10GCC is free software; you can redistribute it and/or modify
e23a6527 11it under the terms of the GNU General Public License as published by
12the Free Software Foundation; either version 2, or (at your option)
13any later version.
14
049df704 15GCC is distributed in the hope that it will be useful,
e23a6527 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
049df704 21along with GCC; see the file COPYING. If not, write to
e23a6527 22the Free Software Foundation, 59 Temple Place - Suite 330,
23Boston, MA 02111-1307, USA. */
24
25/* This program does not use gensupport.c because it does not need to
26 look at insn patterns, only (define_constants), and we want to
27 minimize dependencies. */
28
805e22b2 29#include "bconfig.h"
e23a6527 30#include "system.h"
805e22b2 31#include "coretypes.h"
32#include "tm.h"
e23a6527 33#include "rtl.h"
34#include "errors.h"
35#include "gensupport.h"
36
37static int print_md_constant PARAMS ((void **, void *));
38extern int main PARAMS ((int, char **));
39
40/* Called via traverse_md_constants; emit a #define for
41 the current constant definition. */
42
43static int
44print_md_constant (slot, info)
45 void **slot;
46 void *info;
47{
48 struct md_constant *def = *slot;
49 FILE *file = info;
50
51 fprintf (file, "#define %s %s\n", def->name, def->value);
52 return 1;
53}
54
55int
56main (argc, argv)
57 int argc;
58 char **argv;
59{
60 int dummy1, dummy2;
61 rtx desc;
62
63 progname = "genconstants";
64
65 if (argc <= 1)
cb8bacb6 66 fatal ("no input file name");
e23a6527 67
68 if (init_md_reader (argv[1]) != SUCCESS_EXIT_CODE)
69 return (FATAL_EXIT_CODE);
70
71 /* Scan and discard the entire file. This has the side effect
72 of loading up the constants table that we wish to scan. */
73 do
74 desc = read_md_rtx (&dummy1, &dummy2);
75 while (desc);
76
77 puts ("/* Generated automatically by the program `genconstants'");
78 puts (" from the machine description file `md'. */\n");
79 puts ("#ifndef GCC_INSN_CONSTANTS_H");
80 puts ("#define GCC_INSN_CONSTANTS_H\n");
81
82 traverse_md_constants (print_md_constant, stdout);
83
84 puts ("\n#endif /* GCC_INSN_CONSTANTS_H */");
85
86 if (ferror (stdout) || fflush (stdout) || fclose (stdout))
87 return FATAL_EXIT_CODE;
88
89 return SUCCESS_EXIT_CODE;
90}
91