1 #ifndef Rose_MultiSemantics2_H
2 #define Rose_MultiSemantics2_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 #include "BaseSemantics2.h"
10 namespace InstructionSemantics2 {
59 namespace MultiSemantics {
64 std::vector<std::string> subdomain_names;
85 typedef std::vector<BaseSemantics::SValuePtr> Subvalues;
90 explicit SValue(
size_t nbits)
98 void init(
const SValue &other);
111 ASSERT_not_null(retval);
152 virtual
bool isBottom() const ROSE_OVERRIDE;
154 virtual
void hash(Combinatorics::Hasher&) const override;
172 virtual
void set_width(
size_t nbits) ROSE_OVERRIDE;
177 virtual
bool is_number() const ROSE_OVERRIDE;
179 virtual uint64_t
get_number() const ROSE_OVERRIDE;
188 return idx<subvalues.size() && subvalues[idx]!=NULL;
197 ASSERT_require(idx<subvalues.size() && subvalues[idx]!=NULL);
198 return subvalues[idx];
205 ASSERT_require(value==NULL || value->nBits()==
nBits());
206 if (idx>=subvalues.size())
207 subvalues.resize(idx+1);
208 subvalues[idx] = value;
217 typedef void RegisterState;
226 typedef void MemoryState;
253 typedef std::vector<BaseSemantics::RiscOperatorsPtr> Subdomains;
254 Subdomains subdomains;
255 std::vector<bool> active;
327 return subdomains.size();
337 return idx<subdomains.size() && subdomains[idx]!=NULL && active[idx];
349 virtual void set_active(
size_t idx,
bool status);
381 typedef std::vector<SValuePtr> Inputs;
389 : ops_(ops), idx_(0) {
390 init(arg1, arg2, arg3);
393 : ops_(ops), inputs_(inputs), idx_(0) {
414 void init(
const SValuePtr &arg1,
const SValuePtr &arg2,
const SValuePtr &arg3);
417 bool inputs_are_valid()
const;
426 virtual
BaseSemantics::SValuePtr undefined_(
size_t nbits) ROSE_OVERRIDE;
427 virtual
BaseSemantics::SValuePtr unspecified_(
size_t nbits) ROSE_OVERRIDE;
428 virtual
BaseSemantics::SValuePtr number_(
size_t nbits, uint64_t value) ROSE_OVERRIDE;
429 virtual
BaseSemantics::SValuePtr boolean_(
bool) ROSE_OVERRIDE;
430 virtual
BaseSemantics::SValuePtr bottom_(
size_t nbits) ROSE_OVERRIDE;
485 SgAsmFloatType*) ROSE_OVERRIDE;
487 SgAsmFloatType*) ROSE_OVERRIDE;
489 SgAsmFloatType*) ROSE_OVERRIDE;
491 SgAsmFloatType*) ROSE_OVERRIDE;
virtual BaseSemantics::SValuePtr fpSign(const BaseSemantics::SValuePtr &, SgAsmFloatType *) ROSE_OVERRIDE
Sign of floating-point value.
BaseSemantics::RiscOperatorsPtr operator->() const
Return the subdomain for the current cursor position.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
boost::shared_ptr< void > MemoryStatePtr
Shared-ownership pointer to a multi-semantics memory state.
void next()
Advance to the next valid subdomain.
boost::shared_ptr< void > StatePtr
Shared-ownership pointer to a multi-semantics state.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::StatePtr &state, const SmtSolverPtr &solver=SmtSolverPtr()) const ROSE_OVERRIDE
Virtual allocating constructor.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr()) const ROSE_OVERRIDE
Virtual allocating constructor.
static SValuePtr instance()
Construct a prototypical value.
virtual SValuePtr svalue_empty(size_t nbits)
Convenience function for SValue::create_empty().
virtual BaseSemantics::SValuePtr fpIsZero(const BaseSemantics::SValuePtr &, SgAsmFloatType *) ROSE_OVERRIDE
Whether a floating-point value is equal to zero.
virtual BaseSemantics::SValuePtr reinterpret(const BaseSemantics::SValuePtr &, SgAsmType *) ROSE_OVERRIDE
Reinterpret an expression as a different type.
virtual BaseSemantics::SValuePtr negate(const BaseSemantics::SValuePtr &a) ROSE_OVERRIDE
Two's complement.
virtual BaseSemantics::SValuePtr addWithCarries(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b, const BaseSemantics::SValuePtr &c, BaseSemantics::SValuePtr &carry_out) ROSE_OVERRIDE
Used for printing RISC operators with formatting.
virtual bool isBottom() const ROSE_OVERRIDE
Determines whether a value is a data-flow bottom.
virtual Formatter & get_formatter()
Returns a formatter containing the names of the subdomains.
virtual bool may_equal(const BaseSemantics::SValuePtr &other, const SmtSolverPtr &solver=SmtSolverPtr()) const ROSE_OVERRIDE
Determines if two multidomain values might be equal.
Base class for machine instructions.
virtual bool is_active(size_t idx) const
Returns true if a subdomain is active.
virtual BaseSemantics::SValuePtr fpIsInfinity(const BaseSemantics::SValuePtr &, SgAsmFloatType *) ROSE_OVERRIDE
Whether a floating-point value is infinity.
virtual BaseSemantics::SValuePtr fpAdd(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, SgAsmFloatType *) ROSE_OVERRIDE
Add two floating-point values.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
static RiscOperatorsPtr instance(const RegisterDictionary *regdict)
Static allocating constructor.
virtual BaseSemantics::SValuePtr fpConvert(const BaseSemantics::SValuePtr &, SgAsmFloatType *, SgAsmFloatType *) ROSE_OVERRIDE
Convert from one floating-point type to another.
virtual BaseSemantics::SValuePtr fpIsDenormalized(const BaseSemantics::SValuePtr &, SgAsmFloatType *) ROSE_OVERRIDE
Whether a floating-point value is denormalized.
Holds a value or nothing.
virtual SValuePtr protoval() const
Property: Prototypical semantic value.
virtual bool is_number() const ROSE_OVERRIDE
Determines if the value is a concrete number.
Main namespace for the ROSE library.
virtual BaseSemantics::SValuePtr fpToInteger(const BaseSemantics::SValuePtr &, SgAsmFloatType *, const BaseSemantics::SValuePtr &) ROSE_OVERRIDE
Construct an integer value from a floating-point value.
virtual bool must_equal(const BaseSemantics::SValuePtr &other, const SmtSolverPtr &solver=SmtSolverPtr()) const ROSE_OVERRIDE
Determines if two multidomain values must be equal.
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to multi-semantics RISC operators.
virtual BaseSemantics::SValuePtr fpSubtract(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, SgAsmFloatType *) ROSE_OVERRIDE
Subtract one floating-point value from another.
virtual BaseSemantics::SValuePtr readRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &dflt) ROSE_OVERRIDE
Reads a value from a register.
Defines RISC operators for the MultiSemantics domain.
virtual BaseSemantics::SValuePtr signedDivide(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b) ROSE_OVERRIDE
Divides two signed values.
virtual BaseSemantics::SValuePtr peekMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt) ROSE_OVERRIDE
Read memory without side effects.
Reference-counting intrusive smart pointer.
virtual void clear_active(size_t idx)
Makes a subdomain inactive.
virtual Sawyer::Optional< BaseSemantics::SValuePtr > createOptionalMerge(const BaseSemantics::SValuePtr &other, const BaseSemantics::MergerPtr &, const SmtSolverPtr &) const ROSE_OVERRIDE
Possibly create a new value by merging two existing values.
BaseSemantics::RiscOperatorsPtr operator*() const
Return the subdomain for the current cursor position.
virtual BaseSemantics::SValuePtr fpMultiply(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, SgAsmFloatType *) ROSE_OVERRIDE
Multiply two floating-point values.
virtual void before(size_t idx)
Called before each subdomain RISC operation.
virtual uint64_t get_number() const ROSE_OVERRIDE
Virtual API.
Base classes for instruction semantics.
static SValuePtr promote(const BaseSemantics::SValuePtr &v)
Promote a base value to a MultiSemantics value.
virtual void writeMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &data, const BaseSemantics::SValuePtr &cond) ROSE_OVERRIDE
Writes a value to memory.
virtual void set_active(size_t idx, bool status)
Makes a subdomain active or inactive.
Describes (part of) a physical CPU register.
virtual BaseSemantics::SValuePtr copy(size_t new_width=0) const ROSE_OVERRIDE
Create a new value from an existing value, changing the width if new_width is non-zero.
virtual void set_subvalue(size_t idx, const BaseSemantics::SValuePtr &value)
Insert a subdomain value.
BaseSemantics::SValuePtr operator()(const BaseSemantics::SValuePtr &) const
Returns subdomain value of its multidomain argument.
virtual bool is_valid(size_t idx) const
Returns true if a subdomain value is valid.
Sawyer::SharedPointer< class SValue > SValuePtr
Shared-ownership pointer to a multi-semantic value.
virtual void after(size_t idx)
Called after each subdomain RISC operation.
virtual BaseSemantics::SValuePtr peekRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &dflt) ROSE_OVERRIDE
Obtain a register value without side effects.
Base class for semantic values.
virtual size_t add_subdomain(const BaseSemantics::RiscOperatorsPtr &subdomain, const std::string &name, bool activate=true)
Add a subdomain to this MultiSemantics domain.
boost::shared_ptr< void > RegisterStatePtr
Shared-ownership pointer to a multi-semantics register state.
virtual void invalidate(size_t idx)
Removes a subdomain value and marks it as invalid.
virtual BaseSemantics::RiscOperatorsPtr get_subdomain(size_t idx) const
Returns the RiscOperators for a subdomain.
virtual BaseSemantics::SValuePtr fpIsNan(const BaseSemantics::SValuePtr &, SgAsmFloatType *) ROSE_OVERRIDE
Whether a floating-point value is a special not-a-number bit pattern.
virtual BaseSemantics::SValuePtr fpRoundTowardZero(const BaseSemantics::SValuePtr &, SgAsmFloatType *) ROSE_OVERRIDE
Round toward zero.
virtual void writeRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &a) ROSE_OVERRIDE
Writes a value to a register.
SharedPointer< U > dynamicCast() const
Dynamic cast.
Base class for most instruction semantics RISC operators.
virtual size_t nsubdomains() const
Returns the number of subdomains added to this MultiDomain.
Iterates over valid subdomains whose inputs are valid.
virtual BaseSemantics::SValuePtr bottom_(size_t nbits) const ROSE_OVERRIDE
Data-flow bottom value.
virtual BaseSemantics::SValuePtr unspecified_(size_t nbits) const ROSE_OVERRIDE
Create a new unspecified MultiSemantics value.
virtual BaseSemantics::SValuePtr unsignedDivide(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b) ROSE_OVERRIDE
Divides two unsigned values.
virtual BaseSemantics::SValuePtr fpFromInteger(const BaseSemantics::SValuePtr &, SgAsmFloatType *) ROSE_OVERRIDE
Construct a floating-point value from an integer value.
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.
size_t nBits() const
Property: value width.
virtual void set_width(size_t nbits) ROSE_OVERRIDE
Virtual API.
Base class for binary types.
virtual BaseSemantics::SValuePtr undefined_(size_t nbits) const ROSE_OVERRIDE
Create a new undefined MultiSemantics value.
virtual BaseSemantics::SValuePtr readMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt, const BaseSemantics::SValuePtr &cond) ROSE_OVERRIDE
Reads a value from memory.
Sawyer::SharedPointer< SValue > SValuePtr
Shared-ownership pointer to a semantic value in any domain.
virtual void hash(Combinatorics::Hasher &) const override
Hash this semantic value.
Type of values manipulated by the MultiSemantics domain.
virtual BaseSemantics::SValuePtr get_subvalue(size_t idx) const
Return a subdomain value.
virtual BaseSemantics::SValuePtr signedModulo(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b) ROSE_OVERRIDE
Calculates modulo with signed values.
virtual void print(std::ostream &o, BaseSemantics::Formatter &) const ROSE_OVERRIDE
Print multi-line output for this object.
Defines registers available for a particular architecture.
virtual SmtSolverPtr solver() const
Property: Satisfiability module theory (SMT) solver.
virtual BaseSemantics::SValuePtr unsignedMultiply(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b) ROSE_OVERRIDE
Multiply two unsigned values.
virtual const std::string & name() const
Property: Name used for debugging.
virtual BaseSemantics::SValuePtr fpSquareRoot(const BaseSemantics::SValuePtr &, SgAsmFloatType *) ROSE_OVERRIDE
Square root.
virtual BaseSemantics::SValuePtr fpEffectiveExponent(const BaseSemantics::SValuePtr &, SgAsmFloatType *) ROSE_OVERRIDE
Exponent of floating-point value.
virtual BaseSemantics::SValuePtr number_(size_t nbits, uint64_t number) const ROSE_OVERRIDE
Create a MultiSemantics value holding a concrete value.
virtual SValuePtr create_empty(size_t nbits) const
Create a new MultiSemantics value with no valid subvalues.
virtual BaseSemantics::SValuePtr fpDivide(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, SgAsmFloatType *) ROSE_OVERRIDE
Divide one floating-point value by another.
virtual BaseSemantics::SValuePtr signedMultiply(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b) ROSE_OVERRIDE
Multiplies two signed values.
size_t idx() const
Return the subdomain index for the current cursor position.
bool at_end() const
Returns true when the cursor has gone past the last valid subdomain.
virtual BaseSemantics::SValuePtr unsignedModulo(const BaseSemantics::SValuePtr &a, const BaseSemantics::SValuePtr &b) ROSE_OVERRIDE
Calculates modulo with unsigned values.
std::shared_ptr< class SmtSolver > SmtSolverPtr
Reference-counting pointer for SMT solvers.
virtual void print(std::ostream &, BaseSemantics::Formatter &) const ROSE_OVERRIDE
Print a value to a stream using default format.