1#ifndef UTIL_IREP2_UTILS_H_
2#define UTIL_IREP2_UTILS_H_
22 if (!is_pointer_type(a) || !is_pointer_type(b))
27 if (!is_code_type(sub_a) || !is_code_type(sub_b))
39 return t->
type_id == type2t::unsignedbv_id ||
40 t->
type_id == type2t::signedbv_id;
51 return t->
type_id == type2t::fixedbv_id || t->
type_id == type2t::floatbv_id;
57 return is_equality2t(e) || is_notequal2t(e) || is_lessthan2t(e) ||
58 is_greaterthan2t(e) || is_lessthanequal2t(e) ||
59 is_greaterthanequal2t(e);
65 return t->
type_id == type2t::unsignedbv_id ||
66 t->
type_id == type2t::signedbv_id ||
67 t->
type_id == type2t::fixedbv_id || t->
type_id == type2t::floatbv_id ||
78 return is_number_type(t) || is_pointer_type(t) || is_empty_type(t) ||
108 return is_array_type(t) || is_vector_type(t);
118 if (is_array_type(t))
120 if (is_vector_type(t))
127 if (is_array_type(t))
129 if (is_vector_type(t))
136 if (is_array_type(t))
138 if (is_vector_type(t))
155 return t->
expr_id == expr2t::constant_int_id ||
156 t->
expr_id == expr2t::constant_fixedbv_id ||
157 t->
expr_id == expr2t::constant_floatbv_id ||
158 t->
expr_id == expr2t::constant_bool_id;
164 t->
expr_id == expr2t::constant_struct_id ||
165 t->
expr_id == expr2t::constant_union_id ||
166 t->
expr_id == expr2t::constant_array_id ||
167 t->
expr_id == expr2t::constant_array_of_id ||
168 t->
expr_id == expr2t::constant_vector_id;
173 if (is_pointer_type(t) && is_symbol2t(t))
184 return t->
type_id == type2t::struct_id || t->
type_id == type2t::union_id;
194 return expr->
expr_id == expr2t::neg_id || expr->
expr_id == expr2t::abs_id ||
195 expr->
expr_id == expr2t::add_id || expr->
expr_id == expr2t::sub_id ||
196 expr->
expr_id == expr2t::mul_id || expr->
expr_id == expr2t::div_id ||
197 expr->
expr_id == expr2t::modulus_id;
202 return expr->
expr_id == expr2t::lessthan_id ||
203 expr->
expr_id == expr2t::lessthanequal_id ||
204 expr->
expr_id == expr2t::greaterthan_id ||
205 expr->
expr_id == expr2t::greaterthanequal_id ||
206 expr->
expr_id == expr2t::equality_id ||
207 expr->
expr_id == expr2t::notequal_id;
218 if (is_constant_bool2t(expr) && to_constant_bool2t(expr).
value)
221 if (is_constant_int2t(expr) && !to_constant_int2t(expr).
value.is_zero())
225 is_constant_floatbv2t(expr) && !to_constant_floatbv2t(expr).
value.is_zero())
229 is_constant_fixedbv2t(expr) && !to_constant_fixedbv2t(expr).
value.is_zero())
243 if (is_constant_bool2t(expr) && !to_constant_bool2t(expr).
value)
246 if (is_constant_int2t(expr) && to_constant_int2t(expr).
value.is_zero())
250 is_constant_floatbv2t(expr) && to_constant_floatbv2t(expr).
value.is_zero())
254 is_constant_fixedbv2t(expr) && to_constant_fixedbv2t(expr).
value.is_zero())
267 static const expr2tc c = constant_bool2tc(
true);
273 static const expr2tc c = constant_bool2tc(
false);
279 return constant_int2tc(type, std::move(val));
295 if (is_array_type(subtype))
366template <
typename Func>
370 assert(is_constant_vector2t(op1) || is_constant_vector2t(op2));
386 if (is_constant_vector2t(op1) && is_constant_vector2t(op2))
388 std::vector<expr2tc> members = to_constant_vector2t(op1).datatype_members;
390 for (
size_t i = 0; i < members.size(); i++)
392 auto &
A = members[i];
394 auto new_op = func(
A->type,
A, B);
397 return constant_vector2tc(op1->
type, std::move(members));
417 bool is_op1_vec = is_constant_vector2t(op1);
418 expr2tc c = !is_op1_vec ? op1 : op2;
419 expr2tc v = is_op1_vec ? op1 : op2;
420 std::vector<expr2tc> members = to_constant_vector2t(v).datatype_members;
421 for (
size_t i = 0; i < members.size(); i++)
423 auto &op = members[i];
426 if (is_vector_type(c))
431 auto e1 = is_op1_vec ? op : lane;
432 auto e2 = is_op1_vec ? lane : op;
433 auto new_op = func(op->type, e1, e2);
437 auto folded = new_op->do_simplify();
442 return constant_vector2tc(v->
type, std::move(members));
476 std::unordered_set<expr2tc, irep2_hash> &symbols);
type2tc get_uint_type(unsigned int sz)
Definition c_types.cpp:384
type2tc get_uint32_type()
Definition c_types.cpp:348
Type of functions.
Definition irep2_type.h:333
std::vector< type2tc > arguments
Definition irep2_type.h:367
type2tc ret_type
Definition irep2_type.h:368
bool ellipsis
Definition irep2_type.h:399
Constant vector.
Definition irep2_expr.h:578
std::vector< expr2tc > datatype_members
Definition irep2_expr.h:580
expr_ids
Enumeration identifying each sort of expr.
Definition irep2.h:730
const expr_ids expr_id
Instance of expr_ids recording tihs exprs type.
Definition irep2.h:907
const type2tc type
Type of this expr.
Definition irep2.h:910
expr2tc simplify() const
Simplify an expression.
Definition expr_simplifier.cpp:40
Struct type.
Definition irep2_type.h:99
Symbol type.
Definition irep2_expr.h:625
irep_idt thename
Definition irep2_expr.h:629
unsigned int get_width() const
Fetch bit width of this type.
Definition irep2_type.cpp:352
const type_ids type_id
Instance of type_ids recording this types type.
Definition irep2.h:693
const typet & subtype() const
Definition type.h:17
configt config
Definition config.cpp:8
void irep2_bad_family_cast(unsigned actual, const char *accessor)
Definition irep2_type.cpp:61
irep_container< type2t > type2tc
Definition irep2.h:430
bool is_nil_expr(const expr2tc &exp)
Definition irep2.h:916
irep_container< expr2t > expr2tc
Definition irep2.h:431
expr2tc disjunction(std::vector< expr2tc > cs)
Build the left-associative OR-chain of cs.
Definition irep2_utils.cpp:41
bool is_true(const expr2tc &expr)
Test if expr is true.
Definition irep2_utils.h:216
bool is_constant(const expr2tc &t)
Definition irep2_utils.h:171
bool is_fractional_type(const type2tc &t)
Test whether type is a float/double.
Definition irep2_utils.h:49
std::string indent_str_irep2(unsigned int indent)
Definition irep2_utils.cpp:326
bool is_constant_expr(const expr2tc &t)
Definition irep2_utils.h:161
expr2tc conjunction(std::vector< expr2tc > cs)
Build the left-associative AND-chain of cs: and(and(and(c0, c1), c2), ...).
Definition irep2_utils.cpp:29
bool is_structure_type(const type2tc &t)
Definition irep2_utils.h:182
bool is_comp_expr(const expr2tc &expr)
Definition irep2_utils.h:200
bool is_scalar_type(const type2tc &t)
Definition irep2_utils.h:76
bool is_multi_dimensional_array(const type2tc &t)
Definition irep2_utils.h:87
bool simplify(expr2tc &expr)
Definition irep2_utils.h:301
expr2tc distribute_vector_operation(Func func, const expr2tc &op1, const expr2tc &op2)
Distribute the functor func over op1 and op2 at least one of those must be a vector.
Definition irep2_utils.h:368
void make_not(expr2tc &expr)
Negate expr in place.
Definition irep2_utils.cpp:6
expr2tc gen_zero(const type2tc &type, bool array_as_array_of=false)
Build the canonical zero value of type.
Definition irep2_utils.cpp:64
bool is_number_type(const type2tc &t)
Test whether type is a number type - bv, fixedbv or floatbv.
Definition irep2_utils.h:63
expr2tc gen_ulong(BigInt v)
Definition irep2_utils.h:282
bool is_constant_number(const expr2tc &t)
Definition irep2_utils.h:153
const expr2tc & array_or_vector_size(const type2tc &t)
Definition irep2_utils.h:125
bool is_arith_expr(const expr2tc &expr)
Definition irep2_utils.h:192
bool array_or_vector_size_is_infinite(const type2tc &t)
Definition irep2_utils.h:134
const type2tc & array_or_vector_subtype(const type2tc &t)
Definition irep2_utils.h:116
bool is_bv_type(const type2tc &t)
Test whether type is an integer.
Definition irep2_utils.h:37
expr2tc gen_one(const type2tc &type)
Build the canonical one value of type.
Definition irep2_utils.cpp:157
irep_idt quantifier_direct_bound_name(const expr2tc &binder)
As quantifier_bound_name, but empty unless binder is (a typecast of) address_of(symbol),...
Definition irep2_utils.cpp:781
void get_symbols(const expr2tc &expr, std::unordered_set< expr2tc, irep2_hash > &symbols)
Collect every user-level symbol2t referenced by expr into symbols.
Definition irep2_utils.cpp:301
expr2tc gen_nondet(const type2tc &type)
Build a sideeffect2t of kind nondet of type, i.e.
Definition irep2_utils.cpp:53
bool is_false(const expr2tc &expr)
Test if expr is false.
Definition irep2_utils.h:241
const expr2tc & gen_false_expr()
Definition irep2_utils.h:271
bool is_comparison_expr(const expr2tc &e)
Test whether e is a relational comparison: ==, !=, <, >, <=, >=.
Definition irep2_utils.h:55
bool same_function_pointer_ignoring_argument_names(const type2tc &a, const type2tc &b)
Definition irep2_utils.h:18
bool is_array_or_vector_type(const type2tc &t)
Definition irep2_utils.h:106
expr2tc make_cmp_value(const type2tc &t, int v)
Definition irep2_utils.cpp:286
bool is_byte_type(const type2tc &t)
Definition irep2_utils.h:143
const type2tc & get_base_array_subtype(const type2tc &type)
Definition irep2_utils.h:292
expr2tc gen_long(const type2tc &type, BigInt val)
Definition irep2_utils.h:277
std::vector< expr2tc > pad_struct_operands(const struct_type2t &st, std::vector< expr2tc > ops)
Insert a zero operand at each reserved padding-member position so a struct literal's operand list mat...
Definition irep2_utils.cpp:757
irep_idt quantifier_bound_name(const expr2tc &binder)
Base name of the variable a forall2t/exists2t binds, or an empty id when binder holds no symbol at al...
Definition irep2_utils.cpp:773
const expr2tc & gen_true_expr()
Definition irep2_utils.h:265
#define A
Definition logf.c:22
void verify_rewrite(const expr2tc &before, const expr2tc &after)
Consult the installed checker.
Definition simplification_check.h:53
const vector_typet & to_vector_type(const typet &type)
Definition std_types.h:723
const code_typet & to_code_type(const typet &type)
Definition std_types.h:384
const array_typet & to_array_type(const typet &type)
Definition std_types.h:425
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
Definition std_types.h:460