[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: small C++ API additions



On Wed, 2017-03-29 at 17:10 -0400, Joseph Jevnik wrote:
> Hello all,
> 
> I have been playing around with the C++ wrapper for gccjit and have
> noticed a
> few things missing from the C API. I have written up four small
> patches to add
> the missing features.
> new-function-ptr-type.patch: Adds a method on 'context' to create a
> new function
> pointer type.
> 
> new-union-type.patch: Adds a method on 'context' for creating a new
> union
> type. This also adds a 'union_' class like 'struct_' which subclasses
> 'type'.
> 
> set_fields.patch: Adds a method to 'struct_' for setting the fields
> of an opaque
> struct type. The C++ wrapper already allowed creation of opaque
> structs but
> didn't have a way to populate them for creating recusive structures
> like linked
> lists.
> 
> operator-call.patch: Adds a variadic dispatch for
> 'function::operator()' when
> compiling with C++11 support. This extends 'function(a, b, c, ...)
> for arbitrary
> amounts of arguments without needing to create a vector to pass the
> arguments
> in. Right now this just dispatches through the vector case but could
> be changed
> to use a 'std::array<rvalue, sizeof...(Args)>' in the future. This is
> mostly
> just to simplify the API for fixed arity calls which have a lot of
> arguments.

Thanks!

BTW, a nit: isn't the official value of __cplusplus for C++11 201103L,
hence:

#if __cplusplus >= 201103L

rather than:

#if __cplusplus >= 201100L

for the parameter packs?

I wonder if we need to generalize the C++ test suite so that it tests
the API for various different versions of the C++ standard.

> Currently all of these patches are missing tests. I found the C tests
> but didn't
> see anything for the C++ API. I would love to add some cases for
> these but I
> just don't know where to look.

Have a look at gcc/testsuite/jit.dg/*.cc

You can run individual test cases via (e.g.):

  make check-jit RUNTESTFLAGS="-v -v jit.exp=test-quadratic.cc"

(see https://dmalcolm.fedorapeople.org/gcc/newbies-guide/working-with-t
he-testsuite.html )

> This is my first time posting to any of the GCC mailing lists or
> working on GCC
> at all so please let me know if this is not the correct place to post
> this or if
> I have done something incorrectly.

This is the correct mailing list, and an excellent start; thanks.

Note that currently we're deep in feature freeze for gcc 7.  That said,
the C++ API to libgccjit is explicitly called out as having less
stability guarantees than the rest of the project, so we may be able to
violate that feature freeze.

Please can you add tests and documentation and post the updated patches
as separate emails (it's easier to deal with that way).

For sufficiently large contributions, you need to either file a
copyright assignment to the FSF, or to make a copyright disclaimer. 
 See the instructions here:
  https://gcc.gnu.org/contribute.html#legal
I'm not sure exactly what the threshold is for a contribution to be
called "large", but I suspect that you've reached that threshold
(especially after tests and docs are added to the patches).

> Thank you for your time!

Thanks again
Dave