19 expr.
id() == ID_plus || expr.
id() == ID_minus ||
20 expr.
id() ==
"no-overflow-plus" || expr.
id() ==
"no-overflow-minus");
24 if(type.
id()!=ID_unsignedbv &&
25 type.
id()!=ID_signedbv &&
26 type.
id()!=ID_fixedbv &&
27 type.
id()!=ID_floatbv &&
28 type.
id()!=ID_range &&
29 type.
id()!=ID_complex &&
42 "operator " + expr.
id_string() +
" takes at least one operand");
46 op0.
type() == type,
"add/sub with mixed types:\n" + expr.
pretty());
50 bool subtract=(expr.
id()==ID_minus ||
51 expr.
id()==
"no-overflow-minus");
53 bool no_overflow=(expr.
id()==
"no-overflow-plus" ||
54 expr.
id()==
"no-overflow-minus");
56 typet arithmetic_type = (type.
id() == ID_vector || type.
id() == ID_complex)
61 (arithmetic_type.
id()==ID_signedbv ||
65 for(exprt::operandst::const_iterator
66 it=operands.begin()+1;
67 it!=operands.end(); it++)
70 it->type() == type,
"add/sub with mixed types:\n" + expr.
pretty());
74 if(type.
id()==ID_vector || type.
id()==ID_complex)
76 std::size_t sub_width =
79 INVARIANT(sub_width != 0,
"vector elements shall have nonzero bit width");
81 width % sub_width == 0,
82 "total vector bit width shall be a multiple of the element bit width");
84 std::size_t size=width/sub_width;
87 for(std::size_t i=0; i<size; i++)
90 tmp_op.resize(sub_width);
92 for(std::size_t j=0; j<tmp_op.size(); j++)
94 const std::size_t index = i * sub_width + j;
95 INVARIANT(index < op.size(),
"bit index shall be within bounds");
96 tmp_op[j] = op[index];
100 tmp_result.resize(sub_width);
102 for(std::size_t j=0; j<tmp_result.size(); j++)
104 const std::size_t index = i * sub_width + j;
105 INVARIANT(index < bv.size(),
"bit index shall be within bounds");
106 tmp_result[j] = bv[index];
114 tmp_result=float_utils.
add_sub(tmp_result, tmp_op, subtract);
120 tmp_result.size() == sub_width,
121 "applying the add/sub operation shall not change the bitwidth");
123 for(std::size_t j=0; j<tmp_result.size(); j++)
125 const std::size_t index = i * sub_width + j;
126 INVARIANT(index < bv.size(),
"bit index shall be within bounds");
127 bv[index] = tmp_result[j];
131 else if(type.
id()==ID_floatbv)
135 bv=float_utils.
add_sub(bv, op, subtract);
Pre-defined bitvector types.
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a typet to a floatbv_typet.
virtual const bvt & convert_bv(const exprt &expr, const optionalt< std::size_t > expected_width=nullopt)
Convert expression to vector of literalts, using an internal cache to speed up conversion if availabl...
virtual bvt convert_add_sub(const exprt &expr)
bvt conversion_failed(const exprt &expr)
Print that the expression of x has failed conversion, then return a vector of x's width.
virtual std::size_t boolbv_width(const typet &type) const
bvt add_sub_no_overflow(const bvt &op0, const bvt &op1, bool subtract, representationt rep)
bvt add_sub(const bvt &op0, const bvt &op1, bool subtract)
Base class for all expressions.
std::vector< exprt > operandst
typet & type()
Return the type of the expression.
virtual bvt add_sub(const bvt &src1, const bvt &src2, bool subtract)
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
const std::string & id_string() const
const irep_idt & id() const
const typet & subtype() const
The type of an expression, extends irept.
std::vector< literalt > bvt
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
const multi_ary_exprt & to_multi_ary_expr(const exprt &expr)
Cast an exprt to a multi_ary_exprt.
const type_with_subtypet & to_type_with_subtype(const typet &type)