1#ifndef ROSE_BinaryAnalysis_InstructionSemantics_MultiSemantics_H
2#define ROSE_BinaryAnalysis_InstructionSemantics_MultiSemantics_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
6#include <Rose/BinaryAnalysis/BasicTypes.h>
7#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics.h>
10namespace BinaryAnalysis {
11namespace InstructionSemantics {
60namespace MultiSemantics {
65 std::vector<std::string> subdomain_names;
93 typedef std::vector<BaseSemantics::SValuePtr> Subvalues;
98 explicit SValue(
size_t nbits);
101 void init(
const SValue &other);
200typedef void RegisterState;
209typedef void MemoryState;
243 typedef std::vector<BaseSemantics::RiscOperatorsPtr> Subdomains;
244 Subdomains subdomains;
245 std::vector<bool> active;
349 typedef std::vector<SValuePtr> Inputs;
379 bool inputs_are_valid()
const;
Base class for most instruction semantics RISC operators.
virtual SmtSolverPtr solver() const
Property: Satisfiability module theory (SMT) solver.
virtual SValuePtr protoval() const
Property: Prototypical semantic value.
virtual const std::string & name() const
Property: Name used for debugging.
IteStatus
Status for iteWithStatus operation.
Base class for semantic values.
Iterates over valid subdomains whose inputs are valid.
size_t idx() const
Return the subdomain index for the current cursor position.
BaseSemantics::RiscOperatorsPtr operator->() const
Return the subdomain for the current cursor position.
static Inputs inputs(const BaseSemantics::SValuePtr &arg1=BaseSemantics::SValuePtr(), const BaseSemantics::SValuePtr &arg2=BaseSemantics::SValuePtr(), const BaseSemantics::SValuePtr &arg3=BaseSemantics::SValuePtr())
Class method to construct the array of inputs from a variable number of arguments.
BaseSemantics::RiscOperatorsPtr operator*() const
Return the subdomain for the current cursor position.
BaseSemantics::SValuePtr operator()(const BaseSemantics::SValuePtr &) const
Returns subdomain value of its multidomain argument.
bool at_end() const
Returns true when the cursor has gone past the last valid subdomain.
void next()
Advance to the next valid subdomain.
Defines RISC operators for the MultiSemantics domain.
virtual BaseSemantics::SValuePtr extract(const BaseSemantics::SValuePtr &a, size_t begin_bit, size_t end_bit) override
Extracts bits from a value.
virtual BaseSemantics::SValuePtr add(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b) override
Adds two integers of equal size.
virtual BaseSemantics::SValuePtr invert(const BaseSemantics::SValuePtr &a) override
One's complement.
virtual void before(size_t)
Called before each subdomain RISC operation.
virtual BaseSemantics::SValuePtr fpIsZero(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Whether a floating-point value is equal to zero.
virtual BaseSemantics::SValuePtr peekMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt) override
Read memory without side effects.
virtual BaseSemantics::SValuePtr peekRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &dflt) override
Obtain a register value without side effects.
virtual void clear_active(size_t idx)
Makes a subdomain inactive.
virtual BaseSemantics::SValuePtr or_(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b) override
Computes bit-wise OR of two values.
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 reinterpret(const BaseSemantics::SValuePtr &, SgAsmType *) override
Reinterpret an expression as a different type.
virtual BaseSemantics::SValuePtr signedMultiply(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b) override
Multiplies two signed values.
virtual BaseSemantics::SValuePtr unsignedModulo(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b) override
Calculates modulo with unsigned values.
virtual BaseSemantics::SValuePtr boolean_(bool) override
Returns a Boolean value.
virtual BaseSemantics::SValuePtr number_(size_t nbits, uint64_t value) override
Returns a number of the specified bit width.
RiscOperatorsPtr Ptr
Shared-ownership pointer.
virtual BaseSemantics::SValuePtr fpIsInfinity(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Whether a floating-point value is infinity.
virtual BaseSemantics::SValuePtr undefined_(size_t nbits) override
Returns a new undefined value.
virtual BaseSemantics::SValuePtr fpConvert(const BaseSemantics::SValuePtr &, SgAsmFloatType *, SgAsmFloatType *) override
Convert from one floating-point type to another.
virtual void startInstruction(SgAsmInstruction *insn) override
Called at the beginning of every instruction.
virtual void print(std::ostream &o, BaseSemantics::Formatter &) const override
Print multi-line output for this object.
virtual BaseSemantics::SValuePtr negate(const BaseSemantics::SValuePtr &a) override
Two's complement.
virtual BaseSemantics::SValuePtr rotateLeft(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &nbits) override
Rotate bits to the left.
virtual BaseSemantics::SValuePtr fpIsNan(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Whether a floating-point value is a special not-a-number bit pattern.
virtual BaseSemantics::SValuePtr leastSignificantSetBit(const BaseSemantics::SValuePtr &a) override
Returns position of least significant set bit; zero when no bits are set.
virtual BaseSemantics::SValuePtr and_(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b) override
Computes bit-wise AND of two values.
virtual BaseSemantics::SValuePtr filterIndirectJumpTarget(const BaseSemantics::SValuePtr &) override
Invoked to filter indirect jumps.
virtual BaseSemantics::SValuePtr bottom_(size_t nbits) override
Returns a data-flow bottom value.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual allocating constructor.
virtual BaseSemantics::RiscOperatorsPtr get_subdomain(size_t idx) const
Returns the RiscOperators for a subdomain.
static RiscOperatorsPtr instanceFromRegisters(const RegisterDictionaryPtr &)
Static allocating constructor.
virtual BaseSemantics::SValuePtr fpAdd(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Add two floating-point values.
virtual BaseSemantics::SValuePtr fpEffectiveExponent(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Exponent of floating-point value.
virtual BaseSemantics::SValuePtr shiftRight(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &nbits) override
Returns arg shifted right logically (no sign bit).
virtual BaseSemantics::SValuePtr fpRoundTowardZero(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Round toward zero.
virtual BaseSemantics::SValuePtr concat(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b) override
Concatenates the bits of two values.
virtual BaseSemantics::SValuePtr unspecified_(size_t nbits) override
Returns a new undefined value.
virtual BaseSemantics::SValuePtr xor_(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b) override
Computes bit-wise XOR of two values.
virtual void finishInstruction(SgAsmInstruction *insn) override
Called at the end of every instruction.
virtual BaseSemantics::SValuePtr filterReturnTarget(const BaseSemantics::SValuePtr &) override
Invoked to filter return targets.
virtual BaseSemantics::SValuePtr fpSign(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Sign of floating-point value.
virtual BaseSemantics::SValuePtr signedDivide(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b) override
Divides two signed values.
virtual BaseSemantics::SValuePtr fpIsDenormalized(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Whether a floating-point value is denormalized.
virtual BaseSemantics::SValuePtr fpMultiply(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Multiply two floating-point values.
virtual BaseSemantics::SValuePtr signedModulo(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b) override
Calculates modulo with signed values.
virtual void after(size_t)
Called after each subdomain RISC operation.
virtual BaseSemantics::SValuePtr fpSubtract(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Subtract one floating-point value from another.
virtual void set_active(size_t idx, bool status)
Makes a subdomain active or inactive.
virtual BaseSemantics::SValuePtr equalToZero(const BaseSemantics::SValuePtr &a) override
Determines whether a value is equal to zero.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::StatePtr &, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual allocating constructor.
virtual BaseSemantics::SValuePtr fpSquareRoot(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Square root.
virtual Formatter & get_formatter()
Returns a formatter containing the names of the subdomains.
virtual BaseSemantics::SValuePtr unsignedMultiply(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b) override
Multiply two unsigned values.
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.
virtual BaseSemantics::SValuePtr iteWithStatus(const BaseSemantics::SValuePtr &cond, const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b, IteStatus &) override
If-then-else with status.
virtual void writeRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &a) override
Writes a value to a register.
virtual BaseSemantics::SValuePtr fpDivide(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Divide one floating-point value by another.
virtual BaseSemantics::SValuePtr readRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &dflt) override
Reads a value from a register.
virtual BaseSemantics::SValuePtr shiftRightArithmetic(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &nbits) override
Returns arg shifted right arithmetically (with sign bit).
virtual void writeMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &data, const BaseSemantics::SValuePtr &cond) override
Writes a value to memory.
virtual bool is_active(size_t idx) const
Returns true if a subdomain is active.
virtual size_t add_subdomain(const BaseSemantics::RiscOperatorsPtr &subdomain, const std::string &name, bool activate=true)
Add a subdomain to this MultiSemantics domain.
virtual BaseSemantics::SValuePtr shiftLeft(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &nbits) override
Returns arg shifted left.
virtual BaseSemantics::SValuePtr filterCallTarget(const BaseSemantics::SValuePtr &) override
Invoked to filter call targets.
virtual BaseSemantics::SValuePtr fpToInteger(const BaseSemantics::SValuePtr &, SgAsmFloatType *, const BaseSemantics::SValuePtr &) override
Construct an integer value from a floating-point value.
virtual BaseSemantics::SValuePtr rotateRight(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &nbits) override
Rotate bits to the right.
virtual BaseSemantics::SValuePtr signExtend(const BaseSemantics::SValuePtr &a, size_t new_width) override
Sign extends a value.
virtual BaseSemantics::SValuePtr unsignedDivide(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b) override
Divides two unsigned values.
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 SValuePtr svalue_empty(size_t nbits)
Convenience function for SValue::create_empty().
virtual size_t nsubdomains() const
Returns the number of subdomains added to this MultiDomain.
virtual BaseSemantics::SValuePtr mostSignificantSetBit(const BaseSemantics::SValuePtr &a) override
Returns position of most significant set bit; zero when no bits are set.
virtual BaseSemantics::SValuePtr fpFromInteger(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Construct a floating-point value from an integer value.
Type of values manipulated by the MultiSemantics domain.
virtual void print(std::ostream &, BaseSemantics::Formatter &) const override
Print a value to a stream using default format.
virtual void set_subvalue(size_t idx, const BaseSemantics::SValuePtr &value)
Insert a subdomain value.
virtual BaseSemantics::SValuePtr copy(size_t=0) const override
Create a new value from an existing value, changing the width if new_width is non-zero.
virtual BaseSemantics::SValuePtr undefined_(size_t nbits) const override
Create a new undefined MultiSemantics value.
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.
virtual BaseSemantics::SValuePtr unspecified_(size_t nbits) const override
Create a new unspecified MultiSemantics value.
virtual bool isBottom() const override
Determines whether a value is a data-flow bottom.
virtual bool is_valid(size_t idx) const
Returns true if a subdomain value is valid.
static SValuePtr promote(const BaseSemantics::SValuePtr &)
Promote a base value to a MultiSemantics value.
virtual BaseSemantics::SValuePtr number_(size_t nbits, uint64_t number) const override
Create a MultiSemantics value holding a concrete value.
virtual uint64_t get_number() const override
Virtual API.
static SValuePtr instance()
Construct a prototypical value.
virtual BaseSemantics::SValuePtr get_subvalue(size_t idx) const
Return a subdomain value.
virtual bool must_equal(const BaseSemantics::SValuePtr &other, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Determines if two multidomain values must be equal.
virtual BaseSemantics::SValuePtr bottom_(size_t nbits) const override
Data-flow bottom value.
virtual void invalidate(size_t idx)
Removes a subdomain value and marks it as invalid.
virtual void set_width(size_t nbits) override
Virtual API.
virtual bool is_number() const override
Determines if the value is a concrete number.
virtual void hash(Combinatorics::Hasher &) const override
Hash this semantic value.
virtual SValuePtr create_empty(size_t nbits) const
Create a new MultiSemantics value with no valid subvalues.
virtual bool may_equal(const BaseSemantics::SValuePtr &other, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Determines if two multidomain values might be equal.
Describes (part of) a physical CPU register.
Holds a value or nothing.
Reference-counting intrusive smart pointer.
Base class for machine instructions.
Base class for binary types.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
Sawyer::SharedPointer< class SValue > SValuePtr
Shared-ownership pointer to a multi-semantic value.
boost::shared_ptr< void > RegisterStatePtr
Shared-ownership pointer to a multi-semantics register state.
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to multi-semantics RISC operators.
boost::shared_ptr< void > MemoryStatePtr
Shared-ownership pointer to a multi-semantics memory state.
boost::shared_ptr< void > StatePtr
Shared-ownership pointer to a multi-semantics state.
std::shared_ptr< SmtSolver > SmtSolverPtr
Reference counting pointer.