This is the mail archive of the gcc@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]

Re: RFC: Defining and using target vectors


Quoting "Joseph S. Myers" <joseph@codesourcery.com>:

struct cumulative_args could always be defined (automatically) to contain
a union between the target structures

This assumes - every target uses a structure, and - the names of all target's structures are unambigous, and - the full definition of all the targets structures are available when the GCC component in question is compiled, and can all be included together. This would also imply that it is impossible to retrofit a target, or use a frontend that was compiled when a different set of targets was compiled in.

, so that casting to a pointer to the
union then to a pointer to one of those structures is well defined.
Though it seems more natural for struct cumulative_args to be the first
element of the target structures, and in the multi-target case to contain
a magic number that can be checked in the inline function (at least when
checking is enabled) to make sure the structure is one for the right
target.

You could do this with: typedef struct { int arch; void *p; } cumulative_args_t; or typedef struct { int arch; void *p; } *cumulative_args_t;

with regards to the conversion function, that could be provided in
target-def.h

static inline CUMULATIVE_ARGS *
get_cumulative_args (cumulative_args_t arg)
{
  gcc_assert (arg.arch == TARGET_NUM);
  return (CUMULATIVE_ARGS *) arg.p;
}

static inline cumulative_args_t
pack_cumulative_args (CUMULATIVE_ARGS *arg)
{
  cumulative_arg_t ret;
  ret.arch = TARGET_NUM;
  ret.p = (void *) arg;
  return ret;
}

Suggestions for better names etc. welcome.


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