11 create_code (gcc_jit_context
*ctxt
, void *user_data
)
13 /* Let's try to inject the equivalent of:
17 return bitcast(x, int32_t);
21 gcc_jit_context_get_int_type (ctxt
, 4, 1);
22 gcc_jit_type
*float_type
=
23 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_FLOAT
);
26 gcc_jit_context_new_param (
30 gcc_jit_param
*params
[1] = {x
};
31 gcc_jit_function
*func
=
32 gcc_jit_context_new_function (ctxt
,
34 GCC_JIT_FUNCTION_EXPORTED
,
39 gcc_jit_block
*initial
=
40 gcc_jit_function_new_block (func
, "initial");
42 gcc_jit_block_end_with_return(initial
, NULL
,
43 gcc_jit_context_new_bitcast(ctxt
,
45 gcc_jit_param_as_rvalue(x
),
51 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
53 typedef int32_t (*my_bitcast_fn_type
) (float);
54 CHECK_NON_NULL (result
);
55 my_bitcast_fn_type my_bitcast
=
56 (my_bitcast_fn_type
)gcc_jit_result_get_code (result
, "my_bitcast");
57 CHECK_NON_NULL (my_bitcast
);
58 int32_t val
= my_bitcast (3.1415927f
);
59 note ("my_bitcast returned: 0x%x", val
);
60 CHECK_VALUE (val
, 0x40490FDB);