Rizin
unix-like reverse engineering framework and cli tools
value.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 RizinOrg <info@rizin.re>
2 // SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
3 // SPDX-FileCopyrightText: 2021 heersin <teablearcher@gmail.com>
4 // SPDX-License-Identifier: LGPL-3.0-only
5 
7 
14  RzILVal *ret;
15  ret = RZ_NEW0(RzILVal);
16  if (!ret) {
17  return NULL;
18  }
19  ret->type = type;
20  return ret;
21 }
22 
31  if (!ret) {
32  return NULL;
33  }
34  ret->data.bv = bv;
35  return ret;
36 }
37 
46  if (!ret) {
47  return NULL;
48  }
49  ret->data.b = b;
50  return ret;
51 }
52 
57  RzILVal *ret = rz_il_value_new(sort.type);
58  if (!ret) {
59  return NULL;
60  }
61  switch (sort.type) {
63  ret->data.b = rz_il_bool_new(false);
64  if (!ret->data.b) {
65  rz_il_value_free(ret);
66  return NULL;
67  }
68  break;
70  ret->data.bv = rz_bv_new_zero(sort.props.bv.length);
71  if (!ret->data.bv) {
72  rz_il_value_free(ret);
73  return NULL;
74  }
75  break;
76  }
77  return ret;
78 }
79 
87  RzILBool *b = NULL;
88  RzBitVector *bv = NULL;
89 
90  switch (val->type) {
92  b = rz_il_bool_new(val->data.b->b);
93  return b ? rz_il_value_new_bool(b) : NULL;
95  bv = rz_bv_dup(val->data.bv);
96  return bv ? rz_il_value_new_bitv(bv) : NULL;
97  default:
99  return NULL;
100  }
101 }
102 
108  if (!val) {
109  return;
110  }
111  switch (val->type) {
113  rz_il_bool_free(val->data.b);
114  break;
116  rz_bv_free(val->data.bv);
117  break;
118  default:
119  break;
120  }
121  free(val);
122 }
123 
128  RzILSortPure r = { 0 };
129  r.type = val->type;
130  if (val->type == RZ_IL_TYPE_PURE_BITVECTOR) {
131  r.props.bv.length = rz_bv_len(val->data.bv);
132  }
133  return r;
134 }
135 
143  switch (val->type) {
145  return rz_bv_new_from_ut64(1, val->data.b->b ? 1 : 0);
147  return rz_bv_dup(val->data.bv);
148  default:
150  return NULL;
151  }
152 }
153 
158  rz_return_val_if_fail(a && b, false);
159  if (a->type != b->type) {
160  return false;
161  }
162  switch (a->type) {
164  return a->data.b->b == b->data.b->b;
166  return rz_bv_eq(a->data.bv, b->data.bv);
167  default:
169  return false;
170  }
171 }
ut16 val
Definition: armass64_const.h:6
RZ_API RzILBool * rz_il_bool_new(bool true_or_false)
Definition: bool.c:11
RZ_API void rz_il_bool_free(RzILBool *bool_var)
Definition: bool.c:74
#define RZ_API
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API RzILSortPure rz_il_value_get_sort(RZ_NONNULL RzILVal *val)
Definition: value.c:127
RZ_API RZ_OWN RzILVal * rz_il_value_new_zero_of(RzILSortPure sort)
Definition: value.c:56
RZ_API RZ_OWN RzILVal * rz_il_value_dup(RZ_NONNULL const RzILVal *val)
Definition: value.c:85
RZ_API RZ_OWN RzILVal * rz_il_value_new(RzILTypePure type)
Definition: value.c:13
RZ_API RZ_OWN RzBitVector * rz_il_value_to_bv(RZ_NONNULL const RzILVal *val)
Definition: value.c:141
RZ_API RZ_OWN RzILVal * rz_il_value_new_bitv(RZ_NONNULL RzBitVector *bv)
Definition: value.c:28
RZ_API bool rz_il_value_eq(RZ_NONNULL const RzILVal *a, RZ_NONNULL const RzILVal *b)
Definition: value.c:157
RZ_API void rz_il_value_free(RZ_NULLABLE RzILVal *val)
Definition: value.c:107
RZ_API RZ_OWN RzILVal * rz_il_value_new_bool(RZ_NONNULL RzILBool *b)
Definition: value.c:43
int type
Definition: mipsasm.c:17
#define rz_warn_if_reached()
Definition: rz_assert.h:29
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API RZ_OWN RzBitVector * rz_bv_dup(const RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:167
RZ_API void rz_bv_free(RZ_NULLABLE RzBitVector *bv)
Definition: bitvector.c:85
RZ_API ut32 rz_bv_len(RZ_NONNULL const RzBitVector *bv)
Definition: bitvector.c:1140
RZ_API RZ_OWN RzBitVector * rz_bv_new_from_ut64(ut32 length, ut64 value)
Definition: bitvector.c:1161
#define rz_bv_new_zero(l)
Definition: rz_bitvector.h:105
RZ_API bool rz_bv_eq(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:1041
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_NONNULL
Definition: rz_types.h:64
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41
RzILTypePure
Definition: sort.h:23
@ RZ_IL_TYPE_PURE_BOOL
Definition: sort.h:24
@ RZ_IL_TYPE_PURE_BITVECTOR
Definition: sort.h:25
structure for bitvector
Definition: rz_bitvector.h:19
struct rz_il_sort_pure_t::@283::@284 bv
union rz_il_sort_pure_t::@283 props
RzILTypePure type
Definition: sort.h:29
RzValUnion data
data pointer
Definition: value.h:26
RzILTypePure type
type of value
Definition: value.h:25
RzBitVector * bv
Definition: value.h:17
RzILBool * b
Definition: value.h:18