[PATCH] AmigaOS 4 port contribution

Marcus Comstedt marcus@mc.pp.se
Sun Oct 5 18:59:00 GMT 2003


kenner@vlsi1.ultra.nyu.edu (Richard Kenner) writes:

> We put blanks before open parens, just as one example.

Yes, I know.  I've tried to remember this, but maybe I forgot it in
some places.  I'll go through the patch and check this.  Thanks.


>     Well, the code is portable, it's just that since the attribute is only
>     defined on AmigaOS it seems a bit silly to do the check for it on all
>     targets.  
> 
>     The thing has to be done in the front end though, since the extra
>     argument has to be included when doing check_function_arguments().  Of
>     course, I can move the actual code to the backend and make a call from
>     the front end, but that somehow seems like a layering violation.
> 
> It may be or it may not be.  It depends on exactly what the code is doing.

Ok, what it does is this:  If a function pointer which is a member of
a struct and which has the attribute "libcall" is called, then a
pointer to the struct is sent as an implicit extra argument.  That is,
given the declaration

   struct my_interface {
      void (*func)(struct my_interface *, int x, int y) __attribute__((libcall));
   };

and a call

   i->func(17, 42);

then actually

   i->func(i, 17, 42);

is called.  The idea is of course that you export the interface of
some "object" through a struct which also has some instance data that
the code needs, and when you call the functions they get a reference
to this instance data without you having to specify the variable
holding the pointer to the interface twice.  The AmigaOS system
libraries use this kind of interfaces heavily, but they can be found
elsewhere too, such as in the JNI as I mentioned.  There you have the
JNIEnv struct which contains a bunch of function pointers, some
private instance data, and all the functions take the pointer to the
JNIEnv as the first argument.  In order to exploit the attribute for
JNI you'd have to add it to the function pointers declared in jni.h of
course, which might be a bit impractical.

Anyway, this is exactly what the code is doing:  It checks if the
called function has the libcall attribute, and is a member of a
struct.  In that case it prepends a pointer to that struct to the
argument list.

So what do you think?  The functionality "add an extra argument to the
argument list" is of course completely portable, but the usefulness of
the attribute is somewhat limited on non-AmigaOS systems since you
don't have a large set of libraries using it already.  So that's why I
decided to minimize the impact on other targets with an #ifdef.

If I were to move the code to the backend, I would probably define
some DECORATE_FUNCTION_PARAMETERS macro, which is defined as unity in
defaults.h, and which build_function_call passes params though before
calling convert_arguments.  But I'm open to further suggestions of
course.


  // Marcus





More information about the Gcc-patches mailing list