ROSE 0.11.145.237
RegisterStateGeneric.h
1#ifndef ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_RegisterStateGeneric_H
2#define ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_RegisterStateGeneric_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5
6#include <Rose/BinaryAnalysis/AddressSet.h>
7#include <Rose/BinaryAnalysis/BasicTypes.h>
8#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/RegisterState.h>
9#include <Rose/Exception.h>
10
11#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
12#include <boost/serialization/access.hpp>
13#include <boost/serialization/base_object.hpp>
14#include <boost/serialization/export.hpp>
15#endif
16
17#include <Sawyer/IntervalSetMap.h>
18
19namespace Rose {
20namespace BinaryAnalysis {
21namespace InstructionSemantics {
22namespace BaseSemantics {
23
43 // Basic Types
45public:
48
51
58 public:
60 };
61
66
71 struct RegStore {
72 unsigned majr, minr;
73
74#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
75 private:
76 friend class boost::serialization::access;
77
78 template<class S>
79 void serialize(S &s, const unsigned /*version*/) {
80 s & BOOST_SERIALIZATION_NVP(majr);
81 s & BOOST_SERIALIZATION_NVP(minr);
82 }
83#endif
84
85 public:
86 RegStore(); // for serialization
88 bool operator<(const RegStore&) const;
89 };
90
91
93 // Types for storing values
95public:
97 struct RegPair {
99 SValuePtr value;
100
101#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
102 private:
103 friend class boost::serialization::access;
104
105 template<class S>
106 void serialize(S &s, const unsigned /*version*/) {
107 s & BOOST_SERIALIZATION_NVP(desc);
108 s & BOOST_SERIALIZATION_NVP(value);
109 }
110#endif
111
112 public:
113 ~RegPair();
114 RegPair(); // for serialization
115
116 public:
118 BitRange location() const;
120 };
121
123 using RegPairs = std::vector<RegPair>;
124
127
128
130 // Types for Boolean properties
132public:
139
144
145
147 // Types for storing addresses
149public:
152
155
156
158 // Data members
160private:
161 RegisterProperties properties_; // Boolean properties for each bit of each register.
162 RegisterAddressSet writers_; // Writing instruction address set for each bit of each register
163 bool accessModifiesExistingLocations_; // Can read/write modify existing locations?
164 bool accessCreatesLocations_; // Can new locations be created?
165
166protected:
176
178 // Serialization
180#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
181private:
182 friend class boost::serialization::access;
183
184 template<class S>
185 void serialize(S &s, const unsigned /*version*/) {
186 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(RegisterState);
187 s & BOOST_SERIALIZATION_NVP(properties_);
188 s & BOOST_SERIALIZATION_NVP(writers_);
189 s & BOOST_SERIALIZATION_NVP(accessModifiesExistingLocations_);
190 s & BOOST_SERIALIZATION_NVP(accessCreatesLocations_);
191 s & BOOST_SERIALIZATION_NVP(registers_);
192 }
193#endif
194
196 // Normal constructors
197 //
198 // These are protected because objects of this class are reference counted and always allocated on the heap.
200public:
202
203protected:
204 RegisterStateGeneric(); // for serialization
205
206
208
210
212 // Static allocating constructors
214public:
222
225
227 // Virtual constructors
229public:
230 virtual RegisterStatePtr create(const SValuePtr &protoval, const RegisterDictionaryPtr&) const override;
231 virtual AddressSpacePtr clone() const override;
232
234 // Dynamic pointer casts
236public:
240
242 // Object properties
244public:
259 bool accessModifiesExistingLocations() const /*final*/;
268 RegisterStateGeneric *rstate_;
269 bool savedValue_;
270 public:
273 };
274
282 bool accessCreatesLocations() const /*final*/;
283 virtual void accessCreatesLocations(bool);
291 RegisterStateGeneric *rstate_;
292 bool savedValue_;
293 public:
296 };
297
298
300 // Inherited non-constructors
302public:
303 virtual void clear() override;
304 virtual void zero() override;
307 virtual void writeRegister(RegisterDescriptor, const SValuePtr &value, RiscOperators*) override;
308 virtual void print(std::ostream&, Formatter&) const override;
309 virtual bool merge(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override;
310 virtual void hash(Combinatorics::Hasher&, RiscOperators *addrOps, RiscOperators *valOps) const override;
311
312
314 // Initialization
316public:
320 virtual void initialize_large();
321
326 virtual void initialize_small();
327
332 void initialize_nonoverlapping(const std::vector<RegisterDescriptor>&, bool initialize_to_zero);
333
334
336 // Value storage queries
338public:
349
361
365
371
378
384
389
390
392 // Traversals
394public:
396 class Visitor {
397 public:
398 virtual ~Visitor() {}
399 virtual SValuePtr operator()(RegisterDescriptor, const SValuePtr&) = 0;
400 };
401
435 virtual void traverse(Visitor&);
436
437
439 // Writer addresses
441public:
459
466
472 virtual bool insertWriters(RegisterDescriptor, const AddressSet &writerVas);
473
479 virtual void eraseWriters(RegisterDescriptor, const AddressSet &writerVas);
480
485 virtual void setWriters(RegisterDescriptor, const AddressSet &writers);
486
494 virtual void eraseWriters();
499 // Per-register bit Boolean properties
501public:
529
536
542
549 virtual void eraseProperties();
556 virtual std::vector<RegisterDescriptor>
558 const InputOutputPropertySet &prohibited = InputOutputPropertySet()) const;
559
560 // Documented in super class
563
565 // Non-public APIs
567protected:
568 void deep_copy_values();
569
570 // Given a register descriptor return information about what's stored in the state. The two return values are:
571 //
572 // accessedParts represent the parts of the reigster (matching major and minor numbers) that are present in the
573 // state and overlap with the specified register.
574 //
575 // preservedParts represent the parts of the register that are present in the state but don't overlap with the
576 // specified register.
577 void scanAccessedLocations(RegisterDescriptor reg, RiscOperators *ops,
578 RegPairs &accessedParts /*out*/, RegPairs &preservedParts /*out*/) const;
579
580 // Given a register descriptor, zero out all the stored parts of the same register (by matching major and minor numbers)
581 // if the stored part overlaps with the specified register.
582 void clearOverlappingLocations(RegisterDescriptor);
583
584 void assertStorageConditions(const std::string &where, RegisterDescriptor what) const;
585};
586
587} // namespace
588} // namespace
589} // namespace
590} // namespace
591
592#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
594#endif
595
596#endif
597#endif
virtual void updateReadProperties(RegisterDescriptor) override
Update register properties after reading a register.
virtual void zero() override
Set all registers to the zero.
virtual bool insertProperties(RegisterDescriptor, const InputOutputPropertySet &)
Insert Boolean properties.
virtual bool insertWriters(RegisterDescriptor, const AddressSet &writerVas)
Insert writer information.
virtual void print(std::ostream &, Formatter &) const override
Print an address space.
virtual void hash(Combinatorics::Hasher &, RiscOperators *addrOps, RiscOperators *valOps) const override
Hash this address space.
virtual ExtentMap stored_parts(RegisterDescriptor) const
Returns a description of which bits of a register are stored.
virtual void eraseWriters(RegisterDescriptor)
Erase all writers.
virtual void erase_register(RegisterDescriptor, RiscOperators *)
Cause a register to not be stored.
virtual SValuePtr readRegister(RegisterDescriptor, const SValuePtr &dflt, RiscOperators *) override
Read a value from a register.
virtual void clear() override
Removes stored values from the register state.
virtual void setWriters(RegisterDescriptor, const AddressSet &writers)
Set writer information.
virtual bool is_wholly_stored(RegisterDescriptor) const
Determines if the specified register is wholly stored in the state.
virtual void traverse(Visitor &)
Traverse register/value pairs.
virtual RegPairs overlappingRegisters(RegisterDescriptor) const
Find stored registers overlapping with specified register.
virtual bool hasWritersAny(RegisterDescriptor) const
Whether a register has writers.
virtual void initialize_large()
Initialize all registers of the dictionary.
virtual bool is_exactly_stored(RegisterDescriptor) const
Determines if the specified register is stored exactly in the state.
virtual bool is_partly_stored(RegisterDescriptor) const
Determines if some of the specified register is stored in the state.
static RegisterStateGenericPtr instance(const SValuePtr &protoval, const RegisterDictionaryPtr &)
Instantiate a new register state.
virtual void initialize_small()
Initialize all registers of the dictionary.
virtual AddressSpacePtr clone() const override
Deep-copy of this address space.
virtual void eraseProperties(RegisterDescriptor)
Erase all Boolean properties.
virtual bool hasPropertyAny(RegisterDescriptor, InputOutputProperty) const
Whether a register has the specified property.
virtual bool hasWritersAll(RegisterDescriptor) const
Whether a register has writers.
virtual AddressSet getWritersIntersection(RegisterDescriptor) const
Get writer information.
virtual AddressSet getWritersUnion(RegisterDescriptor) const
Get writer information.
virtual SValuePtr peekRegister(RegisterDescriptor, const SValuePtr &dflt, RiscOperators *) override
Read a register without side effects.
void initialize_nonoverlapping(const std::vector< RegisterDescriptor > &, bool initialize_to_zero)
Initialize the specified registers of the dictionary.
virtual bool eraseProperties(RegisterDescriptor, const InputOutputPropertySet &)
Erase Boolean properties.
virtual void eraseWriters(RegisterDescriptor, const AddressSet &writerVas)
Erase specified writers.
virtual void writeRegister(RegisterDescriptor, const SValuePtr &value, RiscOperators *) override
Write a value to a register.
bool accessModifiesExistingLocations() const
Property: Whether stored registers are adapted to access patterns.
bool accessCreatesLocations() const
Property: Whether access can create new locations.
virtual void updateWriteProperties(RegisterDescriptor, InputOutputProperty) override
Update register properties after writing to a register.
static RegisterStateGenericPtr instance(const RegisterStateGenericPtr &other)
Instantiate a new copy of an existing register state.
virtual RegisterStatePtr create(const SValuePtr &protoval, const RegisterDictionaryPtr &) const override
Virtual constructor.
virtual bool hasPropertyAll(RegisterDescriptor, InputOutputProperty) const
Whether a register has the specified property.
virtual InputOutputPropertySet getPropertiesUnion(RegisterDescriptor) const
Get properties.
virtual std::vector< RegisterDescriptor > findProperties(const InputOutputPropertySet &required, const InputOutputPropertySet &prohibited=InputOutputPropertySet()) const
Get registers having certain properties.
virtual bool merge(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override
Merge address spaces for data flow analysis.
virtual RegPairs get_stored_registers() const
Returns the list of all registers and their values.
static RegisterStateGenericPtr promote(const AddressSpacePtr &from)
Run-time promotion of a base address space pointer to a RegisterStateGeneric pointer.
virtual void setProperties(RegisterDescriptor, const InputOutputPropertySet &)
Assign property set.
virtual InputOutputPropertySet getPropertiesIntersection(RegisterDescriptor) const
Get properties.
Base class for most instruction semantics RISC operators.
Describes (part of) a physical CPU register.
Base class for all ROSE exceptions.
Mapping from integers to sets.
Base classes for instruction semantics.
boost::shared_ptr< class RegisterStateGeneric > RegisterStateGenericPtr
Shared-ownership pointer to generic register states.
boost::shared_ptr< AddressSpace > AddressSpacePtr
Shared-ownership pointer for AddressSpace objects.
Sawyer::Container::Set< InputOutputProperty > InputOutputPropertySet
Set of Boolean properties.
boost::shared_ptr< RegisterState > RegisterStatePtr
Shared-ownership pointer to a register state.
The ROSE library.