ROSE 0.11.145.192
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#include <boost/serialization/access.hpp>
12#include <boost/serialization/base_object.hpp>
13#include <boost/serialization/export.hpp>
14#include <Sawyer/IntervalSetMap.h>
15
16namespace Rose {
17namespace BinaryAnalysis {
18namespace InstructionSemantics {
19namespace BaseSemantics {
20
40 // Basic Types
42public:
45
48
55 public:
57 };
58
63
68 struct RegStore {
69 unsigned majr, minr;
70
71#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
72 private:
73 friend class boost::serialization::access;
74
75 template<class S>
76 void serialize(S &s, const unsigned /*version*/) {
77 s & BOOST_SERIALIZATION_NVP(majr);
78 s & BOOST_SERIALIZATION_NVP(minr);
79 }
80#endif
81
82 public:
83 RegStore(); // for serialization
85 bool operator<(const RegStore&) const;
86 };
87
88
90 // Types for storing values
92public:
94 struct RegPair {
96 SValuePtr value;
97
98#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
99 private:
100 friend class boost::serialization::access;
101
102 template<class S>
103 void serialize(S &s, const unsigned /*version*/) {
104 s & BOOST_SERIALIZATION_NVP(desc);
105 s & BOOST_SERIALIZATION_NVP(value);
106 }
107#endif
108
109 public:
110 ~RegPair();
111 RegPair(); // for serialization
112
113 public:
115 BitRange location() const;
117 };
118
120 using RegPairs = std::vector<RegPair>;
121
124
125
127 // Types for Boolean properties
129public:
136
141
142
144 // Types for storing addresses
146public:
149
152
153
155 // Data members
157private:
158 RegisterProperties properties_; // Boolean properties for each bit of each register.
159 RegisterAddressSet writers_; // Writing instruction address set for each bit of each register
160 bool accessModifiesExistingLocations_; // Can read/write modify existing locations?
161 bool accessCreatesLocations_; // Can new locations be created?
162
163protected:
173
175 // Serialization
177#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
178private:
179 friend class boost::serialization::access;
180
181 template<class S>
182 void serialize(S &s, const unsigned /*version*/) {
183 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(RegisterState);
184 s & BOOST_SERIALIZATION_NVP(properties_);
185 s & BOOST_SERIALIZATION_NVP(writers_);
186 s & BOOST_SERIALIZATION_NVP(accessModifiesExistingLocations_);
187 s & BOOST_SERIALIZATION_NVP(accessCreatesLocations_);
188 s & BOOST_SERIALIZATION_NVP(registers_);
189 }
190#endif
191
193 // Normal constructors
194 //
195 // These are protected because objects of this class are reference counted and always allocated on the heap.
197public:
199
200protected:
201 RegisterStateGeneric(); // for serialization
202
203
205
207
209 // Static allocating constructors
211public:
219
222
224 // Virtual constructors
226public:
227 virtual RegisterStatePtr create(const SValuePtr &protoval, const RegisterDictionaryPtr&) const override;
228 virtual AddressSpacePtr clone() const override;
229
231 // Dynamic pointer casts
233public:
237
239 // Object properties
241public:
256 bool accessModifiesExistingLocations() const /*final*/;
265 RegisterStateGeneric *rstate_;
266 bool savedValue_;
267 public:
270 };
271
279 bool accessCreatesLocations() const /*final*/;
280 virtual void accessCreatesLocations(bool);
288 RegisterStateGeneric *rstate_;
289 bool savedValue_;
290 public:
293 };
294
295
297 // Inherited non-constructors
299public:
300 virtual void clear() override;
301 virtual void zero() override;
304 virtual void writeRegister(RegisterDescriptor, const SValuePtr &value, RiscOperators*) override;
305 virtual void print(std::ostream&, Formatter&) const override;
306 virtual bool merge(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override;
307 virtual void hash(Combinatorics::Hasher&, RiscOperators *addrOps, RiscOperators *valOps) const override;
308
309
311 // Initialization
313public:
317 virtual void initialize_large();
318
323 virtual void initialize_small();
324
329 void initialize_nonoverlapping(const std::vector<RegisterDescriptor>&, bool initialize_to_zero);
330
331
333 // Value storage queries
335public:
346
358
362
368
375
381
386
387
389 // Traversals
391public:
393 class Visitor {
394 public:
395 virtual ~Visitor() {}
396 virtual SValuePtr operator()(RegisterDescriptor, const SValuePtr&) = 0;
397 };
398
432 virtual void traverse(Visitor&);
433
434
436 // Writer addresses
438public:
456
463
469 virtual bool insertWriters(RegisterDescriptor, const AddressSet &writerVas);
470
476 virtual void eraseWriters(RegisterDescriptor, const AddressSet &writerVas);
477
482 virtual void setWriters(RegisterDescriptor, const AddressSet &writers);
483
491 virtual void eraseWriters();
496 // Per-register bit Boolean properties
498public:
526
533
539
546 virtual void eraseProperties();
553 virtual std::vector<RegisterDescriptor>
555 const InputOutputPropertySet &prohibited = InputOutputPropertySet()) const;
556
557 // Documented in super class
560
562 // Non-public APIs
564protected:
565 void deep_copy_values();
566
567 // Given a register descriptor return information about what's stored in the state. The two return values are:
568 //
569 // accessedParts represent the parts of the reigster (matching major and minor numbers) that are present in the
570 // state and overlap with the specified register.
571 //
572 // preservedParts represent the parts of the register that are present in the state but don't overlap with the
573 // specified register.
574 void scanAccessedLocations(RegisterDescriptor reg, RiscOperators *ops,
575 RegPairs &accessedParts /*out*/, RegPairs &preservedParts /*out*/) const;
576
577 // Given a register descriptor, zero out all the stored parts of the same register (by matching major and minor numbers)
578 // if the stored part overlaps with the specified register.
579 void clearOverlappingLocations(RegisterDescriptor);
580
581 void assertStorageConditions(const std::string &where, RegisterDescriptor what) const;
582};
583
584} // namespace
585} // namespace
586} // namespace
587} // namespace
588
589#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
591#endif
592
593#endif
594#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.