From: Florian Krohm Date: Tue, 8 Jul 2025 09:45:47 +0000 (+0000) Subject: Refactor IRICB X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9203727b159879ce17b1290bfe8cee97730c6ac;p=thirdparty%2Fvalgrind.git Refactor IRICB 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. --- diff --git a/VEX/priv/ir_inject.c b/VEX/priv/ir_inject.c index e62a2d850..f642c834d 100644 --- a/VEX/priv/ir_inject.c +++ b/VEX/priv/ir_inject.c @@ -46,13 +46,12 @@ /* 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 ---*/ /*---------------------------------------------------------------*/ diff --git a/VEX/pub/libvex.h b/VEX/pub/libvex.h index 2dbfbe770..870747d35 100644 --- a/VEX/pub/libvex.h +++ b/VEX/pub/libvex.h @@ -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 * ); diff --git a/memcheck/tests/vbit-test/main.c b/memcheck/tests/vbit-test/main.c index db829ddda..d40365219 100644 --- a/memcheck/tests/vbit-test/main.c +++ b/memcheck/tests/vbit-test/main.c @@ -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; diff --git a/memcheck/tests/vbit-test/valgrind.c b/memcheck/tests/vbit-test/valgrind.c index 55ff3647d..204bf57ac 100644 --- a/memcheck/tests/vbit-test/valgrind.c +++ b/memcheck/tests/vbit-test/valgrind.c @@ -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 }; }