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>
10#include <Sawyer/Attribute.h>
11#include <Sawyer/Cached.h>
12#include <Sawyer/Map.h>
13#include <Sawyer/Optional.h>
14#include <Sawyer/SharedPointer.h>
15#include <Sawyer/Synchronization.h>
17#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
18#include <boost/serialization/access.hpp>
22namespace BinaryAnalysis {
23namespace Partitioner2 {
110#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
112 friend class boost::serialization::access;
113 template<
class S>
void serialize(S &s,
const unsigned );
177 mutable SAWYER_THREAD_TRAITS::Mutex mutex_;
180 rose_addr_t startVa_;
181 std::string comment_;
182 std::vector<SgAsmInstruction*> insns_;
184 std::vector<DataBlockPtr> dblocks_;
190 static const size_t bigBlock_ = 200;
203 void clearCacheNS()
const;
211#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
213 friend class boost::serialization::access;
214 template<
class S>
void serializeCommon(S&,
const unsigned version);
215 template<
class S>
void save(S&,
const unsigned version)
const;
216 template<
class S>
void load(S&,
const unsigned version);
217 BOOST_SERIALIZATION_SPLIT_MEMBER();
248 return instance(startVa, partitioner);
259 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
273 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
284 const std::string&
comment()
const {
return comment_; }
285 void comment(
const std::string &s) { comment_ = s; }
308 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
332 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
333 return insns_.size();
344 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
345 return insns_.empty();
381 const std::vector<SgAsmInstruction*>&
instructions()
const {
return insns_; }
467 const std::vector<DataBlockPtr>&
dataBlocks()
const {
return dblocks_; }
584 void mayReturn(
bool flag)
const { mayReturn_.
set(flag); }
592 void popsStack(
bool flag)
const { popsStack_.
set(flag); }
612 void thaw() { isFrozen_ =
false; }
Information related to instruction semantics.
BaseSemantics::DispatcherPtr dispatcher
How instructions are dispatched.
bool wasDropped
Whether the semantics had been dropped and reconstructed.
BasicBlockSemantics()
Construct an empty semantics object.
bool usingDispatcher
Whether semantic state is up-to-date.
BaseSemantics::StatePtr initialState
Initial state for semantics.
bool isSemanticsDropped() const
Determines whether semantics have been dropped.
bool isSemanticsError() const
Determines whether a semantics error was encountered.
Sawyer::Optional< BaseSemantics::StatePtr > optionalPenultimateState
The state just prior to executing the final instruction.
BaseSemantics::RiscOperatorsPtr operators
Risc operators.
BaseSemantics::StatePtr finalState() const
Return the final semantic state.
const Semantics::SValuePtr & expr() const
Symbolic expression for the successor address.
EdgeType type() const
Type of successor.
void confidence(Confidence c)
Confidence level of this successor.
Confidence confidence() const
Confidence level of this successor.
BasicBlockSemantics semantics() const
Return information about semantics.
const Sawyer::Cached< bool > & popsStack() const
Pops stack property.
void clearCache()
Clear all cached data.
Sawyer::Optional< size_t > instructionIndex(SgAsmInstruction *) const
Position of an instruction.
const Sawyer::Cached< bool > & isFunctionCall() const
Is a function call?
const std::vector< DataBlockPtr > & dataBlocks() const
Data blocks owned.
AddressIntervalSet insnAddresses() const
Get all instruction addresses.
void successors(const Successors &)
Control flow successors.
SgAsmInstruction * instructionExists(rose_addr_t startVa) const
Determine if this basic block contains an instruction at a specific address.
const Sawyer::Cached< std::set< rose_addr_t > > & ghostSuccessors() const
Ghost successors.
void insertSuccessor(const BaseSemantics::SValuePtr &, EdgeType type=E_NORMAL, Confidence confidence=ASSUMED)
Insert a new successor.
void insertSuccessor(rose_addr_t va, size_t nBits, EdgeType type=E_NORMAL, Confidence confidence=ASSUMED)
Insert a new successor.
std::string printableName() const
A printable name for this basic block.
size_t nDataBlocks() const
Get the number of data blocks owned.
bool isEmpty() const
Return true if this basic block has no instructions.
Sawyer::Optional< size_t > instructionIndex(rose_addr_t) const
Position of an instruction.
void sourceLocation(const SourceLocation &loc)
Optional location in source code.
rose_addr_t fallthroughVa() const
Get the address after the end of the final instruction.
Sawyer::Optional< size_t > instructionExists(SgAsmInstruction *) const
Determines if this basic block contains the specified instruction.
static Ptr instance(rose_addr_t startVa, const PartitionerConstPtr &partitioner)
Static allocating constructor.
DataBlockPtr eraseDataBlock(const DataBlockPtr &)
Remove specified or equivalent data block from this basic block.
bool insertDataBlock(const DataBlockPtr &)
Make this basic block own the specified data block or equivalent data block.
void comment(const std::string &s)
Comment.
rose_addr_t address() const
Get the address for a basic block.
void clearSuccessors()
Clear all successor information.
void dropSemantics(const PartitionerConstPtr &)
Drops semantic information.
const SourceLocation & sourceLocation() const
Optional location in source code.
BasicBlockSuccessors Successors
All successors in no particular order.
Sawyer::SharedPointer< BasicBlock > Ptr
Shared pointer to a basic block.
void append(const PartitionerConstPtr &, SgAsmInstruction *)
Append an instruction to a basic block.
const Sawyer::Cached< bool > & isFunctionReturn() const
Is a function return?
virtual Ptr create(rose_addr_t startVa, const PartitionerConstPtr &partitioner) const
Virtual constructor.
std::set< rose_addr_t > explicitConstants() const
Set of explicit constants.
size_t nInstructions() const
Get the number of instructions in this block.
const Sawyer::Cached< Successors > & successors() const
Control flow successors.
DataBlockPtr dataBlockExists(const DataBlockPtr &) const
Determine if this basic block contains the specified data block or equivalent data block.
const std::vector< SgAsmInstruction * > & instructions() const
Get the instructions for this block.
bool isFrozen() const
Determine if basic block is read-only.
BasicBlockSemantics undropSemantics(const PartitionerConstPtr &)
Undrop semantics.
const Sawyer::Cached< bool > & mayReturn() const
May-return property.
void pop()
Undo the latest append.
AddressIntervalSet dataAddresses() const
Addresses that are part of static data.
const std::string & comment() const
Comment.
Partitions instructions into basic blocks and functions.
Information about a source location.
API and storage for attributes.
Implements cache data members.
void set(const Value &x) const
Assign a new value.
Container associating values with keys.
Holds a value or nothing.
Base class for reference counted objects.
Reference-counting intrusive smart pointer.
Base class for machine instructions.
Base classes for instruction semantics.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
Sawyer::SharedPointer< const Partitioner > PartitionerConstPtr
Shared-ownership pointer for Partitioner.
std::vector< BasicBlockSuccessor > BasicBlockSuccessors
All successors in no particular order.
EdgeType
Partitioner control flow edge types.
@ E_USER_DEFINED
User defined edge.
@ E_NORMAL
Normal control flow edge, nothing special.
Confidence
How sure are we of something.
@ ASSUMED
The value is an assumption without any proof.
Sawyer::SharedPointer< DataBlock > DataBlockPtr
Shared-ownership pointer for DataBlock.