gencodes.c 2.51 KB
Newer Older
Tom Wood committed
1 2 3
/* Generate from machine description:
   - some macros CODE_FOR_... giving the insn_code_number value
   for each of the defined standard insn names.
Jeff Law committed
4
   Copyright (C) 1987, 1991, 1995, 1998,
5
   1999, 2000, 2001 Free Software Foundation, Inc.
Tom Wood committed
6

7
This file is part of GCC.
Tom Wood committed
8

9 10 11 12
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
Tom Wood committed
13

14 15 16 17
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.
Tom Wood committed
18 19

You should have received a copy of the GNU General Public License
20 21 22
along with GCC; see the file COPYING.  If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.  */
Tom Wood committed
23 24


25
#include "hconfig.h"
26
#include "system.h"
Tom Wood committed
27
#include "rtl.h"
Zack Weinberg committed
28
#include "errors.h"
Clinton Popetz committed
29
#include "gensupport.h"
Tom Wood committed
30

31
static void gen_insn PARAMS ((const char *, int));
32

Tom Wood committed
33
static void
34 35 36
gen_insn (name, code)
     const char *name;
     int code;
Tom Wood committed
37
{
38 39 40
  /* Don't mention instructions whose names are the null string
     or begin with '*'.  They are in the machine description just
     to be recognized.  */
41 42
  if (name[0] != 0 && name[0] != '*')
    printf ("  CODE_FOR_%s = %d,\n", name, code);
Tom Wood committed
43 44
}

45
extern int main PARAMS ((int, char **));
46

Tom Wood committed
47 48 49 50 51 52 53
int
main (argc, argv)
     int argc;
     char **argv;
{
  rtx desc;

Zack Weinberg committed
54
  progname = "gencodes";
Tom Wood committed
55 56

  if (argc <= 1)
57
    fatal ("no input file name");
Tom Wood committed
58

59
  if (init_md_reader_args (argc, argv) != SUCCESS_EXIT_CODE)
Clinton Popetz committed
60
    return (FATAL_EXIT_CODE);
Tom Wood committed
61

62 63 64 65 66 67 68 69
  puts ("\
/* Generated automatically by the program `gencodes'\n\
   from the machine description file `md'.  */\n\
\n\
#ifndef GCC_INSN_CODES_H\n\
#define GCC_INSN_CODES_H\n\
\n\
enum insn_code {");
Tom Wood committed
70 71 72 73 74

  /* Read the machine description.  */

  while (1)
    {
Clinton Popetz committed
75
      int line_no;
76
      int insn_code_number;
Clinton Popetz committed
77 78 79

      desc = read_md_rtx (&line_no, &insn_code_number);
      if (desc == NULL)
Tom Wood committed
80 81 82
	break;

      if (GET_CODE (desc) == DEFINE_INSN || GET_CODE (desc) == DEFINE_EXPAND)
83
	gen_insn (XSTR (desc, 0), insn_code_number);
Tom Wood committed
84 85
    }

86 87 88 89
  puts ("CODE_FOR_nothing\n\
};\n\
\n\
#endif /* GCC_INSN_CODES_H */");
90 91 92

  if (ferror (stdout) || fflush (stdout) || fclose (stdout))
    return FATAL_EXIT_CODE;
Tom Wood committed
93

94
  return SUCCESS_EXIT_CODE;
Tom Wood committed
95
}
96 97

/* Define this so we can link with print-rtl.o to get debug_rtx function.  */
98

99 100
const char *
get_insn_name (code)
101
     int code ATTRIBUTE_UNUSED;
102 103 104
{
  return NULL;
}