ROSE  0.9.11.42
DataBlock.h
1 #ifndef ROSE_Partitioner2_DataBlock_H
2 #define ROSE_Partitioner2_DataBlock_H
3 
4 #include <Partitioner2/BasicTypes.h>
5 #include <SageBuilderAsm.h>
6 
7 #include <boost/serialization/access.hpp>
8 #include <Sawyer/Attribute.h>
9 #include <Sawyer/SharedPointer.h>
10 
11 #include <string>
12 
13 namespace Rose {
14 namespace BinaryAnalysis {
15 namespace Partitioner2 {
16 
21 public:
24 
25 private:
26  bool isFrozen_; // true if object is read-only because it's in the CFG
27  rose_addr_t startVa_; // starting address
28  SgAsmType *type_; // type of data stored in this block
29  size_t nAttachedOwners_; // number of attached basic blocks and functions that own this data
30  std::string comment_;
31 
32 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
33 private:
34  friend class boost::serialization::access;
35 
36  template<class S>
37  void serialize(S &s, const unsigned version) {
38  // s & boost::serialization::base_object<Sawyer::Attribute::Storage>(*this); -- not serialized
39  s & BOOST_SERIALIZATION_NVP(isFrozen_);
40  s & BOOST_SERIALIZATION_NVP(startVa_);
41  if (version >= 1) {
42  s & BOOST_SERIALIZATION_NVP(type_);
43  s & BOOST_SERIALIZATION_NVP(comment_);
44  } else if (S::is_loading::value) {
45  size_t nBytes = 0;
46  s & boost::serialization::make_nvp("size_", nBytes);
48  }
49  s & BOOST_SERIALIZATION_NVP(nAttachedOwners_);
50  }
51 #endif
52 
53 protected:
54  // needed for serialization
55  DataBlock()
56  : isFrozen_(false), startVa_(0), type_(NULL), nAttachedOwners_(0) {}
57 
58  DataBlock(rose_addr_t startVa, SgAsmType *type)
59  : isFrozen_(false), startVa_(startVa), type_(type), nAttachedOwners_(0) {}
60 
61 public:
63  static Ptr instance(rose_addr_t startVa, SgAsmType*);
64 
70  static Ptr instanceBytes(rose_addr_t startVa, size_t nBytes);
71 
75  bool isFrozen() const { return isFrozen_; }
76 
78  rose_addr_t address() const { return startVa_; }
79 
81  size_t size() const;
82 
88  SgAsmType* type() const { return type_; }
89  void type(SgAsmType *t);
95  const std::string& comment() const { return comment_; }
96  void comment(const std::string& s) { comment_ = s; }
102  size_t nAttachedOwners() const { return nAttachedOwners_; }
103 
105  AddressInterval extent() const;
106 
108  std::string printableName() const;
109 
116  std::vector<uint8_t> read(const MemoryMap::Ptr&) const;
117 
118 private:
119  friend class Partitioner;
120  void freeze() { isFrozen_ = true; }
121  void thaw() { isFrozen_ = false; }
122  size_t incrementOwnerCount();
123  size_t decrementOwnerCount();
124  void nAttachedOwners(size_t);
125 };
126 
127 
128 } // namespace
129 } // namespace
130 } // namespace
131 
132 // Class versions must be at global scope
133 BOOST_CLASS_VERSION(Rose::BinaryAnalysis::Partitioner2::DataBlock, 1);
134 
135 #endif
const std::string & comment() const
Property: Comment.
Definition: DataBlock.h:95
Sawyer::SharedPointer< DataBlock > Ptr
Shared pointer to a data block.
Definition: DataBlock.h:23
bool isFrozen() const
Determine if data block is read-only.
Definition: DataBlock.h:75
SgAsmIntegerType * buildTypeU8()
8-bit unsigned
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:78
size_t size() const
Returns the size in bytes.
static Ptr instance(rose_addr_t startVa, SgAsmType *)
Static allocating constructor.
AddressInterval extent() const
Addresses represented.
Base class for binary types.
Base class for reference counted objects.
Definition: SharedObject.h:64
void comment(const std::string &s)
Property: Comment.
Definition: DataBlock.h:96
std::vector< uint8_t > read(const MemoryMap::Ptr &) const
Read static data from a memory map.
API and storage for attributes.
Definition: Attribute.h:208
static Ptr instanceBytes(rose_addr_t startVa, size_t nBytes)
Static allocating constructor.
Partitions instructions into basic blocks and functions.
Definition: Partitioner.h:293
size_t nAttachedOwners() const
Number of attached basic block and function owners.
Definition: DataBlock.h:102
SgAsmVectorType * buildTypeVector(size_t, SgAsmType *)
Fixed-size, packed array.
SgAsmType * type() const
Property: Type of data stored in this block.
Definition: DataBlock.h:88