]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Refactor IRICB
authorFlorian Krohm <flo2030@eich-krohm.de>
Tue, 8 Jul 2025 09:45:47 +0000 (09:45 +0000)
committerFlorian Krohm <flo2030@eich-krohm.de>
Tue, 8 Jul 2025 09:45:47 +0000 (09:45 +0000)
So far there was only one application of IR injection, namely vbit-test.
Soonish there will be another.
Refactor the IRICB to separate out the structure for the application's
payload.

VEX/priv/ir_inject.c
VEX/pub/libvex.h
memcheck/tests/vbit-test/main.c
memcheck/tests/vbit-test/valgrind.c

index e62a2d8506771511f7fff01ea93576ed6c85df8a..f642c834db4dd11150b73141e5e05e87e00a2c82 100644 (file)
 
 /* The IR Injection Control Block. vex_inject_ir will query its contents
    to construct IR statements for testing purposes. */
-static IRICB iricb;
-
+static IRICB the_iricb;
 
 void
 LibVEX_InitIRI(const IRICB *iricb_in)
 {
-   iricb = *iricb_in;  // copy in
+   the_iricb = *iricb_in;  // copy in
 }
 
 
@@ -190,9 +189,10 @@ store(IRSB *irsb, IREndness endian, HWord haddr, IRExpr *data)
 
 /* Inject IR stmts depending on the data provided in the control
    block iricb. */
-void
-vex_inject_ir(IRSB *irsb, IREndness endian)
+static void
+vex_inject_ir_vbit(IRSB *irsb, IREndness endian)
 {
+   IRICB_vbit_payload iricb = the_iricb.vbit;
    IRExpr *data, *rounding_mode, *opnd1, *opnd2, *opnd3, *opnd4;
 
    rounding_mode = NULL;
@@ -321,6 +321,19 @@ vex_inject_ir(IRSB *irsb, IREndness endian)
    }
 }
 
+void
+vex_inject_ir(IRSB *irsb, IREndness endian)
+{
+   switch (the_iricb.kind) {
+   case IRICB_vbit:
+      vex_inject_ir_vbit(irsb, endian);
+      break;
+
+   default:
+      vpanic("unknown IRICB kind");
+   }
+}
+
 /*---------------------------------------------------------------*/
 /*--- end                                         ir_inject.c ---*/
 /*---------------------------------------------------------------*/
index 2dbfbe770e2b47a94c2cbf88afeddd0fa5a944fb..870747d354ae6985972b3a5a201526010151e68f 100644 (file)
@@ -960,7 +960,13 @@ extern void LibVEX_ShowStats ( void );
 
 #define NO_ROUNDING_MODE (~0u)
 
-typedef 
+typedef
+   enum {
+      IRICB_vbit,
+   }
+   IRICB_t;
+
+typedef
    struct {
       IROp  op;        // the operation to perform
       HWord result;    // address of the result
@@ -976,14 +982,23 @@ typedef
       UInt  rounding_mode;
       UInt  num_operands; // excluding rounding mode, if any
       /* The following two members describe if this operand has immediate
-       *  operands. There are a few restrictions:
-       *    (1) An operator can have at most one immediate operand.
+       * operands. There are a few restrictions:
+       * (1) An operator can have at most one immediate operand.
        * (2) If there is an immediate operand, it is the right-most operand
-       *  An immediate_index of 0 means there is no immediate operand.
+       * An immediate_index of 0 means there is no immediate operand.
        */
       UInt immediate_type;  // size of immediate Ity_I8, Ity_16
       UInt immediate_index; // operand number: 1, 2
    }
+   IRICB_vbit_payload;
+
+typedef
+   struct {
+      IRICB_t kind;
+      union {
+         IRICB_vbit_payload vbit;
+      };
+   }
    IRICB;
 
 extern void LibVEX_InitIRI ( const IRICB * );
index db829dddaa866d39883931660ab8045f957184d2..d403652190983ff8df75ea95d06c7dd352feef0a 100644 (file)
@@ -183,7 +183,7 @@ main(int argc, char *argv[])
 
       valgrind_vex_init_for_iri(&iricb);
 
-      switch (iricb.num_operands) {
+      switch (iricb.vbit.num_operands) {
       case 1:
          num_unary_tests += test_unary_op(op, data);
          break;
index 55ff3647dac427017e15ed219b8ede23ac391d7e..204bf57ac913f242a56ad9b43904f17636fc057b 100644 (file)
@@ -31,7 +31,7 @@
 IRICB
 new_iricb(const irop_t *op, test_data_t *data)
 {
-   IRICB cb;
+   IRICB_vbit_payload cb;
 
    cb.op = op->op;
    cb.result = (HWord)&data->result.value;
@@ -52,7 +52,7 @@ new_iricb(const irop_t *op, test_data_t *data)
    cb.immediate_index = op->immediate_index;
    cb.immediate_type  = op->immediate_type;
 
-   return cb;
+   return (IRICB) { .kind = IRICB_vbit, .vbit = cb };
 }