| 1 |
#include <stdlib.h> |
| 2 |
#include <stdio.h> |
| 3 |
|
| 4 |
#include "libgccjit.h" |
| 5 |
|
| 6 |
#include "harness.h" |
| 7 |
|
| 8 |
void |
| 9 |
create_code (gcc_jit_context *ctxt, void *user_data) |
| 10 |
{ |
| 11 |
/* Do nothing. */ |
| 12 |
} |
| 13 |
|
| 14 |
void |
| 15 |
verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) |
| 16 |
{ |
| 17 |
/* Get the built-in functions. */ |
| 18 |
gcc_jit_function *builtin_sin = |
| 19 |
gcc_jit_context_get_builtin_function (ctxt, "sin"); |
| 20 |
|
| 21 |
CHECK_VALUE (gcc_jit_function_get_param_count(builtin_sin), 1); |
| 22 |
|
| 23 |
gcc_jit_type *double_type = |
| 24 |
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_DOUBLE); |
| 25 |
CHECK_VALUE (gcc_jit_function_get_return_type(builtin_sin), double_type); |
| 26 |
CHECK (!gcc_jit_type_is_integral(double_type)); |
| 27 |
|
| 28 |
gcc_jit_type *bool_type = |
| 29 |
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_BOOL); |
| 30 |
CHECK (gcc_jit_type_is_bool(bool_type)); |
| 31 |
CHECK (!gcc_jit_type_is_integral(bool_type)); |
| 32 |
|
| 33 |
gcc_jit_type *aligned_bool_type = |
| 34 |
gcc_jit_type_get_aligned(gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_BOOL), 8); |
| 35 |
CHECK (gcc_jit_type_is_bool(aligned_bool_type)); |
| 36 |
CHECK (bool_type != aligned_bool_type); |
| 37 |
CHECK_VALUE (gcc_jit_type_unqualified(aligned_bool_type), bool_type); |
| 38 |
|
| 39 |
CHECK_VALUE (gcc_jit_type_unqualified(gcc_jit_type_get_const(bool_type)), bool_type); |
| 40 |
CHECK_VALUE (gcc_jit_type_unqualified(gcc_jit_type_get_volatile(bool_type)), bool_type); |
| 41 |
|
| 42 |
gcc_jit_type *int64 = |
| 43 |
gcc_jit_context_get_int_type(ctxt, 8, 1); |
| 44 |
CHECK (gcc_jit_type_is_integral(int64)); |
| 45 |
gcc_jit_type *uint64 = |
| 46 |
gcc_jit_context_get_int_type(ctxt, 8, 0); |
| 47 |
CHECK (gcc_jit_type_is_integral(uint64)); |
| 48 |
gcc_jit_type *int8 = |
| 49 |
gcc_jit_context_get_int_type(ctxt, 1, 1); |
| 50 |
CHECK (gcc_jit_type_is_integral(int8)); |
| 51 |
gcc_jit_type *uint8 = |
| 52 |
gcc_jit_context_get_int_type(ctxt, 1, 0); |
| 53 |
CHECK (gcc_jit_type_is_integral(uint8)); |
| 54 |
|
| 55 |
CHECK (!gcc_jit_type_dyncast_vector(double_type)); |
| 56 |
gcc_jit_type *vec_type = gcc_jit_type_get_vector (double_type, 4); |
| 57 |
gcc_jit_vector_type *vector_type = gcc_jit_type_dyncast_vector(vec_type); |
| 58 |
CHECK (vector_type); |
| 59 |
CHECK (vec_type != double_type); |
| 60 |
CHECK_VALUE (gcc_jit_vector_type_get_element_type(vector_type), double_type); |
| 61 |
CHECK_VALUE (gcc_jit_vector_type_get_num_units(vector_type), 4); |
| 62 |
CHECK (!gcc_jit_type_is_integral(vec_type)); |
| 63 |
|
| 64 |
CHECK (!gcc_jit_type_is_pointer(double_type)); |
| 65 |
CHECK_VALUE (gcc_jit_type_is_pointer(gcc_jit_type_get_pointer(double_type)), double_type); |
| 66 |
|
| 67 |
gcc_jit_type* params[2] = {int8, uint64}; |
| 68 |
gcc_jit_type *function_ptr_type = gcc_jit_context_new_function_ptr_type(ctxt, NULL, int64, 2, params, 0); |
| 69 |
CHECK (!gcc_jit_type_dyncast_function_ptr_type (int64)); |
| 70 |
gcc_jit_function_type *function_type = gcc_jit_type_dyncast_function_ptr_type (function_ptr_type); |
| 71 |
CHECK (function_type); |
| 72 |
int param_count = gcc_jit_function_type_get_param_count(function_type); |
| 73 |
CHECK_VALUE (param_count, 2); |
| 74 |
gcc_jit_type *return_type = gcc_jit_function_type_get_return_type(function_type); |
| 75 |
CHECK_VALUE (return_type, int64); |
| 76 |
gcc_jit_type *param1 = gcc_jit_function_type_get_param_type(function_type, 0); |
| 77 |
CHECK_VALUE (param1, int8); |
| 78 |
gcc_jit_type *param2 = gcc_jit_function_type_get_param_type(function_type, 1); |
| 79 |
CHECK_VALUE (param2, uint64); |
| 80 |
|
| 81 |
gcc_jit_field *field1 = gcc_jit_context_new_field (ctxt, NULL, uint64, "field1"); |
| 82 |
gcc_jit_field *field2 = gcc_jit_context_new_field (ctxt, NULL, double_type, "field2"); |
| 83 |
gcc_jit_field *fields[2] = { field1, field2 }; |
| 84 |
gcc_jit_struct *struct_type = gcc_jit_context_new_struct_type (ctxt, NULL, "testStruct", 2, fields); |
| 85 |
CHECK_VALUE (gcc_jit_struct_get_field_count(struct_type), 2); |
| 86 |
CHECK_VALUE (gcc_jit_struct_get_field(struct_type, 0), field1); |
| 87 |
CHECK_VALUE (gcc_jit_struct_get_field(struct_type, 1), field2); |
| 88 |
CHECK (!gcc_jit_type_is_struct(double_type)); |
| 89 |
gcc_jit_struct *struct_ty = gcc_jit_type_is_struct(gcc_jit_struct_as_type(struct_type)); |
| 90 |
CHECK_VALUE (struct_ty, struct_type); |
| 91 |
|
| 92 |
CHECK (!gcc_jit_type_dyncast_array(double_type)); |
| 93 |
gcc_jit_type* array_type = gcc_jit_context_new_array_type(ctxt, NULL, double_type, 1); |
| 94 |
CHECK_VALUE (gcc_jit_type_dyncast_array(array_type), double_type); |
| 95 |
} |
| 96 |
|