}
}
-/* Expression evaluator for the C language family. Most operations
- are delegated to evaluate_subexp_standard; see that function for a
- description of the arguments. */
-
-struct value *
-evaluate_subexp_c (struct type *expect_type, struct expression *exp,
- int *pos, enum noside noside)
-{
- enum exp_opcode op = exp->elts[*pos].opcode;
-
- switch (op)
- {
- case OP_STRING:
- {
- int oplen, limit;
- struct type *type;
- struct value *result;
- c_string_type dest_type;
- const char *dest_charset;
- int satisfy_expected = 0;
-
- auto_obstack output;
-
- ++*pos;
- oplen = longest_to_int (exp->elts[*pos].longconst);
-
- ++*pos;
- limit = *pos + BYTES_TO_EXP_ELEM (oplen + 1);
- dest_type = ((enum c_string_type_values)
- longest_to_int (exp->elts[*pos].longconst));
- switch (dest_type & ~C_CHAR)
- {
- case C_STRING:
- type = language_string_char_type (exp->language_defn,
- exp->gdbarch);
- break;
- case C_WIDE_STRING:
- type = lookup_typename (exp->language_defn, "wchar_t", NULL, 0);
- break;
- case C_STRING_16:
- type = lookup_typename (exp->language_defn, "char16_t", NULL, 0);
- break;
- case C_STRING_32:
- type = lookup_typename (exp->language_defn, "char32_t", NULL, 0);
- break;
- default:
- internal_error (__FILE__, __LINE__, _("unhandled c_string_type"));
- }
-
- /* Ensure TYPE_LENGTH is valid for TYPE. */
- check_typedef (type);
-
- /* If the caller expects an array of some integral type,
- satisfy them. If something odder is expected, rely on the
- caller to cast. */
- if (expect_type && expect_type->code () == TYPE_CODE_ARRAY)
- {
- struct type *element_type
- = check_typedef (TYPE_TARGET_TYPE (expect_type));
-
- if (element_type->code () == TYPE_CODE_INT
- || element_type->code () == TYPE_CODE_CHAR)
- {
- type = element_type;
- satisfy_expected = 1;
- }
- }
-
- dest_charset = charset_for_string_type (dest_type, exp->gdbarch);
-
- ++*pos;
- while (*pos < limit)
- {
- int len;
-
- len = longest_to_int (exp->elts[*pos].longconst);
-
- ++*pos;
- if (noside != EVAL_SKIP)
- parse_one_string (&output, &exp->elts[*pos].string, len,
- dest_charset, type);
- *pos += BYTES_TO_EXP_ELEM (len);
- }
-
- /* Skip the trailing length and opcode. */
- *pos += 2;
-
- if (noside == EVAL_SKIP)
- {
- /* Return a dummy value of the appropriate type. */
- if (expect_type != NULL)
- result = allocate_value (expect_type);
- else if ((dest_type & C_CHAR) != 0)
- result = allocate_value (type);
- else
- result = value_cstring ("", 0, type);
- return result;
- }
-
- if ((dest_type & C_CHAR) != 0)
- {
- LONGEST value;
-
- if (obstack_object_size (&output) != TYPE_LENGTH (type))
- error (_("Could not convert character "
- "constant to target character set"));
- value = unpack_long (type, (gdb_byte *) obstack_base (&output));
- result = value_from_longest (type, value);
- }
- else
- {
- int i;
-
- /* Write the terminating character. */
- for (i = 0; i < TYPE_LENGTH (type); ++i)
- obstack_1grow (&output, 0);
-
- if (satisfy_expected)
- {
- LONGEST low_bound, high_bound;
- int element_size = TYPE_LENGTH (type);
-
- if (!get_discrete_bounds (expect_type->index_type (),
- &low_bound, &high_bound))
- {
- low_bound = 0;
- high_bound = (TYPE_LENGTH (expect_type) / element_size) - 1;
- }
- if (obstack_object_size (&output) / element_size
- > (high_bound - low_bound + 1))
- error (_("Too many array elements"));
-
- result = allocate_value (expect_type);
- memcpy (value_contents_raw (result), obstack_base (&output),
- obstack_object_size (&output));
- }
- else
- result = value_cstring ((const char *) obstack_base (&output),
- obstack_object_size (&output),
- type);
- }
- return result;
- }
- break;
-
- default:
- break;
- }
- return evaluate_subexp_standard (expect_type, exp, pos, noside);
-}
-
namespace expr
{
lai->set_bool_type (builtin->builtin_int);
}
-const struct exp_descriptor exp_descriptor_c =
-{
- print_subexp_standard,
- operator_length_standard,
- operator_check_standard,
- dump_subexp_body_standard,
- evaluate_subexp_c
-};
-
/* Class representing the C language. */
class c_language : public language_defn
/* See language.h. */
- const struct exp_descriptor *expression_ops () const override
- { return &exp_descriptor_c; }
-
- /* See language.h. */
-
const struct op_print *opcode_print_table () const override
{ return c_op_print_tab; }
};
/* See language.h. */
- const struct exp_descriptor *expression_ops () const override
- { return &exp_descriptor_c; }
-
- /* See language.h. */
-
const struct op_print *opcode_print_table () const override
{ return c_op_print_tab; }
/* See language.h. */
- const struct exp_descriptor *expression_ops () const override
- { return &exp_descriptor_c; }
-
- /* See language.h. */
-
const struct op_print *opcode_print_table () const override
{ return c_op_print_tab; }
};
/* See language.h. */
- const struct exp_descriptor *expression_ops () const override
- { return &exp_descriptor_c; }
-
- /* See language.h. */
-
const struct op_print *opcode_print_table () const override
{ return c_op_print_tab; }
};
return value_assign (arg1, arg2);
}
-/* Expression evaluator for the OpenCL. Most operations are delegated to
- evaluate_subexp_standard; see that function for a description of the
- arguments. */
-
-static struct value *
-evaluate_subexp_opencl (struct type *expect_type, struct expression *exp,
- int *pos, enum noside noside)
-{
- enum exp_opcode op = exp->elts[*pos].opcode;
- struct value *arg1 = NULL;
- struct value *arg2 = NULL;
- struct type *type1, *type2;
-
- switch (op)
- {
- /* Handle assignment and cast operators to support OpenCL-style
- scalar-to-vector widening. */
- case BINOP_ASSIGN:
- (*pos)++;
- arg1 = evaluate_subexp (nullptr, exp, pos, noside);
- type1 = value_type (arg1);
- arg2 = evaluate_subexp (type1, exp, pos, noside);
-
- return eval_opencl_assign (expect_type, exp, noside, op, arg1, arg2);
-
- case UNOP_CAST:
- type1 = exp->elts[*pos + 1].type;
- (*pos) += 2;
- arg1 = evaluate_subexp (type1, exp, pos, noside);
-
- if (noside == EVAL_SKIP)
- return value_from_longest (builtin_type (exp->gdbarch)->
- builtin_int, 1);
-
- return opencl_value_cast (type1, arg1);
-
- case UNOP_CAST_TYPE:
- (*pos)++;
- arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
- type1 = value_type (arg1);
- arg1 = evaluate_subexp (type1, exp, pos, noside);
-
- if (noside == EVAL_SKIP)
- return value_from_longest (builtin_type (exp->gdbarch)->
- builtin_int, 1);
-
- return opencl_value_cast (type1, arg1);
-
- /* Handle binary relational and equality operators that are either not
- or differently defined for GNU vectors. */
- case BINOP_EQUAL:
- case BINOP_NOTEQUAL:
- case BINOP_LESS:
- case BINOP_GTR:
- case BINOP_GEQ:
- case BINOP_LEQ:
- (*pos)++;
- arg1 = evaluate_subexp (nullptr, exp, pos, noside);
- arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
-
- if (noside == EVAL_SKIP)
- return value_from_longest (builtin_type (exp->gdbarch)->
- builtin_int, 1);
-
- return opencl_relop (expect_type, exp, noside, op, arg1, arg2);
-
- /* Handle the logical unary operator not(!). */
- case UNOP_LOGICAL_NOT:
- (*pos)++;
- arg1 = evaluate_subexp (nullptr, exp, pos, noside);
-
- if (noside == EVAL_SKIP)
- return value_from_longest (builtin_type (exp->gdbarch)->
- builtin_int, 1);
-
- return opencl_logical_not (expect_type, exp, noside, op, arg1);
-
- /* Handle the logical operator and(&&) and or(||). */
- case BINOP_LOGICAL_AND:
- case BINOP_LOGICAL_OR:
- (*pos)++;
- arg1 = evaluate_subexp (nullptr, exp, pos, noside);
-
- if (noside == EVAL_SKIP)
- {
- evaluate_subexp (nullptr, exp, pos, noside);
-
- return value_from_longest (builtin_type (exp->gdbarch)->
- builtin_int, 1);
- }
- else
- {
- /* For scalar operations we need to avoid evaluating operands
- unnecessarily. However, for vector operations we always need to
- evaluate both operands. Unfortunately we only know which of the
- two cases apply after we know the type of the second operand.
- Therefore we evaluate it once using EVAL_AVOID_SIDE_EFFECTS. */
- int oldpos = *pos;
-
- arg2 = evaluate_subexp (nullptr, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
- *pos = oldpos;
- type1 = check_typedef (value_type (arg1));
- type2 = check_typedef (value_type (arg2));
-
- if ((type1->code () == TYPE_CODE_ARRAY && type1->is_vector ())
- || (type2->code () == TYPE_CODE_ARRAY && type2->is_vector ()))
- {
- arg2 = evaluate_subexp (nullptr, exp, pos, noside);
-
- return opencl_relop (nullptr, exp, noside, op, arg1, arg2);
- }
- else
- {
- /* For scalar built-in types, only evaluate the right
- hand operand if the left hand operand compares
- unequal(&&)/equal(||) to 0. */
- int res;
- int tmp = value_logical_not (arg1);
-
- if (op == BINOP_LOGICAL_OR)
- tmp = !tmp;
-
- arg2
- = evaluate_subexp (nullptr, exp, pos, tmp ? EVAL_SKIP : noside);
- type1 = language_bool_type (exp->language_defn, exp->gdbarch);
-
- if (op == BINOP_LOGICAL_AND)
- res = !tmp && !value_logical_not (arg2);
- else /* BINOP_LOGICAL_OR */
- res = tmp || !value_logical_not (arg2);
-
- return value_from_longest (type1, res);
- }
- }
-
- /* Handle the ternary selection operator. */
- case TERNOP_COND:
- (*pos)++;
- arg1 = evaluate_subexp (nullptr, exp, pos, noside);
- type1 = check_typedef (value_type (arg1));
- if (type1->code () == TYPE_CODE_ARRAY && type1->is_vector ())
- {
- struct value *arg3, *tmp, *ret;
- struct type *eltype2, *type3, *eltype3;
- int t2_is_vec, t3_is_vec, i;
- LONGEST lowb1, lowb2, lowb3, highb1, highb2, highb3;
-
- arg2 = evaluate_subexp (nullptr, exp, pos, noside);
- arg3 = evaluate_subexp (nullptr, exp, pos, noside);
- type2 = check_typedef (value_type (arg2));
- type3 = check_typedef (value_type (arg3));
- t2_is_vec
- = type2->code () == TYPE_CODE_ARRAY && type2->is_vector ();
- t3_is_vec
- = type3->code () == TYPE_CODE_ARRAY && type3->is_vector ();
-
- /* Widen the scalar operand to a vector if necessary. */
- if (t2_is_vec || !t3_is_vec)
- {
- arg3 = opencl_value_cast (type2, arg3);
- type3 = value_type (arg3);
- }
- else if (!t2_is_vec || t3_is_vec)
- {
- arg2 = opencl_value_cast (type3, arg2);
- type2 = value_type (arg2);
- }
- else if (!t2_is_vec || !t3_is_vec)
- {
- /* Throw an error if arg2 or arg3 aren't vectors. */
- error (_("\
-Cannot perform conditional operation on incompatible types"));
- }
-
- eltype2 = check_typedef (TYPE_TARGET_TYPE (type2));
- eltype3 = check_typedef (TYPE_TARGET_TYPE (type3));
-
- if (!get_array_bounds (type1, &lowb1, &highb1)
- || !get_array_bounds (type2, &lowb2, &highb2)
- || !get_array_bounds (type3, &lowb3, &highb3))
- error (_("Could not determine the vector bounds"));
-
- /* Throw an error if the types of arg2 or arg3 are incompatible. */
- if (eltype2->code () != eltype3->code ()
- || TYPE_LENGTH (eltype2) != TYPE_LENGTH (eltype3)
- || eltype2->is_unsigned () != eltype3->is_unsigned ()
- || lowb2 != lowb3 || highb2 != highb3)
- error (_("\
-Cannot perform operation on vectors with different types"));
-
- /* Throw an error if the sizes of arg1 and arg2/arg3 differ. */
- if (lowb1 != lowb2 || lowb1 != lowb3
- || highb1 != highb2 || highb1 != highb3)
- error (_("\
-Cannot perform conditional operation on vectors with different sizes"));
-
- ret = allocate_value (type2);
-
- for (i = 0; i < highb1 - lowb1 + 1; i++)
- {
- tmp = value_logical_not (value_subscript (arg1, i)) ?
- value_subscript (arg3, i) : value_subscript (arg2, i);
- memcpy (value_contents_writeable (ret) +
- i * TYPE_LENGTH (eltype2), value_contents_all (tmp),
- TYPE_LENGTH (eltype2));
- }
-
- return ret;
- }
- else
- {
- if (value_logical_not (arg1))
- {
- /* Skip the second operand. */
- evaluate_subexp (nullptr, exp, pos, EVAL_SKIP);
-
- return evaluate_subexp (nullptr, exp, pos, noside);
- }
- else
- {
- /* Skip the third operand. */
- arg2 = evaluate_subexp (nullptr, exp, pos, noside);
- evaluate_subexp (nullptr, exp, pos, EVAL_SKIP);
-
- return arg2;
- }
- }
-
- /* Handle STRUCTOP_STRUCT to allow component access on OpenCL vectors. */
- case STRUCTOP_STRUCT:
- {
- int pc = (*pos)++;
- int tem = longest_to_int (exp->elts[pc + 1].longconst);
-
- (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
- arg1 = evaluate_subexp (nullptr, exp, pos, noside);
- type1 = check_typedef (value_type (arg1));
-
- if (noside == EVAL_SKIP)
- {
- return value_from_longest (builtin_type (exp->gdbarch)->
- builtin_int, 1);
- }
- else if (type1->code () == TYPE_CODE_ARRAY && type1->is_vector ())
- {
- return opencl_component_ref (exp, arg1, &exp->elts[pc + 2].string,
- noside);
- }
- else
- {
- struct value *v = value_struct_elt (&arg1, NULL,
- &exp->elts[pc + 2].string, NULL,
- "structure");
-
- if (noside == EVAL_AVOID_SIDE_EFFECTS)
- v = value_zero (value_type (v), VALUE_LVAL (v));
- return v;
- }
- }
- default:
- break;
- }
-
- return evaluate_subexp_c (expect_type, exp, pos, noside);
-}
-
namespace expr
{
} /* namespace expr */
-const struct exp_descriptor exp_descriptor_opencl =
-{
- print_subexp_standard,
- operator_length_standard,
- operator_check_standard,
- dump_subexp_body_standard,
- evaluate_subexp_opencl
-};
-
/* Class representing the OpenCL language. */
class opencl_language : public language_defn
/* See language.h. */
- const struct exp_descriptor *expression_ops () const override
- { return &exp_descriptor_opencl; }
-
- /* See language.h. */
-
const struct op_print *opcode_print_table () const override
{ return c_op_print_tab; }
};