genconstants.c revision 90075
190075Sobrien/* Generate from machine description:
290075Sobrien   a series of #define statements, one for each constant named in
390075Sobrien   a (define_constants ...) pattern.
490075Sobrien
590075Sobrien   Copyright (C) 1987, 1991, 1995, 1998,
690075Sobrien   1999, 2000, 2001 Free Software Foundation, Inc.
790075Sobrien
890075SobrienThis file is part of GCC.
990075Sobrien
1090075SobrienGCC is free software; you can redistribute it and/or modify
1190075Sobrienit under the terms of the GNU General Public License as published by
1290075Sobrienthe Free Software Foundation; either version 2, or (at your option)
1390075Sobrienany later version.
1490075Sobrien
1590075SobrienGCC is distributed in the hope that it will be useful,
1690075Sobrienbut WITHOUT ANY WARRANTY; without even the implied warranty of
1790075SobrienMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1890075SobrienGNU General Public License for more details.
1990075Sobrien
2090075SobrienYou should have received a copy of the GNU General Public License
2190075Sobrienalong with GCC; see the file COPYING.  If not, write to
2290075Sobrienthe Free Software Foundation, 59 Temple Place - Suite 330,
2390075SobrienBoston, MA 02111-1307, USA.  */
2490075Sobrien
2590075Sobrien/* This program does not use gensupport.c because it does not need to
2690075Sobrien   look at insn patterns, only (define_constants), and we want to
2790075Sobrien   minimize dependencies.  */
2890075Sobrien
2990075Sobrien#include "hconfig.h"
3090075Sobrien#include "system.h"
3190075Sobrien#include "rtl.h"
3290075Sobrien#include "errors.h"
3390075Sobrien#include "gensupport.h"
3490075Sobrien
3590075Sobrienstatic int print_md_constant PARAMS ((void **, void *));
3690075Sobrienextern int main PARAMS ((int, char **));
3790075Sobrien
3890075Sobrien/* Called via traverse_md_constants; emit a #define for
3990075Sobrien   the current constant definition.  */
4090075Sobrien
4190075Sobrienstatic int
4290075Sobrienprint_md_constant (slot, info)
4390075Sobrien     void **slot;
4490075Sobrien     void *info;
4590075Sobrien{
4690075Sobrien  struct md_constant *def = *slot;
4790075Sobrien  FILE *file = info;
4890075Sobrien
4990075Sobrien  fprintf (file, "#define %s %s\n", def->name, def->value);
5090075Sobrien  return 1;
5190075Sobrien}
5290075Sobrien
5390075Sobrienint
5490075Sobrienmain (argc, argv)
5590075Sobrien     int argc;
5690075Sobrien     char **argv;
5790075Sobrien{
5890075Sobrien  int dummy1, dummy2;
5990075Sobrien  rtx desc;
6090075Sobrien
6190075Sobrien  progname = "genconstants";
6290075Sobrien
6390075Sobrien  if (argc <= 1)
6490075Sobrien    fatal ("no input file name");
6590075Sobrien
6690075Sobrien  if (init_md_reader (argv[1]) != SUCCESS_EXIT_CODE)
6790075Sobrien    return (FATAL_EXIT_CODE);
6890075Sobrien
6990075Sobrien  /* Scan and discard the entire file.  This has the side effect
7090075Sobrien     of loading up the constants table that we wish to scan.  */
7190075Sobrien  do
7290075Sobrien    desc = read_md_rtx (&dummy1, &dummy2);
7390075Sobrien  while (desc);
7490075Sobrien
7590075Sobrien  puts ("/* Generated automatically by the program `genconstants'");
7690075Sobrien  puts ("   from the machine description file `md'.  */\n");
7790075Sobrien  puts ("#ifndef GCC_INSN_CONSTANTS_H");
7890075Sobrien  puts ("#define GCC_INSN_CONSTANTS_H\n");
7990075Sobrien
8090075Sobrien  traverse_md_constants (print_md_constant, stdout);
8190075Sobrien
8290075Sobrien  puts ("\n#endif /* GCC_INSN_CONSTANTS_H */");
8390075Sobrien
8490075Sobrien  if (ferror (stdout) || fflush (stdout) || fclose (stdout))
8590075Sobrien    return FATAL_EXIT_CODE;
8690075Sobrien
8790075Sobrien  return SUCCESS_EXIT_CODE;
8890075Sobrien}
8990075Sobrien
90