15 #include "../floatbv/float_utils.h" 21 if(type.
id()!=ID_unsignedbv &&
22 type.
id()!=ID_signedbv &&
23 type.
id()!=ID_fixedbv &&
24 type.
id()!=ID_floatbv &&
25 type.
id()!=ID_range &&
26 type.
id()!=ID_complex &&
38 throw "operator "+expr.
id_string()+
" takes at least one operand";
44 std::cerr << expr.
pretty() <<
'\n';
45 throw "add/sub with mixed types";
51 throw "convert_add_sub: unexpected operand 0 width";
53 bool subtract=(expr.
id()==ID_minus ||
54 expr.
id()==
"no-overflow-minus");
56 bool no_overflow=(expr.
id()==
"no-overflow-plus" ||
57 expr.
id()==
"no-overflow-minus");
59 typet arithmetic_type=
60 (type.
id()==ID_vector || type.
id()==ID_complex)?
64 (arithmetic_type.
id()==ID_signedbv ||
68 for(exprt::operandst::const_iterator
69 it=operands.begin()+1;
70 it!=operands.end(); it++)
74 std::cerr << expr.
pretty() <<
'\n';
75 throw "add/sub with mixed types";
81 throw "convert_add_sub: unexpected operand width";
83 if(type.
id()==ID_vector || type.
id()==ID_complex)
89 if(sub_width==0 || width%sub_width!=0)
90 throw "convert_add_sub: unexpected vector operand width";
92 std::size_t size=width/sub_width;
95 for(std::size_t i=0; i<size; i++)
98 tmp_op.resize(sub_width);
100 for(std::size_t j=0; j<tmp_op.size(); j++)
102 assert(i*sub_width+j<op.size());
103 tmp_op[j]=op[i*sub_width+j];
107 tmp_result.resize(sub_width);
109 for(std::size_t j=0; j<tmp_result.size(); j++)
111 assert(i*sub_width+j<bv.size());
112 tmp_result[j]=bv[i*sub_width+j];
119 tmp_result=float_utils.
add_sub(tmp_result, tmp_op, subtract);
124 assert(tmp_result.size()==sub_width);
126 for(std::size_t j=0; j<tmp_result.size(); j++)
128 assert(i*sub_width+j<bv.size());
129 bv[i*sub_width+j]=tmp_result[j];
133 else if(type.
id()==ID_floatbv)
137 bv=float_utils.
add_sub(bv, op, subtract);
The type of an expression.
const typet & follow(const typet &src) const
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
bvt add_sub_no_overflow(const bvt &op0, const bvt &op1, bool subtract, representationt rep)
boolbv_widtht boolbv_width
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a generic typet to a floatbv_typet.
const irep_idt & id() const
virtual bvt convert_add_sub(const exprt &expr)
virtual const bvt & convert_bv(const exprt &expr)
void conversion_failed(const exprt &expr, bvt &bv)
virtual bvt add_sub(const bvt &src1, const bvt &src2, bool subtract)
std::vector< exprt > operandst
Base class for all expressions.
const std::string & id_string() const
const typet & subtype() const
bvt add_sub(const bvt &op0, const bvt &op1, bool subtract)
std::vector< literalt > bvt