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.
/* 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
}
/* 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;
}
}
+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 ---*/
/*---------------------------------------------------------------*/
#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
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 * );
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;
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;
cb.immediate_index = op->immediate_index;
cb.immediate_type = op->immediate_type;
- return cb;
+ return (IRICB) { .kind = IRICB_vbit, .vbit = cb };
}