2 #ifndef Rose_SourceAstSemantics2_H
3 #define Rose_SourceAstSemantics2_H
4 #include <featureTests.h>
5 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
7 #include "Disassembler.h"
8 #include "RegisterStateGeneric.h"
9 #include "NullSemantics2.h"
13 namespace InstructionSemantics2 {
50 namespace SourceAstSemantics {
70 static size_t nVariables_;
75 explicit SValue(
size_t nbits);
78 SValue(
size_t nbits, uint64_t number);
120 SValuePtr retval(
new SValue(*
this));
121 if (new_width!=0 && new_width!=retval->nBits())
122 retval->set_width(new_width);
135 ASSERT_not_null(retval);
151 ASSERT_not_reachable(
"no implementation necessary");
156 ASSERT_not_reachable(
"no implementation necessary");
160 ASSERT_not_reachable(
"no implementation necessary");
168 ASSERT_not_reachable(
"no implementation necessary");
183 virtual const std::string&
ctext()
const {
186 virtual void ctext(
const std::string &s) {
239 : location(location), temporary(temporary), expression(expression) {}
242 bool isValid()
const {
return expression != NULL; }
248 return isValid() && location==NULL && temporary!=NULL;
256 SideEffects sideEffects_;
257 bool executionHalted_;
262 name(
"SourceAstSemantics");
268 name(
"SourceAstSemantics");
317 RiscOperatorsPtr retval = boost::dynamic_pointer_cast<
RiscOperators>(x);
318 ASSERT_not_null(retval);
361 sideEffects_.clear();
362 executionHalted_ =
false;
385 virtual void hlt() ROSE_OVERRIDE;
386 virtual
void cpuid() ROSE_OVERRIDE;
396 size_t begin_bit,
size_t end_bit) ROSE_OVERRIDE;
436 virtual
void interrupt(
int majr,
int minr) ROSE_OVERRIDE;
static std::string unsignedTypeNameForSize(size_t nbits)
Name of integer type used for value.
static RegisterStateGenericPtr instance(const SValuePtr &protoval, const RegisterDictionary *regdict)
Instantiate a new register state.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
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.
BaseSemantics::SValuePtr expression
Expression.
static std::string signedTypeNameForSize(size_t nbits)
Name of integer type used for value.
virtual void hash(Combinatorics::Hasher &) const override
Hash this semantic value.
boost::shared_ptr< class RegisterStateGeneric > RegisterStateGenericPtr
Shared-ownership pointer to generic register states.
virtual bool is_number() const ROSE_OVERRIDE
Virtual API.
static SValuePtr instance_undefined(size_t nbits)
Instantiate an undefined value.
BaseSemantics::SValuePtr location
Optional affected location.
virtual BaseSemantics::SValuePtr number_(size_t nbits, uint64_t value) const ROSE_OVERRIDE
Create a new concrete semantic value.
static RiscOperatorsPtr instance(const BaseSemantics::StatePtr &state, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiates a new RiscOperators object with specified state.
BaseSemantics::RegisterStateGenericPtr RegisterStatePtr
Pointer to register states used by this domain.
static RiscOperatorsPtr instance(const RegisterDictionary *regdict, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiates a new RiscOperators object and configures it to use semantic values and states that are ...
Sawyer::SharedPointer< class SValue > SValuePtr
Shared-ownership pointer for a binary-to-source semantic value.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
NullSemantics::MemoryState MemoryState
Memory state used by this domain.
virtual void ctext(const std::string &s)
C source text associated with this semantic value.
virtual BaseSemantics::SValuePtr signedMultiply(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE
Multiplies two signed values.
Holds a value or nothing.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::StatePtr &state, const SmtSolverPtr &solver=SmtSolverPtr()) const ROSE_OVERRIDE
Virtual allocating constructor.
std::string registerVariableName(RegisterDescriptor)
Global variable name for a register.
void resetState()
Reset state to initial conditions.
BaseSemantics::SValuePtr makeMask(size_t nBits, size_t nSet, size_t sa=0)
Return a bit mask.
virtual SValuePtr protoval() const
Property: Prototypical semantic value.
boost::shared_ptr< class MemoryState > MemoryStatePtr
Shared-ownership pointer to null register state.
virtual void interrupt(int majr, int minr) ROSE_OVERRIDE
Invoked for instructions that cause an interrupt.
Main namespace for the ROSE library.
BaseSemantics::SValuePtr makeSValue(size_t nbits, SgNode *, const std::string &ctext="")
Create a new SValue.
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.
NullSemantics::MemoryStatePtr MemoryStatePtr
Pointer to memory states used by this domain.
BaseSemantics::StatePtr StatePtr
Pointer to states used by this domain.
virtual bool may_equal(const BaseSemantics::SValuePtr &other, const SmtSolverPtr &solver=SmtSolverPtr()) const ROSE_OVERRIDE
Virtual API.
Reference-counting intrusive smart pointer.
static SValuePtr instance()
Instantiate a prototypical SValue.
virtual BaseSemantics::SValuePtr peekMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt) ROSE_OVERRIDE
Read memory without side effects.
virtual BaseSemantics::SValuePtr unsignedModulo(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE
Calculates modulo with unsigned values.
virtual BaseSemantics::SValuePtr signedDivide(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE
Divides two signed values.
static SValuePtr promote(const BaseSemantics::SValuePtr &v)
Promote a base instance to an instance of this class.
std::vector< SideEffect > SideEffects
Side effects in the order they occur.
Base classes for instruction semantics.
virtual void set_width(size_t nbits) ROSE_OVERRIDE
Virtual API.
Describes (part of) a physical CPU register.
virtual bool isBottom() const ROSE_OVERRIDE
Determines whether a value is a data-flow bottom.
This class represents the base class for all IR nodes within Sage III.
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.
static RiscOperatorsPtr promote(const BaseSemantics::RiscOperatorsPtr &x)
Run-time promotion of a base RiscOperators instance to an instance of this semantic domain's operator...
Base class for semantic values.
void haltExecution()
Halt execution.
virtual BaseSemantics::SValuePtr readRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &dflt) ROSE_OVERRIDE
Reads a value from a register.
virtual const std::string & ctext() const
C source text associated with this semantic value.
static RiscOperatorsPtr instance(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiates a new RiscOperators object with specified prototypical values.
static SValuePtr instance_integer(size_t nbits, uint64_t value)
Instantiate an integer constant.
BaseSemantics::SValuePtr saveSideEffect(const BaseSemantics::SValuePtr &expression, const BaseSemantics::SValuePtr &location=BaseSemantics::SValuePtr())
Save a side effect.
Basic semantic operations.
SharedPointer< U > dynamicCast() const
Dynamic cast.
Base class for most instruction semantics RISC operators.
virtual BaseSemantics::SValuePtr undefined_(size_t nbits) const ROSE_OVERRIDE
Create a new undefined semantic value.
BaseSemantics::State State
State used by this domain.
virtual void print(std::ostream &, BaseSemantics::Formatter &) const ROSE_OVERRIDE
Print a value to a stream using default format.
virtual BaseSemantics::SValuePtr unspecified_(size_t nbits) const ROSE_OVERRIDE
Create a new unspecified semantic value.
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer for basic semantic operations.
virtual BaseSemantics::SValuePtr peekRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &dflt) ROSE_OVERRIDE
Obtain a register value without side effects.
virtual BaseSemantics::SValuePtr boolean_(bool value) const ROSE_OVERRIDE
Create a new, Boolean value.
virtual Sawyer::Optional< BaseSemantics::SValuePtr > createOptionalMerge(const BaseSemantics::SValuePtr &, const BaseSemantics::MergerPtr &, const SmtSolverPtr &) const ROSE_OVERRIDE
Possibly create a new value by merging two existing values.
BaseSemantics::SValuePtr temporary
Optional Temporary variable.
virtual BaseSemantics::SValuePtr unsignedMultiply(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE
Multiply two unsigned values.
A RegisterState for any architecture.
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 writeRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &a) ROSE_OVERRIDE
Writes a value to a register.
virtual BaseSemantics::SValuePtr negate(const BaseSemantics::SValuePtr &a_) ROSE_OVERRIDE
Two's complement.
bool isSubstitution() const
Predicate to determine whether side effect is rather a substitution.
void reset()
Reset to initial state.
virtual BaseSemantics::SValuePtr unsignedDivide(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE
Divides two unsigned values.
BaseSemantics::SValuePtr substitute(const BaseSemantics::SValuePtr &expression)
Save input value.
virtual BaseSemantics::SValuePtr signedModulo(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE
Calculates modulo with signed values.
Semantic values for generating C source code ASTs.
Defines registers available for a particular architecture.
virtual SmtSolverPtr solver() const
Property: Satisfiability module theory (SMT) solver.
virtual const std::string & name() const
Property: Name used for debugging.
virtual BaseSemantics::SValuePtr bottom_(size_t nbits) const ROSE_OVERRIDE
Data-flow bottom value.
bool isValid() const
Predicate to determine whether side effect is valid.
const SideEffects & sideEffects() const
Accumulated side effects and substitutions.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr()) const ROSE_OVERRIDE
Virtual allocating constructor.
BaseSemantics::RegisterStateGeneric RegisterState
Register state used by this domain.
std::shared_ptr< class SmtSolver > SmtSolverPtr
Reference-counting pointer for SMT solvers.
virtual bool must_equal(const BaseSemantics::SValuePtr &other, const SmtSolverPtr &solver=SmtSolverPtr()) const ROSE_OVERRIDE
Virtual API.
virtual uint64_t get_number() const ROSE_OVERRIDE
Virtual API.