Add two agent expression helper functions
authorTom Tromey <tom@tromey.com>
Mon, 8 Mar 2021 14:27:57 +0000 (07:27 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 8 Mar 2021 14:28:14 +0000 (07:28 -0700)
This adds a couple of agent expression helper functions that will be
useful when implementing various operations.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

* expop.h (gen_expr_binop, gen_expr_structop): Declare.
* ax-gdb.c (gen_expr_binop): New function.
(gen_expr_structop): Likewise.

gdb/ChangeLog
gdb/ax-gdb.c
gdb/expop.h

index 94ce991895723d9258c9b2542d78b5e0115971f9..2b90a32e74938b5599bd18ee152682c35cb9c12b 100644 (file)
@@ -1,3 +1,9 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+       * expop.h (gen_expr_binop, gen_expr_structop): Declare.
+       * ax-gdb.c (gen_expr_binop): New function.
+       (gen_expr_structop): Likewise.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * expprint.c (expr::dump_for_expression): New functions.
index 728b21dfd6a9ba83e7d869d76385bfec56faacac..1c6a7431143121c90403cb2b091db08f3e25a91e 100644 (file)
@@ -45,6 +45,7 @@
 #include "typeprint.h"
 #include "valprint.h"
 #include "c-lang.h"
+#include "expop.h"
 
 #include "gdbsupport/format.h"
 
@@ -158,6 +159,12 @@ static void gen_expr_binop_rest (struct expression *exp,
                                 struct axs_value *value,
                                 struct axs_value *value1,
                                 struct axs_value *value2);
+static void gen_expr_binop_rest (struct expression *exp,
+                                enum exp_opcode op,
+                                struct agent_expr *ax,
+                                struct axs_value *value,
+                                struct axs_value *value1,
+                                struct axs_value *value2);
 \f
 
 /* Detecting constant expressions.  */
@@ -2458,6 +2465,45 @@ gen_expr_binop_rest (struct expression *exp,
   gen_expr (exp, pc, ax, value2);
   gen_expr_binop_rest (exp, op, ax, value, value1, value2);
 }
+
+/* A helper function that emits a binop based on two operations.  */
+
+void
+gen_expr_binop (struct expression *exp,
+               enum exp_opcode op,
+               expr::operation *lhs, expr::operation *rhs,
+               struct agent_expr *ax, struct axs_value *value)
+{
+  struct axs_value value1, value2;
+
+  lhs->generate_ax (exp, ax, &value1);
+  gen_usual_unary (ax, &value1);
+  rhs->generate_ax (exp, ax, &value2);
+  gen_expr_binop_rest (exp, op, ax, value, &value1, &value2);
+}
+
+/* A helper function that emits a structop based on an operation and a
+   member name.  */
+
+void
+gen_expr_structop (struct expression *exp,
+                  enum exp_opcode op,
+                  expr::operation *lhs,
+                  const char *name,
+                  struct agent_expr *ax, struct axs_value *value)
+{
+  lhs->generate_ax (exp, ax, value);
+  if (op == STRUCTOP_STRUCT)
+    gen_struct_ref (ax, value, name, ".", "structure or union");
+  else if (op == STRUCTOP_PTR)
+    gen_struct_ref (ax, value, name, "->",
+                   "pointer to a structure or union");
+  else
+    /* If this `if' chain doesn't handle it, then the case list
+       shouldn't mention it, and we shouldn't be here.  */
+    internal_error (__FILE__, __LINE__,
+                   _("gen_expr: unhandled struct case"));
+}
 \f
 
 /* Given a single variable and a scope, generate bytecodes to trace
index 97848fd5aa21704eee6793fbcce37d9006671fa6..1bf06139dfb6a35517b296d92f6eb90fdbb6c8f1 100644 (file)
 struct agent_expr;
 struct axs_value;
 
+extern void gen_expr_binop (struct expression *exp,
+                           enum exp_opcode op,
+                           expr::operation *lhs, expr::operation *rhs,
+                           struct agent_expr *ax, struct axs_value *value);
+extern void gen_expr_structop (struct expression *exp,
+                              enum exp_opcode op,
+                              expr::operation *lhs,
+                              const char *name,
+                              struct agent_expr *ax, struct axs_value *value);
+
 namespace expr
 {
 
This page took 0.032384 seconds and 4 git commands to generate.