Rizin
unix-like reverse engineering framework and cli tools
theory_bool.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 heersin <teablearcher@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_il/rz_il_opcodes.h>
5 #include <rz_il/rz_il_vm.h>
6 
11  rz_return_val_if_fail(vm && op && type, NULL);
12 
13  RzILBool *ret = rz_il_bool_new(false);
15  return ret;
16 }
17 
22  rz_return_val_if_fail(vm && op && type, NULL);
23 
24  RzILBool *ret = rz_il_bool_new(true);
26  return ret;
27 }
28 
30  rz_return_val_if_fail(vm && op && type, NULL);
31 
32  RzILOpArgsBoolAnd *op_and = &op->op.booland;
33  RzILBool *x = rz_il_evaluate_bool(vm, op_and->x);
34  RzILBool *y = rz_il_evaluate_bool(vm, op_and->y);
35 
36  RzILBool *result = x && y ? rz_il_bool_and(x, y) : NULL;
38  rz_il_bool_free(y);
39 
41  return result;
42 }
43 
45  rz_return_val_if_fail(vm && op && type, NULL);
46 
47  RzILOpArgsBoolOr *op_or = &op->op.boolor;
48  RzILBool *x = rz_il_evaluate_bool(vm, op_or->x);
49  RzILBool *y = rz_il_evaluate_bool(vm, op_or->y);
50 
51  RzILBool *result = x && y ? rz_il_bool_or(x, y) : NULL;
53  rz_il_bool_free(y);
54 
56  return result;
57 }
58 
60  rz_return_val_if_fail(vm && op && type, NULL);
61 
62  RzILOpArgsBoolXor *op_xor = &op->op.boolxor;
63  RzILBool *x = rz_il_evaluate_bool(vm, op_xor->x);
64  RzILBool *y = rz_il_evaluate_bool(vm, op_xor->y);
65 
66  RzILBool *result = x && y ? rz_il_bool_xor(x, y) : NULL;
68  rz_il_bool_free(y);
69 
71  return result;
72 }
73 
78  rz_return_val_if_fail(vm && op && type, NULL);
79 
80  RzILOpArgsBoolInv *op_inv = &op->op.boolinv;
81  RzILBool *x = rz_il_evaluate_bool(vm, op_inv->x);
82  RzILBool *result = x ? rz_il_bool_not(x) : NULL;
84 
86  return result;
87 }
RZ_API RzILBool * rz_il_bool_xor(RZ_NONNULL RzILBool *a, RZ_NONNULL RzILBool *b)
Definition: bool.c:52
RZ_API RzILBool * rz_il_bool_and(RZ_NONNULL RzILBool *a, RZ_NONNULL RzILBool *b)
Definition: bool.c:26
RZ_API RzILBool * rz_il_bool_new(bool true_or_false)
Definition: bool.c:11
RZ_API RzILBool * rz_il_bool_not(RZ_NONNULL RzILBool *a)
Definition: bool.c:63
RZ_API RzILBool * rz_il_bool_or(RZ_NONNULL RzILBool *a, RZ_NONNULL RzILBool *b)
Definition: bool.c:39
RZ_API void rz_il_bool_free(RzILBool *bool_var)
Definition: bool.c:74
#define NULL
Definition: cris-opc.c:27
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 x
Definition: mipsasm.c:20
int type
Definition: mipsasm.c:17
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
signatures of core theory opcodes
RzILTypePure
Definition: sort.h:23
@ RZ_IL_TYPE_PURE_BOOL
Definition: sort.h:24
op structure for inv (!bool -> bool)
RzILOpBool * x
single operand
op structure for and, or and xor (bool -> bool -> bool)
RzILOpBool * x
left operand
RzILOpBool * y
right operand
An IL op performing a pure computation, 'a pure.
Low-level VM to execute raw IL code.
Definition: rz_il_vm.h:37
void * rz_il_handler_bool_true(RzILVM *vm, RzILOpBool *op, RzILTypePure *type)
also known as b1
Definition: theory_bool.c:21
void * rz_il_handler_bool_and(RzILVM *vm, RzILOpBool *op, RzILTypePure *type)
Definition: theory_bool.c:29
void * rz_il_handler_bool_inv(RzILVM *vm, RzILOpBool *op, RzILTypePure *type)
also known as boolean not
Definition: theory_bool.c:77
void * rz_il_handler_bool_false(RzILVM *vm, RzILOpBool *op, RzILTypePure *type)
also known as b0
Definition: theory_bool.c:10
void * rz_il_handler_bool_xor(RzILVM *vm, RzILOpBool *op, RzILTypePure *type)
Definition: theory_bool.c:59
void * rz_il_handler_bool_or(RzILVM *vm, RzILOpBool *op, RzILTypePure *type)
Definition: theory_bool.c:44
Definition: dis.c:32