34 const std::size_t bit,
37 if(expr.
type().
id()==ID_bool)
44 if(expr.
id()==ID_symbol ||
45 expr.
id()==ID_nondet_symbol)
49 boolbv_mapt::mappingt::const_iterator it_m=
64 else if(expr.
id()==ID_index)
71 throw "literal expects a bit-vector type";
75 throw "literal expects constant index";
81 else if(expr.
id()==ID_member)
91 for(struct_typet::componentst::const_iterator
92 it=components.begin();
96 const typet &subtype=it->type();
98 if(it->get_name()==component_name)
104 throw "literal expects a bit-vector type";
106 offset+=element_width;
109 throw "failed to find component";
113 throw "found no literal for expression";
119 std::pair<bv_cachet::iterator, bool> cache_result=
121 if(!cache_result.second)
123 return cache_result.first->second;
143 return cache_result.first->second;
165 if(expr.
type().
id()==ID_bool)
173 if(expr.
id()==ID_index)
175 else if(expr.
id()==ID_constraint_select_one)
177 else if(expr.
id()==ID_member)
179 else if(expr.
id()==ID_with)
181 else if(expr.
id()==ID_update)
183 else if(expr.
id()==ID_width)
198 if(expr.
type().
id()==ID_unsignedbv ||
199 expr.
type().
id()==ID_signedbv)
202 else if(expr.
id()==ID_case)
204 else if(expr.
id()==ID_cond)
206 else if(expr.
id()==ID_if)
208 else if(expr.
id()==ID_constant)
210 else if(expr.
id()==ID_typecast)
212 else if(expr.
id()==ID_symbol)
214 else if(expr.
id()==ID_bv_literals)
216 else if(expr.
id()==ID_plus || expr.
id()==ID_minus ||
217 expr.
id()==
"no-overflow-plus" ||
218 expr.
id()==
"no-overflow-minus")
220 else if(expr.
id()==ID_mult ||
221 expr.
id()==
"no-overflow-mult")
223 else if(expr.
id()==ID_div)
225 else if(expr.
id()==ID_mod)
227 else if(expr.
id()==ID_shl || expr.
id()==ID_ashr || expr.
id()==ID_lshr ||
228 expr.
id()==ID_rol || expr.
id()==ID_ror)
230 else if(expr.
id()==ID_floatbv_plus || expr.
id()==ID_floatbv_minus ||
231 expr.
id()==ID_floatbv_mult || expr.
id()==ID_floatbv_div ||
232 expr.
id()==ID_floatbv_rem)
234 else if(expr.
id()==ID_floatbv_typecast)
236 else if(expr.
id()==ID_concatenation)
238 else if(expr.
id()==ID_replication)
240 else if(expr.
id()==ID_extractbits)
242 else if(expr.
id()==ID_bitnot || expr.
id()==ID_bitand ||
243 expr.
id()==ID_bitor || expr.
id()==ID_bitxor ||
244 expr.
id()==ID_bitxnor || expr.
id()==ID_bitnor ||
245 expr.
id()==ID_bitnand)
247 else if(expr.
id()==ID_unary_minus ||
248 expr.
id()==
"no-overflow-unary-minus")
250 else if(expr.
id()==ID_unary_plus)
255 else if(expr.
id()==ID_abs)
257 else if(expr.
id() == ID_bswap)
259 else if(expr.
id()==ID_byte_extract_little_endian ||
260 expr.
id()==ID_byte_extract_big_endian)
262 else if(expr.
id()==ID_byte_update_little_endian ||
263 expr.
id()==ID_byte_update_big_endian)
265 else if(expr.
id()==ID_nondet_symbol ||
266 expr.
id()==
"quant_symbol")
268 else if(expr.
id()==ID_struct)
270 else if(expr.
id()==ID_union)
272 else if(expr.
id()==ID_string_constant)
275 else if(expr.
id()==ID_array)
277 else if(expr.
id()==ID_vector)
279 else if(expr.
id()==ID_complex)
281 else if(expr.
id()==ID_complex_real)
283 else if(expr.
id()==ID_complex_imag)
285 else if(expr.
id()==ID_lambda)
287 else if(expr.
id()==ID_array_of)
289 else if(expr.
id()==ID_let)
291 else if(expr.
id()==ID_function_application)
294 else if(expr.
id()==ID_reduction_or || expr.
id()==ID_reduction_and ||
295 expr.
id()==ID_reduction_nor || expr.
id()==ID_reduction_nand ||
296 expr.
id()==ID_reduction_xor || expr.
id()==ID_reduction_xnor)
298 else if(expr.
id()==ID_not)
300 else if(expr.
id()==ID_power)
302 else if(expr.
id()==ID_float_debug1 ||
303 expr.
id()==ID_float_debug2)
309 bvt bv=expr.
id()==ID_float_debug1?
310 float_utils.debug1(bv0, bv1):
311 float_utils.debug2(bv0, bv1);
314 else if(expr.
id() == ID_popcount)
328 throw "lambda takes two operands";
330 if(expr.
type().
id()!=ID_array)
333 const exprt &array_size=
357 if(size*tmp.size()!=width)
358 throw "convert_lambda: unexpected operand width";
360 for(std::size_t j=0; j<tmp.size(); j++)
379 if(bv_sub.size()!=width)
380 throw "bv_literals with wrong size";
382 for(std::size_t i=0; i<width; i++)
396 const irep_idt &identifier=expr.
get(ID_identifier);
398 if(identifier.
empty())
399 throw "convert_symbol got empty identifier";
439 if(expr.
id()==ID_typecast)
441 else if(expr.
id()==ID_equal)
443 else if(expr.
id()==ID_verilog_case_equality ||
444 expr.
id()==ID_verilog_case_inequality)
446 else if(expr.
id()==ID_notequal)
451 else if(expr.
id()==ID_ieee_float_equal ||
452 expr.
id()==ID_ieee_float_notequal)
454 else if(expr.
id()==ID_le || expr.
id()==ID_ge ||
455 expr.
id()==ID_lt || expr.
id()==ID_gt)
457 else if(expr.
id()==ID_extractbit)
459 else if(expr.
id()==ID_forall)
461 else if(expr.
id()==ID_exists)
463 else if(expr.
id()==ID_let)
468 "convert_let must return 1-bit vector for boolean let");
472 else if(expr.
id()==ID_index)
478 else if(expr.
id()==ID_member)
484 else if(expr.
id()==ID_case)
490 else if(expr.
id()==ID_cond)
496 else if(expr.
id()==ID_sign)
501 const irep_idt type_id = operands[0].type().id();
502 if(type_id == ID_signedbv || type_id == ID_fixedbv || type_id == ID_floatbv)
503 return bv[bv.size()-1];
504 if(type_id == ID_unsignedbv)
507 else if(expr.
id()==ID_reduction_or || expr.
id()==ID_reduction_and ||
508 expr.
id()==ID_reduction_nor || expr.
id()==ID_reduction_nand ||
509 expr.
id()==ID_reduction_xor || expr.
id()==ID_reduction_xnor)
511 else if(expr.
id()==ID_onehot || expr.
id()==ID_onehot0)
515 else if(expr.
id()==ID_isnan)
523 return float_utils.
is_NaN(bv);
525 else if(expr.
op0().
type().
id() == ID_fixedbv)
528 else if(expr.
id()==ID_isfinite)
539 else if(expr.
op0().
type().
id() == ID_fixedbv)
542 else if(expr.
id()==ID_isinf)
551 else if(expr.
op0().
type().
id() == ID_fixedbv)
554 else if(expr.
id()==ID_isnormal)
563 else if(expr.
op0().
type().
id() == ID_fixedbv)
577 if(expr.
lhs().
id()==ID_symbol &&
613 exprt dest(ID_bv_literals, type);
615 bv_sub.resize(bv.size());
617 for(std::size_t i=0; i<bv.size(); i++)
634 if(type.
id()==ID_symbol)
637 if(type.
id()!=ID_array)
660 out << pair.first <<
"=" << pair.second.get_value(
prop) <<
'\n';
667 dest.reserve(components.size());
668 std::size_t offset = 0;
669 for(
const auto &comp : components)
671 dest.push_back(offset);
const if_exprt & to_if_expr(const exprt &expr)
Cast a generic exprt to an if_exprt.
virtual bvt convert_case(const exprt &expr)
virtual bvt convert_complex_real(const exprt &expr)
map_entryt & get_map_entry(const irep_idt &identifier, const typet &type)
The type of an expression.
void print_assignment(std::ostream &out) const override
std::vector< std::size_t > offset_mapt
virtual bvt convert_floatbv_typecast(const floatbv_typecast_exprt &expr)
virtual bvt convert_with(const exprt &expr)
const bswap_exprt & to_bswap_expr(const exprt &expr)
Cast a generic exprt to a bswap_exprt.
virtual bvt convert_concatenation(const exprt &expr)
virtual literalt convert_ieee_float_rel(const exprt &expr)
virtual bvt convert_array_of(const array_of_exprt &expr)
virtual bvt convert_bv_reduction(const unary_exprt &expr)
const std::string & id2string(const irep_idt &d)
application of (mathematical) function
literalt convert(const exprt &expr) override
const mod_exprt & to_mod_expr(const exprt &expr)
Cast a generic exprt to a mod_exprt.
bool equality_propagation
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
const div_exprt & to_div_expr(const exprt &expr)
Cast a generic exprt to a div_exprt.
std::vector< irept > subt
virtual literalt convert_onehot(const unary_exprt &expr)
virtual bvt convert_shift(const binary_exprt &expr)
virtual literalt convert_overflow(const exprt &expr)
bvt new_variables(std::size_t width)
generates a bitvector of given width with new variables
unsigned unsafe_string2unsigned(const std::string &str, int base)
virtual bvt convert_byte_extract(const byte_extract_exprt &expr)
boolbv_widtht boolbv_width
virtual literalt convert_equality(const equal_exprt &expr)
bool is_unbounded_array(const typet &type) const override
virtual bvt convert_replication(const replication_exprt &expr)
static var_not unused_var_no()
virtual bvt convert_bv_literals(const exprt &expr)
std::vector< componentt > componentst
virtual bvt convert_struct(const struct_exprt &expr)
const componentst & components() const
virtual bvt convert_function_application(const function_application_exprt &expr)
virtual bvt convert_lambda(const exprt &expr)
Magic numbers used throughout the codebase.
#define CHECK_RETURN(CONDITION)
static mstreamt & eom(mstreamt &m)
void set_to(const exprt &expr, bool value) override
virtual bool literal(const exprt &expr, literalt &literal) const
virtual bvt convert_constant(const constant_exprt &expr)
#define forall_literals(it, bv)
virtual bvt convert_symbol(const exprt &expr)
const let_exprt & to_let_expr(const exprt &expr)
Cast a generic exprt to a let_exprt.
virtual bvt convert_mult(const exprt &expr)
Extract member of struct or union.
const byte_update_exprt & to_byte_update_expr(const exprt &expr)
virtual bvt convert_complex(const exprt &expr)
virtual literalt convert_quantifier(const exprt &expr)
virtual bvt convert_update(const exprt &expr)
literalt is_normal(const bvt &)
virtual literalt land(literalt a, literalt b)=0
const irep_idt & id() const
bool replace_expr(const exprt &what, const exprt &by, exprt &dest)
virtual bvt convert_abs(const abs_exprt &expr)
void print_assignment(std::ostream &out) const override
virtual literalt new_variable()=0
virtual literalt convert_bv_rel(const exprt &expr)
virtual bvt convert_add_sub(const exprt &expr)
const replication_exprt & to_replication_expr(const exprt &expr)
Cast a generic exprt to a replication_exprt.
virtual literalt convert_reduction(const unary_exprt &expr)
virtual const bvt & convert_bv(const exprt &expr)
const extractbit_exprt & to_extractbit_expr(const exprt &expr)
Cast a generic exprt to an extractbit_exprt.
virtual bvt convert_bswap(const bswap_exprt &expr)
virtual size_t no_variables() const =0
void set_literals(const irep_idt &identifier, const typet &type, const bvt &literals)
offset_mapt build_offset_map(const struct_typet &src)
const array_of_exprt & to_array_of_expr(const exprt &expr)
Cast a generic exprt to an array_of_exprt.
virtual bvt convert_bitvector(const exprt &expr)
Converts an expression into its gate-level representation and returns a vector of literals correspond...
API to expression classes.
virtual bvt convert_floatbv_op(const exprt &expr)
const function_application_exprt & to_function_application_expr(const exprt &expr)
Cast a generic exprt to a function_application_exprt.
void conversion_failed(const exprt &expr, bvt &bv)
const irep_idt & get(const irep_namet &name) const
const extractbits_exprt & to_extractbits_expr(const exprt &expr)
Cast a generic exprt to an extractbits_exprt.
const binary_relation_exprt & to_binary_relation_expr(const exprt &expr)
Cast a generic exprt to a binary_relation_exprt.
#define PRECONDITION(CONDITION)
virtual bool boolbv_set_equality_to_true(const equal_exprt &expr)
virtual bool literal(const exprt &expr, std::size_t bit, literalt &literal) const
const member_exprt & to_member_expr(const exprt &expr)
Cast a generic exprt to a member_exprt.
bool has_prefix(const std::string &s, const std::string &prefix)
const exprt & size() const
virtual void set_frozen(literalt)
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast a generic exprt to a symbol_exprt.
virtual bvt convert_union(const union_exprt &expr)
array_exprt to_array_expr() const
convert string into array constant
const typet & follow(const typet &) const
virtual bvt convert_extractbits(const extractbits_exprt &expr)
const struct_typet & to_struct_type(const typet &type)
Cast a generic typet to a struct_typet.
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
const struct_exprt & to_struct_expr(const exprt &expr)
Cast a generic exprt to a struct_exprt.
literalt convert_rest(const exprt &expr) override
const constant_exprt & to_constant_expr(const exprt &expr)
Cast a generic exprt to a constant_exprt.
virtual bvt convert_complex_imag(const exprt &expr)
const floatbv_typecast_exprt & to_floatbv_typecast_expr(const exprt &expr)
Cast a generic exprt to a floatbv_typecast_exprt.
virtual bvt convert_let(const let_exprt &)
virtual bvt convert_cond(const exprt &expr)
std::vector< exprt > operandst
virtual bvt convert_not(const not_exprt &expr)
literalt is_infinity(const bvt &)
unsigned integer2unsigned(const mp_integer &n)
virtual bvt convert_byte_update(const byte_update_exprt &expr)
virtual bvt convert_bv_typecast(const typecast_exprt &expr)
literalt const_literal(bool value)
literalt is_NaN(const bvt &)
exprt lower_popcount(const popcount_exprt &expr, const namespacet &ns)
Lower a popcount_exprt to arithmetic and logic expressions.
const popcount_exprt & to_popcount_expr(const exprt &expr)
Cast a generic exprt to a popcount_exprt.
const equal_exprt & to_equal_expr(const exprt &expr)
Cast a generic exprt to an equal_exprt.
virtual exprt make_free_bv_expr(const typet &type)
virtual bvt convert_constraint_select_one(const exprt &expr)
void record(const function_application_exprt &function_application)
unbounded_arrayt unbounded_array
const shift_exprt & to_shift_expr(const exprt &expr)
Cast a generic exprt to a shift_exprt.
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a generic typet to a floatbv_typet.
virtual bvt convert_vector(const exprt &expr)
const string_constantt & to_string_constant(const exprt &expr)
virtual bvt convert_array(const exprt &expr)
const array_typet & to_array_type(const typet &type)
Cast a generic typet to an array_typet.
Base class for all expressions.
virtual bvt convert_index(const exprt &array, const mp_integer &index)
index operator with constant index
const union_exprt & to_union_expr(const exprt &expr)
Cast a generic exprt to a union_exprt.
std::string to_string(const string_constraintt &expr)
Used for debug printing.
virtual bvt convert_mod(const mod_exprt &expr)
irep_idt get_component_name() const
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast a generic exprt to a typecast_exprt.
const not_exprt & to_not_expr(const exprt &expr)
Cast a generic exprt to an not_exprt.
irept & add(const irep_namet &name)
virtual bvt convert_member(const member_exprt &expr)
virtual bvt convert_if(const if_exprt &expr)
virtual literalt convert_rest(const exprt &expr)
void set_frozen(literalt a) override
const std::string & id_string() const
const abs_exprt & to_abs_expr(const exprt &expr)
Cast a generic exprt to a abs_exprt.
void get_literals(const irep_idt &identifier, const typet &type, const std::size_t width, bvt &literals)
const binary_exprt & to_binary_expr(const exprt &expr)
Cast a generic exprt to a binary_exprt.
virtual bvt convert_unary_minus(const unary_exprt &expr)
virtual literalt convert_verilog_case_equality(const binary_relation_exprt &expr)
virtual bvt convert_div(const div_exprt &expr)
virtual exprt make_bv_expr(const typet &type, const bvt &bv)
#define DATA_INVARIANT(CONDITION, REASON)
void set_to(const exprt &expr, bool value) override
virtual literalt convert_extractbit(const extractbit_exprt &expr)
const std::size_t MAX_FLATTENED_ARRAY_SIZE
const unary_exprt & to_unary_expr(const exprt &expr)
Cast a generic exprt to a unary_exprt.
const byte_extract_exprt & to_byte_extract_expr(const exprt &expr)
virtual void ignoring(const exprt &expr)
const index_exprt & to_index_expr(const exprt &expr)
Cast a generic exprt to an index_exprt.
const irept & find(const irep_namet &name) const
std::vector< literalt > bvt
bvt build_constant(const mp_integer &i, std::size_t width)
virtual literalt convert_typecast(const typecast_exprt &expr)
conversion from bitvector types to boolean
virtual bvt convert_bitwise(const exprt &expr)
virtual bvt convert_power(const binary_exprt &expr)
auto expr_try_dynamic_cast(TExpr &base) -> typename detail::expr_try_dynamic_cast_return_typet< T, TExpr >::type
Try to cast a reference to a generic exprt to a specific derived class.