18 create_code (gcc_jit_context
*ctxt
, void *user_data
)
20 /* Let's try to inject the equivalent of:
22 test_bitfield_access (struct bit_foo *f)
27 gcc_jit_type
*void_type
=
28 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_VOID
);
29 gcc_jit_type
*int_type
=
30 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
32 gcc_jit_context_new_bitfield (ctxt
,
38 gcc_jit_context_new_bitfield (ctxt
,
44 gcc_jit_context_new_bitfield (ctxt
,
50 gcc_jit_context_new_bitfield (ctxt
,
56 gcc_jit_context_new_bitfield (ctxt
,
61 gcc_jit_field
*fields
[] = {i
, x
, y
, z
, j
};
62 gcc_jit_struct
*struct_type
=
63 gcc_jit_context_new_struct_type (ctxt
, NULL
, "bit_foo", 5, fields
);
64 gcc_jit_type
*ptr_type
=
65 gcc_jit_type_get_pointer (gcc_jit_struct_as_type (struct_type
));
67 /* Build the test function. */
68 gcc_jit_param
*param_f
=
69 gcc_jit_context_new_param (ctxt
, NULL
, ptr_type
, "f");
70 gcc_jit_function
*test_fn
=
71 gcc_jit_context_new_function (ctxt
, NULL
,
72 GCC_JIT_FUNCTION_EXPORTED
,
74 "test_bitfield_access",
80 gcc_jit_context_new_binary_op (
82 GCC_JIT_BINARY_OP_PLUS
,
84 gcc_jit_lvalue_as_rvalue (
85 gcc_jit_rvalue_dereference_field (
86 gcc_jit_param_as_rvalue (param_f
),
89 gcc_jit_lvalue_as_rvalue (
90 gcc_jit_rvalue_dereference_field (
91 gcc_jit_param_as_rvalue (param_f
),
96 gcc_jit_block
*block
= gcc_jit_function_new_block (test_fn
, NULL
);
97 gcc_jit_block_add_assignment (
100 gcc_jit_rvalue_dereference_field (
101 gcc_jit_param_as_rvalue (param_f
),
105 gcc_jit_block_end_with_void_return (block
, NULL
);
109 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
111 typedef void (*fn_type
) (struct bit_foo
*);
112 CHECK_NON_NULL (result
);
114 fn_type test_bitfield_access
=
115 (fn_type
)gcc_jit_result_get_code (result
, "test_bitfield_access");
116 CHECK_NON_NULL (test_bitfield_access
);
125 /* Call the JIT-generated function. */
126 test_bitfield_access (&tmp
);
128 /* Verify that the code correctly modified the field "z". */
129 CHECK_VALUE (tmp
.z
, 12);