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]

[PATCH] Adjust -fdump-tree options


Hi,
here's a patch for the -fdump-ast switches.
1) to get some consistency I've renamed them -fdump-tree-foo
2) to get some abstraction the option flags controlling the dump detail
are now symbolic. No need to remember bit positions, just say
	-fdump-tree-optimized-address-slim
3) the documentaion is updated to reflect this, and indicate that not
all options are applicable to all dumps.

ok for mainline?

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2001-09-03  Nathan Sidwell  <nathan@codesourcery.com>

	* c-common.h (tree_dump_index): Add more comments.
	* c-dump.c (dump_files): Name flags `tree' rather than `ast'.
	(dump_option_value_info): New struct.
	(dump_options): New array.
	(dump_switch_p): Parse switch options symbolically.
	* doc/invoke.texi (-fdump-ast): Rename to ...
	(-fdump-tree): ... here. Document options are symbolic, and
	not all are applicable.

Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.82
diff -c -3 -p -r1.82 c-common.h
*** c-common.h	2001/08/24 12:07:40	1.82
--- c-common.h	2001/09/03 10:24:51
*************** extern int c_safe_from_p                
*** 844,852 ****
  
  extern int c_unsafe_for_reeval			PARAMS ((tree));
  
! /* In dump.c */
  
! /* Different tree dump places. */
  enum tree_dump_index
  {
    TDI_all,			/* dump the whole translation unit */
--- 844,853 ----
  
  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 */
*************** enum tree_dump_index
*** 858,864 ****
    TDI_end
  };
  
! /* Bit masks to control tree dumping. */
  #define TDF_ADDRESS	(1 << 0)	/* dump node addresses */
  #define TDF_SLIM	(1 << 1)	/* don't go wild following links */
  
--- 859,867 ----
    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 */
  
Index: c-dump.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-dump.c,v
retrieving revision 1.7
diff -c -3 -p -r1.7 c-dump.c
*** c-dump.c	2001/08/22 14:34:44	1.7
--- c-dump.c	2001/09/03 10:24:52
*************** struct dump_file_info
*** 795,810 ****
    int state;			/* state of play */
  };
  
! /* Table of tree dump switches.  */
  static struct dump_file_info dump_files[TDI_end] =
  {
    {".tu", "dump-translation-unit", 0, 0},
    {".class", "dump-class-hierarchy", 0, 0},
!   {".original", "dump-ast-original", 0, 0},
!   {".optimized", "dump-ast-optimized", 0, 0},
!   {".inlined", "dump-ast-inlined", 0, 0},
  };
  
  /* Begin a tree dump for PHASE. Stores any user supplied flag in
     *FLAG_PTR and returns a stream to write to. If the dump is not
     enabled, returns NULL.
--- 795,828 ----
    int state;			/* state of play */
  };
  
! /* Table of tree dump switches. This must be consistent with the
!    TREE_DUMP_INDEX enumeration in c-common.h */
  static struct dump_file_info dump_files[TDI_end] =
  {
    {".tu", "dump-translation-unit", 0, 0},
    {".class", "dump-class-hierarchy", 0, 0},
!   {".original", "dump-tree-original", 0, 0},
!   {".optimized", "dump-tree-optimized", 0, 0},
!   {".inlined", "dump-tree-inlined", 0, 0},
  };
  
