ROSE  0.11.57.0
DataBlock.h
1 #ifndef ROSE_BinaryAnalysis_Partitioner2_DataBlock_H
2 #define ROSE_BinaryAnalysis_Partitioner2_DataBlock_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
7 #include <SageBuilderAsm.h>
8 #include <Rose/SourceLocation.h>
9 
10 #include <boost/serialization/access.hpp>
11 #include <Sawyer/Attribute.h>
12 #include <Sawyer/SharedPointer.h>
13 
14 #include <string>
15 
16 namespace Rose {
17 namespace BinaryAnalysis {
18 namespace Partitioner2 {
19 
32 public:
35 
36 private:
37  bool isFrozen_; // true if object is read-only because it's in the CFG
38  rose_addr_t startVa_; // starting address
39  SgAsmType *type_; // type of data stored in this block
40  std::string comment_; // arbitrary comment, shown by printableName.
41  std::vector<BasicBlockPtr> attachedBasicBlockOwners_; // attached basic blocks that own this data block, sorted and unique
42  std::vector<FunctionPtr> attachedFunctionOwners_; // attached functions that own this data block, sorted and unique
43  SourceLocation sourceLocation_; // optional location of data in source code
44 
45 
46 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
47 private:
48  friend class boost::serialization::access;
49 
50  template<class S>
51  void serialize(S &s, const unsigned version) {
52  // s & boost::serialization::base_object<Sawyer::Attribute::Storage>(*this); -- not serialized
53  s & BOOST_SERIALIZATION_NVP(isFrozen_);
54  s & BOOST_SERIALIZATION_NVP(startVa_);
55  if (version >= 1) {
56  s & BOOST_SERIALIZATION_NVP(type_);
57  s & BOOST_SERIALIZATION_NVP(comment_);
58  } else if (S::is_loading::value) {
59  size_t nBytes = 0;
60  s & boost::serialization::make_nvp("size_", nBytes);
62  }
63  if (version < 2) {
64  ASSERT_not_reachable("Rose::BinaryAnalysis::Partitioner2::DataBlock version 2 is no longer supported");
65  } else {
66  s & BOOST_SERIALIZATION_NVP(attachedBasicBlockOwners_);
67  s & BOOST_SERIALIZATION_NVP(attachedFunctionOwners_);
68  }
69  if (version >= 3)
70  s & BOOST_SERIALIZATION_NVP(sourceLocation_);
71  }
72 #endif
73 
74 protected:
75  // needed for serialization
76  DataBlock();
77  DataBlock(rose_addr_t startVa, SgAsmType *type);
78 
79 public:
80  ~DataBlock();
81 
82 public:
84  static Ptr instance(rose_addr_t startVa, SgAsmType*);
85 
91  static Ptr instanceBytes(rose_addr_t startVa, size_t nBytes);
92 
96  bool isFrozen() const { return isFrozen_; }
97 
99  rose_addr_t address() const { return startVa_; }
100 
102  size_t size() const;
103 
109  SgAsmType* type() const { return type_; }
110  void type(SgAsmType *t);
116  const std::string& comment() const;
117  void comment(const std::string& s);
123  const SourceLocation& sourceLocation() const { return sourceLocation_; }
124  void sourceLocation(const SourceLocation &loc) { sourceLocation_ = loc; }
130  size_t nAttachedOwners() const;
131 
135  const std::vector<FunctionPtr>& attachedFunctionOwners() const;
136 
140  const std::vector<BasicBlockPtr>& attachedBasicBlockOwners() const;
142  AddressInterval extent() const;
143 
145  std::string printableName() const;
146 
153  std::vector<uint8_t> read(const MemoryMap::Ptr&) const;
154 
155 private:
156  friend class Partitioner;
157  void freeze();
158  void thaw();
159 
160  // Insert the specified owner into this data block.
161  void insertOwner(const BasicBlockPtr&);
162  void insertOwner(const FunctionPtr&);
163 
164  // Erase the specified owner of this data block.
165  void eraseOwner(const BasicBlockPtr&);
166  void eraseOwner(const FunctionPtr&);
167 };
168 
169 
170 } // namespace
171 } // namespace
172 } // namespace
173 
174 // Class versions must be at global scope
175 BOOST_CLASS_VERSION(Rose::BinaryAnalysis::Partitioner2::DataBlock, 3);
176 
177 #endif
178 #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:34
bool isFrozen() const
Determine if data block is read-only.
Definition: DataBlock.h:96
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:99
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:124
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:123
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:290
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:109