CBMC
bv_pointers_wide.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 #ifndef CPROVER_CPROVER_BV_POINTERS_WIDE_H
10 #define CPROVER_CPROVER_BV_POINTERS_WIDE_H
11 
12 #include <util/pointer_expr.h>
13 
16 
17 #include "endianness_map_wide.h"
18 
19 class bv_pointers_widet : public boolbvt
20 {
21 public:
23  const namespacet &,
24  propt &,
26  bool get_array_constraints = false);
27 
28  void finish_eager_conversion() override;
29 
30  std::size_t boolbv_width(const typet &type) const override
31  {
32  if(type.id() == ID_pointer)
33  return 2 * to_pointer_type(type).get_width();
34  else
35  return boolbvt::boolbv_width(type);
36  }
37 
39  endianness_map(const typet &type, bool little_endian) const override
40  {
41  return endianness_map_widet{type, little_endian, ns};
42  }
43 
44 protected:
46 
47  std::size_t get_object_width(const pointer_typet &) const;
48  std::size_t get_offset_width(const pointer_typet &) const;
49 
50  // NOLINTNEXTLINE(readability/identifiers)
51  typedef boolbvt SUB;
52 
53  [[nodiscard]] bvt
54  encode(const mp_integer &object, const pointer_typet &) const;
55 
56  virtual bvt convert_pointer_type(const exprt &);
57 
58  [[nodiscard]] virtual bvt add_addr(const exprt &);
59 
60  // overloading
61  literalt convert_rest(const exprt &) override;
62  bvt convert_bitvector(const exprt &) override; // no cache
63 
64  exprt
65  bv_get_rec(const exprt &, const bvt &, std::size_t offset) const override;
66 
67  [[nodiscard]] std::optional<bvt> convert_address_of_rec(const exprt &);
68 
69  [[nodiscard]] bvt
70  offset_arithmetic(const pointer_typet &, const bvt &, const mp_integer &);
71  [[nodiscard]] bvt offset_arithmetic(
72  const pointer_typet &,
73  const bvt &,
74  const mp_integer &factor,
75  const exprt &index);
76  [[nodiscard]] bvt offset_arithmetic(
77  const pointer_typet &,
78  const bvt &,
79  const mp_integer &factor,
80  const bvt &index_bv);
81 
82  struct postponedt
83  {
84  bvt bv, op;
86 
87  postponedt(bvt _bv, bvt _op, exprt _expr)
88  : bv(std::move(_bv)), op(std::move(_op)), expr(std::move(_expr))
89  {
90  }
91  };
92 
93  typedef std::list<postponedt> postponed_listt;
95 
96  void do_postponed(const postponedt &postponed);
97 
103  bvt object_literals(const bvt &bv, const pointer_typet &type) const;
104 
110  bvt offset_literals(const bvt &bv, const pointer_typet &type) const;
111 
117  static bvt object_offset_encoding(const bvt &object, const bvt &offset);
118 
121  std::vector<bvt> numbered_pointers;
122 };
123 
124 #endif // CPROVER_CPROVER_BV_POINTERS_WIDE_H
const namespacet & ns
Definition: arrays.h:56
bool get_array_constraints
Definition: arrays.h:113
std::size_t get_width() const
Definition: std_types.h:920
Definition: boolbv.h:46
virtual std::size_t boolbv_width(const typet &type) const
Definition: boolbv.h:101
bv_pointers_widet(const namespacet &, propt &, message_handlert &, bool get_array_constraints=false)
virtual bvt convert_pointer_type(const exprt &)
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...
literalt convert_rest(const exprt &) override
bvt convert_bitvector(const exprt &) override
Converts an expression into its gate-level representation and returns a vector of literals correspond...
std::size_t get_object_width(const pointer_typet &) const
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::vector< bvt > numbered_pointers
Table that maps a 'pointer number' to its full-width bit-vector.
pointer_logict pointer_logic
postponed_listt postponed_list
bvt offset_arithmetic(const pointer_typet &, const bvt &, const mp_integer &)
std::optional< bvt > convert_address_of_rec(const exprt &)
std::list< postponedt > postponed_listt
endianness_mapt endianness_map(const typet &type, bool little_endian) const override
void do_postponed(const postponedt &postponed)
exprt bv_get_rec(const exprt &, const bvt &, std::size_t offset) const override
virtual bvt add_addr(const exprt &)
void finish_eager_conversion() override
std::size_t get_offset_width(const pointer_typet &) const
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...
std::size_t boolbv_width(const typet &type) const override
Maps a big-endian offset to a little-endian offset.
Base class for all expressions.
Definition: expr.h:56
const irep_idt & id() const
Definition: irep.h:384
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
API to expression classes for Pointers.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
Definition: pointer_expr.h:93
Pointer Logic.
BigInt mp_integer
Definition: smt_terms.h:17
postponedt(bvt _bv, bvt _op, exprt _expr)