1 #ifndef ROSE_BinaryAnalysis_Partitioner2_BasicBlock_H
2 #define ROSE_BinaryAnalysis_Partitioner2_BasicBlock_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 #include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
7 #include <Rose/BinaryAnalysis/Partitioner2/Semantics.h>
8 #include <Rose/SourceLocation.h>
9 #include <AstSerialization.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) {}
113 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
115 friend class boost::serialization::access;
118 void serialize(S &s,
const unsigned ) {
119 s & BOOST_SERIALIZATION_NVP(expr_);
120 s & BOOST_SERIALIZATION_NVP(type_);
121 s & BOOST_SERIALIZATION_NVP(confidence_);
186 mutable SAWYER_THREAD_TRAITS::Mutex mutex_;
189 rose_addr_t startVa_;
190 std::string comment_;
191 std::vector<SgAsmInstruction*> insns_;
193 std::vector<DataBlockPtr> dblocks_;
199 static const size_t bigBlock_ = 200;
201 InsnAddrMap insnAddrMap_;
212 void clearCacheNS()
const;
220 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
222 friend class boost::serialization::access;
225 void serialize(S &s,
const unsigned version) {
227 s & BOOST_SERIALIZATION_NVP(isFrozen_);
228 s & BOOST_SERIALIZATION_NVP(startVa_);
229 s & BOOST_SERIALIZATION_NVP(comment_);
231 size_t nInsns = insns_.size();
232 s & BOOST_SERIALIZATION_NVP(nInsns);
233 insns_.resize(nInsns);
234 for (
size_t i = 0; i < nInsns; ++i)
235 transferAst(s, insns_[i]);
237 s & BOOST_SERIALIZATION_NVP(insns_);
238 s & boost::serialization::make_nvp(
"dispatcher_", semantics_.
dispatcher);
239 s & boost::serialization::make_nvp(
"operators_", semantics_.
operators);
240 s & boost::serialization::make_nvp(
"initialState_", semantics_.
initialState);
241 s & boost::serialization::make_nvp(
"usingDispatcher_", semantics_.
usingDispatcher);
243 s & BOOST_SERIALIZATION_NVP(dblocks_);
244 s & BOOST_SERIALIZATION_NVP(insnAddrMap_);
245 s & BOOST_SERIALIZATION_NVP(successors_);
246 s & BOOST_SERIALIZATION_NVP(ghostSuccessors_);
247 s & BOOST_SERIALIZATION_NVP(isFunctionCall_);
248 s & BOOST_SERIALIZATION_NVP(isFunctionReturn_);
249 s & BOOST_SERIALIZATION_NVP(mayReturn_);
251 s & BOOST_SERIALIZATION_NVP(popsStack_);
253 s & BOOST_SERIALIZATION_NVP(sourceLocation_);
285 return instance(startVa, partitioner);
296 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
310 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
321 const std::string&
comment()
const {
return comment_; }
322 void comment(
const std::string &s) { comment_ = s; }
345 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
369 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
370 return insns_.size();
381 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
382 return insns_.empty();
418 const std::vector<SgAsmInstruction*>&
instructions()
const {
return insns_; }
504 const std::vector<DataBlockPtr>&
dataBlocks()
const {
return dblocks_; }
621 void mayReturn(
bool flag)
const { mayReturn_.
set(flag); }
629 void popsStack(
bool flag)
const { popsStack_.
set(flag); }
646 friend class Partitioner;
649 void thaw() { isFrozen_ =
false; }
Base classes for instruction semantics.
Confidence confidence() const
Confidence level of this successor.
const std::string & comment() const
Comment.
const Semantics::SValuePtr & expr() const
Symbolic expression for the successor address.
DataBlockPtr dataBlockExists(const DataBlockPtr &) const
Determine if this basic block contains the specified data block or equivalent data block...
virtual Ptr create(rose_addr_t startVa, const PartitionerConstPtr &partitioner) const
Virtual constructor.
Information about a source location.
void pop()
Undo the latest append.
const Sawyer::Cached< std::set< rose_addr_t > > & ghostSuccessors() const
Ghost successors.
DataBlockPtr eraseDataBlock(const DataBlockPtr &)
Remove specified or equivalent data block from this basic block.
size_t nDataBlocks() const
Get the number of data blocks owned.
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.
BaseSemantics::RiscOperatorsPtr operators
Risc operators.
const std::vector< DataBlockPtr > & dataBlocks() const
Data blocks owned.
void confidence(Confidence c)
Confidence level of this successor.
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< 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.
Reference-counting intrusive smart pointer.
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.
bool isSemanticsError() const
Determines whether a semantics error was encountered.
void append(const PartitionerConstPtr &, SgAsmInstruction *)
Append an instruction to a basic block.
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.
Sawyer::SharedPointer< const Partitioner > PartitionerConstPtr
Shared-ownership pointer for Partitioner.
BasicBlockSemantics semantics() const
Return information about semantics.
const Sawyer::Cached< bool > & isFunctionReturn() const
Is a function return?
Normal control flow edge, nothing special.
bool isFrozen() const
Determine if basic block is read-only.
BasicBlockSemantics undropSemantics(const PartitionerConstPtr &)
Undrop semantics.
bool insertDataBlock(const DataBlockPtr &)
Make this basic block own the specified data block or equivalent data block.
std::vector< BasicBlockSuccessor > BasicBlockSuccessors
All successors in no particular order.
void sourceLocation(const SourceLocation &loc)
Optional location in source code.
Sawyer::SharedPointer< BasicBlock > Ptr
Shared pointer to a basic block.
void set(const Value &x) const
Assign a new value.
Base class for reference counted objects.
BaseSemantics::DispatcherPtr dispatcher
How instructions are dispatched.
BasicBlockSuccessors Successors
All successors in no particular order.
void dropSemantics(const PartitionerConstPtr &)
Drops semantic information.
static Ptr instance(rose_addr_t startVa, const PartitionerConstPtr &partitioner)
Static allocating constructor.
size_t nInstructions() const
Get the number of instructions in this block.
BaseSemantics::StatePtr initialState
Initial state for semantics.
API and storage for attributes.
Sawyer::SharedPointer< DataBlock > DataBlockPtr
Shared-ownership pointer for DataBlock.
const Sawyer::Cached< Successors > & successors() const
Control flow successors.
const std::vector< SgAsmInstruction * > & instructions() const
Get the instructions for this block.
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.
rose_addr_t fallthroughVa() const
Get the address after the end of the final instruction.
EdgeType type() const
Type of successor.