ROSE  0.9.9.109
OwnedDataBlock.h
1 #ifndef ROSE_Partitioner2_OwnedDataBlock_H
2 #define ROSE_Partitioner2_OwnedDataBlock_H
3 
4 #include <Partitioner2/BasicBlock.h>
5 #include <Partitioner2/BasicTypes.h>
6 #include <Partitioner2/DataBlock.h>
7 #include <Partitioner2/Function.h>
8 
9 #include <Sawyer/Map.h>
10 
11 #include <boost/serialization/access.hpp>
12 #include <boost/serialization/vector.hpp>
13 
14 namespace Rose {
15 namespace BinaryAnalysis {
16 namespace Partitioner2 {
17 
27  DataBlock::Ptr dblock_; // the data block, non-null
28  std::vector<Function::Ptr> functions_; // functions that own this data block, sorted
29  std::vector<BasicBlock::Ptr> bblocks_; // basic blocks that own this data block, sorted
30 
31 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
32 private:
33  friend class boost::serialization::access;
34 
35  template<class S>
36  void serialize(S &s, const unsigned version) {
37  s & BOOST_SERIALIZATION_NVP(dblock_);
38  s & BOOST_SERIALIZATION_NVP(functions_);
39  s & BOOST_SERIALIZATION_NVP(bblocks_);
40  }
41 #endif
42 
43 public:
50 
54  explicit OwnedDataBlock(const DataBlock::Ptr &dblock): dblock_(dblock) {
55  ASSERT_not_null(dblock);
56  }
57 
62  OwnedDataBlock(const DataBlock::Ptr &dblock, const Function::Ptr &owner)
63  : dblock_(dblock), functions_(1, owner) {
64  ASSERT_not_null(dblock);
65  ASSERT_not_null(owner);
66  }
67 
72  OwnedDataBlock(const DataBlock::Ptr &dblock, const BasicBlock::Ptr &owner)
73  : dblock_(dblock), bblocks_(1, owner) {
74  ASSERT_not_null(dblock);
75  ASSERT_not_null(owner);
76  }
77 
82  bool isValid() const { return dblock_!=NULL; }
83 
87  DataBlock::Ptr dataBlock() const { return dblock_; }
88 
94  size_t insertOwner(const Function::Ptr&);
95 
101  size_t insertOwner(const BasicBlock::Ptr&);
102 
107  size_t eraseOwner(const Function::Ptr&);
108 
113  size_t eraseOwner(const BasicBlock::Ptr&);
114 
119  const std::vector<Function::Ptr>& owningFunctions() const { return functions_; }
120 
125  const std::vector<BasicBlock::Ptr>& owningBasicBlocks() const { return bblocks_; }
126 
129  size_t nFunctionOwners() const { return functions_.size(); }
130 
133  size_t nBasicBlockOwners() const { return bblocks_.size(); }
134 
139  size_t nOwners() const { return functions_.size() + bblocks_.size(); }
140 
145  bool isOwned() const { return !functions_.empty() || !bblocks_.empty(); }
146 };
147 
148 } // namespace
149 } // namespace
150 } // namespace
151 
152 #endif
OwnedDataBlock()
Default constructed null ownership.
OwnedDataBlock(const DataBlock::Ptr &dblock, const Function::Ptr &owner)
Construct a new data block ownership record.
const std::vector< Function::Ptr > & owningFunctions() const
Returns the list of functions that own this data block.
size_t eraseOwner(const Function::Ptr &)
Remove a function owner for this data block.
const std::vector< BasicBlock::Ptr > & owningBasicBlocks() const
Returns the list of basic blocks that own this data block.
Main namespace for the ROSE library.
size_t insertOwner(const Function::Ptr &)
Add a function owner for this data block.
bool isValid() const
Determines whether an ownership record is valid.
DataBlock::Ptr dataBlock() const
Returns the data block for this ownership record.
size_t nOwners() const
Returns the number of owners for this data block.
size_t nFunctionOwners() const
Returns the number of functions that own this data block.
bool isOwned() const
Returns true if this data block is owned.
size_t nBasicBlockOwners() const
Returns the number basic blocks that own this data block.
OwnedDataBlock(const DataBlock::Ptr &dblock, const BasicBlock::Ptr &owner)
Construct a new data block ownership record.
OwnedDataBlock(const DataBlock::Ptr &dblock)
Construct a new data block ownership record.