1 #ifndef ROSE_BinaryAnalysis_Partitioner2_Function_H
2 #define ROSE_BinaryAnalysis_Partitioner2_Function_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics.h>
7 #include <Rose/BinaryAnalysis/CallingConvention.h>
8 #include <Rose/BinaryAnalysis/StackDelta.h>
9 #include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
10 #include <Rose/BinaryAnalysis/Partitioner2/DataBlock.h>
11 #include <Rose/SourceLocation.h>
13 #include <Sawyer/Attribute.h>
14 #include <Sawyer/Cached.h>
15 #include <Sawyer/Map.h>
16 #include <Sawyer/Set.h>
17 #include <Sawyer/SharedPointer.h>
19 #include <boost/serialization/access.hpp>
20 #include <boost/serialization/set.hpp>
21 #include <boost/serialization/string.hpp>
22 #include <boost/serialization/vector.hpp>
25 namespace BinaryAnalysis {
26 namespace Partitioner2 {
51 typedef FunctionPtr
Ptr;
56 std::string demangledName_;
59 std::string reasonComment_;
60 std::set<rose_addr_t> bblockVas_;
61 std::vector<DataBlock::Ptr> dblocks_;
78 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
80 friend class boost::serialization::access;
83 void serialize(S &s,
const unsigned version) {
85 s & BOOST_SERIALIZATION_NVP(entryVa_);
86 s & BOOST_SERIALIZATION_NVP(name_);
87 s & BOOST_SERIALIZATION_NVP(demangledName_);
88 s & BOOST_SERIALIZATION_NVP(comment_);
89 s & BOOST_SERIALIZATION_NVP(reasons_);
90 s & BOOST_SERIALIZATION_NVP(bblockVas_);
91 s & BOOST_SERIALIZATION_NVP(dblocks_);
92 s & BOOST_SERIALIZATION_NVP(isFrozen_);
93 s & BOOST_SERIALIZATION_NVP(ccAnalysis_);
94 s & BOOST_SERIALIZATION_NVP(ccDefinition_);
95 s & BOOST_SERIALIZATION_NVP(stackDeltaAnalysis_);
96 s & BOOST_SERIALIZATION_NVP(stackDeltaOverride_);
98 s & BOOST_SERIALIZATION_NVP(reasonComment_);
100 s & BOOST_SERIALIZATION_NVP(sourceLocation_);
107 : entryVa_(0), reasons_(0), isFrozen_(false) {}
111 : entryVa_(entryVa), name_(name), reasons_(reasons), isFrozen_(false) {
112 bblockVas_.insert(entryVa);
119 static Ptr
instance(rose_addr_t entryVa,
const std::string &name=
"",
unsigned reasons=0) {
122 static Ptr
instance(rose_addr_t entryVa,
unsigned reasons) {
131 rose_addr_t
address()
const {
return entryVa_; }
138 const std::string&
name()
const {
return name_; }
139 void name(
const std::string &name) { name_ =
name; }
157 const std::string&
comment()
const {
return comment_; }
158 void comment(
const std::string &s) { comment_ = s; }
179 void insertReasons(
unsigned reasons) { reasons_ = (reasons_ & 0xffff0000) | reasons; }
185 void eraseReasons(
unsigned reasons) { reasons_ &= ~((0xffff0000 &
reasons) | ((reasons & 0xffff) != 0 ? 0xffff : 0x0)); }
204 return bblockVas_.find(bblockVa) != bblockVas_.end();
216 ASSERT_forbid(isFrozen_);
217 bool wasInserted = bblockVas_.insert(bblockVa).second;
229 ASSERT_forbid(isFrozen_);
230 ASSERT_forbid2(bblockVa==entryVa_,
"function entry block cannot be removed");
232 bblockVas_.erase(bblockVa);
237 const std::vector<DataBlock::Ptr>&
dataBlocks()
const {
return dblocks_; }
373 void freeze() { isFrozen_ =
true; }
374 void thaw() { isFrozen_ =
false; }
void name(const std::string &name)
Property: Optional function name.
bool insertDataBlock(const DataBlock::Ptr &)
Add a data block to this function.
bool ownsBasicBlock(rose_addr_t bblockVa) const
Predicate to test whether a function owns a basic block address.
Information about a source location.
void sourceLocation(const SourceLocation &loc)
Property: Location of function definition in source code, if known.
void callingConventionDefinition(const CallingConvention::Definition::Ptr &ccdef)
Property: Best calling convention definition.
std::string printableName() const
A printable name for the function.
int64_t stackDeltaConcrete() const
Property: Stack delta.
CallingConvention::Definition::Ptr callingConventionDefinition()
Property: Best calling convention definition.
CallingConvention::Analysis & callingConventionAnalysis()
Property: Calling convention analysis results.
void eraseReasons(unsigned reasons)
Remove function reason bits.
InstructionSemantics::BaseSemantics::SValuePtr stackDelta() const
Property: Stack delta.
Sawyer::SharedPointer< DataBlock > Ptr
Shared pointer to a data block.
void reasons(unsigned reasons)
Property: Bit vector of function reasons.
StackDelta::Analysis & stackDeltaAnalysis()
Property: Stack delta analysis results.
const std::string & demangledName() const
Property: Optional demangled name.
Function calling convention.
const std::string & reasonComment() const
Property: Additional comment for why function was detected.
Main namespace for the ROSE library.
static Ptr instance(rose_addr_t entryVa, const std::string &name="", unsigned reasons=0)
Static allocating constructor.
void demangledName(const std::string &name)
Property: Optional demangled name.
size_t nBasicBlocks() const
Number of basic blocks in the function.
Reference-counting intrusive smart pointer.
bool insertBasicBlock(rose_addr_t bblockVa)
Add a basic block to this function.
Sawyer::SharedPointer< Function > FunctionPtr
Shared-ownership pointer for function.
void reasonComment(const std::string &s)
Property: Additional comment for why function was detected.
void comment(const std::string &s)
Property: Optional function comment.
AddressIntervalSet dataAddresses() const
Addresses that are part of static data.
Function does not own the block.
unsigned reasons() const
Property: Bit vector of function reasons.
const Sawyer::Cached< bool > & isNoop() const
Cached results of function no-op analysis.
const std::vector< DataBlock::Ptr > & dataBlocks() const
Returns data blocks owned by this function.
const SourceLocation & sourceLocation() const
Property: Location of function definition in source code, if known.
DataBlock::Ptr dataBlockExists(const DataBlock::Ptr &) const
Determine if this function contains the specified data block, or equivalent.
size_t nDataBlocks() const
Number of data blocks in the function.
Function might own the block in the future.
void clear() const
Remove cached value.
DataBlock::Ptr eraseDataBlock(const DataBlock::Ptr &)
Remove specified or equivalent data block from this function.
const std::set< rose_addr_t > & basicBlockAddresses() const
Returns basic block addresses.
Base class for reference counted objects.
void insertReasons(unsigned reasons)
Insert additional function reason bits.
const StackDelta::Analysis & stackDeltaAnalysis() const
Property: Stack delta analysis results.
Ownership
Manner in which a function owns a block.
bool isThunk() const
True if function is a thunk.
const std::string & name() const
Property: Optional function name.
API and storage for attributes.
const std::string & comment() const
Property: Optional function comment.
static Ptr instance(rose_addr_t entryVa, unsigned reasons)
Static allocating constructor.
rose_addr_t address() const
Read-only property: Entry address.
void eraseBasicBlock(rose_addr_t bblockVa)
Remove a basic block from this function.
Partitions instructions into basic blocks and functions.
FunctionPtr Ptr
Shared-ownership pointer for function.
bool isFrozen() const
Determines whether a function is frozen.
InstructionSemantics::BaseSemantics::SValuePtr stackDeltaOverride() const
Property: Stack delta override.
Function owns the block explicitly, the normal ownership.
const CallingConvention::Analysis & callingConventionAnalysis() const
Property: Calling convention analysis results.