1 #ifndef ROSE_Partitioner2_BasicBlock_H
2 #define ROSE_Partitioner2_BasicBlock_H
4 #include <featureTests.h>
5 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
7 #include <Partitioner2/BasicTypes.h>
8 #include <Partitioner2/DataBlock.h>
9 #include <Partitioner2/Semantics.h>
10 #include <SourceLocation.h>
12 #include <Sawyer/Attribute.h>
13 #include <Sawyer/Cached.h>
14 #include <Sawyer/Map.h>
15 #include <Sawyer/Optional.h>
16 #include <Sawyer/SharedPointer.h>
17 #include <Sawyer/Synchronization.h>
19 #include <boost/serialization/access.hpp>
20 #include <boost/serialization/base_object.hpp>
21 #include <boost/serialization/set.hpp>
22 #include <boost/serialization/string.hpp>
23 #include <boost/serialization/vector.hpp>
27 namespace Partitioner2 {
79 : usingDispatcher(false), wasDropped(false) {}
144 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
146 friend class boost::serialization::access;
149 void serialize(S &s,
const unsigned ) {
150 s & BOOST_SERIALIZATION_NVP(expr_);
151 s & BOOST_SERIALIZATION_NVP(type_);
152 s & BOOST_SERIALIZATION_NVP(confidence_);
184 mutable SAWYER_THREAD_TRAITS::Mutex mutex_;
187 rose_addr_t startVa_;
188 std::string comment_;
189 std::vector<SgAsmInstruction*> insns_;
191 std::vector<DataBlock::Ptr> dblocks_;
197 static const size_t bigBlock_ = 200;
199 InsnAddrMap insnAddrMap_;
211 void clearCacheNS()
const {
213 ghostSuccessors_.
clear();
214 isFunctionCall_.
clear();
215 isFunctionReturn_.
clear();
222 ASSERT_not_null(other);
223 SAWYER_THREAD_TRAITS::LockGuard2 lock(mutex_, other->mutex_);
224 successors_ = other->successors_;
225 ghostSuccessors_ = other->ghostSuccessors_;
226 isFunctionCall_ = other->isFunctionCall_;
227 isFunctionReturn_ = other->isFunctionReturn_;
228 mayReturn_ = other->mayReturn_;
229 popsStack_ = other->popsStack_;
236 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
238 friend class boost::serialization::access;
241 void serialize(S &s,
const unsigned version) {
243 s & BOOST_SERIALIZATION_NVP(isFrozen_);
244 s & BOOST_SERIALIZATION_NVP(startVa_);
245 s & BOOST_SERIALIZATION_NVP(comment_);
246 s & BOOST_SERIALIZATION_NVP(insns_);
247 s & boost::serialization::make_nvp(
"dispatcher_", semantics_.
dispatcher);
248 s & boost::serialization::make_nvp(
"operators_", semantics_.
operators);
249 s & boost::serialization::make_nvp(
"initialState_", semantics_.
initialState);
250 s & boost::serialization::make_nvp(
"usingDispatcher_", semantics_.
usingDispatcher);
252 s & BOOST_SERIALIZATION_NVP(dblocks_);
253 s & BOOST_SERIALIZATION_NVP(insnAddrMap_);
254 s & BOOST_SERIALIZATION_NVP(successors_);
255 s & BOOST_SERIALIZATION_NVP(ghostSuccessors_);
256 s & BOOST_SERIALIZATION_NVP(isFunctionCall_);
257 s & BOOST_SERIALIZATION_NVP(isFunctionReturn_);
258 s & BOOST_SERIALIZATION_NVP(mayReturn_);
260 s & BOOST_SERIALIZATION_NVP(popsStack_);
262 s & BOOST_SERIALIZATION_NVP(sourceLocation_);
272 : isFrozen_(false), startVa_(0) {}
275 BasicBlock(rose_addr_t startVa,
const Partitioner &partitioner)
276 : isFrozen_(false), startVa_(startVa) {
297 return instance(startVa, partitioner);
308 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
322 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
333 const std::string&
comment()
const {
return comment_; }
334 void comment(
const std::string &s) { comment_ = s; }
357 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
381 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
382 return insns_.size();
393 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
394 return insns_.empty();
420 const std::vector<SgAsmInstruction*>&
instructions()
const {
return insns_; }
467 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
468 return dblocks_.size();
510 const std::vector<DataBlock::Ptr>&
dataBlocks()
const {
return dblocks_; }
651 void thaw() { isFrozen_ =
false; }
652 BasicBlockSemantics undropSemanticsNS(
const Partitioner&);
EdgeType type() const
Type of successor.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
const std::string & comment() const
Comment.
Information about a source location.
static Ptr instance(rose_addr_t startVa, const Partitioner &partitioner)
Static allocating constructor.
void pop()
Undo the latest append.
const Sawyer::Cached< std::set< rose_addr_t > > & ghostSuccessors() const
Ghost successors.
Confidence confidence() const
Confidence level of this successor.
DataBlock::Ptr dataBlockExists(const DataBlock::Ptr &) const
Determine if this basic block contains the specified data block or equivalent data block...
size_t nDataBlocks() const
Get the number of data blocks owned.
void dropSemantics(const Partitioner &)
Drops semantic information.
EdgeType
Partitioner control flow edge types.
void insertSuccessor(const BaseSemantics::SValuePtr &, EdgeType type=E_NORMAL, Confidence confidence=ASSUMED)
Insert a new successor.
Base class for machine instructions.
void comment(const std::string &s)
Comment.
bool wasDropped
Whether the semantics had been dropped and reconstructed.
bool usingDispatcher
Whether semantic state is up-to-date.
BaseSemantics::StatePtr finalState() const
Return the final semantic state.
void append(const Partitioner &, SgAsmInstruction *)
Append an instruction to a basic block.
Sawyer::SharedPointer< DataBlock > Ptr
Shared pointer to a data block.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
BaseSemantics::RiscOperatorsPtr operators
Risc operators.
Information related to instruction semantics.
void clearCache()
Clear all cached data.
Main namespace for the ROSE library.
A container holding a set of values.
Sawyer::Optional< BaseSemantics::StatePtr > optionalPenultimateState
The state just prior to executing the final instruction.
rose_addr_t address() const
Get the address for a basic block.
BasicBlockSemantics()
Construct an empty semantics object.
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
const Sawyer::Cached< bool > & popsStack() const
Pops stack property.
AddressIntervalSet dataAddresses() const
Addresses that are part of static data.
Base classes for instruction semantics.
The value is an assumption without any proof.
bool isSemanticsDropped() const
Determines whether semantics have been dropped.
const Sawyer::Cached< bool > & isFunctionCall() const
Is a function call?
SgAsmInstruction * instructionExists(rose_addr_t startVa) const
Determine if this basic block contains an instruction at a specific address.
std::string printableName() const
A printable name for this basic block.
Confidence
How sure are we of something.
const Semantics::SValuePtr & expr() const
Symbolic expression for the successor address.
bool isSemanticsError() const
Determines whether a semantics error was encountered.
const SourceLocation & sourceLocation() const
Optional location in source code.
void clearSuccessors()
Clear all successor information.
bool isEmpty() const
Return true if this basic block has no instructions.
DataBlock::Ptr eraseDataBlock(const DataBlock::Ptr &)
Remove specified or equivalent data block from this basic block.
BasicBlockSemantics semantics() const
Return information about semantics.
const Sawyer::Cached< bool > & isFunctionReturn() const
Is a function return?
Normal control flow edge, nothing special.
void confidence(Confidence c)
Confidence level of this successor.
bool isFrozen() const
Determine if basic block is read-only.
BasicBlockSemantics undropSemantics(const Partitioner &)
Undrop semantics.
void sourceLocation(const SourceLocation &loc)
Optional location in source code.
void clear() const
Remove cached value.
Sawyer::SharedPointer< BasicBlock > Ptr
Shared pointer to a basic block.
const std::vector< DataBlock::Ptr > & dataBlocks() const
Data blocks owned.
Base class for reference counted objects.
BaseSemantics::DispatcherPtr dispatcher
How instructions are dispatched.
bool insertDataBlock(const DataBlock::Ptr &)
Make this basic block own the specified data block or equivalent data block.
size_t nInstructions() const
Get the number of instructions in this block.
BaseSemantics::StatePtr initialState
Initial state for semantics.
API and storage for attributes.
const Sawyer::Cached< Successors > & successors() const
Control flow successors.
virtual Ptr create(rose_addr_t startVa, const Partitioner &partitioner) const
Virtual constructor.
const std::vector< SgAsmInstruction * > & instructions() const
Get the instructions for this block.
Partitions instructions into basic blocks and functions.
AddressIntervalSet insnAddresses() const
Get all instruction addresses.
const Sawyer::Cached< bool > & mayReturn() const
May-return property.
std::set< rose_addr_t > explicitConstants() const
Set of explicit constants.
std::vector< Successor > Successors
All successors in no particular order.
rose_addr_t fallthroughVa() const
Get the address after the end of the final instruction.