summaryrefslogtreecommitdiff
path: root/gcc/print-tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/print-tree.c')
-rw-r--r--gcc/print-tree.c172
1 files changed, 144 insertions, 28 deletions
diff --git a/gcc/print-tree.c b/gcc/print-tree.c
index e8a0c7700f8..689eeb9fe52 100644
--- a/gcc/print-tree.c
+++ b/gcc/print-tree.c
@@ -29,6 +29,7 @@ along with GCC; see the file COPYING3. If not see
#include "diagnostic.h"
#include "gimple-pretty-print.h" /* FIXME */
#include "tree-flow.h"
+#include "tree-dump.h"
#include "dumpfile.h"
/* Define the hash table of nodes already seen.
@@ -44,34 +45,6 @@ struct bucket
static struct bucket **table;
-/* Print the node NODE on standard error, for debugging.
- Most nodes referred to by this one are printed recursively
- down to a depth of six. */
-
-DEBUG_FUNCTION void
-debug_tree (tree node)
-{
- table = XCNEWVEC (struct bucket *, HASH_SIZE);
- print_node (stderr, "", node, 0);
- free (table);
- table = 0;
- putc ('\n', stderr);
-}
-
-/* Print the vector of trees VEC on standard error, for debugging.
- Most nodes referred to by this one are printed recursively
- down to a depth of six. */
-
-DEBUG_FUNCTION void
-debug_vec_tree (vec<tree, va_gc> *vec)
-{
- table = XCNEWVEC (struct bucket *, HASH_SIZE);
- print_vec_tree (stderr, "", vec, 0);
- free (table);
- table = 0;
- putc ('\n', stderr);
-}
-
/* Print PREFIX and ADDR to FILE. */
void
dump_addr (FILE *file, const char *prefix, const void *addr)
@@ -1011,3 +984,146 @@ print_vec_tree (FILE *file, const char *prefix, vec<tree, va_gc> *vec, int inden
print_node (file, temp, elt, indent + 4);
}
}
+
+
+/* Print the node NODE on standard error, for debugging.
+ Most nodes referred to by this one are printed recursively
+ down to a depth of six. */
+
+DEBUG_FUNCTION void
+debug_tree (tree node)
+{
+ table = XCNEWVEC (struct bucket *, HASH_SIZE);
+ print_node (stderr, "", node, 0);
+ free (table);
+ table = 0;
+ putc ('\n', stderr);
+}
+
+DEBUG_FUNCTION void
+debug_raw (const tree_node &ref)
+{
+ debug_tree (const_cast <tree> (&ref));
+}
+
+DEBUG_FUNCTION void
+debug_raw (const tree_node *ptr)
+{
+ if (ptr)
+ debug_raw (*ptr);
+ else
+ fprintf (stderr, "<nil>\n");
+}
+
+static void
+dump_tree_via_hooks (const tree_node *ptr, int options)
+{
+ if (DECL_P (ptr))
+ lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
+ else if (TYPE_P (ptr))
+ lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
+ else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
+ lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
+ else
+ print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
+ fprintf (stderr, "\n");
+}
+
+DEBUG_FUNCTION void
+debug (const tree_node &ref)
+{
+ dump_tree_via_hooks (&ref, 0);
+}
+
+DEBUG_FUNCTION void
+debug (const tree_node *ptr)
+{
+ if (ptr)
+ debug (*ptr);
+ else
+ fprintf (stderr, "<nil>\n");
+}
+
+DEBUG_FUNCTION void
+debug_verbose (const tree_node &ref)
+{
+ dump_tree_via_hooks (&ref, TDF_VERBOSE);
+}
+
+DEBUG_FUNCTION void
+debug_verbose (const tree_node *ptr)
+{
+ if (ptr)
+ debug_verbose (*ptr);
+ else
+ fprintf (stderr, "<nil>\n");
+}
+
+DEBUG_FUNCTION void
+debug_head (const tree_node &ref)
+{
+ debug (ref);
+}
+
+DEBUG_FUNCTION void
+debug_head (const tree_node *ptr)
+{
+ if (ptr)
+ debug_head (*ptr);
+ else
+ fprintf (stderr, "<nil>\n");
+}
+
+DEBUG_FUNCTION void
+debug_body (const tree_node &ref)
+{
+ if (TREE_CODE (&ref) == FUNCTION_DECL)
+ dump_function_to_file (const_cast <tree_node*> (&ref), stderr, 0);
+ else
+ debug (ref);
+}
+
+DEBUG_FUNCTION void
+debug_body (const tree_node *ptr)
+{
+ if (ptr)
+ debug_body (*ptr);
+ else
+ fprintf (stderr, "<nil>\n");
+}
+
+/* Print the vector of trees VEC on standard error, for debugging.
+ Most nodes referred to by this one are printed recursively
+ down to a depth of six. */
+
+DEBUG_FUNCTION void
+debug_vec_tree (vec<tree, va_gc> *vec)
+{
+ tree elt;
+ unsigned ix;
+
+ /* Print the slot this node is in, and its code, and address. */
+ fprintf (stderr, "<VEC");
+ dump_addr (stderr, " ", vec->address ());
+
+ FOR_EACH_VEC_ELT (*vec, ix, elt)
+ {
+ fprintf (stderr, "elt %d ", ix);
+ debug (elt);
+ }
+}
+
+DEBUG_FUNCTION void
+debug (vec<tree, va_gc> &ref)
+{
+ debug_vec_tree (&ref);
+}
+
+DEBUG_FUNCTION void
+debug (vec<tree, va_gc> *ptr)
+{
+ if (ptr)
+ debug (*ptr);
+ else
+ fprintf (stderr, "<nil>\n");
+}