Function pointer handling

Bartosz Szreder bartosz.szreder@huuugegames.com
Sun Jan 1 00:00:00 GMT 2017


Hello David,

>> 1. The documentation doesn't mention existence of
>> gcc_jit_context_new_function_ptr_type() as a mechanism of handling
>> function pointers, yet contains
>> gcc_jit_context_new_call_through_ptr().
>
> [...]
>
> It's just missing documentation.  I'm working on fixing it.
> Have a look at gcc/testsuite/jit.dg/test-calling-function-ptr.c

Thanks, this is very helpful!

>> - What is the proper way of obtaining a function pointer to be passed
>> to gcc_jit_context_new_call_through_ptr()? There doesn't seem to be
>> any counterpart to gcc_jit_lvalue_get_address() for functions. As the
>> name suggests, gcc_jit_lvalue_get_address() works on an L-value and
>> gcc_jit_function type isn't an ancestor of gcc_jit_lvalue in the
>> internal type system, therefore upcasting is impossible.
>
> [...]
>
> If it's a function that's being compiled as part of the same
> gcc_jit_context, then I think you've identified a weakness in the
> current API.  As you say, one fix would be to make gcc_jit_function be
> a subclass of gcc_jit_lvalue (and add casting functions); I don't yet
> know how easy that would be to implement.

Yes, this is the exact use case I'm thinking of.

>From an user's point of view, I believe making gcc_jit_function a
subclass of gcc_jit_lvalue makes for an awkward design. Maybe
something like this would be easier to implement without upending the
current hierarchy:

gcc_jit_rvalue *gcc_jit_context_function_get_address(gcc_jit_context
*ctxt, gcc_jit_function *fun);

Thanks,
Bartosz Szreder



More information about the Jit mailing list