dotgnu-libjit
[Top][All Lists]
Advanced

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

[Dotgnu-libjit] Re: Variable arguments in LibJIT


From: Klaus Treichel
Subject: [Dotgnu-libjit] Re: Variable arguments in LibJIT
Date: Sat, 02 Oct 2010 10:40:52 +0200

Hey Aiden,


Am Samstag, den 02.10.2010, 11:57 +1000 schrieb Aiden Nibali:
> Firstly, I really appreciate the work that has gone into libjit, and I
> understand that you are probably very busy. However, I would
> still like some help using varargs in order to improve my
> Ruby bindings for libjit, libjit-ffi. I've spent hours looking through
> the documentation and grepping through the source code for instances
> of 'vararg', but all to no avail.
> 

Vararg calls are supported only for calling native functions by now.
The part for accessing those variable arguments in jitted functions is
still TODO (and needs very specific backend support).

> Below is my (failed) attempt to generate and apply a variadic function:
> 
>    #include<stdio.h>
>    #include<jit/jit.h>
> 
>    int main(int argc, char **argv)
>    {
>        jit_context_t context;
>        jit_function_t function;
>        jit_type_t params[2], signature;
>        jit_value_t x, y, tmp;
>        jit_int arg1, arg2;
>        void* args[2];
>        jit_int result;
> 
>        context = jit_context_create();
>        jit_context_build_start(context);
> 
>      /* Create vararg signature with 1 fixed parameter */
>        params[0] = jit_type_int;
>        signature = jit_type_create_signature
>            (jit_abi_vararg, jit_type_int, params, 1, 1);
> 
>        function = jit_function_create(context, signature);
> 
>        x = jit_value_get_param(function, 0);
>        y = jit_value_get_param(function, 1); /*<-- Doesn't seem to work! */

With jit_value_get_param only the fixed arguments are accessible.

>        tmp = jit_insn_add(function, x, y);
>        jit_insn_return(function, tmp);
> 
>        jit_function_compile(function);
>        jit_context_build_end(context);
> 
>        arg1 = 3;
>        arg2 = 4;
>        args[0] =&arg1;
>        args[1] =&arg2;
> 
>        /* Create new signature */
>        params[1] = jit_type_int;
>        signature = jit_type_create_signature(jit_abi_cdecl,
> jit_type_int, params, 2, 1);
> 
>        jit_function_apply_vararg(function, signature, args,&result);
> 
>        printf("3 + 4 = %d\n", (int)result);
> 
>        jit_context_destroy(context);
> 
>        return 0;
>    }
> 
> Any ideas on where I went wrong? Are varargs even fully supported yet?
> I could really do with some guidance.

Vararg jitted functions are not yet supported.

In DotGnu we work around this by adding an additional fixed argument
that's a pointer to a structure that holds the number of the variable
arguments, their types and pointers to the values.

Those functions can't be called from native code because of abi
differences.

What we need to add to libjit is a kind of va_arg interface.

> 
> Cheers,
> Aiden

Cheers,
Klaus

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]