Rizin
unix-like reverse engineering framework and cli tools
theory_init.c File Reference

Go to the source code of this file.

Functions

void * rz_il_handler_ite (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_var (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_let (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_pure_unimplemented (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
bool rz_il_handler_effect_unimplemented (RzILVM *vm, RzILOpEffect *op)
 

Function Documentation

◆ rz_il_handler_effect_unimplemented()

bool rz_il_handler_effect_unimplemented ( RzILVM vm,
RzILOpEffect op 
)

Definition at line 76 of file theory_init.c.

76  {
78  RZ_LOG_ERROR("RzIL: unimplemented op handler (%d).\n", (int)op->code);
79  return false;
80 }
#define NULL
Definition: cris-opc.c:27
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
Definition: dis.c:32
struct op_code code
Definition: dis.c:33

References op::code, NULL, RZ_LOG_ERROR, and rz_return_val_if_fail.

◆ rz_il_handler_ite()

void* rz_il_handler_ite ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 7 of file theory_init.c.

7  {
9 
10  RzILOpArgsIte *op_ite = &op->op.ite;
11 
12  RzILBool *condition = rz_il_evaluate_bool(vm, op_ite->condition);
13  if (!condition) {
14  return NULL;
15  }
16  RzILVal *ret;
17  if (condition->b) {
18  ret = rz_il_evaluate_pure(vm, op_ite->x, type); // true branch
19  } else {
20  ret = rz_il_evaluate_pure(vm, op_ite->y, type); // false branch
21  }
22  rz_il_bool_free(condition);
23  return ret;
24 }
RZ_API void rz_il_bool_free(RzILBool *bool_var)
Definition: bool.c:74
RZ_API RZ_NULLABLE RZ_OWN void * rz_il_evaluate_pure(RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpPure *op, RZ_NONNULL RzILTypePure *type)
Definition: il_vm_eval.c:332
RZ_API RZ_NULLABLE RZ_OWN RzILBool * rz_il_evaluate_bool(RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpBool *op)
Definition: il_vm_eval.c:289
int type
Definition: mipsasm.c:17
bool b
Definition: bool.h:15
op structure for ite (bool -> 'a pure -> 'a pure -> 'a pure)
RzILOpPure * y
index of RzILVal operand 2
RzILOpPure * x
index of RzILVal operand 1
RzILOpBool * condition
index of BOOL condition

References rz_il_bool_t::b, rz_il_op_args_ite_t::condition, NULL, rz_il_bool_free(), rz_il_evaluate_bool(), rz_il_evaluate_pure(), rz_return_val_if_fail, type, rz_il_op_args_ite_t::x, and rz_il_op_args_ite_t::y.

◆ rz_il_handler_let()

void* rz_il_handler_let ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 57 of file theory_init.c.

57  {
58  rz_return_val_if_fail(vm && op && type, NULL);
59  RzILOpArgsLet *args = &op->op.let;
60  RzILVal *v = rz_il_evaluate_val(vm, args->exp);
61  if (!v) {
62  return NULL;
63  }
65  void *r = rz_il_evaluate_pure(vm, args->body, type);
66  rz_il_vm_pop_local_pure_var(vm, args->name, prev);
67  return r;
68 }
#define r
Definition: crypto_rc6.c:12
const char * v
Definition: dsignal.c:12
RZ_API RzILLocalPurePrev rz_il_vm_push_local_pure_var(RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *name, RzILVal *val)
Create and assign a new local let binding.
Definition: il_vm.c:215
RZ_API void rz_il_vm_pop_local_pure_var(RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *name, RzILLocalPurePrev prev)
Remove a local let binding and restore the state for the outer context.
Definition: il_vm.c:227
RZ_API RZ_NULLABLE RZ_OWN RzILVal * rz_il_evaluate_val(RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpPure *op)
Definition: il_vm_eval.c:309
int args
Definition: mipsasm.c:18
RZ_NULLABLE RzILVal * RzILLocalPurePrev
Definition: rz_il_vm.h:86
op structure for let_ : 'a var -> 'a pure -> 'b pure -> 'b pure

References args, NULL, r, rz_il_evaluate_pure(), rz_il_evaluate_val(), rz_il_vm_pop_local_pure_var(), rz_il_vm_push_local_pure_var(), rz_return_val_if_fail, type, and v.

◆ rz_il_handler_pure_unimplemented()

void* rz_il_handler_pure_unimplemented ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 70 of file theory_init.c.

70  {
71  rz_return_val_if_fail(vm && op && type, NULL);
72  RZ_LOG_ERROR("RzIL: unimplemented op handler (%d).\n", (int)op->code);
73  return NULL;
74 }

References op::code, NULL, RZ_LOG_ERROR, rz_return_val_if_fail, and type.

◆ rz_il_handler_var()

void* rz_il_handler_var ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 26 of file theory_init.c.

26  {
27  rz_return_val_if_fail(vm && op && type, NULL);
28 
29  RzILOpArgsVar *var_op = &op->op.var;
30  RzILVal *val = rz_il_vm_get_var_value(vm, var_op->kind, var_op->v);
31  if (!val) {
32  RZ_LOG_ERROR("RzIL: reading value of variable \"%s\" of kind %s failed.\n",
33  var_op->v, rz_il_var_kind_name(var_op->kind));
34  return NULL;
35  }
36 
37  if (var_op->kind == RZ_IL_VAR_KIND_GLOBAL) {
39  }
40 
41  void *ret = NULL;
42  switch (val->type) {
45  ret = rz_il_bool_new(val->data.b->b);
46  break;
49  ret = rz_bv_dup(val->data.bv);
50  break;
51  default:
52  break;
53  }
54  return ret;
55 }
ut16 val
Definition: armass64_const.h:6
RZ_API RzILBool * rz_il_bool_new(bool true_or_false)
Definition: bool.c:11
RZ_API RZ_OWN RzILEvent * rz_il_event_var_read_new(RZ_NONNULL const char *name, RZ_NULLABLE const RzILVal *value)
Definition: il_events.c:152
RZ_API RZ_BORROW RzILVal * rz_il_vm_get_var_value(RZ_NONNULL RzILVM *vm, RzILVarKind kind, const char *name)
Definition: il_vm.c:264
RZ_API void rz_il_vm_event_add(RzILVM *vm, RzILEvent *evt)
Definition: il_vm_eval.c:201
RZ_API RZ_OWN RzBitVector * rz_bv_dup(const RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:167
@ RZ_IL_TYPE_PURE_BOOL
Definition: sort.h:24
@ RZ_IL_TYPE_PURE_BITVECTOR
Definition: sort.h:25
op structure for var ('a var -> 'a pure)
RzILVarKind kind
set of variables to pick from
const char * v
name of variable, const one
const char * rz_il_var_kind_name(RzILVarKind kind)
Definition: variable.c:181
@ RZ_IL_VAR_KIND_GLOBAL
global var, usually bound to a physical representation like a register.
Definition: variable.h:47

References rz_il_op_args_var_t::kind, NULL, rz_bv_dup(), rz_il_bool_new(), rz_il_event_var_read_new(), RZ_IL_TYPE_PURE_BITVECTOR, RZ_IL_TYPE_PURE_BOOL, RZ_IL_VAR_KIND_GLOBAL, rz_il_var_kind_name(), rz_il_vm_event_add(), rz_il_vm_get_var_value(), RZ_LOG_ERROR, rz_return_val_if_fail, type, rz_il_op_args_var_t::v, and val.