1 #ifndef ROSE_BinaryAnalysis_InstructionSemantics_IntervalSemantics_H
2 #define ROSE_BinaryAnalysis_InstructionSemantics_IntervalSemantics_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
8 #ifndef __STDC_FORMAT_MACROS
9 #define __STDC_FORMAT_MACROS
13 #include <Rose/BinaryAnalysis/BasicTypes.h>
14 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics.h>
15 #include "integerOps.h"
18 namespace BinaryAnalysis {
19 namespace InstructionSemantics {
23 namespace IntervalSemantics {
53 explicit SValue(
size_t nbits):
57 SValue(
size_t nbits, uint64_t number)
59 number &= IntegerOps::genMask<uint64_t>(nbits);
62 SValue(
size_t nbits, uint64_t v1, uint64_t v2):
64 v1 &= IntegerOps::genMask<uint64_t>(nbits);
65 v2 &= IntegerOps::genMask<uint64_t>(nbits);
66 ASSERT_require(v1<=v2);
69 SValue(
size_t nbits,
const Intervals &intervals):
71 ASSERT_require(!intervals.isEmpty());
72 ASSERT_require((intervals.greatest() <= IntegerOps::genMask<uint64_t>(nbits)));
73 intervals_ = intervals;
87 self->isBottom_ =
true;
131 ASSERT_not_null(retval);
152 SValuePtr retval(
new SValue(*
this));
153 if (new_width!=0 && new_width!=retval->nBits())
154 retval->set_width(new_width);
166 virtual SValuePtr
create(
size_t nbits, uint64_t v1, uint64_t v2) {
172 virtual SValuePtr
create(
size_t nbits,
const Intervals &intervals) {
209 return 1==intervals_.
size();
214 ASSERT_require(1==intervals_.
size());
215 return intervals_.
least();
228 intervals_ = intervals;
277 :
BaseSemantics::MemoryCellList(addrProtoval, valProtoval) {}
279 MemoryState(
const MemoryState &other)
305 return instance(addrProtoval, valProtoval);
427 size_t begin_bit,
size_t end_bit)
override;
virtual void writeMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &data, const BaseSemantics::SValuePtr &cond) override
Writes a value to memory.
Base classes for instruction semantics.
Type of values manipulated by the IntervalSemantics domain.
Simple list-based memory state.
virtual Sawyer::Optional< BaseSemantics::SValuePtr > createOptionalMerge(const BaseSemantics::SValuePtr &other, const BaseSemantics::MergerPtr &, const SmtSolverPtr &) const override
Possibly create a new value by merging two existing values.
boost::shared_ptr< class MemoryState > MemoryStatePtr
Shared-ownership pointer to an interval memory state.
virtual BaseSemantics::MemoryStatePtr create(const BaseSemantics::MemoryCellPtr &protocell) const override
Virtual allocating constructor.
static RiscOperatorsPtr instanceFromState(const BaseSemantics::StatePtr &, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiates a new RiscOperators with specified state.
MemoryStatePtr Ptr
Shared-ownership pointer.
virtual uint64_t get_number() const override
Virtual API.
virtual BaseSemantics::SValuePtr unsignedDivide(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Divides two unsigned values.
virtual bool is_number() const override
Virtual API.
static SValuePtr instance_undefined(size_t nbits)
Instantiate a new undefined value of particular width.
Sawyer::SharedPointer< class SValue > SValuePtr
Shared-ownership pointer to an interval semantic value.
void set_intervals(const Intervals &intervals)
Changes the rangemap stored in the value.
virtual BaseSemantics::SValuePtr unsignedModulo(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Calculates modulo with unsigned values.
virtual SValuePtr svalue_from_bits(size_t nbits, uint64_t possible_bits)
Create a new SValue from a set of possible bits.
static RiscOperatorsPtr instanceFromProtoval(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiates a new RiscOperators object with specified prototypical value.
virtual BaseSemantics::SValuePtr peekMemory(const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt, BaseSemantics::RiscOperators *addrOps, BaseSemantics::RiscOperators *valOps) override
Read a byte from memory without side effects.
virtual BaseSemantics::SValuePtr leastSignificantSetBit(const BaseSemantics::SValuePtr &a_) override
Returns position of least significant set bit; zero when no bits are set.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
virtual BaseSemantics::SValuePtr readMemory(const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt, BaseSemantics::RiscOperators *addrOps, BaseSemantics::RiscOperators *valOps) override
Read a byte from memory.
virtual BaseSemantics::SValuePtr extract(const BaseSemantics::SValuePtr &a_, size_t begin_bit, size_t end_bit) override
Extracts bits from a value.
const Intervals & get_intervals() const
Returns the rangemap stored in this value.
virtual BaseSemantics::SValuePtr signedModulo(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Calculates modulo with signed values.
virtual BaseSemantics::SValuePtr rotateLeft(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Rotate bits to the left.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual allocating constructor.
virtual BaseSemantics::SValuePtr readMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt, const BaseSemantics::SValuePtr &cond) override
Reads a value from memory.
virtual BaseSemantics::SValuePtr signExtend(const BaseSemantics::SValuePtr &a_, size_t new_width) override
Sign extends a value.
virtual SValuePtr create(size_t nbits, const Intervals &intervals)
Construct a ValueType from a rangemap.
virtual BaseSemantics::SValuePtr number_(size_t nbits, uint64_t number) const override
Create a new concrete semantic value.
Holds a value or nothing.
virtual BaseSemantics::SValuePtr mostSignificantSetBit(const BaseSemantics::SValuePtr &a_) override
Returns position of most significant set bit; zero when no bits are set.
RISC operators for interval domains.
virtual bool may_equal(const BaseSemantics::SValuePtr &other, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual API.
Main namespace for the ROSE library.
virtual SValuePtr create(size_t nbits, uint64_t v1, uint64_t v2)
Construct a ValueType that's constrained to be between two unsigned values, inclusive.
virtual BaseSemantics::SValuePtr copy(size_t new_width=0) const override
Create a new value from an existing value, changing the width if new_width is non-zero.
boost::shared_ptr< MemoryCell > MemoryCellPtr
Shared-ownership pointer to a memory cell.
static SValuePtr promote(const BaseSemantics::SValuePtr &v)
Promote a base value to an IntevalSemantics value.
A RegisterState for any architecture.
virtual void writeMemory(const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &value, BaseSemantics::RiscOperators *addrOps, BaseSemantics::RiscOperators *valOps) override
Write a byte to memory.
void insert(const Interval2 &interval)
Insert specified values.
Reference-counting intrusive smart pointer.
virtual BaseSemantics::SValuePtr invert(const BaseSemantics::SValuePtr &a_) override
One's complement.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
virtual BaseSemantics::MemoryStatePtr clone() const override
Virtual allocating copy constructor.
virtual BaseSemantics::SValuePtr concat(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Concatenates the bits of two values.
static SValuePtr instance_hull(size_t nbits, uint64_t v1, uint64_t v2)
Instantiate a new value that's constrained to be between two unsigned values, inclusive.
static SValuePtr instance_unspecified(size_t nbits)
Instantiate a new unspecified value of specific width.
boost::shared_ptr< class RegisterStateGeneric > RegisterStateGenericPtr
Shared-ownership pointer to generic register states.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
virtual SValuePtr svalue_from_intervals(size_t nbits, const Intervals &intervals)
Create a new SValue from a set of intervals.
virtual BaseSemantics::SValuePtr xor_(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Computes bit-wise XOR of two values.
IteStatus
Status for iteWithStatus operation.
static MemoryStatePtr instance(const BaseSemantics::SValuePtr &addrProtoval, const BaseSemantics::SValuePtr &valProtoval)
Instantiate a new memory state with prototypical value.
static SValuePtr instance_integer(size_t nbits, uint64_t number)
Instantiate a new concrete value of particular width.
virtual BaseSemantics::SValuePtr add(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Adds two integers of equal size.
virtual SValuePtr create_from_bits(size_t nbits, uint64_t possible_bits)
Generate ranges from bits.
Describes (part of) a physical CPU register.
static Interval hull(T v1, T v2)
Construct an interval from two endpoints.
virtual BaseSemantics::SValuePtr signedMultiply(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Multiplies two signed values.
virtual BaseSemantics::SValuePtr rotateRight(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Rotate bits to the right.
virtual BaseSemantics::SValuePtr unsignedMultiply(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Multiply two unsigned values.
virtual bool must_equal(const BaseSemantics::SValuePtr &other, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual API.
static SValuePtr instance_copy(const SValuePtr &other)
Instantiate a new copy of an existing value.
SharedPointer< U > dynamicCast() const
Dynamic cast.
Base class for semantic values.
virtual BaseSemantics::SValuePtr shiftLeft(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Returns arg shifted left.
static SValuePtr instance_bottom(size_t nbits)
Instantiate a new data-flow-bottom value of specified width.
virtual BaseSemantics::SValuePtr equalToZero(const BaseSemantics::SValuePtr &a_) override
Determines whether a value is equal to zero.
RiscOperatorsPtr Ptr
Shared-ownership pointer.
Scalar least() const
Returns the minimum scalar contained in this set.
virtual BaseSemantics::SValuePtr signedDivide(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Divides two signed values.
virtual BaseSemantics::SValuePtr negate(const BaseSemantics::SValuePtr &a_) override
Two's complement.
virtual void hash(Combinatorics::Hasher &) const override
Hash this semantic value.
virtual BaseSemantics::SValuePtr unspecified_(size_t nbits) const override
Create a new unspecified semantic value.
virtual bool isBottom() const override
Determines whether a value is a data-flow bottom.
Range of values delimited by endpoints.
virtual BaseSemantics::SValuePtr peekMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt) override
Read memory without side effects.
virtual SmtSolverPtr solver() const
Property: Satisfiability module theory (SMT) solver.
virtual BaseSemantics::SValuePtr or_(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Computes bit-wise OR of two values.
virtual void print(std::ostream &output, BaseSemantics::Formatter &) const override
Print a value to a stream using default format.
std::shared_ptr< SmtSolver > SmtSolverPtr
Reference counting pointer.
virtual BaseSemantics::SValuePtr bottom_(size_t nbits) const override
Data-flow bottom value.
static MemoryStatePtr instance(const BaseSemantics::MemoryCellPtr &protocell)
Instantiate a new memory state with specified prototypical cells and values.
static RiscOperatorsPtr instanceFromRegisters(const RegisterDictionaryPtr &, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiates a new RiscOperators object and configures it to use semantic values and states that are ...
virtual BaseSemantics::SValuePtr shiftRightArithmetic(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Returns arg shifted right arithmetically (with sign bit).
virtual BaseSemantics::SValuePtr shiftRight(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Returns arg shifted right logically (no sign bit).
Sawyer::Container::IntervalSet< Interval > Intervals
Set of intervals.
virtual SValuePtr protoval() const
Property: Prototypical semantic value.
Base class for most instruction semantics RISC operators.
virtual BaseSemantics::SValuePtr unsignedExtend(const BaseSemantics::SValuePtr &a_, size_t new_width) override
Extend (or shrink) operand a so it is nbits wide by adding or removing high-order bits...
virtual BaseSemantics::MemoryStatePtr create(const BaseSemantics::SValuePtr &addrProtoval, const BaseSemantics::SValuePtr &valProtoval) const override
Virtual allocating constructor.
static SValuePtr instance_intervals(size_t nbits, const Intervals &intervals)
Instantiate a new value from a set of intervals.
Interval::Value size() const
Number of scalar elements represented.
virtual BaseSemantics::SValuePtr and_(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Computes bit-wise AND of two values.
uint64_t possible_bits() const
Returns all possible bits that could be set.
virtual BaseSemantics::SValuePtr undefined_(size_t nbits) const override
Create a new undefined semantic value.
Base class for semantics machine states.
static RiscOperatorsPtr promote(const BaseSemantics::RiscOperatorsPtr &)
Run-time promotion of a base RiscOperators pointer to interval operators.
virtual BaseSemantics::SValuePtr iteWithStatus(const BaseSemantics::SValuePtr &sel_, const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_, IteStatus &) override
If-then-else with status.
static SValuePtr instance_from_bits(size_t nbits, uint64_t possible_bits)
Create a value from a set of possible bits.
static SValuePtr instance()
Instantiate a new prototypical value.
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to interval RISC operations.
virtual BaseSemantics::SValuePtr addWithCarries(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_, const BaseSemantics::SValuePtr &c_, BaseSemantics::SValuePtr &carry_out) override
Add two values of equal size and a carry bit.