ROSE  0.11.2.0
DataBlock.h
1 #ifndef ROSE_Partitioner2_DataBlock_H
2 #define ROSE_Partitioner2_DataBlock_H
3 
4 #include <rosePublicConfig.h>
5 #ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
6 
7 #include <Partitioner2/BasicTypes.h>
8 #include <SageBuilderAsm.h>
9 #include <SourceLocation.h>
10 
11 #include <boost/serialization/access.hpp>
12 #include <Sawyer/Attribute.h>
13 #include <Sawyer/SharedPointer.h>
14 
15 #include <string>
16 
17 namespace Rose {
18 namespace BinaryAnalysis {
19 namespace Partitioner2 {
20 
33 public:
36 
37 private:
38  bool isFrozen_; // true if object is read-only because it's in the CFG
39  rose_addr_t startVa_; // starting address
40  SgAsmType *type_; // type of data stored in this block
41  std::string comment_; // arbitrary comment, shown by printableName.
42  std::vector<BasicBlockPtr> attachedBasicBlockOwners_; // attached basic blocks that own this data block, sorted and unique
43  std::vector<FunctionPtr> attachedFunctionOwners_; // attached functions that own this data block, sorted and unique
44  SourceLocation sourceLocation_; // optional location of data in source code
45 
46 
47 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
48 private:
49  friend class boost::serialization::access;
50 
51  template<class S>
52  void serialize(S &s, const unsigned version) {
53  // s & boost::serialization::base_object<Sawyer::Attribute::Storage>(*this); -- not serialized
54  s & BOOST_SERIALIZATION_NVP(isFrozen_);
55  s & BOOST_SERIALIZATION_NVP(startVa_);
56  if (version >= 1) {
57  s & BOOST_SERIALIZATION_NVP(type_);
58  s & BOOST_SERIALIZATION_NVP(comment_);
59  } else if (S::is_loading::value) {
60  size_t nBytes = 0;
61  s & boost::serialization::make_nvp("size_", nBytes);
63  }
64  if (version < 2) {
65  ASSERT_not_reachable("Rose::BinaryAnalysis::Partitioner2::DataBlock version 2 is no longer supported");
66  } else {
67  s & BOOST_SERIALIZATION_NVP(attachedBasicBlockOwners_);
68  s & BOOST_SERIALIZATION_NVP(attachedFunctionOwners_);
69  }
70  if (version >= 3)
71  s & BOOST_SERIALIZATION_NVP(sourceLocation_);
72  }
73 #endif
74 
75 protected:
76  // needed for serialization
77  DataBlock();
78  DataBlock(rose_addr_t startVa, SgAsmType *type);
79 
80 public:
81  ~DataBlock();
82 
83 public:
85  static Ptr instance(rose_addr_t startVa, SgAsmType*);
86 
92  static Ptr instanceBytes(rose_addr_t startVa, size_t nBytes);
93 
97  bool isFrozen() const { return isFrozen_; }
98 
100  rose_addr_t address() const { return startVa_; }
101 
103  size_t size() const;
104 
110  SgAsmType* type() const { return type_; }
111  void type(SgAsmType *t);
117  const std::string& comment() const;
118  void comment(const std::string& s);
124  const SourceLocation& sourceLocation() const { return sourceLocation_; }
125  void sourceLocation(const SourceLocation &loc) { sourceLocation_ = loc; }
131  size_t nAttachedOwners() const;
132 
136  const std::vector<FunctionPtr>& attachedFunctionOwners() const;
137 
141  const std::vector<BasicBlockPtr>& attachedBasicBlockOwners() const;
143  AddressInterval extent() const;
144 
146  std::string printableName() const;
147 
154  std::vector<uint8_t> read(const MemoryMap::Ptr&) const;
155 
156 private:
157  friend class Partitioner;
158  void freeze();
159  void thaw();
160 
161  // Insert the specified owner into this data block.
162  void insertOwner(const BasicBlockPtr&);
163  void insertOwner(const FunctionPtr&);
164 
165  // Erase the specified owner of this data block.
166  void eraseOwner(const BasicBlockPtr&);
167  void eraseOwner(const FunctionPtr&);
168 };
169 
170 
171 } // namespace
172 } // namespace
173 } // namespace
174 
175 // Class versions must be at global scope
176 BOOST_CLASS_VERSION(Rose::BinaryAnalysis::Partitioner2::DataBlock, 3);
177 
178 #endif
179 #endif
const std::string & comment() const
Property: Comment.
Information about a source location.
Sawyer::SharedPointer< DataBlock > Ptr
Shared pointer to a data block.
Definition: DataBlock.h:35
bool isFrozen() const
Determine if data block is read-only.
Definition: DataBlock.h:97
const std::vector< FunctionPtr > & attachedFunctionOwners() const
Functions that are attached to the partitioner and own this data block.
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:100
size_t size() const
Returns the size in bytes.
void sourceLocation(const SourceLocation &loc)
Property: Optional location of data in source code.
Definition: DataBlock.h:125
const std::vector< BasicBlockPtr > & attachedBasicBlockOwners() const
Basic blocks that are attached to the partitioner and own this data block.
static Ptr instance(rose_addr_t startVa, SgAsmType *)
Static allocating constructor.
AddressInterval extent() const
Addresses represented.
const SourceLocation & sourceLocation() const
Property: Optional location of data in source code.
Definition: DataBlock.h:124
Base class for binary types.
Base class for reference counted objects.
Definition: SharedObject.h:64
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:322
size_t nAttachedOwners() const
Number of attached basic block and function owners.
SgAsmVectorType * buildTypeVector(size_t, SgAsmType *)
Fixed-size, packed array.
SgAsmType * type() const
Property: Type of data stored in this block.
Definition: DataBlock.h:110