1/* Generate check macros for tree codes.
2   Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, 2007, 2008
3   Free Software Foundation, Inc.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3.  If not see
19<http://www.gnu.org/licenses/>.  */
20
21#include "bconfig.h"
22#include "system.h"
23#include "coretypes.h"
24#include "tm.h"
25
26#define DEFTREECODE(SYM, NAME, TYPE, LEN) #SYM,
27#define END_OF_BASE_TREE_CODES
28
29static const char *const tree_codes[] = {
30#include "all-tree.def"
31(char*) 0
32};
33
34#undef DEFTREECODE
35#undef END_OF_BASE_TREE_CODES
36
37static void usage (void);
38
39static void
40usage (void)
41{
42  fputs ("Usage: gencheck\n", stderr);
43}
44
45int
46main (int argc, char ** ARG_UNUSED (argv))
47{
48  int i, j;
49
50  switch (argc)
51    {
52    case 1:
53      break;
54
55    default:
56      usage ();
57      return (1);
58    }
59
60  puts ("/* This file is generated using gencheck. Do not edit. */\n");
61  puts ("#ifndef GCC_TREE_CHECK_H");
62  puts ("#define GCC_TREE_CHECK_H\n");
63
64  /* Print macros for checks based on each of the tree code names.  However,
65     since we include the tree nodes from all languages, we must check
66     for duplicate names to avoid defining the same macro twice.  */
67  for (i = 0; tree_codes[i]; i++)
68    {
69      for (j = 0; j < i; j++)
70	if (strcmp (tree_codes[i], tree_codes[j]) == 0)
71	  break;
72
73      if (i == j)
74	printf ("#define %s_CHECK(t)\tTREE_CHECK (t, %s)\n",
75		tree_codes[i], tree_codes[i]);
76    }
77
78  puts ("\n#endif /* GCC_TREE_CHECK_H */");
79  return 0;
80}
81