Commit | Line | Data |
---|---|---|
f4b8a18d | 1 | /* OpenCL language support for GDB, the GNU debugger. |
b811d2c2 | 2 | Copyright (C) 2010-2020 Free Software Foundation, Inc. |
f4b8a18d KW |
3 | |
4 | Contributed by Ken Werner <ken.werner@de.ibm.com>. | |
5 | ||
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 3 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
20 | ||
21 | #include "defs.h" | |
f4b8a18d KW |
22 | #include "gdbtypes.h" |
23 | #include "symtab.h" | |
24 | #include "expression.h" | |
25 | #include "parser-defs.h" | |
f4b8a18d | 26 | #include "language.h" |
a53b64ea | 27 | #include "varobj.h" |
f4b8a18d | 28 | #include "c-lang.h" |
0d12e84c | 29 | #include "gdbarch.h" |
f4b8a18d | 30 | |
f4b8a18d KW |
31 | /* Returns the corresponding OpenCL vector type from the given type code, |
32 | the length of the element type, the unsigned flag and the amount of | |
33 | elements (N). */ | |
34 | ||
35 | static struct type * | |
36 | lookup_opencl_vector_type (struct gdbarch *gdbarch, enum type_code code, | |
37 | unsigned int el_length, unsigned int flag_unsigned, | |
38 | int n) | |
39 | { | |
f4b8a18d | 40 | unsigned int length; |
f4b8a18d KW |
41 | |
42 | /* Check if n describes a valid OpenCL vector size (2, 3, 4, 8, 16). */ | |
43 | if (n != 2 && n != 3 && n != 4 && n != 8 && n != 16) | |
44 | error (_("Invalid OpenCL vector size: %d"), n); | |
45 | ||
46 | /* Triple vectors have the size of a quad vector. */ | |
47 | length = (n == 3) ? el_length * 4 : el_length * n; | |
48 | ||
7bea47f0 AB |
49 | std::function<bool (struct type *)> filter = [&] (struct type *type) |
50 | { | |
51 | LONGEST lowb, highb; | |
52 | ||
53 | return (type->code () == TYPE_CODE_ARRAY && type->is_vector () | |
54 | && get_array_bounds (type, &lowb, &highb) | |
55 | && TYPE_TARGET_TYPE (type)->code () == code | |
56 | && TYPE_TARGET_TYPE (type)->is_unsigned () == flag_unsigned | |
57 | && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) == el_length | |
58 | && TYPE_LENGTH (type) == length | |
59 | && highb - lowb + 1 == n); | |
60 | }; | |
61 | const struct language_defn *lang = language_def (language_opencl); | |
62 | return language_lookup_primitive_type (lang, gdbarch, filter); | |
f4b8a18d KW |
63 | } |
64 | ||
65 | /* Returns nonzero if the array ARR contains duplicates within | |
66 | the first N elements. */ | |
67 | ||
68 | static int | |
69 | array_has_dups (int *arr, int n) | |
70 | { | |
71 | int i, j; | |
72 | ||
73 | for (i = 0; i < n; i++) | |
74 | { | |
75 | for (j = i + 1; j < n; j++) | |
dda83cd7 SM |
76 | { |
77 | if (arr[i] == arr[j]) | |
78 | return 1; | |
79 | } | |
f4b8a18d KW |
80 | } |
81 | ||
82 | return 0; | |
83 | } | |
84 | ||
85 | /* The OpenCL component access syntax allows to create lvalues referring to | |
86 | selected elements of an original OpenCL vector in arbitrary order. This | |
87 | structure holds the information to describe such lvalues. */ | |
88 | ||
89 | struct lval_closure | |
90 | { | |
91 | /* Reference count. */ | |
92 | int refc; | |
93 | /* The number of indices. */ | |
94 | int n; | |
95 | /* The element indices themselves. */ | |
96 | int *indices; | |
97 | /* A pointer to the original value. */ | |
98 | struct value *val; | |
99 | }; | |
100 | ||
101 | /* Allocates an instance of struct lval_closure. */ | |
102 | ||
103 | static struct lval_closure * | |
104 | allocate_lval_closure (int *indices, int n, struct value *val) | |
105 | { | |
41bf6aca | 106 | struct lval_closure *c = XCNEW (struct lval_closure); |
f4b8a18d KW |
107 | |
108 | c->refc = 1; | |
109 | c->n = n; | |
fc270c35 | 110 | c->indices = XCNEWVEC (int, n); |
f4b8a18d KW |
111 | memcpy (c->indices, indices, n * sizeof (int)); |
112 | value_incref (val); /* Increment the reference counter of the value. */ | |
113 | c->val = val; | |
114 | ||
115 | return c; | |
116 | } | |
117 | ||
118 | static void | |
119 | lval_func_read (struct value *v) | |
120 | { | |
121 | struct lval_closure *c = (struct lval_closure *) value_computed_closure (v); | |
122 | struct type *type = check_typedef (value_type (v)); | |
123 | struct type *eltype = TYPE_TARGET_TYPE (check_typedef (value_type (c->val))); | |
6b850546 DT |
124 | LONGEST offset = value_offset (v); |
125 | LONGEST elsize = TYPE_LENGTH (eltype); | |
f4b8a18d KW |
126 | int n, i, j = 0; |
127 | LONGEST lowb = 0; | |
128 | LONGEST highb = 0; | |
129 | ||
78134374 | 130 | if (type->code () == TYPE_CODE_ARRAY |
f4b8a18d KW |
131 | && !get_array_bounds (type, &lowb, &highb)) |
132 | error (_("Could not determine the vector bounds")); | |
133 | ||
134 | /* Assume elsize aligned offset. */ | |
135 | gdb_assert (offset % elsize == 0); | |
136 | offset /= elsize; | |
137 | n = offset + highb - lowb + 1; | |
138 | gdb_assert (n <= c->n); | |
139 | ||
140 | for (i = offset; i < n; i++) | |
141 | memcpy (value_contents_raw (v) + j++ * elsize, | |
142 | value_contents (c->val) + c->indices[i] * elsize, | |
143 | elsize); | |
144 | } | |
145 | ||
146 | static void | |
147 | lval_func_write (struct value *v, struct value *fromval) | |
148 | { | |
149 | struct value *mark = value_mark (); | |
150 | struct lval_closure *c = (struct lval_closure *) value_computed_closure (v); | |
151 | struct type *type = check_typedef (value_type (v)); | |
152 | struct type *eltype = TYPE_TARGET_TYPE (check_typedef (value_type (c->val))); | |
6b850546 DT |
153 | LONGEST offset = value_offset (v); |
154 | LONGEST elsize = TYPE_LENGTH (eltype); | |
f4b8a18d KW |
155 | int n, i, j = 0; |
156 | LONGEST lowb = 0; | |
157 | LONGEST highb = 0; | |
158 | ||
78134374 | 159 | if (type->code () == TYPE_CODE_ARRAY |
f4b8a18d KW |
160 | && !get_array_bounds (type, &lowb, &highb)) |
161 | error (_("Could not determine the vector bounds")); | |
162 | ||
163 | /* Assume elsize aligned offset. */ | |
164 | gdb_assert (offset % elsize == 0); | |
165 | offset /= elsize; | |
166 | n = offset + highb - lowb + 1; | |
167 | ||
168 | /* Since accesses to the fourth component of a triple vector is undefined we | |
169 | just skip writes to the fourth element. Imagine something like this: | |
170 | int3 i3 = (int3)(0, 1, 2); | |
171 | i3.hi.hi = 5; | |
172 | In this case n would be 4 (offset=12/4 + 1) while c->n would be 3. */ | |
173 | if (n > c->n) | |
174 | n = c->n; | |
175 | ||
176 | for (i = offset; i < n; i++) | |
177 | { | |
178 | struct value *from_elm_val = allocate_value (eltype); | |
179 | struct value *to_elm_val = value_subscript (c->val, c->indices[i]); | |
180 | ||
181 | memcpy (value_contents_writeable (from_elm_val), | |
182 | value_contents (fromval) + j++ * elsize, | |
183 | elsize); | |
184 | value_assign (to_elm_val, from_elm_val); | |
185 | } | |
186 | ||
187 | value_free_to_mark (mark); | |
188 | } | |
189 | ||
8cf6f0b1 TT |
190 | /* Return nonzero if bits in V from OFFSET and LENGTH represent a |
191 | synthetic pointer. */ | |
192 | ||
193 | static int | |
194 | lval_func_check_synthetic_pointer (const struct value *v, | |
6b850546 | 195 | LONGEST offset, int length) |
8cf6f0b1 TT |
196 | { |
197 | struct lval_closure *c = (struct lval_closure *) value_computed_closure (v); | |
198 | /* Size of the target type in bits. */ | |
199 | int elsize = | |
200 | TYPE_LENGTH (TYPE_TARGET_TYPE (check_typedef (value_type (c->val)))) * 8; | |
201 | int startrest = offset % elsize; | |
202 | int start = offset / elsize; | |
203 | int endrest = (offset + length) % elsize; | |
204 | int end = (offset + length) / elsize; | |
205 | int i; | |
206 | ||
207 | if (endrest) | |
208 | end++; | |
209 | ||
210 | if (end > c->n) | |
211 | return 0; | |
212 | ||
213 | for (i = start; i < end; i++) | |
214 | { | |
8f9a01ee MS |
215 | int comp_offset = (i == start) ? startrest : 0; |
216 | int comp_length = (i == end) ? endrest : elsize; | |
8cf6f0b1 TT |
217 | |
218 | if (!value_bits_synthetic_pointer (c->val, | |
8f9a01ee MS |
219 | c->indices[i] * elsize + comp_offset, |
220 | comp_length)) | |
8cf6f0b1 TT |
221 | return 0; |
222 | } | |
223 | ||
224 | return 1; | |
225 | } | |
226 | ||
f4b8a18d KW |
227 | static void * |
228 | lval_func_copy_closure (const struct value *v) | |
229 | { | |
230 | struct lval_closure *c = (struct lval_closure *) value_computed_closure (v); | |
231 | ||
232 | ++c->refc; | |
233 | ||
234 | return c; | |
235 | } | |
236 | ||
237 | static void | |
238 | lval_func_free_closure (struct value *v) | |
239 | { | |
240 | struct lval_closure *c = (struct lval_closure *) value_computed_closure (v); | |
241 | ||
242 | --c->refc; | |
243 | ||
244 | if (c->refc == 0) | |
245 | { | |
22bc8444 | 246 | value_decref (c->val); /* Decrement the reference counter of the value. */ |
f4b8a18d KW |
247 | xfree (c->indices); |
248 | xfree (c); | |
f4b8a18d KW |
249 | } |
250 | } | |
251 | ||
c8f2448a | 252 | static const struct lval_funcs opencl_value_funcs = |
f4b8a18d KW |
253 | { |
254 | lval_func_read, | |
255 | lval_func_write, | |
a471c594 JK |
256 | NULL, /* indirect */ |
257 | NULL, /* coerce_ref */ | |
8cf6f0b1 | 258 | lval_func_check_synthetic_pointer, |
f4b8a18d KW |
259 | lval_func_copy_closure, |
260 | lval_func_free_closure | |
261 | }; | |
262 | ||
263 | /* Creates a sub-vector from VAL. The elements are selected by the indices of | |
264 | an array with the length of N. Supported values for NOSIDE are | |
265 | EVAL_NORMAL and EVAL_AVOID_SIDE_EFFECTS. */ | |
266 | ||
267 | static struct value * | |
268 | create_value (struct gdbarch *gdbarch, struct value *val, enum noside noside, | |
269 | int *indices, int n) | |
270 | { | |
271 | struct type *type = check_typedef (value_type (val)); | |
272 | struct type *elm_type = TYPE_TARGET_TYPE (type); | |
273 | struct value *ret; | |
274 | ||
275 | /* Check if a single component of a vector is requested which means | |
276 | the resulting type is a (primitive) scalar type. */ | |
277 | if (n == 1) | |
278 | { | |
279 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
dda83cd7 | 280 | ret = value_zero (elm_type, not_lval); |
f4b8a18d | 281 | else |
dda83cd7 | 282 | ret = value_subscript (val, indices[0]); |
f4b8a18d KW |
283 | } |
284 | else | |
285 | { | |
286 | /* Multiple components of the vector are requested which means the | |
287 | resulting type is a vector as well. */ | |
288 | struct type *dst_type = | |
78134374 | 289 | lookup_opencl_vector_type (gdbarch, elm_type->code (), |
f4b8a18d | 290 | TYPE_LENGTH (elm_type), |
c6d940a9 | 291 | elm_type->is_unsigned (), n); |
f4b8a18d KW |
292 | |
293 | if (dst_type == NULL) | |
294 | dst_type = init_vector_type (elm_type, n); | |
295 | ||
296 | make_cv_type (TYPE_CONST (type), TYPE_VOLATILE (type), dst_type, NULL); | |
297 | ||
298 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
299 | ret = allocate_value (dst_type); | |
300 | else | |
301 | { | |
302 | /* Check whether to create a lvalue or not. */ | |
303 | if (VALUE_LVAL (val) != not_lval && !array_has_dups (indices, n)) | |
304 | { | |
305 | struct lval_closure *c = allocate_lval_closure (indices, n, val); | |
306 | ret = allocate_computed_value (dst_type, &opencl_value_funcs, c); | |
307 | } | |
308 | else | |
309 | { | |
310 | int i; | |
311 | ||
312 | ret = allocate_value (dst_type); | |
313 | ||
314 | /* Copy src val contents into the destination value. */ | |
315 | for (i = 0; i < n; i++) | |
316 | memcpy (value_contents_writeable (ret) | |
317 | + (i * TYPE_LENGTH (elm_type)), | |
318 | value_contents (val) | |
319 | + (indices[i] * TYPE_LENGTH (elm_type)), | |
320 | TYPE_LENGTH (elm_type)); | |
321 | } | |
322 | } | |
323 | } | |
324 | return ret; | |
325 | } | |
326 | ||
327 | /* OpenCL vector component access. */ | |
328 | ||
329 | static struct value * | |
330 | opencl_component_ref (struct expression *exp, struct value *val, char *comps, | |
331 | enum noside noside) | |
332 | { | |
333 | LONGEST lowb, highb; | |
334 | int src_len; | |
335 | struct value *v; | |
336 | int indices[16], i; | |
337 | int dst_len; | |
338 | ||
339 | if (!get_array_bounds (check_typedef (value_type (val)), &lowb, &highb)) | |
340 | error (_("Could not determine the vector bounds")); | |
341 | ||
342 | src_len = highb - lowb + 1; | |
343 | ||
344 | /* Throw an error if the amount of array elements does not fit a | |
345 | valid OpenCL vector size (2, 3, 4, 8, 16). */ | |
346 | if (src_len != 2 && src_len != 3 && src_len != 4 && src_len != 8 | |
347 | && src_len != 16) | |
348 | error (_("Invalid OpenCL vector size")); | |
349 | ||
350 | if (strcmp (comps, "lo") == 0 ) | |
351 | { | |
352 | dst_len = (src_len == 3) ? 2 : src_len / 2; | |
353 | ||
354 | for (i = 0; i < dst_len; i++) | |
355 | indices[i] = i; | |
356 | } | |
357 | else if (strcmp (comps, "hi") == 0) | |
358 | { | |
359 | dst_len = (src_len == 3) ? 2 : src_len / 2; | |
360 | ||
361 | for (i = 0; i < dst_len; i++) | |
362 | indices[i] = dst_len + i; | |
363 | } | |
364 | else if (strcmp (comps, "even") == 0) | |
365 | { | |
366 | dst_len = (src_len == 3) ? 2 : src_len / 2; | |
367 | ||
368 | for (i = 0; i < dst_len; i++) | |
369 | indices[i] = i*2; | |
370 | } | |
371 | else if (strcmp (comps, "odd") == 0) | |
372 | { | |
373 | dst_len = (src_len == 3) ? 2 : src_len / 2; | |
374 | ||
375 | for (i = 0; i < dst_len; i++) | |
dda83cd7 | 376 | indices[i] = i*2+1; |
f4b8a18d KW |
377 | } |
378 | else if (strncasecmp (comps, "s", 1) == 0) | |
379 | { | |
380 | #define HEXCHAR_TO_INT(C) ((C >= '0' && C <= '9') ? \ | |
dda83cd7 SM |
381 | C-'0' : ((C >= 'A' && C <= 'F') ? \ |
382 | C-'A'+10 : ((C >= 'a' && C <= 'f') ? \ | |
383 | C-'a'+10 : -1))) | |
f4b8a18d KW |
384 | |
385 | dst_len = strlen (comps); | |
386 | /* Skip the s/S-prefix. */ | |
387 | dst_len--; | |
388 | ||
389 | for (i = 0; i < dst_len; i++) | |
390 | { | |
391 | indices[i] = HEXCHAR_TO_INT(comps[i+1]); | |
392 | /* Check if the requested component is invalid or exceeds | |
393 | the vector. */ | |
394 | if (indices[i] < 0 || indices[i] >= src_len) | |
395 | error (_("Invalid OpenCL vector component accessor %s"), comps); | |
396 | } | |
397 | } | |
398 | else | |
399 | { | |
400 | dst_len = strlen (comps); | |
401 | ||
402 | for (i = 0; i < dst_len; i++) | |
403 | { | |
404 | /* x, y, z, w */ | |
405 | switch (comps[i]) | |
406 | { | |
407 | case 'x': | |
408 | indices[i] = 0; | |
409 | break; | |
410 | case 'y': | |
411 | indices[i] = 1; | |
412 | break; | |
413 | case 'z': | |
414 | if (src_len < 3) | |
415 | error (_("Invalid OpenCL vector component accessor %s"), comps); | |
416 | indices[i] = 2; | |
417 | break; | |
418 | case 'w': | |
419 | if (src_len < 4) | |
420 | error (_("Invalid OpenCL vector component accessor %s"), comps); | |
421 | indices[i] = 3; | |
422 | break; | |
423 | default: | |
424 | error (_("Invalid OpenCL vector component accessor %s"), comps); | |
425 | break; | |
426 | } | |
427 | } | |
428 | } | |
429 | ||
430 | /* Throw an error if the amount of requested components does not | |
431 | result in a valid length (1, 2, 3, 4, 8, 16). */ | |
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); | |
435 | ||
436 | v = create_value (exp->gdbarch, val, noside, indices, dst_len); | |
437 | ||
438 | return v; | |
439 | } | |
440 | ||
441 | /* Perform the unary logical not (!) operation. */ | |
442 | ||
443 | static struct value * | |
444 | opencl_logical_not (struct expression *exp, struct value *arg) | |
445 | { | |
446 | struct type *type = check_typedef (value_type (arg)); | |
447 | struct type *rettype; | |
448 | struct value *ret; | |
449 | ||
bd63c870 | 450 | if (type->code () == TYPE_CODE_ARRAY && type->is_vector ()) |
f4b8a18d KW |
451 | { |
452 | struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type)); | |
453 | LONGEST lowb, highb; | |
454 | int i; | |
455 | ||
456 | if (!get_array_bounds (type, &lowb, &highb)) | |
457 | error (_("Could not determine the vector bounds")); | |
458 | ||
459 | /* Determine the resulting type of the operation and allocate the | |
460 | value. */ | |
461 | rettype = lookup_opencl_vector_type (exp->gdbarch, TYPE_CODE_INT, | |
462 | TYPE_LENGTH (eltype), 0, | |
463 | highb - lowb + 1); | |
464 | ret = allocate_value (rettype); | |
465 | ||
466 | for (i = 0; i < highb - lowb + 1; i++) | |
467 | { | |
468 | /* For vector types, the unary operator shall return a 0 if the | |
469 | value of its operand compares unequal to 0, and -1 (i.e. all bits | |
470 | set) if the value of its operand compares equal to 0. */ | |
471 | int tmp = value_logical_not (value_subscript (arg, i)) ? -1 : 0; | |
472 | memset (value_contents_writeable (ret) + i * TYPE_LENGTH (eltype), | |
473 | tmp, TYPE_LENGTH (eltype)); | |
474 | } | |
475 | } | |
476 | else | |
477 | { | |
478 | rettype = language_bool_type (exp->language_defn, exp->gdbarch); | |
479 | ret = value_from_longest (rettype, value_logical_not (arg)); | |
480 | } | |
481 | ||
482 | return ret; | |
483 | } | |
484 | ||
485 | /* Perform a relational operation on two scalar operands. */ | |
486 | ||
487 | static int | |
488 | scalar_relop (struct value *val1, struct value *val2, enum exp_opcode op) | |
489 | { | |
490 | int ret; | |
491 | ||
492 | switch (op) | |
493 | { | |
494 | case BINOP_EQUAL: | |
495 | ret = value_equal (val1, val2); | |
496 | break; | |
497 | case BINOP_NOTEQUAL: | |
498 | ret = !value_equal (val1, val2); | |
499 | break; | |
500 | case BINOP_LESS: | |
501 | ret = value_less (val1, val2); | |
502 | break; | |
503 | case BINOP_GTR: | |
504 | ret = value_less (val2, val1); | |
505 | break; | |
506 | case BINOP_GEQ: | |
507 | ret = value_less (val2, val1) || value_equal (val1, val2); | |
508 | break; | |
509 | case BINOP_LEQ: | |
510 | ret = value_less (val1, val2) || value_equal (val1, val2); | |
511 | break; | |
512 | case BINOP_LOGICAL_AND: | |
513 | ret = !value_logical_not (val1) && !value_logical_not (val2); | |
514 | break; | |
515 | case BINOP_LOGICAL_OR: | |
516 | ret = !value_logical_not (val1) || !value_logical_not (val2); | |
517 | break; | |
518 | default: | |
519 | error (_("Attempt to perform an unsupported operation")); | |
520 | break; | |
521 | } | |
522 | return ret; | |
523 | } | |
524 | ||
525 | /* Perform a relational operation on two vector operands. */ | |
526 | ||
527 | static struct value * | |
528 | vector_relop (struct expression *exp, struct value *val1, struct value *val2, | |
529 | enum exp_opcode op) | |
530 | { | |
531 | struct value *ret; | |
532 | struct type *type1, *type2, *eltype1, *eltype2, *rettype; | |
533 | int t1_is_vec, t2_is_vec, i; | |
534 | LONGEST lowb1, lowb2, highb1, highb2; | |
535 | ||
536 | type1 = check_typedef (value_type (val1)); | |
537 | type2 = check_typedef (value_type (val2)); | |
538 | ||
bd63c870 SM |
539 | t1_is_vec = (type1->code () == TYPE_CODE_ARRAY && type1->is_vector ()); |
540 | t2_is_vec = (type2->code () == TYPE_CODE_ARRAY && type2->is_vector ()); | |
f4b8a18d KW |
541 | |
542 | if (!t1_is_vec || !t2_is_vec) | |
543 | error (_("Vector operations are not supported on scalar types")); | |
544 | ||
545 | eltype1 = check_typedef (TYPE_TARGET_TYPE (type1)); | |
546 | eltype2 = check_typedef (TYPE_TARGET_TYPE (type2)); | |
547 | ||
548 | if (!get_array_bounds (type1,&lowb1, &highb1) | |
549 | || !get_array_bounds (type2, &lowb2, &highb2)) | |
550 | error (_("Could not determine the vector bounds")); | |
551 | ||
552 | /* Check whether the vector types are compatible. */ | |
78134374 | 553 | if (eltype1->code () != eltype2->code () |
f4b8a18d | 554 | || TYPE_LENGTH (eltype1) != TYPE_LENGTH (eltype2) |
c6d940a9 | 555 | || eltype1->is_unsigned () != eltype2->is_unsigned () |
f4b8a18d KW |
556 | || lowb1 != lowb2 || highb1 != highb2) |
557 | error (_("Cannot perform operation on vectors with different types")); | |
558 | ||
559 | /* Determine the resulting type of the operation and allocate the value. */ | |
560 | rettype = lookup_opencl_vector_type (exp->gdbarch, TYPE_CODE_INT, | |
561 | TYPE_LENGTH (eltype1), 0, | |
562 | highb1 - lowb1 + 1); | |
563 | ret = allocate_value (rettype); | |
564 | ||
565 | for (i = 0; i < highb1 - lowb1 + 1; i++) | |
566 | { | |
567 | /* For vector types, the relational, equality and logical operators shall | |
568 | return 0 if the specified relation is false and -1 (i.e. all bits set) | |
569 | if the specified relation is true. */ | |
570 | int tmp = scalar_relop (value_subscript (val1, i), | |
571 | value_subscript (val2, i), op) ? -1 : 0; | |
572 | memset (value_contents_writeable (ret) + i * TYPE_LENGTH (eltype1), | |
573 | tmp, TYPE_LENGTH (eltype1)); | |
574 | } | |
575 | ||
576 | return ret; | |
577 | } | |
578 | ||
8954db33 AB |
579 | /* Perform a cast of ARG into TYPE. There's sadly a lot of duplication in |
580 | here from valops.c:value_cast, opencl is different only in the | |
581 | behaviour of scalar to vector casting. As far as possibly we're going | |
582 | to try and delegate back to the standard value_cast function. */ | |
583 | ||
584 | static struct value * | |
585 | opencl_value_cast (struct type *type, struct value *arg) | |
586 | { | |
587 | if (type != value_type (arg)) | |
588 | { | |
589 | /* Casting scalar to vector is a special case for OpenCL, scalar | |
590 | is cast to element type of vector then replicated into each | |
591 | element of the vector. First though, we need to work out if | |
592 | this is a scalar to vector cast; code lifted from | |
593 | valops.c:value_cast. */ | |
594 | enum type_code code1, code2; | |
595 | struct type *to_type; | |
596 | int scalar; | |
597 | ||
598 | to_type = check_typedef (type); | |
599 | ||
78134374 SM |
600 | code1 = to_type->code (); |
601 | code2 = check_typedef (value_type (arg))->code (); | |
8954db33 AB |
602 | |
603 | if (code2 == TYPE_CODE_REF) | |
78134374 | 604 | code2 = check_typedef (value_type (coerce_ref(arg)))->code (); |
8954db33 AB |
605 | |
606 | scalar = (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_BOOL | |
607 | || code2 == TYPE_CODE_CHAR || code2 == TYPE_CODE_FLT | |
608 | || code2 == TYPE_CODE_DECFLOAT || code2 == TYPE_CODE_ENUM | |
609 | || code2 == TYPE_CODE_RANGE); | |
610 | ||
bd63c870 | 611 | if (code1 == TYPE_CODE_ARRAY && to_type->is_vector () && scalar) |
8954db33 AB |
612 | { |
613 | struct type *eltype; | |
614 | ||
615 | /* Cast to the element type of the vector here as | |
616 | value_vector_widen will error if the scalar value is | |
617 | truncated by the cast. To avoid the error, cast (and | |
618 | possibly truncate) here. */ | |
619 | eltype = check_typedef (TYPE_TARGET_TYPE (to_type)); | |
620 | arg = value_cast (eltype, arg); | |
621 | ||
622 | return value_vector_widen (arg, type); | |
623 | } | |
624 | else | |
625 | /* Standard cast handler. */ | |
626 | arg = value_cast (type, arg); | |
627 | } | |
628 | return arg; | |
629 | } | |
630 | ||
f4b8a18d KW |
631 | /* Perform a relational operation on two operands. */ |
632 | ||
633 | static struct value * | |
634 | opencl_relop (struct expression *exp, struct value *arg1, struct value *arg2, | |
635 | enum exp_opcode op) | |
636 | { | |
637 | struct value *val; | |
638 | struct type *type1 = check_typedef (value_type (arg1)); | |
639 | struct type *type2 = check_typedef (value_type (arg2)); | |
78134374 | 640 | int t1_is_vec = (type1->code () == TYPE_CODE_ARRAY |
bd63c870 | 641 | && type1->is_vector ()); |
78134374 | 642 | int t2_is_vec = (type2->code () == TYPE_CODE_ARRAY |
bd63c870 | 643 | && type2->is_vector ()); |
f4b8a18d KW |
644 | |
645 | if (!t1_is_vec && !t2_is_vec) | |
646 | { | |
647 | int tmp = scalar_relop (arg1, arg2, op); | |
648 | struct type *type = | |
649 | language_bool_type (exp->language_defn, exp->gdbarch); | |
650 | ||
651 | val = value_from_longest (type, tmp); | |
652 | } | |
653 | else if (t1_is_vec && t2_is_vec) | |
654 | { | |
655 | val = vector_relop (exp, arg1, arg2, op); | |
656 | } | |
657 | else | |
658 | { | |
659 | /* Widen the scalar operand to a vector. */ | |
660 | struct value **v = t1_is_vec ? &arg2 : &arg1; | |
661 | struct type *t = t1_is_vec ? type2 : type1; | |
662 | ||
78134374 | 663 | if (t->code () != TYPE_CODE_FLT && !is_integral_type (t)) |
f4b8a18d KW |
664 | error (_("Argument to operation not a number or boolean.")); |
665 | ||
8954db33 | 666 | *v = opencl_value_cast (t1_is_vec ? type1 : type2, *v); |
f4b8a18d KW |
667 | val = vector_relop (exp, arg1, arg2, op); |
668 | } | |
669 | ||
670 | return val; | |
671 | } | |
672 | ||
673 | /* Expression evaluator for the OpenCL. Most operations are delegated to | |
674 | evaluate_subexp_standard; see that function for a description of the | |
675 | arguments. */ | |
676 | ||
677 | static struct value * | |
678 | evaluate_subexp_opencl (struct type *expect_type, struct expression *exp, | |
679 | int *pos, enum noside noside) | |
680 | { | |
681 | enum exp_opcode op = exp->elts[*pos].opcode; | |
682 | struct value *arg1 = NULL; | |
683 | struct value *arg2 = NULL; | |
684 | struct type *type1, *type2; | |
685 | ||
686 | switch (op) | |
687 | { | |
8954db33 AB |
688 | /* Handle assignment and cast operators to support OpenCL-style |
689 | scalar-to-vector widening. */ | |
690 | case BINOP_ASSIGN: | |
691 | (*pos)++; | |
fe1fe7ea | 692 | arg1 = evaluate_subexp (nullptr, exp, pos, noside); |
8954db33 AB |
693 | type1 = value_type (arg1); |
694 | arg2 = evaluate_subexp (type1, exp, pos, noside); | |
695 | ||
696 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) | |
697 | return arg1; | |
698 | ||
699 | if (deprecated_value_modifiable (arg1) | |
700 | && VALUE_LVAL (arg1) != lval_internalvar) | |
701 | arg2 = opencl_value_cast (type1, arg2); | |
702 | ||
703 | return value_assign (arg1, arg2); | |
704 | ||
705 | case UNOP_CAST: | |
706 | type1 = exp->elts[*pos + 1].type; | |
707 | (*pos) += 2; | |
708 | arg1 = evaluate_subexp (type1, exp, pos, noside); | |
709 | ||
710 | if (noside == EVAL_SKIP) | |
711 | return value_from_longest (builtin_type (exp->gdbarch)-> | |
712 | builtin_int, 1); | |
713 | ||
714 | return opencl_value_cast (type1, arg1); | |
715 | ||
716 | case UNOP_CAST_TYPE: | |
717 | (*pos)++; | |
718 | arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS); | |
719 | type1 = value_type (arg1); | |
720 | arg1 = evaluate_subexp (type1, exp, pos, noside); | |
721 | ||
722 | if (noside == EVAL_SKIP) | |
723 | return value_from_longest (builtin_type (exp->gdbarch)-> | |
724 | builtin_int, 1); | |
725 | ||
726 | return opencl_value_cast (type1, arg1); | |
727 | ||
f4b8a18d KW |
728 | /* Handle binary relational and equality operators that are either not |
729 | or differently defined for GNU vectors. */ | |
730 | case BINOP_EQUAL: | |
731 | case BINOP_NOTEQUAL: | |
732 | case BINOP_LESS: | |
733 | case BINOP_GTR: | |
734 | case BINOP_GEQ: | |
735 | case BINOP_LEQ: | |
736 | (*pos)++; | |
fe1fe7ea | 737 | arg1 = evaluate_subexp (nullptr, exp, pos, noside); |
f4b8a18d KW |
738 | arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside); |
739 | ||
740 | if (noside == EVAL_SKIP) | |
741 | return value_from_longest (builtin_type (exp->gdbarch)-> | |
742 | builtin_int, 1); | |
743 | ||
744 | return opencl_relop (exp, arg1, arg2, op); | |
745 | ||
746 | /* Handle the logical unary operator not(!). */ | |
747 | case UNOP_LOGICAL_NOT: | |
748 | (*pos)++; | |
fe1fe7ea | 749 | arg1 = evaluate_subexp (nullptr, exp, pos, noside); |
f4b8a18d KW |
750 | |
751 | if (noside == EVAL_SKIP) | |
752 | return value_from_longest (builtin_type (exp->gdbarch)-> | |
753 | builtin_int, 1); | |
754 | ||
755 | return opencl_logical_not (exp, arg1); | |
756 | ||
757 | /* Handle the logical operator and(&&) and or(||). */ | |
758 | case BINOP_LOGICAL_AND: | |
759 | case BINOP_LOGICAL_OR: | |
760 | (*pos)++; | |
fe1fe7ea | 761 | arg1 = evaluate_subexp (nullptr, exp, pos, noside); |
f4b8a18d KW |
762 | |
763 | if (noside == EVAL_SKIP) | |
764 | { | |
fe1fe7ea | 765 | evaluate_subexp (nullptr, exp, pos, noside); |
f4b8a18d KW |
766 | |
767 | return value_from_longest (builtin_type (exp->gdbarch)-> | |
768 | builtin_int, 1); | |
769 | } | |
770 | else | |
771 | { | |
772 | /* For scalar operations we need to avoid evaluating operands | |
85102364 | 773 | unnecessarily. However, for vector operations we always need to |
f4b8a18d KW |
774 | evaluate both operands. Unfortunately we only know which of the |
775 | two cases apply after we know the type of the second operand. | |
776 | Therefore we evaluate it once using EVAL_AVOID_SIDE_EFFECTS. */ | |
777 | int oldpos = *pos; | |
778 | ||
fe1fe7ea | 779 | arg2 = evaluate_subexp (nullptr, exp, pos, EVAL_AVOID_SIDE_EFFECTS); |
f4b8a18d KW |
780 | *pos = oldpos; |
781 | type1 = check_typedef (value_type (arg1)); | |
782 | type2 = check_typedef (value_type (arg2)); | |
783 | ||
bd63c870 SM |
784 | if ((type1->code () == TYPE_CODE_ARRAY && type1->is_vector ()) |
785 | || (type2->code () == TYPE_CODE_ARRAY && type2->is_vector ())) | |
f4b8a18d | 786 | { |
fe1fe7ea | 787 | arg2 = evaluate_subexp (nullptr, exp, pos, noside); |
f4b8a18d KW |
788 | |
789 | return opencl_relop (exp, arg1, arg2, op); | |
790 | } | |
791 | else | |
792 | { | |
793 | /* For scalar built-in types, only evaluate the right | |
794 | hand operand if the left hand operand compares | |
795 | unequal(&&)/equal(||) to 0. */ | |
796 | int res; | |
797 | int tmp = value_logical_not (arg1); | |
798 | ||
799 | if (op == BINOP_LOGICAL_OR) | |
800 | tmp = !tmp; | |
801 | ||
fe1fe7ea SM |
802 | arg2 |
803 | = evaluate_subexp (nullptr, exp, pos, tmp ? EVAL_SKIP : noside); | |
f4b8a18d KW |
804 | type1 = language_bool_type (exp->language_defn, exp->gdbarch); |
805 | ||
806 | if (op == BINOP_LOGICAL_AND) | |
807 | res = !tmp && !value_logical_not (arg2); | |
808 | else /* BINOP_LOGICAL_OR */ | |
809 | res = tmp || !value_logical_not (arg2); | |
810 | ||
811 | return value_from_longest (type1, res); | |
812 | } | |
813 | } | |
814 | ||
815 | /* Handle the ternary selection operator. */ | |
816 | case TERNOP_COND: | |
817 | (*pos)++; | |
fe1fe7ea | 818 | arg1 = evaluate_subexp (nullptr, exp, pos, noside); |
f4b8a18d | 819 | type1 = check_typedef (value_type (arg1)); |
bd63c870 | 820 | if (type1->code () == TYPE_CODE_ARRAY && type1->is_vector ()) |
f4b8a18d KW |
821 | { |
822 | struct value *arg3, *tmp, *ret; | |
823 | struct type *eltype2, *type3, *eltype3; | |
824 | int t2_is_vec, t3_is_vec, i; | |
825 | LONGEST lowb1, lowb2, lowb3, highb1, highb2, highb3; | |
826 | ||
fe1fe7ea SM |
827 | arg2 = evaluate_subexp (nullptr, exp, pos, noside); |
828 | arg3 = evaluate_subexp (nullptr, exp, pos, noside); | |
f4b8a18d KW |
829 | type2 = check_typedef (value_type (arg2)); |
830 | type3 = check_typedef (value_type (arg3)); | |
831 | t2_is_vec | |
bd63c870 | 832 | = type2->code () == TYPE_CODE_ARRAY && type2->is_vector (); |
f4b8a18d | 833 | t3_is_vec |
bd63c870 | 834 | = type3->code () == TYPE_CODE_ARRAY && type3->is_vector (); |
f4b8a18d KW |
835 | |
836 | /* Widen the scalar operand to a vector if necessary. */ | |
837 | if (t2_is_vec || !t3_is_vec) | |
838 | { | |
8954db33 | 839 | arg3 = opencl_value_cast (type2, arg3); |
f4b8a18d KW |
840 | type3 = value_type (arg3); |
841 | } | |
842 | else if (!t2_is_vec || t3_is_vec) | |
843 | { | |
8954db33 | 844 | arg2 = opencl_value_cast (type3, arg2); |
f4b8a18d KW |
845 | type2 = value_type (arg2); |
846 | } | |
847 | else if (!t2_is_vec || !t3_is_vec) | |
848 | { | |
849 | /* Throw an error if arg2 or arg3 aren't vectors. */ | |
850 | error (_("\ | |
851 | Cannot perform conditional operation on incompatible types")); | |
852 | } | |
853 | ||
854 | eltype2 = check_typedef (TYPE_TARGET_TYPE (type2)); | |
855 | eltype3 = check_typedef (TYPE_TARGET_TYPE (type3)); | |
856 | ||
857 | if (!get_array_bounds (type1, &lowb1, &highb1) | |
858 | || !get_array_bounds (type2, &lowb2, &highb2) | |
859 | || !get_array_bounds (type3, &lowb3, &highb3)) | |
860 | error (_("Could not determine the vector bounds")); | |
861 | ||
862 | /* Throw an error if the types of arg2 or arg3 are incompatible. */ | |
78134374 | 863 | if (eltype2->code () != eltype3->code () |
f4b8a18d | 864 | || TYPE_LENGTH (eltype2) != TYPE_LENGTH (eltype3) |
c6d940a9 | 865 | || eltype2->is_unsigned () != eltype3->is_unsigned () |
f4b8a18d KW |
866 | || lowb2 != lowb3 || highb2 != highb3) |
867 | error (_("\ | |
868 | Cannot perform operation on vectors with different types")); | |
869 | ||
870 | /* Throw an error if the sizes of arg1 and arg2/arg3 differ. */ | |
871 | if (lowb1 != lowb2 || lowb1 != lowb3 | |
872 | || highb1 != highb2 || highb1 != highb3) | |
873 | error (_("\ | |
874 | Cannot perform conditional operation on vectors with different sizes")); | |
875 | ||
876 | ret = allocate_value (type2); | |
877 | ||
878 | for (i = 0; i < highb1 - lowb1 + 1; i++) | |
879 | { | |
880 | tmp = value_logical_not (value_subscript (arg1, i)) ? | |
881 | value_subscript (arg3, i) : value_subscript (arg2, i); | |
882 | memcpy (value_contents_writeable (ret) + | |
883 | i * TYPE_LENGTH (eltype2), value_contents_all (tmp), | |
884 | TYPE_LENGTH (eltype2)); | |
885 | } | |
886 | ||
887 | return ret; | |
888 | } | |
889 | else | |
890 | { | |
891 | if (value_logical_not (arg1)) | |
892 | { | |
893 | /* Skip the second operand. */ | |
fe1fe7ea | 894 | evaluate_subexp (nullptr, exp, pos, EVAL_SKIP); |
f4b8a18d | 895 | |
fe1fe7ea | 896 | return evaluate_subexp (nullptr, exp, pos, noside); |
f4b8a18d KW |
897 | } |
898 | else | |
899 | { | |
900 | /* Skip the third operand. */ | |
fe1fe7ea SM |
901 | arg2 = evaluate_subexp (nullptr, exp, pos, noside); |
902 | evaluate_subexp (nullptr, exp, pos, EVAL_SKIP); | |
f4b8a18d KW |
903 | |
904 | return arg2; | |
905 | } | |
906 | } | |
907 | ||
908 | /* Handle STRUCTOP_STRUCT to allow component access on OpenCL vectors. */ | |
909 | case STRUCTOP_STRUCT: | |
910 | { | |
911 | int pc = (*pos)++; | |
912 | int tem = longest_to_int (exp->elts[pc + 1].longconst); | |
913 | ||
914 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); | |
fe1fe7ea | 915 | arg1 = evaluate_subexp (nullptr, exp, pos, noside); |
f4b8a18d KW |
916 | type1 = check_typedef (value_type (arg1)); |
917 | ||
918 | if (noside == EVAL_SKIP) | |
919 | { | |
920 | return value_from_longest (builtin_type (exp->gdbarch)-> | |
921 | builtin_int, 1); | |
922 | } | |
bd63c870 | 923 | else if (type1->code () == TYPE_CODE_ARRAY && type1->is_vector ()) |
f4b8a18d KW |
924 | { |
925 | return opencl_component_ref (exp, arg1, &exp->elts[pc + 2].string, | |
926 | noside); | |
927 | } | |
928 | else | |
929 | { | |
ac1ca910 TT |
930 | struct value *v = value_struct_elt (&arg1, NULL, |
931 | &exp->elts[pc + 2].string, NULL, | |
932 | "structure"); | |
933 | ||
934 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
51415b9f | 935 | v = value_zero (value_type (v), VALUE_LVAL (v)); |
ac1ca910 | 936 | return v; |
f4b8a18d KW |
937 | } |
938 | } | |
939 | default: | |
940 | break; | |
941 | } | |
942 | ||
943 | return evaluate_subexp_c (expect_type, exp, pos, noside); | |
944 | } | |
945 | ||
f4b8a18d KW |
946 | const struct exp_descriptor exp_descriptor_opencl = |
947 | { | |
948 | print_subexp_standard, | |
949 | operator_length_standard, | |
950 | operator_check_standard, | |
951 | op_name_standard, | |
952 | dump_subexp_body_standard, | |
953 | evaluate_subexp_opencl | |
954 | }; | |
955 | ||
0874fd07 AB |
956 | /* Class representing the OpenCL language. */ |
957 | ||
958 | class opencl_language : public language_defn | |
959 | { | |
960 | public: | |
961 | opencl_language () | |
0e25e767 | 962 | : language_defn (language_opencl) |
0874fd07 | 963 | { /* Nothing. */ } |
1fb314aa | 964 | |
6f7664a9 AB |
965 | /* See language.h. */ |
966 | ||
967 | const char *name () const override | |
968 | { return "opencl"; } | |
969 | ||
970 | /* See language.h. */ | |
971 | ||
972 | const char *natural_name () const override | |
973 | { return "OpenCL C"; } | |
974 | ||
1fb314aa AB |
975 | /* See language.h. */ |
976 | void language_arch_info (struct gdbarch *gdbarch, | |
977 | struct language_arch_info *lai) const override | |
978 | { | |
7bea47f0 AB |
979 | /* Helper function to allow shorter lines below. */ |
980 | auto add = [&] (struct type * t) -> struct type * | |
981 | { | |
982 | lai->add_primitive_type (t); | |
983 | return t; | |
984 | }; | |
1fb314aa | 985 | |
7bea47f0 AB |
986 | /* Helper macro to create strings. */ |
987 | #define OCL_STRING(S) #S | |
988 | ||
989 | /* This macro allocates and assigns the type struct pointers | |
990 | for the vector types. */ | |
991 | #define BUILD_OCL_VTYPES(TYPE, ELEMENT_TYPE) \ | |
992 | do \ | |
993 | { \ | |
994 | struct type *tmp; \ | |
995 | tmp = add (init_vector_type (ELEMENT_TYPE, 2)); \ | |
996 | tmp->set_name (OCL_STRING(TYPE ## 2)); \ | |
997 | tmp = add (init_vector_type (ELEMENT_TYPE, 3)); \ | |
998 | tmp->set_name (OCL_STRING(TYPE ## 3)); \ | |
999 | TYPE_LENGTH (tmp) = 4 * TYPE_LENGTH (ELEMENT_TYPE); \ | |
1000 | tmp = add (init_vector_type (ELEMENT_TYPE, 4)); \ | |
1001 | tmp->set_name (OCL_STRING(TYPE ## 4)); \ | |
1002 | tmp = add (init_vector_type (ELEMENT_TYPE, 8)); \ | |
1003 | tmp->set_name (OCL_STRING(TYPE ## 8)); \ | |
1004 | tmp = init_vector_type (ELEMENT_TYPE, 16); \ | |
1005 | tmp->set_name (OCL_STRING(TYPE ## 16)); \ | |
1006 | } \ | |
1007 | while (false) | |
1008 | ||
1009 | struct type *el_type, *char_type, *int_type; | |
1010 | ||
1011 | char_type = el_type = add (arch_integer_type (gdbarch, 8, 0, "char")); | |
1012 | BUILD_OCL_VTYPES (char, el_type); | |
1013 | el_type = add (arch_integer_type (gdbarch, 8, 1, "uchar")); | |
1014 | BUILD_OCL_VTYPES (uchar, el_type); | |
1015 | el_type = add (arch_integer_type (gdbarch, 16, 0, "short")); | |
1016 | BUILD_OCL_VTYPES (short, el_type); | |
1017 | el_type = add (arch_integer_type (gdbarch, 16, 1, "ushort")); | |
1018 | BUILD_OCL_VTYPES (ushort, el_type); | |
1019 | int_type = el_type = add (arch_integer_type (gdbarch, 32, 0, "int")); | |
1020 | BUILD_OCL_VTYPES (int, el_type); | |
1021 | el_type = add (arch_integer_type (gdbarch, 32, 1, "uint")); | |
1022 | BUILD_OCL_VTYPES (uint, el_type); | |
1023 | el_type = add (arch_integer_type (gdbarch, 64, 0, "long")); | |
1024 | BUILD_OCL_VTYPES (long, el_type); | |
1025 | el_type = add (arch_integer_type (gdbarch, 64, 1, "ulong")); | |
1026 | BUILD_OCL_VTYPES (ulong, el_type); | |
1027 | el_type = add (arch_float_type (gdbarch, 16, "half", floatformats_ieee_half)); | |
1028 | BUILD_OCL_VTYPES (half, el_type); | |
1029 | el_type = add (arch_float_type (gdbarch, 32, "float", floatformats_ieee_single)); | |
1030 | BUILD_OCL_VTYPES (float, el_type); | |
1031 | el_type = add (arch_float_type (gdbarch, 64, "double", floatformats_ieee_double)); | |
1032 | BUILD_OCL_VTYPES (double, el_type); | |
1033 | ||
1034 | add (arch_boolean_type (gdbarch, 8, 1, "bool")); | |
1035 | add (arch_integer_type (gdbarch, 8, 1, "unsigned char")); | |
1036 | add (arch_integer_type (gdbarch, 16, 1, "unsigned short")); | |
1037 | add (arch_integer_type (gdbarch, 32, 1, "unsigned int")); | |
1038 | add (arch_integer_type (gdbarch, 64, 1, "unsigned long")); | |
1039 | add (arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 1, "size_t")); | |
1040 | add (arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 0, "ptrdiff_t")); | |
1041 | add (arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 0, "intptr_t")); | |
1042 | add (arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 1, "uintptr_t")); | |
1043 | add (arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void")); | |
1fb314aa AB |
1044 | |
1045 | /* Type of elements of strings. */ | |
7bea47f0 | 1046 | lai->set_string_char_type (char_type); |
1fb314aa AB |
1047 | |
1048 | /* Specifies the return type of logical and relational operations. */ | |
7bea47f0 | 1049 | lai->set_bool_type (int_type, "int"); |
1fb314aa | 1050 | } |
fbfb0a46 AB |
1051 | |
1052 | /* See language.h. */ | |
1053 | ||
1054 | void print_type (struct type *type, const char *varstring, | |
1055 | struct ui_file *stream, int show, int level, | |
1056 | const struct type_print_options *flags) const override | |
1057 | { | |
1058 | /* We nearly always defer to C type printing, except that vector types | |
1059 | are considered primitive in OpenCL, and should always be printed | |
1060 | using their TYPE_NAME. */ | |
1061 | if (show > 0) | |
1062 | { | |
1063 | type = check_typedef (type); | |
bd63c870 | 1064 | if (type->code () == TYPE_CODE_ARRAY && type->is_vector () |
fbfb0a46 AB |
1065 | && type->name () != NULL) |
1066 | show = 0; | |
1067 | } | |
1068 | ||
1069 | c_print_type (type, varstring, stream, show, level, flags); | |
1070 | } | |
1ac14a04 AB |
1071 | |
1072 | /* See language.h. */ | |
1073 | ||
1074 | enum macro_expansion macro_expansion () const override | |
1075 | { return macro_expansion_c; } | |
5aba6ebe AB |
1076 | |
1077 | /* See language.h. */ | |
1078 | ||
1079 | const struct exp_descriptor *expression_ops () const override | |
1080 | { return &exp_descriptor_opencl; } | |
b7c6e27d AB |
1081 | |
1082 | /* See language.h. */ | |
1083 | ||
1084 | const struct op_print *opcode_print_table () const override | |
1085 | { return c_op_print_tab; } | |
0874fd07 AB |
1086 | }; |
1087 | ||
1088 | /* Single instance of the OpenCL language class. */ | |
1089 | ||
1090 | static opencl_language opencl_language_defn; |