A question on egcs prototype

H.J. Lu hjl@lucon.org
Mon Sep 22 18:14:00 GMT 1997


> 
> If you clean up the style issues and punt the other problems
> you were trying to fix with those kludges (like I asked you

Another problem is the part of my prototyping work.

The guideline of my gcc prototyping work is

1. It should cover all functions used in gcc.
2. It should need only the minimal change in gcc structure.
3. It should use the original scheme as much as possible.

In gcc, config.h should be included before "rtl.h" and "tree.h".
But some config.h may need to declare system dependent function
prototypes which, in turn, may need enum rtx_code, enum tree_code,
and maybe other enums, which are defined using those *.def files.
Those *.def are included multiple times to define various things
in a consistent manner. Through some magic, everything seems to
work so far.

When we add function prototype into config.h, we need to define
those enums first before "rtl.h" or "tree.h" included. But it
won't work with the current gcc source code since we cannot define
those enums twice: once in config.h, the other in "rtl.h", "tree.h",
or other .h file. We have to make some changes to get it to work.

The current way to define those enums is in a .h file there is

#define RTX_CODE        enum rtx_code
enum rtx_code  {
#define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS)   ENUM ,
#include "rtl.def"
#undef DEF_RTL_EXPR
LAST_AND_UNUSED_RTX_CODE};

and in the .def file, there is

DEF_RTL_EXPR(UNKNOWN, "UnKnown", "*", 'x')
DEF_RTL_EXPR...........

We only define those enum once since we only include the .h file once.

I can think of 2 ways to be able to define those enums either in
config.h or the .h file:

1. We keep the .def files unchanged and we modify the .h file such
that

#ifndef DEFINE_enum_rtx_code
#define DEFINE_enum_rtx_code
#define RTX_CODE        enum rtx_code
enum rtx_code  {
#define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS)   ENUM ,
#include "rtl.def"
#undef DEF_RTL_EXPR
LAST_AND_UNUSED_RTX_CODE};
#endif /* DEFINE_enum_rtx_code */

and we add the same code to every system dependent file which needs
enum rtx_code before rtl.h is included.

The drawback of this scheme is we have to duplicate many codes
all over the places.

2. My current scheme, which was rejected, changes the .def file into

#if !defined (NEED_enum_rtx_code) || !defined(DEFINE_enum_rtx_code)

#ifdef NEED_enum_rtx_code

#ifndef DEFINE_enum_rtx_code
#define DEFINE_enum_rtx_code
#endif

enum rtx_code
{
#define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS)   ENUM ,
#endif

DEF_RTL_EXPR(UNKNOWN, "UnKnown", "*", 'x')
DEF_RTL_EXPR...........

#ifdef NEED_enum_rtx_code
#undef DEF_RTL_EXPR
LAST_AND_UNUSED_RTX_CODE
};
#endif

In config.h or rtl.h, we just need to do

#define NEED_enum_rtx_code
#include "rtl.def"
#undef NEED_enum_rtx_code

It is much simpler where those enums need to be defined. The drawback
of this approach is the *.def file may not be everyone's likes.

Another problem with prototype and enums are RETURN and AND are used
both in rtl.def and c-parse.h for different purposes. My kludge is to
assume if RETURN or AND are defined, enum rtx_code is not really used.
To keep gcc happy, I just leave enum rtx_code empty in this case.

I am open to any reasonable suggestions. I'd like to get over with
it as soon as possible.

Thanks.


H.J.



More information about the Gcc mailing list