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
6 #include <Rose/BinaryAnalysis/BasicTypes.h>
7 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/BasicTypes.h>
8 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/RegisterState.h>
9 #include <Rose/Exception.h>
11 #include <boost/serialization/access.hpp>
12 #include <boost/serialization/base_object.hpp>
13 #include <boost/serialization/export.hpp>
14 #include <Sawyer/IntervalSetMap.h>
17 namespace BinaryAnalysis {
18 namespace InstructionSemantics {
60 :
Rose::Exception(
"accessed register is not available in register state") {}
75 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
77 friend class boost::serialization::access;
80 void serialize(S &s,
const unsigned ) {
81 s & BOOST_SERIALIZATION_NVP(majr);
82 s & BOOST_SERIALIZATION_NVP(minr);
91 bool operator<(
const RegStore &other)
const {
92 return majr<other.majr || (majr==other.majr && minr<other.minr);
106 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
108 friend class boost::serialization::access;
111 void serialize(S &s,
const unsigned ) {
112 s & BOOST_SERIALIZATION_NVP(desc);
113 s & BOOST_SERIALIZATION_NVP(value);
168 RegisterProperties properties_;
169 RegisterAddressSet writers_;
170 bool accessModifiesExistingLocations_;
171 bool accessCreatesLocations_;
187 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
189 friend class boost::serialization::access;
192 void serialize(S &s,
const unsigned ) {
194 s & BOOST_SERIALIZATION_NVP(properties_);
195 s & BOOST_SERIALIZATION_NVP(writers_);
196 s & BOOST_SERIALIZATION_NVP(accessModifiesExistingLocations_);
197 s & BOOST_SERIALIZATION_NVP(accessCreatesLocations_);
198 s & BOOST_SERIALIZATION_NVP(registers_);
209 : accessModifiesExistingLocations_(true), accessCreatesLocations_(true) {}
212 : RegisterState(protoval, regdict), accessModifiesExistingLocations_(true), accessCreatesLocations_(true) {
216 RegisterStateGeneric(
const RegisterStateGeneric &other)
217 : RegisterState(other), properties_(other.properties_), writers_(other.writers_),
218 accessModifiesExistingLocations_(other.accessModifiesExistingLocations_),
219 accessCreatesLocations_(other.accessCreatesLocations_), registers_(other.registers_) {
239 static RegisterStateGenericPtr
instance(
const RegisterStateGenericPtr &other) {
264 ASSERT_not_null(retval);
341 virtual void clear()
override;
342 virtual void zero()
override;
594 virtual std::vector<RegisterDescriptor>
606 void deep_copy_values();
616 RegPairs &accessedParts , RegPairs &preservedParts )
const;
622 void assertStorageConditions(
const std::string &where,
RegisterDescriptor what)
const;
630 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
virtual void updateWriteProperties(RegisterDescriptor, InputOutputProperty) override
Update register properties after writing to a register.
Base classes for instruction semantics.
std::vector< RegPair > RegPairs
Vector of register/value pairs.
unsigned majorNumber() const
Property: Major number.
Guards whether access is able to create new locations.
virtual bool is_wholly_stored(RegisterDescriptor) const
Determines if the specified register is wholly stored in the state.
Functors for traversing register values in a register state.
size_t nBits() const
Property: Size in bits.
Sawyer::Container::IntervalSetMap< BitRange, AddressSet > BitAddressSet
Virtual addresses per bit.
virtual void clear() override
Removes stored values from the register state.
SValuePtr protoval() const
Return the protoval.
virtual bool hasPropertyAll(RegisterDescriptor, InputOutputProperty) const
Whether a register has the specified property.
virtual bool insertWriters(RegisterDescriptor, const AddressSet &writerVas)
Insert writer information.
virtual void accessCreatesLocations(bool b)
Property: Whether access can create new locations.
Sawyer::Container::Map< RegStore, BitProperties > RegisterProperties
Boolean properties for all registers.
virtual void erase_register(RegisterDescriptor, RiscOperators *)
Cause a register to not be stored.
void initialize_nonoverlapping(const std::vector< RegisterDescriptor > &, bool initialize_to_zero)
Initialize the specified registers of the dictionary.
virtual bool hasWritersAll(RegisterDescriptor) const
Whether a register has writers.
virtual void eraseProperties()
Erase all Boolean properties.
RegisterDictionaryPtr regdict
Registers that are able to be stored by this state.
virtual void eraseWriters()
Erase all writers.
virtual void setProperties(RegisterDescriptor, const InputOutputPropertySet &)
Assign property set.
virtual void initialize_small()
Initialize all registers of the dictionary.
virtual RegisterStatePtr clone() const override
Make a copy of this register state.
Sawyer::Container::Set< InputOutputProperty > InputOutputPropertySet
Set of Boolean properties.
bool accessModifiesExistingLocations() const
Property: Whether stored registers are adapted to access patterns.
Mapping from integers to sets.
boost::shared_ptr< RegisterState > RegisterStatePtr
Shared-ownership pointer to a register state.
Sawyer::Container::Interval< size_t > BitRange
A range of bits indexes.
virtual void hash(Combinatorics::Hasher &, RiscOperators *) const override
Hash the register state.
virtual void writeRegister(RegisterDescriptor, const SValuePtr &value, RiscOperators *) override
Write a value to a register.
Main namespace for the ROSE library.
virtual AddressSet getWritersUnion(RegisterDescriptor) const
Get writer information.
A RegisterState for any architecture.
virtual void accessModifiesExistingLocations(bool b)
Property: Whether stored registers are adapted to access patterns.
bool accessCreatesLocations() const
Property: Whether access can create new locations.
A register descriptor and its value.
virtual void zero() override
Set all registers to the zero.
virtual bool hasPropertyAny(RegisterDescriptor, InputOutputProperty) const
Whether a register has the specified property.
static Interval baseSize(size_t lo, size_t size)
Construct an interval from one endpoint and a size.
boost::shared_ptr< class RegisterStateGeneric > RegisterStateGenericPtr
Shared-ownership pointer to generic register states.
static RegisterStateGenericPtr promote(const RegisterStatePtr &from)
Run-time promotion of a base register state pointer to a RegisterStateGeneric pointer.
virtual SValuePtr readRegister(RegisterDescriptor, const SValuePtr &dflt, RiscOperators *) override
Read a value from a register.
Sawyer::Container::Map< RegStore, BitAddressSet > RegisterAddressSet
Virtual addresses for all registers.
Sawyer::Container::IntervalSetMap< BitRange, InputOutputPropertySet > BitProperties
Boolean properties per bit.
virtual bool insertProperties(RegisterDescriptor, const InputOutputPropertySet &)
Insert Boolean properties.
virtual RegPairs overlappingRegisters(RegisterDescriptor) const
Find stored registers overlapping with specified register.
virtual bool is_partly_stored(RegisterDescriptor) const
Determines if some of the specified register is stored in the state.
Describes (part of) a physical CPU register.
Sawyer::Container::Map< RegStore, RegPairs > Registers
Values for all registers.
virtual InputOutputPropertySet getPropertiesUnion(RegisterDescriptor) const
Get properties.
virtual void updateReadProperties(RegisterDescriptor) override
Update register properties after reading a register.
virtual void print(std::ostream &, Formatter &) const override
Print the register contents.
virtual void setWriters(RegisterDescriptor, const AddressSet &writers)
Set writer information.
RegisterStatePtr Ptr
Shared-ownership pointer.
Registers registers_
Values for registers that have been accessed.
Guards whether access can change set of existing locations.
size_t offset() const
Property: Offset to least-significant bit.
virtual ExtentMap stored_parts(RegisterDescriptor) const
Returns a description of which bits of a register are stored.
virtual InputOutputPropertySet getPropertiesIntersection(RegisterDescriptor) const
Get properties.
The set of all registers and their values.
static RegisterStateGenericPtr instance(const SValuePtr &protoval, const RegisterDictionaryPtr ®dict)
Instantiate a new register state.
virtual AddressSet getWritersIntersection(RegisterDescriptor) const
Get writer information.
virtual RegPairs get_stored_registers() const
Returns the list of all registers and their values.
Exception when register storage is not present.
Sawyer::SharedPointer< SValue > SValuePtr
Shared-ownership pointer to a semantic value in any domain.
static RegisterStateGenericPtr instance(const RegisterStateGenericPtr &other)
Instantiate a new copy of an existing register state.
Sawyer::Container::Set< rose_addr_t > AddressSet
Set of virtual addresses.
virtual SValuePtr peekRegister(RegisterDescriptor, const SValuePtr &dflt, RiscOperators *) override
Read a register without side effects.
Base class for most instruction semantics RISC operators.
virtual bool is_exactly_stored(RegisterDescriptor) const
Determines if the specified register is stored exactly in the state.
virtual RegisterStatePtr create(const SValuePtr &protoval, const RegisterDictionaryPtr ®dict) const override
Virtual constructor.
unsigned minorNumber() const
Property: Minor number.
Base class for all ROSE exceptions.
virtual std::vector< RegisterDescriptor > findProperties(const InputOutputPropertySet &required, const InputOutputPropertySet &prohibited=InputOutputPropertySet()) const
Get registers having certain properties.
InputOutputProperty
Boolean properties related to I/O.
virtual void traverse(Visitor &)
Traverse register/value pairs.
virtual bool merge(const RegisterStatePtr &other, RiscOperators *) override
Merge register states for data flow analysis.
virtual bool hasWritersAny(RegisterDescriptor) const
Whether a register has writers.
virtual void initialize_large()
Initialize all registers of the dictionary.