genconstants.c revision 132718
190075Sobrien/* Generate from machine description: 290075Sobrien a series of #define statements, one for each constant named in 390075Sobrien a (define_constants ...) pattern. 490075Sobrien 5132718Skan Copyright (C) 1987, 1991, 1995, 1998, 1999, 2000, 2001, 2003 6132718Skan 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 29132718Skan#include "bconfig.h" 3090075Sobrien#include "system.h" 31132718Skan#include "coretypes.h" 32132718Skan#include "tm.h" 3390075Sobrien#include "rtl.h" 3490075Sobrien#include "errors.h" 3590075Sobrien#include "gensupport.h" 3690075Sobrien 37132718Skanstatic int print_md_constant (void **, void *); 3890075Sobrien 3990075Sobrien/* Called via traverse_md_constants; emit a #define for 4090075Sobrien the current constant definition. */ 4190075Sobrien 4290075Sobrienstatic int 43132718Skanprint_md_constant (void **slot, void *info) 4490075Sobrien{ 4590075Sobrien struct md_constant *def = *slot; 4690075Sobrien FILE *file = info; 4790075Sobrien 4890075Sobrien fprintf (file, "#define %s %s\n", def->name, def->value); 4990075Sobrien return 1; 5090075Sobrien} 5190075Sobrien 5290075Sobrienint 53132718Skanmain (int argc, char **argv) 5490075Sobrien{ 5590075Sobrien int dummy1, dummy2; 5690075Sobrien rtx desc; 5790075Sobrien 5890075Sobrien progname = "genconstants"; 5990075Sobrien 6090075Sobrien if (argc <= 1) 6190075Sobrien fatal ("no input file name"); 6290075Sobrien 6390075Sobrien if (init_md_reader (argv[1]) != SUCCESS_EXIT_CODE) 6490075Sobrien return (FATAL_EXIT_CODE); 6590075Sobrien 6690075Sobrien /* Scan and discard the entire file. This has the side effect 6790075Sobrien of loading up the constants table that we wish to scan. */ 6890075Sobrien do 6990075Sobrien desc = read_md_rtx (&dummy1, &dummy2); 7090075Sobrien while (desc); 7190075Sobrien 7290075Sobrien puts ("/* Generated automatically by the program `genconstants'"); 7390075Sobrien puts (" from the machine description file `md'. */\n"); 7490075Sobrien puts ("#ifndef GCC_INSN_CONSTANTS_H"); 7590075Sobrien puts ("#define GCC_INSN_CONSTANTS_H\n"); 7690075Sobrien 7790075Sobrien traverse_md_constants (print_md_constant, stdout); 7890075Sobrien 7990075Sobrien puts ("\n#endif /* GCC_INSN_CONSTANTS_H */"); 8090075Sobrien 8190075Sobrien if (ferror (stdout) || fflush (stdout) || fclose (stdout)) 8290075Sobrien return FATAL_EXIT_CODE; 8390075Sobrien 8490075Sobrien return SUCCESS_EXIT_CODE; 8590075Sobrien} 8690075Sobrien 87