8 struct assignable_struct
15 union assignable_union
22 /* Verify that compound assignment works; let's try to inject the
25 struct assignable_struct
26 test_struct_assignment (struct assignable_struct x)
28 struct assignable_struct y, z;
34 and the same, for "union assignable_union". */
36 /* Make the type "struct assignable_struct" or "union assignable_union". */
39 make_type (gcc_jit_context
*ctxt
, int make_union
)
42 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
43 gcc_jit_type
*t_char
=
44 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_CHAR
);
45 gcc_jit_type
*t_float
=
46 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_FLOAT
);
49 gcc_jit_context_new_field (ctxt
,
54 gcc_jit_context_new_field (ctxt
,
59 gcc_jit_context_new_field (ctxt
,
63 gcc_jit_field
*fields
[] = {a
, b
, c
};
65 return gcc_jit_context_new_union_type (ctxt
, NULL
,
69 return gcc_jit_struct_as_type (
70 gcc_jit_context_new_struct_type (ctxt
, NULL
,
76 make_function (gcc_jit_context
*ctxt
, int make_union
, const char *funcname
)
78 gcc_jit_type
*test_type
= make_type (ctxt
, make_union
);
80 gcc_jit_context_new_param (ctxt
, NULL
,
82 gcc_jit_function
*fn
=
83 gcc_jit_context_new_function (ctxt
, NULL
,
84 GCC_JIT_FUNCTION_EXPORTED
,
90 gcc_jit_function_new_local (fn
, NULL
, test_type
, "y");
92 gcc_jit_function_new_local (fn
, NULL
, test_type
, "z");
93 gcc_jit_block
*block
=
94 gcc_jit_function_new_block (fn
, NULL
);
95 gcc_jit_block_add_assignment (block
, NULL
,
96 y
, gcc_jit_param_as_rvalue (x
));
97 gcc_jit_block_add_assignment (block
, NULL
,
98 z
, gcc_jit_lvalue_as_rvalue (y
));
99 gcc_jit_block_end_with_return (block
, NULL
,
100 gcc_jit_lvalue_as_rvalue (z
));
104 create_code (gcc_jit_context
*ctxt
, void *user_data
)
106 make_function (ctxt
, 0, "test_struct_assignment");
107 make_function (ctxt
, 1, "test_union_assignment");
111 verify_test_struct_assignment (gcc_jit_result
*result
)
113 typedef struct assignable_struct (*fn_type
) (struct assignable_struct
);
114 fn_type test_struct_assignment
=
115 (fn_type
)gcc_jit_result_get_code (result
, "test_struct_assignment");
116 CHECK_NON_NULL (test_struct_assignment
);
118 struct assignable_struct s
, t
;
122 t
= test_struct_assignment (s
);
123 CHECK_VALUE (t
.a
, 500);
124 CHECK_VALUE (t
.b
, 'A');
125 CHECK_VALUE (t
.c
, 1.0);
129 verify_test_union_assignment (gcc_jit_result
*result
)
131 typedef union assignable_union (*fn_type
) (union assignable_union
);
132 fn_type test_union_assignment
=
133 (fn_type
)gcc_jit_result_get_code (result
, "test_union_assignment");
134 CHECK_NON_NULL (test_union_assignment
);
136 union assignable_union p
, q
;
139 q
= test_union_assignment (p
);
140 CHECK_VALUE (q
.a
, 500);
143 q
= test_union_assignment (p
);
144 CHECK_VALUE (q
.b
, 'A');
147 q
= test_union_assignment (p
);
148 CHECK_VALUE (q
.c
, 1.0);
152 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
154 CHECK_NON_NULL (result
);
155 verify_test_struct_assignment (result
);
156 verify_test_union_assignment (result
);