lightning
[Top][All Lists]
Advanced

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

Re: [Lightning] How to use jit_str


From: Paulo César Pereira de Andrade
Subject: Re: [Lightning] How to use jit_str
Date: Fri, 2 Jan 2015 14:10:20 -0200

2015-01-01 14:59 GMT-02:00 Vaso Peras-Likodric <address@hidden>:
> For one project I am force to use lightning lib. Can this library load/write
> data to memory

  Hi,

> I try to use jit_str but it is not working:
>
> #include <stdio.h>
> #include <lightning.h>
>
> typedef unsigned int Word;
>
> static jit_state_t *_jit;
>
> jit_state_t* jit_states[2];
>
> typedef int (*pifii)(int, int);       /* Pointer to Int Function of Int */
>
> int main(int argc, char *argv[])
> {
>   int i;
>   pifii      f[2];
>   jit_node_t *in1;               /* offset of the argument */
>   jit_node_t *in2;               /* offset of the argument */
>
>
>   Word memory[1];
>
>   init_jit(argv[0]);
>
>   jit_states[0] = _jit = jit_new_state();
>
>   jit_prolog   ();
>   in1 = jit_arg      ();
>   in2 = jit_arg      ();
>         jit_getarg   (JIT_R2, in1);
>         jit_getarg   (JIT_R1, in2);
>         jit_str      (JIT_R2, JIT_R2);
>         jit_retr     (JIT_R2);
>
>         f[0] = (pifii)jit_emit();
>         jit_clear_state();
>   f[0](memory, memory);

  This should work on 32 bit. On 64 bit it will fail because
you are using int instead of long.

  Unless it is a typed, or unsigned operation, when there is
a suffix, lightning emits signed wordsize operations.

  I suspect it is not working because you are running the
code on 64 bit. A quick pseudo patch fix is:

-typedef unsigned int Word;
+typedef unsigned long Word;
...
-typedef int (*pifii)(int, int);       /* Pointer to Int Function of Int */
+typedef int (*pifii)(long*, int);       /* Pointer to Int Function of Int */

> ---
> Best Regards,
> Vaso Peras-Likodric
>
> msn: address@hidden
> skype:vaso.likodric
> GSM: +381 63 494 158


Thanks,
Paulo



reply via email to

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