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 for having internal macros as functions, take 2


Hi.

Here's an update on the "turn those internal macros into
functions" work.  I rewrote it, so forget the previous set of
patches.  This is more robust and catches "declaration" errors
in PROVIDE_MACRO_... marks better.

 Is this OK (to check in)?
Or is it Somewhat-ok, Mmm-let's-just-not-do-it-that-way or
Let's-forget-about-this-thing-entirely-until-macros-work-in-gdb?

I'll try to describe better with less detail up front than in
my previous patch, to help the decision process on this.

Here's how it works:

Markers are added in header files with interesting macros.  For
example:
   PROVIDE_MACRO_FUNCTION (XEXP, rtx, (rtx, int))
belonging in rtl.h, and:
   PROVIDE_MACRO_VALUE (PROP_DEATH_NOTES, int)
belonging in basic-block.h.
 The marks stay close to the macro definition, so when macros
are modified, any necessary change to the corresponding 
P_M_F/P_M_V mark is spotted right away, instead of at
compilation time.

The difference between P_M_F and P_M_V is that P_M_F takes
parameters, while P_M_V does not.

These marks are picked up by a script, which generates a C file
from a list of header files containing these marks.  For the
above examples, the generated code will look like:

   static inline rtx XEXP__macro_value PARAMS ((rtx,int));
   static inline rtx
   XEXP__macro_value (arg0, arg1)
	rtx arg0 ATTRIBUTE_UNUSED;
	int arg1 ATTRIBUTE_UNUSED;
   {
     return XEXP (arg0, arg1);
   }

   static inline int PROP_DEATH_NOTES__macro_value PARAMS ((void));
   static inline int
   PROP_DEATH_NOTES__macro_value ()
   {
     return PROP_DEATH_NOTES  ;
   }

   #undef XEXP
   extern rtx XEXP PARAMS ((rtx,int));
   rtx
   XEXP (arg0, arg1)
	 rtx arg0 ATTRIBUTE_UNUSED;
	 int arg1 ATTRIBUTE_UNUSED;
   {
     return XEXP__macro_value (arg0, arg1);
   }

   #undef PROP_DEATH_NOTES
   extern int PROP_DEATH_NOTES PARAMS ((void));
   int
   PROP_DEATH_NOTES ()
   {
     return PROP_DEATH_NOTES__macro_value ();
   }

So in gdb, we get functions to call for the marked macros, but
there are no declarations or anything seen from normal source
files - P_M_F and P_M_V are defined as empty there.

Note that when generating code as above, there's no need for
checking if
   #define FOO(a) a+42
   int (FOO) (a) int a; { return a*42; }
(i.e. parameter-macros not expanded without parameters)
is accepted by the compiler, as was proposed before.  That
construct does not work with some compilers, and macro-functions
should IMHO be accessible for all bootstrap compilers, not just
gcc.

Note that non-parameter-macros must be accessed as empty-parameter
macros.  I did not find a solution to my taste to get the values
of those macros without parenthesis or otherwise make them look
like variables.

I'll repeat what I said before: defining variables with the
corresponding names have the problem that they must generally be
updated when the variable is accessed.  I cannot think of any
other way to do that than by calling a function somewhere.  The
call could perhaps be hidden better, but that would be just too
complicated to care for.

If it's bad to see those macros as functions, we can hide it
somewhat by having the following in .gdbinit:
 define pmv
 p $()
 end

so it's accessed in gdb as:

 (gdb) p TYPE_QUAL_RESTRICT
 $8 = {int ()} 0x804ca30 <TYPE_QUAL_RESTRICT>
 (gdb) pmv
 $9 = 4

:-)


This patch contains just markers for common non-front-end
macros.  I'll send some front-end patches if this whole idea and
implementation is at all acceptable.

I worked on a side-track where the expansion of the macro was
also available in gdb, but that made the generated source and
object code relatively larger, and did not have much new value.
You normally get the information you want with M-. (find-tag).
Some figures may be in order: the object code grew (figures are
comparatively accurate, but has grown a few k since) from:
   text	   data	    bss	    dec	    hex	filename
  63033	      0	      0	  63033	   f639	xmacfuns.o
to:
  16757	      0	      0	  16757	   4175	xmacfuns.o
I can add back that code if it's actually something wanted.  It
just generated arrays and functions to lookup a function pointer
and return a string, preferably accessed through a gdb macro
("pmx").


The main caveats, some mentioned before:
* The shell script is slow even after some optimization work
  (like removing all calls to external programs from the inner
  loops); it takes just over a minute to generate xmacfuns.c.
  If this is seen as too long, I believe it'll just have to be
  rewritten in C to make it faster.

* The main drawback of turning non-parameter macros into
  functions is that when expressions are e.g. copy-pasted in gdb
  for expressions that are valid on pointers (from gdb:s view),
  it will silently look like the macro has a nonzero and
  normally large value.

* Empty (default-)definitions are generated in the *config.h
  files; see configure.in.  I hope putting it there is not a
  mortal sin.  I see no alternative.  The definitions cannot be
  put in ansidecl.h (like ATTRIBUTE_UNUSED, PROTO/PARAMS and
  friends), because gansidecl.h is not included from target-
  specific files like libgcc2.c, but machmode.h is.  
   Moving the P_M_V/P_M_F markers out of the dual-use header
  files and into its own file would solve that, but it would
  IMHO be bad to separate the macro mark from the definition.


Sat Jan  1 18:14:01 2000  Hans-Peter Nilsson  <hp@bitrange.com>

	* genmacfuns: New script to generate functions from macros.

	* configure.in (macro-functions): New enable-test.
	(for machine in $build $host $target, after machine tests): Add
	PROVIDE_MACRO_FUNCTION and PROVIDE_MACRO_VALUE to xm_defines.
	(Making the *config.h files) [for def in `eval echo '$'$define`]:
	Add support for parametrized macros.

	* config.in, cstamp-h.in, configure: Rebuilt.

	* acconfig.h (ENABLE_MACRO_DEBUGGING): New.

	* Makefile.in (USE_MACRO_DEBUGGING): New.
	(OBJS): Add xmacfuns.o.
	(STAGESTUFF): Add s-xmacfuns.
	(MACRO_FUNCTION_DEFINITION_FILES): New.
	(xmacfuns.o, xmacfuns.c, s-xmacfuns): New.

	* gengenrtl.c (genmacro): Add PROVIDE_MACRO_FUNCTION for
	generated macros.

	* basic-block.h, function.h, tree.h, regs.h, rtl.h: Add
	PROVIDE_MACRO_FUNCTION and PROVIDE_MACRO_VALUE markers.
	* machmode.h: Ditto.  Update copyright.

brgds, H-P

funmacro3.patch.gz


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