This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Generalize tree-dumping infrastructure


This patch generalizes the tree-dump code so that it can be used from 
non-C front ends. With this, I have successfully linked and used 
-fdump-translation-unit from gcj, though it needs a bit more work on the 
Java side before it is really useful.

BTW Should we rename c-dump.{c,h} to tree-dump.{c,h} ?

regards

Bryce


2001-11-20  Bryce McKinlay  <bryce@waitaki.otago.ac.nz>

	* c-dump.c: Include c-tree.h, not c-common.h.
	(lang_type_quals): Declare.
	(dequeue_and_dump): Use lang_type_quals function if set to retrieve
	language-specific qualifiers for a type node.
	* c-common.h (C_TYPE_QUALS): Removed.
	Move declarations for c-dump.c to...
	* tree.h: ... here. Also declare dump_tree_fn lang_dump_tree.
	* Makefile.in: Move c-dump.o to language-independent back-end.

cp:
2001-11-20  Bryce McKinlay  <bryce@waitaki.otago.ac.nz>

	* cp-tree.h (CP_TYPE_QUALS): Don't use C_TYPE_QUALS.
	* decl.c (cxx_init_decl_processing): Set lang_type_quals.


Index: c-dump.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-dump.c,v
retrieving revision 1.11
diff -u -r1.11 c-dump.c
--- c-dump.c	2001/10/29 23:01:44	1.11
+++ c-dump.c	2001/11/20 03:10:22
@@ -22,7 +22,7 @@
 #include "config.h"
 #include "system.h"
 #include "tree.h"
-#include "c-common.h"
+#include "c-tree.h"
 #include "splay-tree.h"
 #include "diagnostic.h"
 #include "toplev.h"
@@ -34,6 +34,11 @@
 
 dump_tree_fn lang_dump_tree;
 
+/* A callback function defined by front-ends to determine type qualifiers
+   in a language-specific way.  */
+
+type_quals_fn lang_type_quals;
+
 static unsigned int queue PARAMS ((dump_info_p, tree, int));
 static void dump_index PARAMS ((dump_info_p, unsigned int));
 static void dequeue_and_dump PARAMS ((dump_info_p));
