16 create_code (gcc_jit_context
*ctxt
, void *user_data
)
18 /* Let's try to inject the equivalent of:
20 test_access (struct foo *f)
25 gcc_jit_type
*void_type
=
26 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_VOID
);
27 gcc_jit_type
*int_type
=
28 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
30 gcc_jit_context_new_field (ctxt
,
35 gcc_jit_context_new_field (ctxt
,
40 gcc_jit_context_new_field (ctxt
,
44 gcc_jit_field
*fields
[] = {x
, y
, z
};
45 gcc_jit_struct
*struct_type
=
46 gcc_jit_context_new_struct_type (ctxt
, NULL
, "foo", 3, fields
);
47 gcc_jit_type
*ptr_type
=
48 gcc_jit_type_get_pointer (gcc_jit_struct_as_type (struct_type
));
50 /* Build the test function. */
51 gcc_jit_param
*param_f
=
52 gcc_jit_context_new_param (ctxt
, NULL
, ptr_type
, "f");
53 gcc_jit_function
*test_fn
=
54 gcc_jit_context_new_function (ctxt
, NULL
,
55 GCC_JIT_FUNCTION_EXPORTED
,
63 gcc_jit_context_new_binary_op (
65 GCC_JIT_BINARY_OP_MULT
,
67 gcc_jit_lvalue_as_rvalue (
68 gcc_jit_rvalue_dereference_field (
69 gcc_jit_param_as_rvalue (param_f
),
72 gcc_jit_lvalue_as_rvalue (
73 gcc_jit_rvalue_dereference_field (
74 gcc_jit_param_as_rvalue (param_f
),
79 gcc_jit_block
*block
= gcc_jit_function_new_block (test_fn
, NULL
);
80 gcc_jit_block_add_assignment (
83 gcc_jit_rvalue_dereference_field (
84 gcc_jit_param_as_rvalue (param_f
),
88 gcc_jit_block_end_with_void_return (block
, NULL
);
92 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
94 typedef void (*fn_type
) (struct foo
*);
95 CHECK_NON_NULL (result
);
98 (fn_type
)gcc_jit_result_get_code (result
, "test_access");
99 CHECK_NON_NULL (test_access
);
106 /* Call the JIT-generated function. */
109 /* Verify that the code correctly modified the field "z". */
110 CHECK_VALUE (tmp
.z
, 35);