38 unsigned int el_length,
unsigned int flag_unsigned,
44 if (n != 2 && n != 3 && n != 4 && n != 8 && n != 16)
45 error (_(
"Invalid OpenCL vector size: %d"), n);
48 length = (n == 3) ? el_length * 4 : el_length * n;
50 auto filter = [&] (
struct type *
type)
60 && highb - lowb + 1 == n);
74 for (i = 0; i < n; i++)
76 for (j = i + 1; j < n; j++)
125 LONGEST offset = v->
offset ();
126 LONGEST elsize = eltype->
length ();
131 if (
type->
code () == TYPE_CODE_ARRAY
133 error (_(
"Could not determine the vector bounds"));
136 gdb_assert (offset % elsize == 0);
138 n = offset + highb - lowb + 1;
139 gdb_assert (n <= c->n);
141 for (i = offset; i < n; i++)
155 LONGEST offset = v->
offset ();
156 LONGEST elsize = eltype->
length ();
161 if (
type->
code () == TYPE_CODE_ARRAY
163 error (_(
"Could not determine the vector bounds"));
166 gdb_assert (offset % elsize == 0);
168 n = offset + highb - lowb + 1;
178 for (i = offset; i < n; i++)
184 fromval->
contents ().data () + j++ * elsize,
195 LONGEST
offset,
int length)
201 int startrest = offset % elsize;
202 int start = offset / elsize;
203 int endrest = (offset + length) % elsize;
204 int end = (offset + length) / elsize;
213 for (i = start; i < end; i++)
215 int comp_offset = (i == start) ? startrest : 0;
216 int comp_length = (i == end) ? endrest : elsize;
288 struct type *dst_type =
293 if (dst_type == NULL)
315 for (i = 0; i <
n; i++)
317 + (i * elm_type->
length ()),
340 error (_(
"Could not determine the vector bounds"));
342 src_len = highb - lowb + 1;
346 if (src_len != 2 && src_len != 3 && src_len != 4 && src_len != 8
348 error (_(
"Invalid OpenCL vector size"));
350 if (strcmp (comps,
"lo") == 0 )
352 dst_len = (src_len == 3) ? 2 : src_len / 2;
354 for (i = 0; i < dst_len; i++)
357 else if (strcmp (comps,
"hi") == 0)
359 dst_len = (src_len == 3) ? 2 : src_len / 2;
361 for (i = 0; i < dst_len; i++)
362 indices[i] = dst_len + i;
364 else if (strcmp (comps,
"even") == 0)
366 dst_len = (src_len == 3) ? 2 : src_len / 2;
368 for (i = 0; i < dst_len; i++)
371 else if (strcmp (comps,
"odd") == 0)
373 dst_len = (src_len == 3) ? 2 : src_len / 2;
375 for (i = 0; i < dst_len; i++)
378 else if (strncasecmp (comps,
"s", 1) == 0)
380#define HEXCHAR_TO_INT(C) ((C >= '0' && C <= '9') ? \
381 C-'0' : ((C >= 'A' && C <= 'F') ? \
382 C-'A'+10 : ((C >= 'a' && C <= 'f') ? \
385 dst_len = strlen (comps);
389 for (i = 0; i < dst_len; i++)
394 if (indices[i] < 0 || indices[i] >= src_len)
395 error (_(
"Invalid OpenCL vector component accessor %s"), comps);
400 dst_len = strlen (comps);
402 for (i = 0; i < dst_len; i++)
415 error (_(
"Invalid OpenCL vector component accessor %s"), comps);
420 error (_(
"Invalid OpenCL vector component accessor %s"), comps);
424 error (_(
"Invalid OpenCL vector component accessor %s"), comps);
432 if (dst_len != 1 && dst_len != 2 && dst_len != 3 && dst_len != 4
433 && dst_len != 8 && dst_len != 16)
434 error (_(
"Invalid OpenCL vector component accessor %s"), comps);
449 struct type *rettype;
459 error (_(
"Could not determine the vector bounds"));
468 for (i = 0; i < highb - lowb + 1; i++)
515 case BINOP_LOGICAL_AND:
518 case BINOP_LOGICAL_OR:
522 error (_(
"Attempt to perform an unsupported operation"));
535 struct type *type1, *type2, *eltype1, *eltype2, *rettype;
536 int t1_is_vec, t2_is_vec, i;
537 LONGEST lowb1, lowb2, highb1, highb2;
542 t1_is_vec = (type1->
code () == TYPE_CODE_ARRAY && type1->
is_vector ());
543 t2_is_vec = (type2->
code () == TYPE_CODE_ARRAY && type2->
is_vector ());
545 if (!t1_is_vec || !t2_is_vec)
546 error (_(
"Vector operations are not supported on scalar types"));
553 error (_(
"Could not determine the vector bounds"));
556 if (eltype1->
code () != eltype2->
code ()
559 || lowb1 != lowb2 || highb1 != highb2)
560 error (_(
"Cannot perform operation on vectors with different types"));
568 for (i = 0; i < highb1 - lowb1 + 1; i++)
576 + i * eltype1->
length ()),
599 struct type *to_type;
604 code1 = to_type->
code ();
607 if (code2 == TYPE_CODE_REF)
610 scalar = (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_BOOL
611 || code2 == TYPE_CODE_CHAR || code2 == TYPE_CODE_FLT
612 || code2 == TYPE_CODE_DECFLOAT || code2 == TYPE_CODE_ENUM
613 || code2 == TYPE_CODE_RANGE);
615 if (code1 == TYPE_CODE_ARRAY && to_type->
is_vector () && scalar)
645 int t1_is_vec = (type1->
code () == TYPE_CODE_ARRAY
647 int t2_is_vec = (type2->
code () == TYPE_CODE_ARRAY
650 if (!t1_is_vec && !t2_is_vec)
658 else if (t1_is_vec && t2_is_vec)
665 struct value **v = t1_is_vec ? &arg2 : &arg1;
666 struct type *t = t1_is_vec ? type2 : type1;
669 error (_(
"Argument to operation not a number or boolean."));
707 if (type1->
code () == TYPE_CODE_ARRAY && type1->
is_vector ())
740 if ((type1->
code () == TYPE_CODE_ARRAY && type1->
is_vector ())
741 || (type2->
code () == TYPE_CODE_ARRAY && type2->
is_vector ()))
754 if (op == BINOP_LOGICAL_OR)
761 if (op == BINOP_LOGICAL_OR)
777 if (type1->
code () == TYPE_CODE_ARRAY && type1->
is_vector ())
779 struct value *arg2, *arg3, *tmp, *ret;
780 struct type *eltype2, *type2, *type3, *eltype3;
781 int t2_is_vec, t3_is_vec, i;
782 LONGEST lowb1, lowb2, lowb3, highb1, highb2, highb3;
794 if (t2_is_vec || !t3_is_vec)
797 type3 = arg3->
type ();
799 else if (!t2_is_vec || t3_is_vec)
802 type2 = arg2->
type ();
804 else if (!t2_is_vec || !t3_is_vec)
808Cannot perform conditional operation on incompatible types"));
817 error (_(
"Could not determine the vector bounds"));
820 if (eltype2->
code () != eltype3->
code ()
823 || lowb2 != lowb3 || highb2 != highb3)
825Cannot perform operation on vectors with different types"));
828 if (lowb1 != lowb2 || lowb1 != lowb3
829 || highb1 != highb2 || highb1 != highb3)
831Cannot perform conditional operation on vectors with different sizes"));
835 for (i = 0; i < highb1 - lowb1 + 1; i++)
868 const char *
name ()
const override
874 {
return "OpenCL C"; }
881 auto add = [&] (
struct type * t) ->
struct type *
888#define OCL_STRING(S) #S
892#define BUILD_OCL_VTYPES(TYPE, ELEMENT_TYPE) \
896 tmp = add (init_vector_type (ELEMENT_TYPE, 2)); \
897 tmp->set_name (OCL_STRING(TYPE ## 2)); \
898 tmp = add (init_vector_type (ELEMENT_TYPE, 3)); \
899 tmp->set_name (OCL_STRING(TYPE ## 3)); \
900 tmp->set_length (4 * (ELEMENT_TYPE)->length ()); \
901 tmp = add (init_vector_type (ELEMENT_TYPE, 4)); \
902 tmp->set_name (OCL_STRING(TYPE ## 4)); \
903 tmp = add (init_vector_type (ELEMENT_TYPE, 8)); \
904 tmp->set_name (OCL_STRING(TYPE ## 8)); \
905 tmp = init_vector_type (ELEMENT_TYPE, 16); \
906 tmp->set_name (OCL_STRING(TYPE ## 16)); \
910 struct type *el_type, *char_type, *int_type;
964 struct ui_file *stream,
int show,
int level,
struct value * opencl_value_cast(struct type *type, struct value *arg)
struct value * opencl_relop(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2)
void c_print_type(struct type *type, const char *varstring, struct ui_file *stream, int show, int level, enum language language, const struct type_print_options *flags)
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
std::tuple< Arg... > m_storage
void print_type(struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override
bool can_print_type_offsets() const override
void language_arch_info(struct gdbarch *gdbarch, struct language_arch_info *lai) const override
const char * natural_name() const override
const char * name() const override
enum macro_expansion macro_expansion() const override
@ EVAL_AVOID_SIDE_EFFECTS
int gdbarch_ptr_bit(struct gdbarch *gdbarch)
struct type * init_integer_type(type_allocator &alloc, int bit, int unsigned_p, const char *name)
int is_integral_type(struct type *t)
struct type * make_cv_type(int cnst, int voltl, struct type *type, struct type **typeptr)
struct type * init_vector_type(struct type *elt_type, int n)
const struct floatformat * floatformats_ieee_single[BFD_ENDIAN_UNKNOWN]
struct type * init_float_type(type_allocator &alloc, int bit, const char *name, const struct floatformat **floatformats, enum bfd_endian byte_order)
bool get_array_bounds(struct type *type, LONGEST *low_bound, LONGEST *high_bound)
const struct floatformat * floatformats_ieee_half[BFD_ENDIAN_UNKNOWN]
const struct floatformat * floatformats_ieee_double[BFD_ENDIAN_UNKNOWN]
struct type * init_boolean_type(type_allocator &alloc, int bit, int unsigned_p, const char *name)
struct type * check_typedef(struct type *type)
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
const struct language_defn * language_def(enum language lang)
struct type * language_lookup_primitive_type(const struct language_defn *la, struct gdbarch *gdbarch, const char *name)
struct type * language_bool_type(const struct language_defn *la, struct gdbarch *gdbarch)
struct value * opencl_value_cast(struct type *type, struct value *arg)
struct value * opencl_relop(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2)
static struct lval_closure * allocate_lval_closure(int *indices, int n, struct value *val)
#define HEXCHAR_TO_INT(C)
struct value * opencl_logical_not(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg)
static void lval_func_write(struct value *v, struct value *fromval)
#define BUILD_OCL_VTYPES(TYPE, ELEMENT_TYPE)
static void lval_func_free_closure(struct value *v)
static struct value * vector_relop(struct expression *exp, struct value *val1, struct value *val2, enum exp_opcode op)
static struct value * opencl_component_ref(struct expression *exp, struct value *val, const char *comps, enum noside noside)
struct value * eval_opencl_assign(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2)
static void lval_func_read(struct value *v)
static const struct lval_funcs opencl_value_funcs
static void * lval_func_copy_closure(const struct value *v)
static int array_has_dups(int *arr, int n)
static bool lval_func_check_synthetic_pointer(const struct value *v, LONGEST offset, int length)
static struct value * create_value(struct gdbarch *gdbarch, struct value *val, enum noside noside, int *indices, int n)
static int scalar_relop(struct value *val1, struct value *val2, enum exp_opcode op)
static struct type * lookup_opencl_vector_type(struct gdbarch *gdbarch, enum type_code code, unsigned int el_length, unsigned int flag_unsigned, int n)
static opencl_language opencl_language_defn
const struct language_defn * language_defn
void set_string_char_type(struct type *type)
void add_primitive_type(struct type *type)
void set_bool_type(struct type *type, const char *name=nullptr)
enum language la_language
struct type * target_type() const
const char * name() const
static struct value * zero(struct type *type, enum lval_type lv)
gdb::array_view< const gdb_byte > contents_all()
bool deprecated_modifiable() const
static struct value * allocate_computed(struct type *type, const struct lval_funcs *funcs, void *closure)
gdb::array_view< gdb_byte > contents_writeable()
static struct value * allocate(struct type *type)
gdb::array_view< const gdb_byte > contents()
gdb::array_view< gdb_byte > contents_raw()
struct type * type() const
void * computed_closure() const
enum lval_type lval() const
bool bits_synthetic_pointer(LONGEST offset, LONGEST length) const
bool value_logical_not(struct value *arg1)
struct value * value_subscript(struct value *array, LONGEST index)
struct value * value_vector_widen(struct value *scalar_value, struct type *vector_type)
int value_equal(struct value *arg1, struct value *arg2)
int value_less(struct value *arg1, struct value *arg2)
struct value * value_struct_elt(struct value **argp, gdb::optional< gdb::array_view< value * > > args, const char *name, int *static_memfuncp, const char *err)
struct value * value_cast(struct type *type, struct value *arg2)
struct value * value_assign(struct value *toval, struct value *fromval)
struct value * value_from_longest(struct type *type, LONGEST num)
struct value * coerce_ref(struct value *arg)