aboutsummaryrefslogtreecommitdiff
path: root/gdb/ax-gdb.c
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:20 -0700
commit9307d17b7a97bd49baf0d877785c43cf203b7cee (patch)
tree2a3cc7312867dfa2d2c1565739a3bf77b2be9e4c /gdb/ax-gdb.c
parentae64ba58b3bc5a9a023974f37515aee9862548fd (diff)
downloadbinutils-9307d17b7a97bd49baf0d877785c43cf203b7cee.zip
binutils-9307d17b7a97bd49baf0d877785c43cf203b7cee.tar.gz
binutils-9307d17b7a97bd49baf0d877785c43cf203b7cee.tar.bz2
Implement some unary operations
This introduces a couple of new template classes and then uses them to implement some simple unary operations. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * expop.h (unary_ftype): New typedef. (unop_operation, usual_ax_binop_operation): New templates. (unary_plus_operation, unary_neg_operation) (unary_complement_operation, unary_logical_not_operation): New typedefs. * eval.c (eval_op_plus, eval_op_neg, eval_op_complement) (eval_op_lognot): No longer static. * ax-gdb.c (gen_expr_unop): New function.
Diffstat (limited to 'gdb/ax-gdb.c')
-rw-r--r--gdb/ax-gdb.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index 8d5e4ff..c87b290 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -2694,6 +2694,53 @@ gen_expr_structop (struct expression *exp,
internal_error (__FILE__, __LINE__,
_("gen_expr: unhandled struct case"));
}
+
+/* A helper function that emits a unary operation. */
+
+void
+gen_expr_unop (struct expression *exp,
+ enum exp_opcode op,
+ expr::operation *lhs,
+ struct agent_expr *ax, struct axs_value *value)
+{
+ struct axs_value value1, value2;
+
+ switch (op)
+ {
+ case UNOP_NEG:
+ gen_int_literal (ax, &value1, 0,
+ builtin_type (ax->gdbarch)->builtin_int);
+ gen_usual_unary (ax, &value1); /* shouldn't do much */
+ lhs->generate_ax (exp, ax, &value2);
+ gen_usual_unary (ax, &value2);
+ gen_usual_arithmetic (ax, &value1, &value2);
+ gen_binop (ax, value, &value1, &value2, aop_sub, aop_sub, 1, "negation");
+ break;
+
+ case UNOP_PLUS:
+ /* + FOO is equivalent to 0 + FOO, which can be optimized. */
+ lhs->generate_ax (exp, ax, value);
+ gen_usual_unary (ax, value);
+ break;
+
+ case UNOP_LOGICAL_NOT:
+ lhs->generate_ax (exp, ax, value);
+ gen_usual_unary (ax, value);
+ gen_logical_not (ax, value, builtin_type (ax->gdbarch)->builtin_int);
+ break;
+
+ case UNOP_COMPLEMENT:
+ lhs->generate_ax (exp, ax, value);
+ gen_usual_unary (ax, value);
+ gen_integral_promotions (ax, value);
+ gen_complement (ax, value);
+ break;
+
+ default:
+ gdb_assert_not_reached ("invalid case in gen_expr_unop");
+ }
+}
+
/* Given a single variable and a scope, generate bytecodes to trace