ROSE  0.9.9.139
DataBlock.h
1 #ifndef ROSE_Partitioner2_DataBlock_H
2 #define ROSE_Partitioner2_DataBlock_H
3 
4 #include <Partitioner2/BasicTypes.h>
5 
6 #include <boost/serialization/access.hpp>
7 #include <Sawyer/Attribute.h>
8 #include <Sawyer/SharedPointer.h>
9 
10 #include <string>
11 
12 namespace Rose {
13 namespace BinaryAnalysis {
14 namespace Partitioner2 {
15 
20 public:
23 
24 private:
25  bool isFrozen_; // true if object is read-only because it's in the CFG
26  rose_addr_t startVa_; // starting address
27  size_t size_; // size in bytes; FIXME[Robb P. Matzke 2014-08-12]: replace with type
28  size_t nAttachedOwners_; // number of attached basic blocks and functions that own this data
29 
30 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
31 private:
32  friend class boost::serialization::access;
33 
34  template<class S>
35  void serialize(S &s, const unsigned version) {
36  // s & boost::serialization::base_object<Sawyer::Attribute::Storage>(*this); -- not serialized
37  s & BOOST_SERIALIZATION_NVP(isFrozen_);
38  s & BOOST_SERIALIZATION_NVP(startVa_);
39  s & BOOST_SERIALIZATION_NVP(size_);
40  s & BOOST_SERIALIZATION_NVP(nAttachedOwners_);
41  }
42 #endif
43 
44 protected:
45  // needed for serialization
46  DataBlock(): isFrozen_(false), startVa_(0), size_(0), nAttachedOwners_(0) {}
47 
48  // use instance() instead
49  DataBlock(rose_addr_t startVa, size_t size): startVa_(startVa), size_(size), nAttachedOwners_(0) {
50  ASSERT_require(size_ > 0);
51  }
52 
53 public:
57  static Ptr instance(rose_addr_t startVa, size_t size) {
58  return Ptr(new DataBlock(startVa, size));
59  }
60 
64  virtual Ptr create(rose_addr_t startVa, size_t size) const {
65  return instance(startVa, size);
66  }
67 
71  bool isFrozen() const { return isFrozen_; }
72 
74  rose_addr_t address() const { return startVa_; }
75 
77  size_t size() const { return size_; }
78 
85  void size(size_t nBytes);
86 
90  size_t nAttachedOwners() const { return nAttachedOwners_; }
91 
94 
96  std::string printableName() const;
97 
98 private:
99  friend class Partitioner;
100  void freeze() { isFrozen_ = true; }
101  void thaw() { isFrozen_ = false; }
102  size_t incrementOwnerCount();
103  size_t decrementOwnerCount();
104 };
105 
106 
107 } // namespace
108 } // namespace
109 } // namespace
110 
111 #endif
Sawyer::SharedPointer< DataBlock > Ptr
Shared pointer to a data block.
Definition: DataBlock.h:22
static Ptr instance(rose_addr_t startVa, size_t size)
Static allocating constructor.
Definition: DataBlock.h:57
bool isFrozen() const
Determine if data block is read-only.
Definition: DataBlock.h:71
std::string printableName() const
A printable name for this data block.
Main namespace for the ROSE library.
rose_addr_t address() const
Returns the starting address.
Definition: DataBlock.h:74
size_t size() const
Returns the size in bytes.
Definition: DataBlock.h:77
static Interval baseSize(T lo, T size)
Construct an interval from one endpoint and a size.
Definition: Interval.h:161
AddressInterval extent() const
Addresses represented.
Definition: DataBlock.h:93
Base class for reference counted objects.
Definition: SharedObject.h:22
API and storage for attributes.
Definition: Attribute.h:208
Partitions instructions into basic blocks and functions.
Definition: Partitioner.h:290
size_t nAttachedOwners() const
Number of attached basic block and function owners.
Definition: DataBlock.h:90
virtual Ptr create(rose_addr_t startVa, size_t size) const
Virtual constructor.
Definition: DataBlock.h:64