1 #ifndef ROSE_BinaryAnalysis_Partitioner2_BasicBlock_H
2 #define ROSE_BinaryAnalysis_Partitioner2_BasicBlock_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 #include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
7 #include <Rose/BinaryAnalysis/Partitioner2/DataBlock.h>
8 #include <Rose/BinaryAnalysis/Partitioner2/Semantics.h>
9 #include <Rose/SourceLocation.h>
11 #include <Sawyer/Attribute.h>
12 #include <Sawyer/Cached.h>
13 #include <Sawyer/Map.h>
14 #include <Sawyer/Optional.h>
15 #include <Sawyer/SharedPointer.h>
16 #include <Sawyer/Synchronization.h>
18 #include <boost/serialization/access.hpp>
19 #include <boost/serialization/base_object.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 {
78 : usingDispatcher(false), wasDropped(false) {}
143 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
145 friend class boost::serialization::access;
148 void serialize(S &s,
const unsigned ) {
149 s & BOOST_SERIALIZATION_NVP(expr_);
150 s & BOOST_SERIALIZATION_NVP(type_);
151 s & BOOST_SERIALIZATION_NVP(confidence_);
183 mutable SAWYER_THREAD_TRAITS::Mutex mutex_;
186 rose_addr_t startVa_;
187 std::string comment_;
188 std::vector<SgAsmInstruction*> insns_;
190 std::vector<DataBlock::Ptr> dblocks_;
196 static const size_t bigBlock_ = 200;
198 InsnAddrMap insnAddrMap_;
210 void clearCacheNS()
const {
212 ghostSuccessors_.
clear();
213 isFunctionCall_.
clear();
214 isFunctionReturn_.
clear();
221 ASSERT_not_null(other);
222 SAWYER_THREAD_TRAITS::LockGuard2 lock(mutex_, other->mutex_);
223 successors_ = other->successors_;
224 ghostSuccessors_ = other->ghostSuccessors_;
225 isFunctionCall_ = other->isFunctionCall_;
226 isFunctionReturn_ = other->isFunctionReturn_;
227 mayReturn_ = other->mayReturn_;
228 popsStack_ = other->popsStack_;
235 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
237 friend class boost::serialization::access;
240 void serialize(S &s,
const unsigned version) {
242 s & BOOST_SERIALIZATION_NVP(isFrozen_);
243 s & BOOST_SERIALIZATION_NVP(startVa_);
244 s & BOOST_SERIALIZATION_NVP(comment_);
245 s & BOOST_SERIALIZATION_NVP(insns_);
246 s & boost::serialization::make_nvp(
"dispatcher_", semantics_.
dispatcher);
247 s & boost::serialization::make_nvp(
"operators_", semantics_.
operators);
248 s & boost::serialization::make_nvp(
"initialState_", semantics_.
initialState);
249 s & boost::serialization::make_nvp(
"usingDispatcher_", semantics_.
usingDispatcher);
251 s & BOOST_SERIALIZATION_NVP(dblocks_);
252 s & BOOST_SERIALIZATION_NVP(insnAddrMap_);
253 s & BOOST_SERIALIZATION_NVP(successors_);
254 s & BOOST_SERIALIZATION_NVP(ghostSuccessors_);
255 s & BOOST_SERIALIZATION_NVP(isFunctionCall_);
256 s & BOOST_SERIALIZATION_NVP(isFunctionReturn_);
257 s & BOOST_SERIALIZATION_NVP(mayReturn_);
259 s & BOOST_SERIALIZATION_NVP(popsStack_);
261 s & BOOST_SERIALIZATION_NVP(sourceLocation_);
271 : isFrozen_(false), startVa_(0) {}
274 BasicBlock(rose_addr_t startVa,
const Partitioner &partitioner)
275 : isFrozen_(false), startVa_(startVa) {
296 return instance(startVa, partitioner);
307 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
321 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
332 const std::string&
comment()
const {
return comment_; }
333 void comment(
const std::string &s) { comment_ = s; }
356 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
380 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
381 return insns_.size();
392 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
393 return insns_.empty();
429 const std::vector<SgAsmInstruction*>&
instructions()
const {
return insns_; }
475 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
476 return dblocks_.size();
518 const std::vector<DataBlock::Ptr>&
dataBlocks()
const {
return dblocks_; }
635 void mayReturn(
bool flag)
const { mayReturn_.
set(flag); }
643 void popsStack(
bool flag)
const { popsStack_.
set(flag); }
660 friend class Partitioner;
661 void init(
const Partitioner&);
663 void thaw() { isFrozen_ =
false; }
664 BasicBlockSemantics undropSemanticsNS(
const Partitioner&);
Base classes for instruction semantics.
EdgeType type() const
Type of successor.
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.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
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.
BaseSemantics::RiscOperatorsPtr operators
Risc operators.
Information related to instruction semantics.
void clearCache()
Clear all cached data.
Main namespace for the ROSE library.
Sawyer::Optional< size_t > instructionIndex(rose_addr_t) const
Position of an instruction.
Sawyer::Optional< BaseSemantics::StatePtr > optionalPenultimateState
The state just prior to executing the final instruction.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
rose_addr_t address() const
Get the address for a basic block.
BasicBlockSemantics()
Construct an empty semantics object.
const Sawyer::Cached< bool > & popsStack() const
Pops stack property.
AddressIntervalSet dataAddresses() const
Addresses that are part of static data.
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.
void set(const Value &x) const
Assign a new value.
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.