From 33b79214629c2b1b219e82bb34aed5fb03913634 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 8 Mar 2021 07:27:57 -0700 Subject: [PATCH] Introduce opencl_structop_operation This adds class opencl_structop_operation, which implements STRUCTOP_STRUCT for OpenCL. gdb/ChangeLog 2021-03-08 Tom Tromey * opencl-lang.c (opencl_structop_operation::evaluate): New method. * c-exp.h (class opencl_structop_operation): New. --- gdb/ChangeLog | 6 ++++++ gdb/c-exp.h | 16 ++++++++++++++++ gdb/opencl-lang.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 257f881e1cd..3c7d68374b2 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2021-03-08 Tom Tromey + + * opencl-lang.c (opencl_structop_operation::evaluate): New + method. + * c-exp.h (class opencl_structop_operation): New. + 2021-03-08 Tom Tromey * opencl-lang.c (opencl_logical_not): No longer static. Change diff --git a/gdb/c-exp.h b/gdb/c-exp.h index 1afe2d2fbee..58a16d5c0c8 100644 --- a/gdb/c-exp.h +++ b/gdb/c-exp.h @@ -170,6 +170,22 @@ using opencl_leq_operation = opencl_binop_operation; +/* STRUCTOP_STRUCT implementation for OpenCL. */ +class opencl_structop_operation + : public structop_base_operation +{ +public: + + using structop_base_operation::structop_base_operation; + + value *evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) override; + + enum exp_opcode opcode () const override + { return STRUCTOP_STRUCT; } +}; + }/* namespace expr */ #endif /* C_EXP_H */ diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c index 8ddcd76c589..317163966cd 100644 --- a/gdb/opencl-lang.c +++ b/gdb/opencl-lang.c @@ -958,6 +958,34 @@ Cannot perform conditional operation on vectors with different sizes")); return evaluate_subexp_c (expect_type, exp, pos, noside); } +namespace expr +{ + +value * +opencl_structop_operation::evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) +{ + value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside); + struct type *type1 = check_typedef (value_type (arg1)); + + if (type1->code () == TYPE_CODE_ARRAY && type1->is_vector ()) + return opencl_component_ref (exp, arg1, std::get<1> (m_storage).c_str (), + noside); + else + { + struct value *v = value_struct_elt (&arg1, NULL, + std::get<1> (m_storage).c_str (), + NULL, "structure"); + + if (noside == EVAL_AVOID_SIDE_EFFECTS) + v = value_zero (value_type (v), VALUE_LVAL (v)); + return v; + } +} + +} /* namespace expr */ + const struct exp_descriptor exp_descriptor_opencl = { print_subexp_standard, -- 2.30.2