+ /* Define a name->number mapping for a dump flag value. */
+ struct dump_option_value_info
+ {
+   const char *name;		/* the name of the value */
+   int value;			/* the value of the name */
+ };
+ 
+ /* Table of dump options. This must be consistent with the TDF_* flags
+    in c-common.h */
+ static const struct dump_option_value_info dump_options[] =
+ {
+   {"address", TDF_ADDRESS},
+   {"slim", TDF_SLIM},
+   {"all", ~0},
+   {NULL, 0}
+ };
+ 
  /* Begin a tree dump for PHASE. Stores any user supplied flag in
     *FLAG_PTR and returns a stream to write to. If the dump is not
     enabled, returns NULL.
*************** dump_switch_p (arg)
*** 876,888 ****
    for (ix = 0; ix != TDI_end; ix++)
      if ((option_value = skip_leading_substring (arg, dump_files[ix].swtch)))
        {
  	dump_files[ix].state = -1;
! 	if (*option_value == '-')
! 	  dump_files[ix].flags
! 	    = read_integral_parameter (option_value + 1, arg, 0);
! 	else if (*option_value)
! 	  warning ("ignoring `%s' at end of `-f%s'",
! 		   option_value, dump_files[ix].swtch);
  	
  	return 1;
        }
--- 894,931 ----
    for (ix = 0; ix != TDI_end; ix++)
      if ((option_value = skip_leading_substring (arg, dump_files[ix].swtch)))
        {
+ 	const char *ptr = option_value;
+ 	int flags = 0;
+ 	
+ 	while (*ptr)
+ 	  {
+ 	    const struct dump_option_value_info *option_ptr;
+ 	    const char *end_ptr;
+ 	    unsigned length;
+ 	    
+ 	    while (*ptr == '-')
+ 	      ptr++;
+ 	    end_ptr = strchr (ptr, '-');
+ 	    if (!end_ptr)
+ 	      end_ptr = ptr + strlen (ptr);
+ 	    length = end_ptr - ptr;
+ 	    
+ 	    for (option_ptr = dump_options; option_ptr->name;
+ 		 option_ptr++)
+ 	      if (strlen (option_ptr->name) == length
+ 		  && !memcmp (option_ptr->name, ptr, length))
+ 		{
+ 		  flags |= option_ptr->value;
+ 		  goto found;
+ 		}
+ 	    warning ("ignoring unknown option `%.*s' in `-f%s'",
+ 		     length, ptr, dump_files[ix].swtch);
+ 	  found:;
+ 	    ptr = end_ptr;
+ 	  }
+ 	
  	dump_files[ix].state = -1;
! 	dump_files[ix].flags = flags;
  	
  	return 1;
        }
Index: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.49
diff -c -3 -p -r1.49 invoke.texi
*** invoke.texi	2001/08/21 02:34:14	1.49
--- invoke.texi	2001/09/03 10:24:54
*************** in the following sections.
*** 239,246 ****
  -a  -ax  -d@var{letters}  -dumpspecs  -dumpmachine  -dumpversion @gol
  -fdump-unnumbered -fdump-translation-unit@r{[}-@var{n}@r{]} @gol
  -fdump-class-hierarchy@r{[}-@var{n}@r{]} @gol
! -fdump-ast-original@r{[}-@var{n}@r{]} -fdump-ast-optimized@r{[}-@var{n}@r{]} @gol
! -fdump-ast-inlined@r{[}-@var{n}@r{]} @gol
  -fmem-report  -fpretend-float @gol
  -fprofile-arcs  -ftest-coverage  -ftime-report @gol
  -g  -g@var{level}  -gcoff  -gdwarf  -gdwarf-1  -gdwarf-1+  -gdwarf-2 @gol
--- 239,246 ----
  -a  -ax  -d@var{letters}  -dumpspecs  -dumpmachine  -dumpversion @gol
  -fdump-unnumbered -fdump-translation-unit@r{[}-@var{n}@r{]} @gol
  -fdump-class-hierarchy@r{[}-@var{n}@r{]} @gol
! -fdump-tree-original@r{[}-@var{n}@r{]} -fdump-tree-optimized@r{[}-@var{n}@r{]} @gol
! -fdump-tree-inlined@r{[}-@var{n}@r{]} @gol
  -fmem-report  -fpretend-float @gol
  -fprofile-arcs  -ftest-coverage  -ftime-report @gol
  -g  -g@var{level}  -gcoff  -gdwarf  -gdwarf-1  -gdwarf-1+  -gdwarf-2 @gol
*************** use diff on debugging dumps for compiler
*** 2974,3012 ****
  options, in particular with and without @option{-g}.
  
  @item -fdump-translation-unit @r{(C and C++ only)}
! @itemx -fdump-translation-unit-@var{number} @r{(C and C++ only)}
  @opindex fdump-translation-unit
  Dump a representation of the tree structure for the entire translation
  unit to a file.  The file name is made by appending @file{.tu} to the
! source file name.  If the @samp{-@var{number}} form is used, @var{number}
! controls the details of the dump as described for the @option{-fdump-ast} options.
  
  @item -fdump-class-hierarchy @r{(C++ only)}
! @itemx -fdump-class-hierarchy-@var{number} @r{(C++ only)}
  @opindex fdump-class-hierarchy
  Dump a representation of each class's hierarchy and virtual function
  table layout to a file.  The file name is made by appending @file{.class}
! to the source file name.  If the @samp{-@var{number}} form is used, @var{number}
! controls the details of the dump as described for the @option{-fdump-ast}
! options.
! 
! @item -fdump-ast-@var{switch} @r{(C++ only)}
! @itemx -fdump-ast-@var{switch}-@var{number} @r{(C++ only)}
! @opindex fdump-ast
! Control the dumping at various stages of processing the abstract syntax
! tree to a file.  The file name is generated by appending a switch
! specific suffix to the source file name.  If the @samp{-@var{number}} form is
! used, @var{number} is a bit mask which controls the details of the
! dump.  The following bits are meaningful (these are not set symbolically,
! as the primary function of these dumps is for debugging gcc itself):
  
  @table @samp
! @item bit0 (1)
  Print the address of each node.  Usually this is not meaningful as it
! changes according to the environment and source file.
! @item bit1 (2)
! Inhibit dumping of members of a scope or body of a function, unless they
! are reachable by some other path.
  @end table
  
  The following tree dumps are possible:
--- 2974,3018 ----
  options, in particular with and without @option{-g}.
  
  @item -fdump-translation-unit @r{(C and C++ only)}
! @itemx -fdump-translation-unit-@var{options} @r{(C and C++ only)}
  @opindex fdump-translation-unit
  Dump a representation of the tree structure for the entire translation
  unit to a file.  The file name is made by appending @file{.tu} to the
! source file name.  If the @samp{-@var{options}} form is used, @var{options}
! controls the details of the dump as described for the
! @option{-fdump-tree} options.
  
  @item -fdump-class-hierarchy @r{(C++ only)}
! @itemx -fdump-class-hierarchy-@var{options} @r{(C++ only)}
  @opindex fdump-class-hierarchy
  Dump a representation of each class's hierarchy and virtual function
  table layout to a file.  The file name is made by appending @file{.class}
! to the source file name.  If the @samp{-@var{options}} form is used,
! @var{options} controls the details of the dump as described for the
! @option{-fdump-tree} options.
! 
! @item -fdump-tree-@var{switch} @r{(C++ only)}
! @itemx -fdump-tree-@var{switch}-@var{options} @r{(C++ only)}
! @opindex fdump-tree
! Control the dumping at various stages of processing the intermediate
! language tree to a file.  The file name is generated by appending a switch
! specific suffix to the source file name.  If the @samp{-@var{options}}
! form is used, @var{options} is a list of @samp{-} separated options that
! control the details of the dump. Not all options are applicable to all
! dumps, those which are not meaningful will be ignored. The following
! options are available
  
  @table @samp
! @item address
  Print the address of each node.  Usually this is not meaningful as it
! changes according to the environment and source file. Its primary use
! is for tying up a dump file with a debug environment.
! @item slim
! Inhibit dumping of members of a scope or body of a function merely
! because that scope has been reached. Only dump such items when they
! are directly reachable by some other path.
! @item all
! Turn on all options.
  @end table
  
  The following tree dumps are possible:

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