2 #ifndef ROSE_BinaryAnalysis_InstructionSemantics_SourceAstSemantics_H
3 #define ROSE_BinaryAnalysis_InstructionSemantics_SourceAstSemantics_H
4 #include <featureTests.h>
5 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
7 #include <Rose/BinaryAnalysis/BasicTypes.h>
8 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/RegisterStateGeneric.h>
9 #include <Rose/BinaryAnalysis/InstructionSemantics/NullSemantics.h>
12 namespace BinaryAnalysis {
13 namespace InstructionSemantics {
50 namespace SourceAstSemantics {
77 static size_t nVariables_;
82 explicit SValue(
size_t nbits);
85 SValue(
size_t nbits, uint64_t number);
127 SValuePtr retval(
new SValue(*
this));
128 if (new_width!=0 && new_width!=retval->nBits())
129 retval->set_width(new_width);
142 ASSERT_not_null(retval);
158 ASSERT_not_reachable(
"no implementation necessary");
163 ASSERT_not_reachable(
"no implementation necessary");
167 ASSERT_not_reachable(
"no implementation necessary");
175 ASSERT_not_reachable(
"no implementation necessary");
190 virtual const std::string&
ctext()
const {
193 virtual void ctext(
const std::string &s) {
251 : location(location), temporary(temporary), expression(expression) {}
254 bool isValid()
const {
return expression != NULL; }
260 return isValid() && location==NULL && temporary!=NULL;
268 SideEffects sideEffects_;
269 bool executionHalted_;
346 sideEffects_.clear();
347 executionHalted_ =
false;
370 virtual void hlt()
override;
371 virtual void cpuid()
override;
381 size_t begin_bit,
size_t end_bit)
override;
422 virtual void interrupt(
int majr,
int minr)
override;
virtual BaseSemantics::SValuePtr bottom_(size_t nbits) const override
Data-flow bottom value.
static SValuePtr instance()
Instantiate a prototypical SValue.
virtual bool must_equal(const BaseSemantics::SValuePtr &, const SmtSolverPtr &=SmtSolverPtr()) const override
Virtual API.
virtual bool is_number() const override
Virtual API.
virtual BaseSemantics::SValuePtr unspecified_(size_t nbits) override
Returns a new undefined value.
Semantic values for generating C source code ASTs.
virtual void ctext(const std::string &s)
C source text associated with this semantic value.
BaseSemantics::StatePtr StatePtr
Pointer to states used by this domain.
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer for basic semantic operations.
BaseSemantics::SValuePtr location
Optional affected location.
virtual BaseSemantics::SValuePtr or_(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Computes bit-wise OR of two values.
virtual BaseSemantics::SValuePtr peekRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &dflt) override
Obtain a register value without side effects.
bool isValid() const
Predicate to determine whether side effect is valid.
virtual uint64_t get_number() const override
Virtual API.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
virtual BaseSemantics::SValuePtr signedDivide(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Divides two signed values.
BaseSemantics::SValuePtr makeSValue(size_t nbits, SgNode *, const std::string &ctext="")
Create a new SValue.
static std::string signedTypeNameForSize(size_t nbits)
Name of integer type used for value.
virtual BaseSemantics::SValuePtr xor_(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Computes bit-wise XOR of two values.
virtual BaseSemantics::SValuePtr number_(size_t nbits, uint64_t value) const override
Create a new concrete semantic value.
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 isBottom() const override
Determines whether a value is a data-flow bottom.
virtual BaseSemantics::SValuePtr undefined_(size_t nbits) const override
Create a new undefined semantic value.
Holds a value or nothing.
Sawyer::SharedPointer< class SValue > SValuePtr
Shared-ownership pointer for a binary-to-source semantic value.
virtual BaseSemantics::SValuePtr signExtend(const BaseSemantics::SValuePtr &a_, size_t new_width) override
Sign extends a value.
virtual void print(std::ostream &, BaseSemantics::Formatter &) const override
Print a value to a stream using default format.
virtual BaseSemantics::SValuePtr and_(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Computes bit-wise AND of two values.
Main namespace for the ROSE library.
virtual BaseSemantics::SValuePtr signedModulo(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Calculates modulo with signed values.
BaseSemantics::SValuePtr saveSideEffect(const BaseSemantics::SValuePtr &expression, const BaseSemantics::SValuePtr &location=BaseSemantics::SValuePtr())
Save a side effect.
void resetState()
Reset state to initial conditions.
virtual void cpuid() override
Invoked for the x86 CPUID instruction.
A RegisterState for any architecture.
RiscOperatorsPtr Ptr
Shared-ownership pointer.
virtual BaseSemantics::SValuePtr boolean_(bool value) const override
Create a new, Boolean value.
Reference-counting intrusive smart pointer.
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 ...
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
BaseSemantics::SValuePtr substitute(const BaseSemantics::SValuePtr &expression)
Save input value.
boost::shared_ptr< class MemoryState > MemoryStatePtr
Shared-ownership pointer.
virtual BaseSemantics::SValuePtr add(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Adds two integers of equal size.
virtual BaseSemantics::SValuePtr rotateLeft(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Rotate bits to the left.
virtual BaseSemantics::SValuePtr shiftRight(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Returns arg shifted right logically (no sign bit).
virtual void hlt() override
Invoked for the x86 HLT instruction.
static RiscOperatorsPtr instanceFromState(const BaseSemantics::StatePtr &, const SmtSolverPtr &)
Instantiates a new RiscOperators object with specified state.
virtual BaseSemantics::SValuePtr signedMultiply(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Multiplies two signed values.
virtual BaseSemantics::SValuePtr mostSignificantSetBit(const BaseSemantics::SValuePtr &a_) override
Returns position of most significant set bit; zero when no bits are set.
boost::shared_ptr< class RegisterStateGeneric > RegisterStateGenericPtr
Shared-ownership pointer to generic register states.
std::string registerVariableName(RegisterDescriptor)
Global variable name for a register.
static SValuePtr promote(const BaseSemantics::SValuePtr &v)
Promote a base instance to an instance of this class.
bool isSubstitution() const
Predicate to determine whether side effect is rather a substitution.
IteStatus
Status for iteWithStatus operation.
virtual void writeRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &a) override
Writes a value to a register.
virtual BaseSemantics::SValuePtr unsignedMultiply(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Multiply two unsigned values.
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 extract(const BaseSemantics::SValuePtr &a_, size_t begin_bit, size_t end_bit) override
Extracts bits from a value.
static std::string unsignedTypeNameForSize(size_t nbits)
Name of integer type used for value.
Describes (part of) a physical CPU register.
BaseSemantics::RegisterStateGeneric RegisterState
Register state used by this domain.
This class represents the base class for all IR nodes within Sage III.
Basic semantic 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.
virtual BaseSemantics::SValuePtr unsignedModulo(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Calculates modulo with unsigned values.
virtual BaseSemantics::SValuePtr invert(const BaseSemantics::SValuePtr &a_) override
One's complement.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual allocating constructor.
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.
BaseSemantics::SValuePtr makeMask(size_t nBits, size_t nSet, size_t sa=0)
Return a bit mask.
static SValuePtr instance_integer(size_t nbits, uint64_t value)
Instantiate an integer constant.
virtual BaseSemantics::SValuePtr iteWithStatus(const BaseSemantics::SValuePtr &sel_, const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_, IteStatus &) override
If-then-else with status.
virtual void interrupt(int majr, int minr) override
Invoked for instructions that cause an interrupt.
SharedPointer< U > dynamicCast() const
Dynamic cast.
BaseSemantics::RegisterStateGenericPtr RegisterStatePtr
Pointer to register states used by this domain.
const SideEffects & sideEffects() const
Accumulated side effects and substitutions.
Base class for semantic values.
virtual bool may_equal(const BaseSemantics::SValuePtr &, const SmtSolverPtr &=SmtSolverPtr()) const override
Virtual API.
virtual Sawyer::Optional< BaseSemantics::SValuePtr > createOptionalMerge(const BaseSemantics::SValuePtr &, const BaseSemantics::MergerPtr &, const SmtSolverPtr &) const override
Possibly create a new value by merging two existing values.
virtual BaseSemantics::SValuePtr shiftRightArithmetic(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Returns arg shifted right arithmetically (with sign bit).
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 void set_width(size_t) override
Virtual API.
BaseSemantics::State State
State used by this domain.
virtual BaseSemantics::SValuePtr unspecified_(size_t nbits) const override
Create a new unspecified semantic value.
NullSemantics::MemoryState MemoryState
Memory state used by this domain.
virtual BaseSemantics::SValuePtr rdtsc() override
Invoked for the x86 RDTSC instruction.
virtual SmtSolverPtr solver() const
Property: Satisfiability module theory (SMT) solver.
static SValuePtr instance_undefined(size_t nbits)
Instantiate an undefined value.
std::shared_ptr< SmtSolver > SmtSolverPtr
Reference counting pointer.
virtual BaseSemantics::SValuePtr readRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &dflt) override
Reads a value from a register.
virtual SValuePtr protoval() const
Property: Prototypical semantic value.
void reset()
Reset to initial state.
static RiscOperatorsPtr promote(const BaseSemantics::RiscOperatorsPtr &)
Run-time promotion of a base RiscOperators instance to an instance of this semantic domain's operator...
Base class for most instruction semantics RISC operators.
virtual BaseSemantics::SValuePtr shiftLeft(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Returns arg shifted left.
static RiscOperatorsPtr instanceFromProtoval(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiates a new RiscOperators object with specified prototypical values.
virtual BaseSemantics::SValuePtr equalToZero(const BaseSemantics::SValuePtr &a_) override
Determines whether a value is equal to zero.
BaseSemantics::SValuePtr expression
Expression.
Base class for semantics machine states.
NullSemantics::MemoryStatePtr MemoryStatePtr
Pointer to memory states used by this domain.
virtual const std::string & ctext() const
C source text associated with this semantic value.
virtual BaseSemantics::SValuePtr peekMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt) override
Read memory without side effects.
virtual BaseSemantics::SValuePtr readMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt, const BaseSemantics::SValuePtr &cond) override
Reads a value from memory.
std::vector< SideEffect > SideEffects
Side effects in the order they occur.
BaseSemantics::SValuePtr temporary
Optional Temporary variable.
virtual void hash(Combinatorics::Hasher &) const override
Hash this semantic value.
virtual BaseSemantics::SValuePtr concat(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Concatenates the bits of two values.
virtual BaseSemantics::SValuePtr rotateRight(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Rotate bits to the right.
virtual BaseSemantics::SValuePtr negate(const BaseSemantics::SValuePtr &a_) override
Two's complement.
void haltExecution()
Halt execution.