genattr-common.c 2.52 KB
Newer Older
Joseph Myers committed
1 2 3
/* Generate attribute information shared between driver and core
   compilers (insn-attr-common.h) from machine description.  Split out
   of genattr.c.
4
   Copyright (C) 1991-2016 Free Software Foundation, Inc.
Joseph Myers committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

This file is part of GCC.

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 3, or (at your option) any later
version.

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.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */


#include "bconfig.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "rtl.h"
#include "errors.h"
#include "read-md.h"
#include "gensupport.h"

32 33 34 35
static void
write_upcase (const char *str)
{
  for (; *str; str++)
36
    putchar (TOUPPER (*str));
37 38 39
}

static void
40
gen_attr (md_rtx_info *info)
41 42 43
{
  const char *p, *tag;

44
  rtx attr = info->def;
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
  p = XSTR (attr, 1);
  if (*p != '\0')
    {
      printf ("enum attr_%s {", XSTR (attr, 0));

      while ((tag = scan_comma_elt (&p)) != 0)
	{
	  write_upcase (XSTR (attr, 0));
	  putchar ('_');
	  while (tag != p)
	    putchar (TOUPPER (*tag++));
	  if (*p == ',')
	    fputs (", ", stdout);
	}
      fputs ("};\n", stdout);
    }
}

Joseph Myers committed
63
int
64
main (int argc, const char **argv)
Joseph Myers committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
{
  bool have_delay = false;
  bool have_sched = false;

  progname = "genattr-common";

  if (!init_rtx_reader_args (argc, argv))
    return (FATAL_EXIT_CODE);

  puts ("/* Generated automatically by the program `genattr-common'");
  puts ("   from the machine description file `md'.  */\n");
  puts ("#ifndef GCC_INSN_ATTR_COMMON_H");
  puts ("#define GCC_INSN_ATTR_COMMON_H\n");

  /* Read the machine description.  */

81 82 83 84 85 86 87
  md_rtx_info info;
  while (read_md_rtx (&info))
    switch (GET_CODE (info.def))
      {
      case DEFINE_ATTR:
	gen_attr (&info);
	break;
Joseph Myers committed
88

89
      case DEFINE_DELAY:
90
	have_delay = true;
Joseph Myers committed
91 92
	break;

93 94 95 96 97 98 99
      case DEFINE_INSN_RESERVATION:
	if (!have_sched)
	  {
	    printf ("#define INSN_SCHEDULING\n");
	    have_sched = true;
	  }
	break;
100

101 102 103
      default:
	break;
      }
104 105

	    printf ("#define DELAY_SLOTS %d\n", have_delay);
Joseph Myers committed
106 107 108 109 110 111 112
  puts ("\n#endif /* GCC_INSN_ATTR_COMMON_H */");

  if (ferror (stdout) || fflush (stdout) || fclose (stdout))
    return FATAL_EXIT_CODE;

  return SUCCESS_EXIT_CODE;
}