|
From: | Michael Rolnik |
Subject: | Re: [Libjit] Global variables |
Date: | Fri, 10 Jun 2016 12:37:27 +0300 |
Hi Michael,
On Wed, Jun 8, 2016 at 1:35 PM, Michael Rolnik <address@hidden> wrote:
> Is there a way to create a global variables and access them from a function?
> How?
>
Probably it's more complicated than it should be. The memory
for a global variable should be allocated separately. E.g. have it
defined as a C-variable in a program that uses libjit.
static int32_t g_var;
Have a type for the address of this variable.
jit_type_t type_int32_ptr = jit_type_create_pointer(jit_type_int, 0);
In every jit function that is to use this variable define a jit value for
its address.
jit_value_t g_var_addr = jit_value_create_nint_constant(
a_func, type_int32_ptr, (jit_nint) &g_var);
And use jit_insn_load_relative() and jit_insn_store_relative() with
this address and zero offset.
Regards,
Aleksey
[Prev in Thread] | Current Thread | [Next in Thread] |