10 create_code (gcc_jit_context
*ctxt
, void *user_data
)
12 /* Let's try to inject the equivalent of:
16 return (char)(long) x;
19 gcc_jit_type
*int_type
=
20 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
21 gcc_jit_type
*long_type
=
22 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_LONG
);
23 gcc_jit_type
*return_type
=
24 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_CHAR
);
27 gcc_jit_context_new_param (
31 gcc_jit_param
*params
[1] = {x
};
32 gcc_jit_function
*func
=
33 gcc_jit_context_new_function (ctxt
,
35 GCC_JIT_FUNCTION_EXPORTED
,
40 gcc_jit_block
*initial
=
41 gcc_jit_function_new_block (func
, "initial");
43 gcc_jit_block_end_with_return(initial
, NULL
,
44 gcc_jit_context_new_cast(ctxt
,
46 gcc_jit_context_new_cast(ctxt
,
48 gcc_jit_param_as_rvalue(x
),
56 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
58 typedef int (*my_casts_fn_type
) (int);
59 CHECK_NON_NULL (result
);
60 my_casts_fn_type my_casts
=
61 (my_casts_fn_type
)gcc_jit_result_get_code (result
, "my_casts");
62 CHECK_NON_NULL (my_casts
);
63 char val
= my_casts (10);
64 note ("my_casts returned: %d", val
);
65 CHECK_VALUE (val
, 10);