aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-03-08 07:27:57 -0700
committerTom Tromey <tom@tromey.com>2021-03-08 07:28:17 -0700
commit9186293fd6bd4c3a4855c7aa62ad2ab1734077e6 (patch)
tree96b8629642559901874a0b406eb729307c82a379
parent1594e0bb3d35b05aa53519f08021fb15bf26f1dc (diff)
downloadgdb-9186293fd6bd4c3a4855c7aa62ad2ab1734077e6.zip
gdb-9186293fd6bd4c3a4855c7aa62ad2ab1734077e6.tar.gz
gdb-9186293fd6bd4c3a4855c7aa62ad2ab1734077e6.tar.bz2
Introduce ternop_cond_operation
This adds class ternop_cond_operation, which implements TERNOP_COND. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * expop.h (class ternop_cond_operation): New. * ax-gdb.c (ternop_cond_operation::do_generate_ax): New method.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/ax-gdb.c29
-rw-r--r--gdb/expop.h31
3 files changed, 65 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c3fc9c8..5eb9dca 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2021-03-08 Tom Tromey <tom@tromey.com>
+ * expop.h (class ternop_cond_operation): New.
+ * ax-gdb.c (ternop_cond_operation::do_generate_ax): New method.
+
+2021-03-08 Tom Tromey <tom@tromey.com>
+
* expop.h (class ternop_slice_operation): New.
* eval.c (eval_op_ternop): No longer static.
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index e25e294..87aa210 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -2390,6 +2390,35 @@ internalvar_operation::do_generate_ax (struct expression *exp,
"expressions cannot use convenience variables."), name);
}
+void
+ternop_cond_operation::do_generate_ax (struct expression *exp,
+ struct agent_expr *ax,
+ struct axs_value *value,
+ struct type *cast_type)
+{
+ struct axs_value value1, value2, value3;
+ int if1, end;
+
+ std::get<0> (m_storage)->generate_ax (exp, ax, &value1);
+ gen_usual_unary (ax, &value1);
+ /* For (A ? B : C), it's easiest to generate subexpression
+ bytecodes in order, but if_goto jumps on true, so we invert
+ the sense of A. Then we can do B by dropping through, and
+ jump to do C. */
+ gen_logical_not (ax, &value1, builtin_type (ax->gdbarch)->builtin_int);
+ if1 = ax_goto (ax, aop_if_goto);
+ std::get<1> (m_storage)->generate_ax (exp, ax, &value2);
+ gen_usual_unary (ax, &value2);
+ end = ax_goto (ax, aop_goto);
+ ax_label (ax, if1, ax->len);
+ std::get<2> (m_storage)->generate_ax (exp, ax, &value3);
+ gen_usual_unary (ax, &value3);
+ ax_label (ax, end, ax->len);
+ /* This is arbitrary - what if B and C are incompatible types? */
+ value->type = value2.type;
+ value->kind = value2.kind;
+}
+
}
/* This handles the middle-to-right-side of code generation for binary
diff --git a/gdb/expop.h b/gdb/expop.h
index 436a011..0f5b504 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -734,6 +734,37 @@ public:
{ return TERNOP_SLICE; }
};
+class ternop_cond_operation
+ : public maybe_constant_operation<operation_up, operation_up, operation_up>
+{
+public:
+
+ using maybe_constant_operation::maybe_constant_operation;
+
+ value *evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside) override
+ {
+ struct value *val
+ = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+
+ if (value_logical_not (val))
+ return std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
+ return std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+ }
+
+ enum exp_opcode opcode () const override
+ { return TERNOP_COND; }
+
+protected:
+
+ void do_generate_ax (struct expression *exp,
+ struct agent_expr *ax,
+ struct axs_value *value,
+ struct type *cast_type)
+ override;
+};
+
} /* namespace expr */
#endif /* EXPOP_H */