ROSE 0.11.145.192
DataFlowSemantics.h
1#ifndef ROSE_BinaryAnalysis_InstructionSemantics_DataFlowSemantics_H
2#define ROSE_BinaryAnalysis_InstructionSemantics_DataFlowSemantics_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5
6#include <Rose/BinaryAnalysis/AbstractLocation.h>
7#include <Rose/BinaryAnalysis/BasicTypes.h>
8#include <Rose/BinaryAnalysis/InstructionSemantics/MultiSemantics.h>
9
10#include <Sawyer/Assert.h>
11#include <Sawyer/Graph.h>
12
13namespace Rose {
14namespace BinaryAnalysis {
15namespace InstructionSemantics {
16namespace DataFlowSemantics {
17
45
51
53typedef boost::shared_ptr<class RiscOperators> RiscOperatorsPtr;
54
64public:
67
69 using Ptr = RiscOperatorsPtr;
70
71private:
72 RegisterDictionaryPtr regdict_; // register dictionary used to print abstract locations
73 size_t innerDomainId_; // subdomain identifier for the dataflow's inner domain
74 size_t userDomainId_; // subdomain identifier for the user-supplied domain (memory addrs)
75 DataFlowGraph dflow_; // dataflow graph accumulated over processInstruction() calls.
76
77 void init(const BaseSemantics::RiscOperatorsPtr &userDomain);
78
79 // The normal C++ constructors; protected because this object is reference counted
80protected:
81 explicit RiscOperators(const BaseSemantics::RiscOperatorsPtr &userDomain);
82
83public:
88 static RiscOperatorsPtr instance(const BaseSemantics::RiscOperatorsPtr &childOps);
89
90 // Virtual constructors inherited from the super class. These are disabled because users are expected to create this
91 // dataflow semantics framework only through the "instance" method. (But we still must override them.)
92private:
93 virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::SValuePtr &/*protoval*/,
94 const SmtSolverPtr& = SmtSolverPtr()) const override;
95
97 const SmtSolverPtr& = SmtSolverPtr()) const override;
98
99 // Dynamic pointer cast
100public:
103 static RiscOperatorsPtr promote(const BaseSemantics::RiscOperatorsPtr&);
104
105public:
110
112 const DataFlowGraph& getGraph() const;
113
114private:
115 // Temporarily disables a subdomain, restoring it the its original state when this object is canceled or destroyed.
116 class TemporarilyDeactivate {
118 size_t id_;
119 bool wasActive_, canceled_;
120 public:
121 TemporarilyDeactivate(MultiSemantics::RiscOperators*, size_t id);
122 ~TemporarilyDeactivate();
123 void cancel();
124 };
125
126 // Insert edges (and vertices if necessary) into the data flow graph, dgraph_
127 void insertDataFlowEdge(const AbstractLocation &source, const AbstractLocation &target, DataFlowEdge::EdgeType);
128 void insertDataFlowEdges(const BaseSemantics::SValuePtr &svalue, const AbstractLocation &target);
129
130 // Override state-accessing methods. These methods do the normal thing in the user domain, but in the dataflow domain they
131 // behave differently. When reading, they return the set of abstract locations that were read (either a register or the
132 // address for the bytes of memory); when writing they add vertices and edges to the dataflow graph.
133public:
135 const BaseSemantics::SValuePtr &dflt) override;
137 const BaseSemantics::SValuePtr &dflt) override;
138
139 virtual void writeRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &a_) override;
140
142 const BaseSemantics::SValuePtr &dflt_,
143 const BaseSemantics::SValuePtr &cond) override;
144
146 const BaseSemantics::SValuePtr &dflt_) override;
147
148 virtual void writeMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr_,
149 const BaseSemantics::SValuePtr &data_, const BaseSemantics::SValuePtr &cond) override;
150
151protected:
152 BaseSemantics::SValuePtr readOrPeekMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr,
153 const BaseSemantics::SValuePtr &dflt,
154 const BaseSemantics::SValuePtr &cond, bool allowSideEffects);
155
156};
157
158} // namespace
159} // namespace
160} // namespace
161} // namespace
162
163#endif
164#endif
virtual void writeRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &a_) override
Writes a value to a register.
virtual BaseSemantics::SValuePtr readRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &dflt) override
Reads a value from a register.
virtual BaseSemantics::SValuePtr peekRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &dflt) override
Obtain a register value without side effects.
virtual BaseSemantics::SValuePtr peekMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr_, const BaseSemantics::SValuePtr &dflt_) override
Read memory without side effects.
static RiscOperatorsPtr instance(const BaseSemantics::RiscOperatorsPtr &childOps)
Static allocating constructor.
const DataFlowGraph & getGraph() const
Return the dataflow graph.
virtual void writeMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr_, const BaseSemantics::SValuePtr &data_, const BaseSemantics::SValuePtr &cond) override
Writes a value to memory.
virtual BaseSemantics::SValuePtr readMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr_, const BaseSemantics::SValuePtr &dflt_, const BaseSemantics::SValuePtr &cond) override
Reads a value from memory.
static RiscOperatorsPtr promote(const BaseSemantics::RiscOperatorsPtr &)
Run-time promotion of a base RiscOperators pointer to operators for this domain.
Defines RISC operators for the MultiSemantics domain.
Describes (part of) a physical CPU register.
Graph containing user-defined vertices and edges.
Definition Graph.h:634
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
std::shared_ptr< SmtSolver > SmtSolverPtr
Reference counting pointer.
The ROSE library.
const size_t INVALID_INDEX
Invalid array index.
Definition Constants.h:25
EdgeType edgeType
Whether edge resets or augments previous flows to target.
size_t sequence
Edge sequence number unique and constant within graph.