1#ifndef ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_State_H
2#define ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_State_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/BasicTypes.h>
7#include <Rose/BinaryAnalysis/RegisterDescriptor.h>
8#include <Combinatorics.h>
10#include <boost/enable_shared_from_this.hpp>
11#include <boost/serialization/access.hpp>
12#include <boost/serialization/export.hpp>
13#include <boost/serialization/nvp.hpp>
14#include <boost/serialization/shared_ptr.hpp>
17namespace BinaryAnalysis {
18namespace InstructionSemantics {
42class State:
public boost::enable_shared_from_this<State> {
49 std::vector<AddressSpacePtr> addressSpaces_;
54#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
56 friend class boost::serialization::access;
59 void serialize(S &s,
const unsigned version) {
60 ASSERT_require2(version >= 2, version);
61 s & BOOST_SERIALIZATION_NVP(protoval_);
62 s & BOOST_SERIALIZATION_NVP(addressSpaces_);
399 void printMemory(std::ostream &stream,
const std::string &prefix =
"")
const;
419 void print(std::ostream &stream,
const std::string &prefix =
"")
const;
434 void print(std::ostream &stream)
const { obj->print(stream, fmt); }
459std::ostream& operator<<(std::ostream&,
const State&);
467#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
Addresses for base address space.
Base class for most instruction semantics RISC operators.
Base class for semantics machine states.
RegisterStatePtr interruptState() const
Property: Interrupt state.
virtual void writeRegister(RegisterDescriptor desc, const SValuePtr &value, RiscOperators *ops)
Write a value to a register.
MemoryStatePtr memoryState() const
Property: Memory state.
WithFormatter with_format(Formatter &fmt)
Used for printing states with formatting.
virtual bool merge(const StatePtr &other, RiscOperators *addrOps, RiscOperators *valOps)
Merge operation for data flow analysis.
SValuePtr read(const AddressSpacePtr &, const AddressSpaceAddress &, const SValuePtr &dflt, RiscOperators &addrOps, RiscOperators &valOps)
Read a value from an address space.
virtual bool writeInterrupt(unsigned major, unsigned minor, const SValuePtr &value, RiscOperators *valOps)
Write an interrupt state.
SValuePtr protoval() const
Property: Prototypical value.
void printMemory(std::ostream &stream, const std::string &prefix="") const
Print memory contents.
std::string toString() const
Convert the state to a string for debugging.
virtual void printInterrupts(std::ostream &stream, Formatter &fmt) const
Print interrupt states.
static StatePtr instance(const StatePtr &other)
Instantiate a new copy of an existing state.
AddressSpacePtr findFirstAddressSpace(AddressSpacePurpose, const std::string &name) const
Find the first address space with the specified purpose and name.
virtual SValuePtr readInterrupt(unsigned major, unsigned minor, const SValuePtr &dflt, RiscOperators *valOps)
Read an interrupt state.
SValuePtr peek(const AddressSpacePtr &, const AddressSpaceAddress &, const SValuePtr &dflt, RiscOperators &addrOps, RiscOperators &valOps)
Peek at a value in an address space.
const std::vector< AddressSpacePtr > & addressSpaces() const
The list of all address spaces.
virtual void clear()
Initialize state.
virtual StatePtr create(const RegisterStatePtr ®isters, const MemoryStatePtr &memory) const
Virtual constructor.
bool isInterruptDefinitelyClear(unsigned major, unsigned minor, RiscOperators *valOps)
Test an interrupt.
static StatePtr instance(const RegisterStatePtr ®isters, const MemoryStatePtr &memory, const RegisterStatePtr &interrupts)
Instantiate a new state object with specified register, memory, and interrupt address spaces.
bool hasInterruptState() const
Tests whether an interrupt state is present.
SValuePtr raiseInterrupt(unsigned major, unsigned minor, RiscOperators *valOps)
Raise an interrupt.
WithFormatter operator+(Formatter &fmt)
Used for printing states with formatting.
StatePtr Ptr
Shared-ownership pointer.
virtual void printRegisters(std::ostream &stream, Formatter &fmt) const
Print the register contents.
virtual SValuePtr peekRegister(RegisterDescriptor desc, const SValuePtr &dflt, RiscOperators *ops)
Read register without side effects.
virtual void hash(Combinatorics::Hasher &, RiscOperators *addrOps, RiscOperators *valOps) const
Compute a hash of the state.
virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps)
Read a value from memory.
virtual SValuePtr peekInterrupt(unsigned major, unsigned minor, const SValuePtr &dflt, RiscOperators *valOps)
Read an interrupt state without side effects.
virtual void print(std::ostream &, Formatter &) const
Print the state.
void write(const AddressSpacePtr &, const AddressSpaceAddress &, const SValuePtr &value, RiscOperators &addrOps, RiscOperators &valOps)
Write a value to an address space.
SValuePtr clearInterrupt(unsigned major, unsigned minor, RiscOperators *valOps)
Clear an interrupt.
bool isInterruptDefinitelyRaised(unsigned major, unsigned minor, RiscOperators *valOps)
Test an interrupt.
void print(std::ostream &stream, const std::string &prefix="") const
Print the state.
virtual StatePtr clone() const
Virtual copy constructor.
void interruptState(const RegisterStatePtr &)
Property: Interrupt state.
WithFormatter operator+(const std::string &linePrefix)
Used for printing states with formatting.
virtual void writeMemory(const SValuePtr &addr, const SValuePtr &value, RiscOperators *addrOps, RiscOperators *valOps)
Write a value to memory.
virtual void printMemory(std::ostream &stream, Formatter &fmt) const
Print memory contents.
void printRegisters(std::ostream &stream, const std::string &prefix="")
Print the register contents.
void insertAddressSpace(const AddressSpacePtr &)
Insert an address space into this state.
void clearMemory()
Clear all memory locations.
RegisterStatePtr registerState() const
Property: Register state.
virtual SValuePtr readRegister(RegisterDescriptor desc, const SValuePtr &dflt, RiscOperators *ops)
Read a value from a register.
AddressSpacePtr findFirstAddressSpace(AddressSpacePurpose) const
Find the first address space with the specified purpose.
virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps)
Read from memory without side effects.
static StatePtr instance(const RegisterStatePtr ®isters, const MemoryStatePtr &memory)
Instantiate a new state object with specified register and memory address spaces.
void zeroRegisters()
Initialize all registers to zero.
void printInterrupts(std::ostream &, const std::string &prefix="")
Print interrupt states.
Describes (part of) a physical CPU register.
Base classes for instruction semantics.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
AddressSpacePurpose
Purpose that an address space serves.
boost::shared_ptr< AddressSpace > AddressSpacePtr
Shared-ownership pointer for AddressSpace objects.
boost::shared_ptr< RegisterState > RegisterStatePtr
Shared-ownership pointer to a register state.