(root)/
gcc-13.2.0/
gcc/
testsuite/
jit.dg/
test-reflection.c
       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  
      63    CHECK (!gcc_jit_type_is_pointer(double_type));
      64    CHECK_VALUE (gcc_jit_type_is_pointer(gcc_jit_type_get_pointer(double_type)), double_type);
      65  
      66    gcc_jit_type* params[2] = {int8, uint64};
      67    gcc_jit_type *function_ptr_type = gcc_jit_context_new_function_ptr_type(ctxt, NULL, int64, 2, params, 0);
      68    CHECK (!gcc_jit_type_dyncast_function_ptr_type (int64));
      69    gcc_jit_function_type *function_type = gcc_jit_type_dyncast_function_ptr_type (function_ptr_type);
      70    CHECK (function_type);
      71    int param_count = gcc_jit_function_type_get_param_count(function_type);
      72    CHECK_VALUE (param_count, 2);
      73    gcc_jit_type *return_type = gcc_jit_function_type_get_return_type(function_type);
      74    CHECK_VALUE (return_type, int64);
      75    gcc_jit_type *param1 = gcc_jit_function_type_get_param_type(function_type, 0);
      76    CHECK_VALUE (param1, int8);
      77    gcc_jit_type *param2 = gcc_jit_function_type_get_param_type(function_type, 1);
      78    CHECK_VALUE (param2, uint64);
      79  
      80    gcc_jit_field *field1 = gcc_jit_context_new_field (ctxt, NULL, uint64, "field1");
      81    gcc_jit_field *field2 = gcc_jit_context_new_field (ctxt, NULL, double_type, "field2");
      82    gcc_jit_field *fields[2] = { field1, field2 };
      83    gcc_jit_struct *struct_type = gcc_jit_context_new_struct_type (ctxt, NULL, "testStruct", 2, fields);
      84    CHECK_VALUE (gcc_jit_struct_get_field_count(struct_type), 2);
      85    CHECK_VALUE (gcc_jit_struct_get_field(struct_type, 0), field1);
      86    CHECK_VALUE (gcc_jit_struct_get_field(struct_type, 1), field2);
      87    CHECK (!gcc_jit_type_is_struct(double_type));
      88    gcc_jit_struct *struct_ty = gcc_jit_type_is_struct(gcc_jit_struct_as_type(struct_type));
      89    CHECK_VALUE (struct_ty, struct_type);
      90  
      91    CHECK (!gcc_jit_type_dyncast_array(double_type));
      92    gcc_jit_type* array_type = gcc_jit_context_new_array_type(ctxt, NULL, double_type, 1);
      93    CHECK_VALUE (gcc_jit_type_dyncast_array(array_type), double_type);
      94  }
      95