CBMC
bv_pointers.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 
10 #ifndef CPROVER_SOLVERS_FLATTENING_BV_POINTERS_H
11 #define CPROVER_SOLVERS_FLATTENING_BV_POINTERS_H
12 
13 #include "boolbv.h"
14 #include "pointer_logic.h"
15 
16 class bv_pointerst:public boolbvt
17 {
18 public:
20  const namespacet &,
21  propt &,
23  bool get_array_constraints = false);
24 
25  void finish_eager_conversion() override;
26 
28  endianness_map(const typet &, bool little_endian) const override;
29 
30 protected:
32 
33  std::size_t get_object_width(const pointer_typet &) const;
34  std::size_t get_offset_width(const pointer_typet &) const;
35  std::size_t get_address_width(const pointer_typet &) const;
36 
37  // NOLINTNEXTLINE(readability/identifiers)
38  typedef boolbvt SUB;
39 
40  [[nodiscard]] bvt
41  encode(const mp_integer &object, const pointer_typet &) const;
42 
43  virtual bvt convert_pointer_type(const exprt &);
44 
45  [[nodiscard]] virtual bvt add_addr(const exprt &);
46 
47  // overloading
48  literalt convert_rest(const exprt &) override;
49  bvt convert_bitvector(const exprt &) override; // no cache
50 
51  exprt
52  bv_get_rec(const exprt &, const bvt &, std::size_t offset) const override;
53 
54  [[nodiscard]] std::optional<bvt> convert_address_of_rec(const exprt &);
55 
56  [[nodiscard]] bvt
57  offset_arithmetic(const pointer_typet &, const bvt &, const mp_integer &);
58  [[nodiscard]] bvt offset_arithmetic(
59  const pointer_typet &,
60  const bvt &,
61  const mp_integer &factor,
62  const exprt &index);
63  [[nodiscard]] bvt offset_arithmetic(
64  const pointer_typet &type,
65  const bvt &bv,
66  const exprt &factor,
67  const exprt &index);
68  [[nodiscard]] bvt offset_arithmetic(
69  const pointer_typet &,
70  const bvt &,
71  const mp_integer &factor,
72  const bvt &index_bv);
73 
74  struct postponedt
75  {
76  bvt bv, op;
78 
79  postponedt(bvt _bv, bvt _op, exprt _expr)
80  : bv(std::move(_bv)), op(std::move(_op)), expr(std::move(_expr))
81  {
82  }
83  };
84 
85  typedef std::list<postponedt> postponed_listt;
87 
91  std::pair<exprt, exprt> prepare_postponed_is_dynamic_object(
92  std::vector<symbol_exprt> &placeholders) const;
93 
96  std::unordered_map<exprt, exprt, irep_hash>
97  prepare_postponed_object_size(std::vector<symbol_exprt> &placeholders) const;
98 
104  bvt object_literals(const bvt &bv, const pointer_typet &type) const;
105 
111  bvt offset_literals(const bvt &bv, const pointer_typet &type) const;
112 
118  static bvt object_offset_encoding(const bvt &object, const bvt &offset);
119 };
120 
121 #endif // CPROVER_SOLVERS_FLATTENING_BV_POINTERS_H
bool get_array_constraints
Definition: arrays.h:114
Definition: boolbv.h:46
std::size_t get_object_width(const pointer_typet &) const
Definition: bv_pointers.cpp:77
pointer_logict pointer_logic
Definition: bv_pointers.h:31
std::unordered_map< exprt, exprt, irep_hash > prepare_postponed_object_size(std::vector< symbol_exprt > &placeholders) const
Create Boolean functions describing all objects of each known object size over placeholders as input ...
bvt offset_arithmetic(const pointer_typet &, const bvt &, const mp_integer &)
postponed_listt postponed_list
Definition: bv_pointers.h:86
std::size_t get_address_width(const pointer_typet &) const
Definition: bv_pointers.cpp:91
virtual bvt add_addr(const exprt &)
endianness_mapt endianness_map(const typet &, bool little_endian) const override
Definition: bv_pointers.cpp:72
boolbvt SUB
Definition: bv_pointers.h:38
void finish_eager_conversion() override
exprt bv_get_rec(const exprt &, const bvt &, std::size_t offset) const override
static bvt object_offset_encoding(const bvt &object, const bvt &offset)
Construct a pointer encoding from given encodings of object and offset.
bvt encode(const mp_integer &object, const pointer_typet &) const
std::pair< exprt, exprt > prepare_postponed_is_dynamic_object(std::vector< symbol_exprt > &placeholders) const
Create Boolean functions describing all dynamic and all not-dynamic object encodings over placeholder...
std::list< postponedt > postponed_listt
Definition: bv_pointers.h:85
std::size_t get_offset_width(const pointer_typet &) const
Definition: bv_pointers.cpp:83
literalt convert_rest(const exprt &) override
bv_pointerst(const namespacet &, propt &, message_handlert &, bool get_array_constraints=false)
bvt convert_bitvector(const exprt &) override
Converts an expression into its gate-level representation and returns a vector of literals correspond...
bvt object_literals(const bvt &bv, const pointer_typet &type) const
Given a pointer encoded in bv, extract the literals identifying the object that the pointer points to...
Definition: bv_pointers.cpp:96
std::optional< bvt > convert_address_of_rec(const exprt &)
bvt offset_literals(const bvt &bv, const pointer_typet &type) const
Given a pointer encoded in bv, extract the literals representing the offset into an object that the p...
virtual bvt convert_pointer_type(const exprt &)
Maps a big-endian offset to a little-endian offset.
Base class for all expressions.
Definition: expr.h:56
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
Definition: pointer_expr.h:24
TO_BE_DOCUMENTED.
Definition: prop.h:25
The type of an expression, extends irept.
Definition: type.h:29
std::vector< literalt > bvt
Definition: literal.h:201
Pointer Logic.
BigInt mp_integer
Definition: smt_terms.h:17
postponedt(bvt _bv, bvt _op, exprt _expr)
Definition: bv_pointers.h:79