9 make_test_of_constant (gcc_jit_context
*ctxt
,
11 gcc_jit_rvalue
*rvalue
,
14 /* Make a test function of the form:
19 and return a debug dump of VALUE so that
20 the caller can sanity-check the debug dump implementation.
22 gcc_jit_function
*test_fn
=
23 gcc_jit_context_new_function (ctxt
, NULL
,
24 GCC_JIT_FUNCTION_EXPORTED
,
29 gcc_jit_block
*initial
= gcc_jit_function_new_block (test_fn
, "initial");
30 gcc_jit_block_end_with_return (initial
, NULL
, rvalue
);
33 /**********************************************************************
34 Tests of gcc_jit_context_new_rvalue_from_int.
35 **********************************************************************/
38 make_test_of_int_constant (gcc_jit_context
*ctxt
,
43 /* Make a test function of the form:
48 and return a debug dump of VALUE so that
49 the caller can sanity-check the debug dump implementation.
51 gcc_jit_rvalue
*rvalue
=
52 gcc_jit_context_new_rvalue_from_int (ctxt
, type
, value
);
53 make_test_of_constant (ctxt
, type
, rvalue
, funcname
);
54 return gcc_jit_object_get_debug_string (
55 gcc_jit_rvalue_as_object (rvalue
));
59 make_tests_of_int_constants (gcc_jit_context
*ctxt
)
61 gcc_jit_type
*int_type
=
62 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
65 make_test_of_int_constant (ctxt
,
68 "test_int_constant_0"),
70 make_test_of_int_constant (ctxt
,
73 "test_int_constant_INT_MAX");
74 make_test_of_int_constant (ctxt
,
77 "test_int_constant_INT_MIN");
81 verify_int_constants (gcc_jit_result
*result
)
83 typedef int (*test_fn
) (void);
85 test_fn test_int_constant_0
=
86 (test_fn
)gcc_jit_result_get_code (result
,
87 "test_int_constant_0");
88 CHECK_NON_NULL (test_int_constant_0
);
89 CHECK_VALUE (test_int_constant_0 (), 0);
91 test_fn test_int_constant_INT_MAX
=
92 (test_fn
)gcc_jit_result_get_code (result
,
93 "test_int_constant_INT_MAX");
94 CHECK_NON_NULL (test_int_constant_INT_MAX
);
95 CHECK_VALUE (test_int_constant_INT_MAX (), INT_MAX
);
97 test_fn test_int_constant_INT_MIN
=
98 (test_fn
)gcc_jit_result_get_code (result
,
99 "test_int_constant_INT_MIN");
100 CHECK_NON_NULL (test_int_constant_INT_MIN
);
101 CHECK_VALUE (test_int_constant_INT_MIN (), INT_MIN
);
104 /**********************************************************************
105 Tests of gcc_jit_context_new_rvalue_from_long.
106 **********************************************************************/
109 make_test_of_long_constant (gcc_jit_context
*ctxt
,
112 const char *funcname
)
114 /* Make a test function of the form:
119 and return a debug dump of VALUE so that
120 the caller can sanity-check the debug dump implementation.
122 gcc_jit_rvalue
*rvalue
=
123 gcc_jit_context_new_rvalue_from_long (ctxt
, type
, value
);
124 make_test_of_constant (ctxt
, type
, rvalue
, funcname
);
125 return gcc_jit_object_get_debug_string (
126 gcc_jit_rvalue_as_object (rvalue
));
130 make_tests_of_long_constants (gcc_jit_context
*ctxt
)
132 gcc_jit_type
*long_type
=
133 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_LONG
);
136 make_test_of_long_constant (ctxt
,
139 "test_long_constant_0"),
141 make_test_of_long_constant (ctxt
,
144 "test_long_constant_LONG_MAX");
145 make_test_of_long_constant (ctxt
,
148 "test_long_constant_LONG_MIN");
152 verify_long_constants (gcc_jit_result
*result
)
154 typedef long (*test_fn
) (void);
156 test_fn test_long_constant_0
=
157 (test_fn
)gcc_jit_result_get_code (result
,
158 "test_long_constant_0");
159 CHECK_NON_NULL (test_long_constant_0
);
160 CHECK_VALUE (test_long_constant_0 (), 0);
162 test_fn test_long_constant_LONG_MAX
=
163 (test_fn
)gcc_jit_result_get_code (result
,
164 "test_long_constant_LONG_MAX");
165 CHECK_NON_NULL (test_long_constant_LONG_MAX
);
166 CHECK_VALUE (test_long_constant_LONG_MAX (), LONG_MAX
);
168 test_fn test_long_constant_LONG_MIN
=
169 (test_fn
)gcc_jit_result_get_code (result
,
170 "test_long_constant_LONG_MIN");
171 CHECK_NON_NULL (test_long_constant_LONG_MIN
);
172 CHECK_VALUE (test_long_constant_LONG_MIN (), LONG_MIN
);
175 /**********************************************************************
176 Tests of gcc_jit_context_new_rvalue_from_double.
177 **********************************************************************/
180 make_test_of_double_constant (gcc_jit_context
*ctxt
,
183 const char *funcname
)
185 /* Make a test function of the form:
186 double funcname (void)
190 and return a debug dump of VALUE so that
191 the caller can sanity-check the debug dump implementation.
193 gcc_jit_rvalue
*rvalue
=
194 gcc_jit_context_new_rvalue_from_double (ctxt
, type
, value
);
195 make_test_of_constant (ctxt
, type
, rvalue
, funcname
);
196 return gcc_jit_object_get_debug_string (
197 gcc_jit_rvalue_as_object (rvalue
));
201 make_tests_of_double_constants (gcc_jit_context
*ctxt
)
203 gcc_jit_type
*double_type
=
204 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_DOUBLE
);
206 make_test_of_double_constant (ctxt
,
209 "test_double_constant_0_5");
210 make_test_of_double_constant (ctxt
,
213 "test_double_constant_1e100");
214 make_test_of_double_constant (ctxt
,
217 "test_double_constant_DBL_MIN");
218 make_test_of_double_constant (ctxt
,
221 "test_double_constant_DBL_MAX");
225 verify_double_constants (gcc_jit_result
*result
)
227 typedef double (*test_fn
) (void);
229 test_fn test_double_constant_0_5
=
230 (test_fn
)gcc_jit_result_get_code (result
,
231 "test_double_constant_0_5");
232 CHECK_NON_NULL (test_double_constant_0_5
);
233 CHECK_VALUE (test_double_constant_0_5 (), 0.5);
235 test_fn test_double_constant_1e100
=
236 (test_fn
)gcc_jit_result_get_code (result
,
237 "test_double_constant_1e100");
238 CHECK_NON_NULL (test_double_constant_1e100
);
239 CHECK_VALUE (test_double_constant_1e100 (), 1e100
);
241 test_fn test_double_constant_DBL_MIN
=
242 (test_fn
)gcc_jit_result_get_code (result
,
243 "test_double_constant_DBL_MIN");
244 CHECK_NON_NULL (test_double_constant_DBL_MIN
);
245 CHECK_VALUE (test_double_constant_DBL_MIN (), DBL_MIN
);
247 test_fn test_double_constant_DBL_MAX
=
248 (test_fn
)gcc_jit_result_get_code (result
,
249 "test_double_constant_DBL_MAX");
250 CHECK_NON_NULL (test_double_constant_DBL_MAX
);
251 CHECK_VALUE (test_double_constant_DBL_MAX (), DBL_MAX
);
254 /**********************************************************************
255 Tests of gcc_jit_context_new_rvalue_from_ptr.
256 **********************************************************************/
259 make_test_of_ptr_constant (gcc_jit_context
*ctxt
,
262 const char *funcname
)
264 /* Make a test function of the form:
265 void *funcname (void)
269 and return a debug dump of VALUE so that
270 the caller can sanity-check the debug dump implementation.
272 gcc_jit_rvalue
*rvalue
=
273 gcc_jit_context_new_rvalue_from_ptr (ctxt
, type
, value
);
274 make_test_of_constant (ctxt
, type
, rvalue
, funcname
);
275 return gcc_jit_object_get_debug_string (
276 gcc_jit_rvalue_as_object (rvalue
));
280 make_tests_of_ptr_constants (gcc_jit_context
*ctxt
)
282 gcc_jit_type
*ptr_type
=
283 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_VOID_PTR
);
286 make_test_of_ptr_constant (ctxt
,
289 "test_ptr_constant_0"),
292 make_test_of_ptr_constant (ctxt
,
295 "test_ptr_constant_0xdeadbeef"),
296 "(void *)0xdeadbeef");
300 verify_ptr_constants (gcc_jit_result
*result
)
302 typedef void *(*test_fn
) (void);
304 test_fn test_ptr_constant_0
=
305 (test_fn
)gcc_jit_result_get_code (result
,
306 "test_ptr_constant_0");
307 CHECK_NON_NULL (test_ptr_constant_0
);
308 CHECK_VALUE (test_ptr_constant_0 (), 0);
310 test_fn test_ptr_constant_0xdeadbeef
=
311 (test_fn
)gcc_jit_result_get_code (result
,
312 "test_ptr_constant_0xdeadbeef");
313 CHECK_NON_NULL (test_ptr_constant_0xdeadbeef
);
314 CHECK_VALUE (test_ptr_constant_0xdeadbeef (), (void *)0xdeadbeef);
317 /**********************************************************************
319 **********************************************************************/
322 create_code (gcc_jit_context
*ctxt
, void *user_data
)
324 make_tests_of_int_constants (ctxt
);
325 make_tests_of_long_constants (ctxt
);
326 make_tests_of_double_constants (ctxt
);
327 make_tests_of_ptr_constants (ctxt
);
331 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
333 CHECK_NON_NULL (result
);
335 verify_int_constants (result
);
336 verify_long_constants (result
);
337 verify_double_constants (result
);
338 verify_ptr_constants (result
);