cprover
boolbv_abs.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 #include "boolbv.h"
10 
11 #include <util/std_types.h>
12 
13 #include "boolbv_type.h"
14 
16 
18 {
19  const std::size_t width = boolbv_width(expr.type());
20 
21  if(width==0)
22  return conversion_failed(expr);
23 
24  const bvt &op_bv=convert_bv(expr.op());
25 
26  if(expr.op().type()!=expr.type())
27  return conversion_failed(expr);
28 
29  const bvtypet bvtype = get_bvtype(expr.type());
30 
31  if(bvtype==bvtypet::IS_FIXED ||
32  bvtype==bvtypet::IS_SIGNED ||
33  bvtype==bvtypet::IS_UNSIGNED)
34  {
35  return bv_utils.absolute_value(op_bv);
36  }
37  else if(bvtype==bvtypet::IS_FLOAT)
38  {
39  float_utilst float_utils(prop, to_floatbv_type(expr.type()));
40  return float_utils.abs(op_bv);
41  }
42 
43  return conversion_failed(expr);
44 }
bv_utilst bv_utils
Definition: boolbv.h:93
const exprt & op() const
Definition: std_expr.h:340
boolbv_widtht boolbv_width
Definition: boolbv.h:90
typet & type()
Definition: expr.h:56
virtual bvt convert_abs(const abs_exprt &expr)
Definition: boolbv_abs.cpp:17
virtual const bvt & convert_bv(const exprt &expr)
Definition: boolbv.cpp:116
void conversion_failed(const exprt &expr, bvt &bv)
Definition: boolbv.h:108
bvt absolute_value(const bvt &op)
Definition: bv_utils.cpp:773
bvtypet get_bvtype(const typet &type)
Definition: boolbv_type.cpp:12
bvtypet
Definition: boolbv_type.h:16
API to type classes.
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a generic typet to a floatbv_typet.
Definition: std_types.h:1382
absolute value
Definition: std_expr.h:388
bvt abs(const bvt &)
std::vector< literalt > bvt
Definition: literal.h:200