@@ -374,7 +379,12 @@
   else if (code_class == 't')
     {
       /* All types have qualifiers.  */
-      int quals = C_TYPE_QUALS (t);
+      int quals;
+      if (lang_type_quals)
+        quals = (*lang_type_quals) (t);
+      else
+        quals = TYPE_QUALS (t);
+      
       if (quals != TYPE_UNQUALIFIED)
 	{
 	  fprintf (di->stream, "qual: %c%c%c     ",
@@ -796,7 +806,7 @@
 };
 
 /* Table of tree dump switches. This must be consistent with the
-   TREE_DUMP_INDEX enumeration in c-common.h */
+   TREE_DUMP_INDEX enumeration in tree.h */
 static struct dump_file_info dump_files[TDI_end] =
 {
   {".tu", "dump-translation-unit", 0, 0},
@@ -814,7 +824,7 @@
 };
 
 /* Table of dump options. This must be consistent with the TDF_* flags
-   in c-common.h */
+   in tree.h */
 static const struct dump_option_value_info dump_options[] =
 {
   {"address", TDF_ADDRESS},
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.286
diff -u -r1.286 tree.h
--- tree.h	2001/11/19 20:38:03	1.286
+++ tree.h	2001/11/20 03:10:22
@@ -3059,6 +3059,52 @@
 
 typedef tree (*walk_tree_fn)		PARAMS ((tree *, int *, void *));
 
+/* In c-dump.c */
+
+/* Different tree dump places.  When you add new tree dump places,
+   extend the DUMP_FILES array in c-dump.c */
+enum tree_dump_index
+{
+  TDI_all,			/* dump the whole translation unit */
+  TDI_class,			/* dump class hierarchy */
+  TDI_original,			/* dump each function before optimizing it */
+  TDI_optimized,		/* dump each function after optimizing it */
+  TDI_inlined,			/* dump each function after inlining
+				   within it.  */
+  TDI_end
+};
+
+/* Bit masks to control tree dumping. Not all values are applicable to
+   all tree dumps. Add new ones at the end. When you define new
+   values, extend the DUMP_OPTIONS array in c-dump.c */
+#define TDF_ADDRESS	(1 << 0)	/* dump node addresses */
+#define TDF_SLIM	(1 << 1)	/* don't go wild following links */
+
+typedef struct dump_info *dump_info_p;
+
+/* A callback function used dump language-specific parts of tree
+   nodes.  Returns non-zero if it does not want the usual dumping of
+   the second argument.  */
+
+typedef int (*dump_tree_fn) PARAMS ((dump_info_p, tree));
+
+extern dump_tree_fn lang_dump_tree;
+
+/* A callback function defined by front-ends to evaluate type qualifiers
+   in a language-specific way.  */
+
+typedef int (*type_quals_fn) PARAMS ((tree));
+
+extern type_quals_fn lang_type_quals;
+
+extern int dump_flag			PARAMS ((dump_info_p, int, tree));
+extern int dump_enabled_p		PARAMS ((enum tree_dump_index));
+extern FILE *dump_begin			PARAMS ((enum tree_dump_index, int *));
+extern void dump_end			PARAMS ((enum tree_dump_index, FILE *));
+extern void dump_node			PARAMS ((tree, int, FILE *));
+extern int dump_switch_p                PARAMS ((const char *));
+extern const char *dump_flag_name	PARAMS ((enum tree_dump_index));
+
 
 /* Redefine abort to report an internal error w/o coredump, and
    reporting the location of the error in the source file.  This logic
Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.98
diff -u -r1.98 c-common.h
--- c-common.h	2001/11/18 11:04:40	1.98
+++ c-common.h	2001/11/20 03:10:22
@@ -457,14 +457,6 @@
 #define C_TYPE_FUNCTION_P(type) \
   (TREE_CODE (type) == FUNCTION_TYPE)
 
-/* Return the qualifiers that apply to this type.  In C++, that means
-   descending through array types.  Note that this macro evaluates its
-   arguments more than once.  */
-#define C_TYPE_QUALS(TYPE)				\
-  (TYPE_QUALS ((TREE_CODE (TYPE) == ARRAY_TYPE		\
-		&& c_language == clk_cplusplus)		\
-	       ? strip_array_types (TYPE) : TYPE))
-
 /* For convenience we define a single macro to identify the class of
    object or incomplete types.  */
 #define C_TYPE_OBJECT_OR_INCOMPLETE_P(type) \
@@ -818,45 +810,6 @@
 #endif
 
 extern int c_unsafe_for_reeval			PARAMS ((tree));
-
-/* In c-dump.c */
-
-/* Different tree dump places.  When you add new tree dump places,
-   extend the DUMP_FILES array in c-dump.c */
-enum tree_dump_index
-{
-  TDI_all,			/* dump the whole translation unit */
-  TDI_class,			/* dump class hierarchy */
-  TDI_original,			/* dump each function before optimizing it */
-  TDI_optimized,		/* dump each function after optimizing it */
-  TDI_inlined,			/* dump each function after inlining
-				   within it.  */
-  TDI_end
-};
-
-/* Bit masks to control tree dumping. Not all values are applicable to
-   all tree dumps. Add new ones at the end. When you define new
-   values, extend the DUMP_OPTIONS array in c-dump.c */
-#define TDF_ADDRESS	(1 << 0)	/* dump node addresses */
-#define TDF_SLIM	(1 << 1)	/* don't go wild following links */
-
-typedef struct dump_info *dump_info_p;
-
-/* A callback function used dump language-specific parts of tree
-   nodes.  Returns non-zero if it does not want the usual dumping of
-   the second argument.  */
-
-typedef int (*dump_tree_fn) PARAMS ((dump_info_p, tree));
-
-extern dump_tree_fn lang_dump_tree;
-
-extern int dump_flag			PARAMS ((dump_info_p, int, tree));
-extern int dump_enabled_p		PARAMS ((enum tree_dump_index));
-extern FILE *dump_begin			PARAMS ((enum tree_dump_index, int *));
-extern void dump_end			PARAMS ((enum tree_dump_index, FILE *));
-extern void dump_node			PARAMS ((tree, int, FILE *));
-extern int dump_switch_p                PARAMS ((const char *));
-extern const char *dump_flag_name	PARAMS ((enum tree_dump_index));
 
 /* Information recorded about each file examined during compilation.  */
 
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.786
diff -u -r1.786 Makefile.in
--- Makefile.in	2001/11/19 20:55:13	1.786
+++ Makefile.in	2001/11/20 03:10:23
@@ -723,7 +723,7 @@
 
 # Language-specific object files for C and Objective C.
 C_AND_OBJC_OBJS = attribs.o c-errors.o c-lex.o c-pragma.o c-decl.o c-typeck.o \
-  c-convert.o c-aux-info.o c-common.o c-format.o c-semantics.o c-dump.o \
+  c-convert.o c-aux-info.o c-common.o c-format.o c-semantics.o \
   libcpp.a $(C_TARGET_OBJS)
 
 # Language-specific object files for C.
@@ -733,20 +733,21 @@
 
 OBJS = alias.o bb-reorder.o bitmap.o builtins.o caller-save.o calls.o	\
  cfg.o cfganal.o cfgbuild.o cfgcleanup.o cfgloop.o cfgrtl.o combine.o	\
- conflict.o convert.o cse.o cselib.o dbxout.o debug.o dependence.o df.o	\
- diagnostic.o doloop.o dominance.o dwarf2asm.o dwarf2out.o dwarfout.o	\
- emit-rtl.o except.o explow.o expmed.o expr.o final.o flow.o 		\
- fold-const.o function.o gcse.o genrtl.o ggc-common.o global.o graph.o	\
- haifa-sched.o hash.o hashtable.o ifcvt.o insn-attrtab.o insn-emit.o	\
- insn-extract.o insn-opinit.o insn-output.o insn-peep.o insn-recog.o	\
- integrate.o intl.o jump.o  langhooks.o lcm.o lists.o local-alloc.o 	\
- loop.o mbchar.o optabs.o params.o predict.o print-rtl.o print-tree.o	\
- profile.o real.o recog.o reg-stack.o regclass.o regmove.o regrename.o	\
- reload.o reload1.o reorg.o resource.o rtl.o rtlanal.o rtl-error.o	\
- sbitmap.o sched-deps.o sched-ebb.o sched-rgn.o sched-vis.o sdbout.o	\
- sibcall.o simplify-rtx.o splay-tree.o ssa.o ssa-ccp.o ssa-dce.o stmt.o	\
- stor-layout.o stringpool.o timevar.o toplev.o tree.o tree-inline.o 	\
- unroll.o varasm.o varray.o version.o xcoffout.o cfglayout.o		\
+ conflict.o convert.o cse.o cselib.o c-dump.o dbxout.o debug.o 		\
+ dependence.o df.o diagnostic.o doloop.o dominance.o dwarf2asm.o 	\
+ dwarf2out.o dwarfout.o emit-rtl.o except.o explow.o expmed.o expr.o 	\
+ final.o flow.o fold-const.o function.o gcse.o genrtl.o ggc-common.o 	\
+ global.o graph.o haifa-sched.o hash.o hashtable.o ifcvt.o 		\
+ insn-attrtab.o insn-emit.o insn-extract.o insn-opinit.o insn-output.o 	\
+ insn-peep.o insn-recog.o integrate.o intl.o jump.o  langhooks.o lcm.o 	\
+ lists.o local-alloc.o loop.o mbchar.o optabs.o params.o predict.o 	\
+ print-rtl.o print-tree.o profile.o real.o recog.o reg-stack.o 		\
+ regclass.o regmove.o regrename.o reload.o reload1.o reorg.o resource.o \
+ rtl.o rtlanal.o rtl-error.o sbitmap.o sched-deps.o sched-ebb.o 	\
+ sched-rgn.o sched-vis.o sdbout.o sibcall.o simplify-rtx.o splay-tree.o \
+ ssa.o ssa-ccp.o ssa-dce.o stmt.o stor-layout.o stringpool.o timevar.o	\
+ toplev.o tree.o tree-inline.o unroll.o varasm.o varray.o version.o	\
+ xcoffout.o cfglayout.o							\
  $(GGC) $(out_object_file) $(EXTRA_OBJS)
 
 BACKEND = main.o libbackend.a
@@ -1264,10 +1265,6 @@
 	c-lex.h flags.h toplev.h output.h c-pragma.h $(RTL_H) $(GGC_H) \
 	$(EXPR_H)
 
-c-dump.o: c-dump.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(C_TREE_H) \
-	c-lex.h flags.h toplev.h output.h c-pragma.h $(RTL_H) $(GGC_H) \
-	$(EXPR_H) $(SPLAY_TREE_H) c-dump.h
-
 # Language-independent files.
 
 DRIVER_DEFINES = \
@@ -1315,6 +1312,10 @@
 dumpvers: dumpvers.c
 
 version.o: version.c version.h
+
+c-dump.o: c-dump.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(RTL_H) $(C_TREE_H) \
+	flags.h toplev.h c-pragma.h $(GGC_H) $(EXPR_H) $(SPLAY_TREE_H) \
+	c-dump.h
 
 ggc-common.o: ggc-common.c $(CONFIG_H) $(SYSTEM_H) $(RTL_H) $(TREE_H) \
 	flags.h $(GGC_H) varray.h hash.h $(HASHTAB_H) $(TM_P_H)
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.655
diff -u -r1.655 cp-tree.h
--- cp-tree.h	2001/11/16 19:17:32	1.655
+++ cp-tree.h	2001/11/20 03:10:24
@@ -1130,7 +1130,7 @@
 
 /* The type qualifiers for this type, including the qualifiers on the
    elements for an array type.  */
-#define CP_TYPE_QUALS(NODE) C_TYPE_QUALS (NODE)
+#define CP_TYPE_QUALS(NODE) (TYPE_QUALS (strip_array_types (NODE)))
 
 /* Nonzero if this type is const-qualified.  */
 #define CP_TYPE_CONST_P(NODE)				\
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.827
diff -u -r1.827 decl.c
--- decl.c	2001/11/18 06:31:18	1.827
+++ decl.c	2001/11/20 03:10:26
@@ -6409,6 +6409,7 @@
   mark_lang_status = &mark_cp_function_context;
   lang_safe_from_p = &c_safe_from_p;
   lang_dump_tree = &cp_dump_tree;
+  lang_type_quals = &cp_type_quals;
   lang_missing_noreturn_ok_p = &cp_missing_noreturn_ok_p;
 
   cp_parse_init ();

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]