ROSE 0.11.145.192
|
Interior node of an expression tree for instruction semantics.
Each interior node has an operator (constant for the life of the node and obtainable with get_operator()) and zero or more children. Children are added to the interior node during the construction phase. Once construction is complete, the children should only change in ways that don't affect the value of the node as a whole (since this node might be pointed to by any number of expressions).
Definition at line 1073 of file SymbolicExpression.h.
#include <Rose/BinaryAnalysis/SymbolicExpression.h>
Public Member Functions | |
virtual bool | mustEqual (const Ptr &other, const SmtSolverPtr &solver=SmtSolverPtr()) override |
Returns true if two expressions must be equal (cannot be unequal). | |
virtual bool | mayEqual (const Ptr &other, const SmtSolverPtr &solver=SmtSolverPtr()) override |
Returns true if two expressions might be equal, but not necessarily be equal. | |
virtual bool | isEquivalentTo (const Ptr &other) override |
Tests two expressions for structural equivalence. | |
virtual bool | isEquivalentHelper (Node *, EquivPairs &) override |
virtual int | compareStructure (const Ptr &other) override |
Compare two expressions structurally for sorting. | |
virtual Ptr | substitute (const Ptr &from, const Ptr &to, const SmtSolverPtr &solver=SmtSolverPtr()) override |
Substitute one value for another. | |
virtual VisitAction | depthFirstTraversal (Visitor &) const override |
Traverse the expression. | |
virtual uint64_t | nNodes () const override |
Computes the size of an expression by counting the number of nodes. | |
virtual const Nodes & | children () const override |
Arguments. | |
virtual Operator | getOperator () const override |
Operator for interior nodes. | |
virtual size_t | nChildren () const override |
Number of arguments. | |
virtual const Ptr & | child (size_t idx) const override |
Argument. | |
virtual Node * | childRaw (size_t idx) const override |
Argument. | |
virtual Sawyer::Optional< uint64_t > | toUnsigned () const override |
The unsigned integer value of the expression. | |
virtual Sawyer::Optional< int64_t > | toSigned () const override |
The signed integer value of the expression. | |
virtual bool | isConstant () const override |
True if this expression is a constant. | |
virtual bool | isVariable2 () const override |
True if this expression is a variable. | |
Ptr | simplifyTop (const SmtSolverPtr &solver=SmtSolverPtr()) |
Simplifies the specified interior node. | |
Ptr | foldConstants (const Simplifier &) |
Perform constant folding. | |
InteriorPtr | associative () |
Simplifies non-associative operators by flattening the specified interior node with its children that are the same interior node type. | |
InteriorPtr | commutative () |
Simplifies commutative operators by sorting arguments. | |
InteriorPtr | idempotent (const SmtSolverPtr &solver=SmtSolverPtr()) |
Simplifies idempotent operators. | |
Ptr | involutary () |
Simplifies involutary operators. | |
Ptr | additiveNesting (const SmtSolverPtr &solver=SmtSolverPtr()) |
Simplifies nested shift-like operators. | |
Ptr | identity (uint64_t ident, const SmtSolverPtr &solver=SmtSolverPtr()) |
Removes identity arguments. | |
Ptr | poisonNan (const SmtSolverPtr &solver=SmtSolverPtr()) |
Returns NaN if any argument is NaN. | |
Ptr | unaryNoOp () |
Replaces a binary operator with its only argument. | |
Ptr | rewrite (const Simplifier &simplifier, const SmtSolverPtr &solver=SmtSolverPtr()) |
Simplify an interior node. | |
virtual void | print (std::ostream &, Formatter &) const override |
Print the expression to a stream. | |
Public Member Functions inherited from Rose::BinaryAnalysis::SymbolicExpression::Node | |
Type | type () const |
Type of value. | |
Ptr | substituteMultiple (const ExprExprHashMap &substitutions, const SmtSolverPtr &solver=SmtSolverPtr()) |
Rewrite expression by substituting subexpressions. | |
Ptr | renameVariables (ExprExprHashMap &index, size_t &nextVariableId, const SmtSolverPtr &solver=SmtSolverPtr()) |
Rewrite using lowest numbered variable names. | |
bool | isIntegerExpr () const |
True if this expression is of an integer type. | |
bool | isFloatingPointExpr () const |
True if this expression is of a floating-point type. | |
bool | isMemoryExpr () const |
True if this expression is of a memory type. | |
bool | isScalarExpr () const |
True if the expression is a scalar type. | |
bool | isIntegerConstant () const |
True if this expression is an integer constant. | |
bool | isFloatingPointConstant () const |
True if this epxression is a floating-point constant. | |
bool | isScalarConstant () const |
True if this expression is a scalar constant. | |
bool | isFloatingPointNan () const |
True if this expression is a floating-point NaN constant. | |
Sawyer::Optional< uint64_t > | variableId () const |
Variable ID number. | |
bool | isIntegerVariable () const |
True if this expression is an integer variable. | |
bool | isFloatingPointVariable () const |
True if this expression is a floating-point variable. | |
bool | isMemoryVariable () const |
True if this expression is a memory state variable. | |
bool | isScalarVariable () const |
True if this expression is a scalar variable. | |
size_t | nBits () const |
Property: Number of significant bits. | |
unsigned | flags () const |
Property: User-defined bit flags. | |
Ptr | newFlags (unsigned flags) const |
Sets flags. | |
size_t | domainWidth () const |
Property: Width for memory expressions. | |
bool | isScalar () const |
Check whether expression is scalar. | |
uint64_t | nNodesUnique () const |
Number of unique nodes in expression. | |
std::set< LeafPtr > | getVariables () const |
Returns the variables appearing in the expression. | |
bool | isHashed () const |
Returns true if this node has a hash value computed and cached. | |
Hash | hash () const |
Returns (and caches) the hash value for this node. | |
void | hash (Hash) const |
std::string | toString () const |
Convert expression to string. | |
void | assertAcyclic () const |
Asserts that expressions are acyclic. | |
std::vector< Ptr > | findCommonSubexpressions () const |
Find common subexpressions. | |
bool | matchAddVariableConstant (LeafPtr &variable, LeafPtr &constant) const |
Determine whether an expression is a variable plus a constant. | |
InteriorPtr | isOperator (Operator) const |
True (non-null) if this node is the specified operator. | |
const std::string & | comment () const |
Property: Comment. | |
void | comment (const std::string &s) |
Property: Comment. | |
void | userData (boost::any &data) |
Property: User-defined data. | |
const boost::any & | userData () const |
Property: User-defined data. | |
InteriorPtr | isInteriorNode () const |
Dynamic cast of this object to an interior node. | |
Interior * | isInteriorNodeRaw () const |
Dynamic cast of this object to an interior node. | |
LeafPtr | isLeafNode () const |
Dynamic cast of this object to a leaf node. | |
Leaf * | isLeafNodeRaw () const |
Dynamic cast of this object to a leaf node. | |
WithFormatter | withFormat (Formatter &fmt) |
Combines a node with a formatter for printing. | |
WithFormatter | operator+ (Formatter &fmt) |
Combines a node with a formatter for printing. | |
void | print (std::ostream &o) const |
Print the expression to a stream. | |
Public Member Functions inherited from Sawyer::SharedObject | |
SharedObject () | |
Default constructor. | |
SharedObject (const SharedObject &) | |
Copy constructor. | |
virtual | ~SharedObject () |
Virtual destructor. | |
SharedObject & | operator= (const SharedObject &) |
Assignment. | |
Public Member Functions inherited from Sawyer::SharedFromThis< Node > | |
SharedPointer< Node > | sharedFromThis () |
Create a shared pointer from this . | |
SharedPointer< const Node > | sharedFromThis () const |
Create a shared pointer from this . | |
Public Member Functions inherited from Sawyer::Attribute::Storage< SyncTag > | |
Storage () | |
Default constructor. | |
Storage (const Storage &other) | |
Copy constructor. | |
Storage & | operator= (const Storage &other) |
Assignment operator. | |
bool | attributeExists (Id id) const |
Check attribute existence. | |
void | eraseAttribute (Id id) |
Erase an attribute. | |
void | clearAttributes () |
Erase all attributes. | |
template<typename T > | |
void | setAttribute (Id id, const T &value) |
Store an attribute. | |
template<typename T > | |
bool | setAttributeMaybe (Id id, const T &value) |
Store an attribute if not already present. | |
template<typename T > | |
T | getAttribute (Id id) const |
Get an attribute that is known to exist. | |
template<typename T > | |
Sawyer::Optional< T > | getAttributeMaybe (const Id id) const |
Return an attribute if it exists, or else nothing. | |
template<typename T > | |
T | attributeOrElse (Id id, const T &dflt) const |
Return an attribute or a specified value. | |
template<typename T > | |
T | attributeOrDefault (Id id) const |
Return an attribute or a default-constructed value. | |
template<typename T > | |
Sawyer::Optional< T > | optionalAttribute (Id id) const |
Return the attribute as an optional value. | |
size_t | nAttributes () const |
Number of attributes stored. | |
std::vector< Id > | attributeIds () const |
Returns ID numbers for all IDs stored in this container. | |
Static Public Member Functions | |
static Ptr | instance (Operator op, const Ptr &a, const SmtSolverPtr &solver=SmtSolverPtr(), const std::string &comment="", unsigned flags=0) |
Create a new expression node. | |
static Ptr | instance (const Type &type, Operator op, const Ptr &a, const SmtSolverPtr &solver=SmtSolverPtr(), const std::string &comment="", unsigned flags=0) |
Create a new expression node. | |
static Ptr | instance (Operator op, const Ptr &a, const Ptr &b, const SmtSolverPtr &solver=SmtSolverPtr(), const std::string &comment="", unsigned flags=0) |
Create a new expression node. | |
static Ptr | instance (const Type &type, Operator op, const Ptr &a, const Ptr &b, const SmtSolverPtr &solver=SmtSolverPtr(), const std::string &comment="", unsigned flags=0) |
Create a new expression node. | |
static Ptr | instance (Operator op, const Ptr &a, const Ptr &b, const Ptr &c, const SmtSolverPtr &solver=SmtSolverPtr(), const std::string &comment="", unsigned flags=0) |
Create a new expression node. | |
static Ptr | instance (const Type &type, Operator op, const Ptr &a, const Ptr &b, const Ptr &c, const SmtSolverPtr &solver=SmtSolverPtr(), const std::string &comment="", unsigned flags=0) |
Create a new expression node. | |
static Ptr | instance (Operator op, const Nodes &arguments, const SmtSolverPtr &solver=SmtSolverPtr(), const std::string &comment="", unsigned flags=0) |
Create a new expression node. | |
static Ptr | instance (const Type &type, Operator op, const Nodes &arguments, const SmtSolverPtr &solver=SmtSolverPtr(), const std::string &comment="", unsigned flags=0) |
Create a new expression node. | |
Static Public Member Functions inherited from Sawyer::SmallObject | |
static SynchronizedPoolAllocator & | poolAllocator () |
Return the pool allocator for this class. | |
static void * | operator new (size_t size) |
static void | operator delete (void *ptr, size_t size) |
Protected Member Functions | |
void | addChild (const Ptr &child) |
Appends child as a new child of this node. | |
void | adjustWidth (const Type &) |
Adjust width based on operands. | |
void | adjustBitFlags (unsigned extraFlags) |
Adjust user-defined bit flags. | |
Protected Member Functions inherited from Rose::BinaryAnalysis::SymbolicExpression::Node | |
Node (const std::string &comment, unsigned flags=0) | |
void | printFlags (std::ostream &o, unsigned flags, char &bracket) const |
Additional Inherited Members | |
Public Types inherited from Rose::BinaryAnalysis::SymbolicExpression::Node | |
using | EquivPairs = std::map< Node *, std::vector< std::pair< Node *, bool > > > |
Public Types inherited from Sawyer::Attribute::Storage< SyncTag > | |
typedef SynchronizationTraits< SyncTag > | Sync |
Static Public Attributes inherited from Rose::BinaryAnalysis::SymbolicExpression::Node | |
static const unsigned | RESERVED_FLAGS = 0x0000ffff |
These flags are reserved for use within ROSE. | |
static const unsigned | INDETERMINATE = 0x00000001 |
Value is somehow indeterminate. | |
static const unsigned | UNSPECIFIED = 0x00000002 |
Value is somehow unspecified. | |
static const unsigned | BOTTOM = 0x00000004 |
Value represents bottom in dataflow analysis. | |
static boost::logic::tribool(* | mayEqualCallback )(const Ptr &a, const Ptr &b, const SmtSolverPtr &) |
User-supplied predicate to augment alias checking. | |
Protected Attributes inherited from Rose::BinaryAnalysis::SymbolicExpression::Node | |
Type | type_ |
unsigned | flags_ |
Bit flags. | |
std::string | comment_ |
Optional comment. | |
Hash | hashval_ |
Optional hash used as a quick way to indicate that two expressions are different. | |
boost::any | userData_ |
Additional user-specified data. | |
|
overridevirtual |
Returns true if two expressions must be equal (cannot be unequal).
If an SMT solver is specified then that solver is used to answer this question, otherwise equality is established by looking only at the structure of the two expressions. Two expressions can be equal without being the same width (e.g., a 32-bit constant zero is equal to a 16-bit constant zero).
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
|
overridevirtual |
Returns true if two expressions might be equal, but not necessarily be equal.
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
|
overridevirtual |
Tests two expressions for structural equivalence.
Two leaf nodes are equivalent if they are the same width and have equal values or are the same variable. Two interior nodes are equivalent if they are the same width, the same operation, have the same number of children, and those children are all pairwise equivalent.
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
|
overridevirtual |
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
|
overridevirtual |
Compare two expressions structurally for sorting.
Returns -1 if this
is less than other
, 0 if they are structurally equal, and 1 if this
is greater than other
. This function returns zero when an only when isEquivalentTo returns zero, but isEquivalentTo can be much faster since it uses hashing.
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
|
overridevirtual |
Substitute one value for another.
Finds all occurrances of from
in this expression and replace them with to
. If a substitution occurs, then a new expression is returned. The matching of from
to sub-parts of this expression uses structural equivalence, the isEquivalentTo predicate. The from
and to
expressions must have the same width.
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
|
overridevirtual |
Traverse the expression.
The expression is traversed in a depth-first visit. The final return value is the final return value of the last call to the visitor.
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
|
inlineoverridevirtual |
Computes the size of an expression by counting the number of nodes.
Operates in constant time. Note that it is possible (even likely) for the 64-bit return value to overflow in expressions when many nodes are shared. For instance, the following loop will create an expression that contains more than 2^64 nodes:
When an overflow occurs the result is meaningless.
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
Definition at line 1139 of file SymbolicExpression.h.
|
inlineoverridevirtual |
Arguments.
Returns the arguments of an operation for an interior node, or an empty list for a leaf node.
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
Definition at line 1140 of file SymbolicExpression.h.
Referenced by Rose::BinaryAnalysis::SymbolicExpression::substitute().
|
inlineoverridevirtual |
Operator for interior nodes.
Return the operator for interior nodes, or OP_NONE for leaf nodes that have no operator.
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
Definition at line 1141 of file SymbolicExpression.h.
Referenced by Rose::BinaryAnalysis::SymbolicExpression::substitute().
|
inlineoverridevirtual |
Number of arguments.
Returns the number of children for an interior node, zero for leaf nodes.
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
Definition at line 1142 of file SymbolicExpression.h.
Referenced by Rose::BinaryAnalysis::SymbolicExpression::substitute().
|
overridevirtual |
Argument.
Returns the specified argument by index. If the index is out of range, then returns null. A leaf node always returns null since it never has children.
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
|
overridevirtual |
Argument.
Returns the specified argument by index. If the index is out of range, then returns null. A leaf node always returns null since it never has children.
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
|
inlineoverridevirtual |
The unsigned integer value of the expression.
Returns nothing if the expression is not a concrete integer value or the value is too wide to be represented by the return type.
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
Definition at line 1145 of file SymbolicExpression.h.
|
inlineoverridevirtual |
The signed integer value of the expression.
Returns nothing if the expression is not a concrete integer value or the value doesn't fit in the return type.
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
Definition at line 1146 of file SymbolicExpression.h.
|
inlineoverridevirtual |
True if this expression is a constant.
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
Definition at line 1147 of file SymbolicExpression.h.
|
inlineoverridevirtual |
True if this expression is a variable.
Warning: Leaf nodes have a deprecated isVariable method that returns false for memory state variables, thus this method has a "2" appended to its name. After a suitable period of deprecation for Leaf::isVariable, a new isVariable will be added to this class hiearchy and will have the same semantics as isVariable2, which will become deprecated.
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
Definition at line 1148 of file SymbolicExpression.h.
Ptr Rose::BinaryAnalysis::SymbolicExpression::Interior::simplifyTop | ( | const SmtSolverPtr & | solver = SmtSolverPtr() | ) |
Simplifies the specified interior node.
Returns a new node if necessary, otherwise returns this. The SMT solver is optional and my be the null pointer.
Ptr Rose::BinaryAnalysis::SymbolicExpression::Interior::foldConstants | ( | const Simplifier & | ) |
Perform constant folding.
This method returns either a new expression (if changes were mde) or the original expression. The simplifier is specific to the kind of operation at the node being simplified.
InteriorPtr Rose::BinaryAnalysis::SymbolicExpression::Interior::associative | ( | ) |
Simplifies non-associative operators by flattening the specified interior node with its children that are the same interior node type.
Call this only if the top node is a truly non-associative. A new node is returned only if changed. When calling both nonassociative and commutative, it's usually more appropriate to call nonassociative first.
InteriorPtr Rose::BinaryAnalysis::SymbolicExpression::Interior::commutative | ( | ) |
Simplifies commutative operators by sorting arguments.
The arguments are sorted so that all the interior nodes come before the leaf nodes. Call this only if the top node is truly commutative. A new node is returned only if changed. When calling both nonassociative and commutative, it's usually more appropriate to call nonassociative first.
InteriorPtr Rose::BinaryAnalysis::SymbolicExpression::Interior::idempotent | ( | const SmtSolverPtr & | solver = SmtSolverPtr() | ) |
Simplifies idempotent operators.
An idempotent operator I is one such that X I X = X. For operators that have more than two operands, only those repeated neighboring operands are reduced to a single operand. Therefore, if the operator is commutative, then do the commutative simplification before the idempotent simplification. Returns either a new, simplified expression or the original unmodified expression.
Ptr Rose::BinaryAnalysis::SymbolicExpression::Interior::involutary | ( | ) |
Simplifies involutary operators.
An involutary operator is one that is its own inverse. This method should only be called if this node is an interior node whose operator has the involutary property (such as invert or negate). Returns either a new expression that is simplified, or the original expression.
Ptr Rose::BinaryAnalysis::SymbolicExpression::Interior::additiveNesting | ( | const SmtSolverPtr & | solver = SmtSolverPtr() | ) |
Simplifies nested shift-like operators.
Simplifies (shift AMT1 (shift AMT2 X)) to (shift (add AMT1 AMT2) X). The SMT solver may be null.
Ptr Rose::BinaryAnalysis::SymbolicExpression::Interior::identity | ( | uint64_t | ident, |
const SmtSolverPtr & | solver = SmtSolverPtr() |
||
) |
Removes identity arguments.
Returns either a new expression or the original expression. The solver may be a null pointer.
Ptr Rose::BinaryAnalysis::SymbolicExpression::Interior::poisonNan | ( | const SmtSolverPtr & | solver = SmtSolverPtr() | ) |
Returns NaN if any argument is NaN.
If any argument is NaN then a new NaN constant expression is returned, otherwise the original expression is returned. The solver may be a null pointer.
Ptr Rose::BinaryAnalysis::SymbolicExpression::Interior::unaryNoOp | ( | ) |
Replaces a binary operator with its only argument.
Returns either a new expression or the original expression.
Ptr Rose::BinaryAnalysis::SymbolicExpression::Interior::rewrite | ( | const Simplifier & | simplifier, |
const SmtSolverPtr & | solver = SmtSolverPtr() |
||
) |
Simplify an interior node.
Returns a new node if this node could be simplified, otherwise returns this node. When the simplification could result in a leaf node, we return an OP_NOOP interior node instead. The SMT solver is optional and may be the null pointer.
|
overridevirtual |
Print the expression to a stream.
The output is an S-expression with no line-feeds. The format of the output is controlled by the mutable Formatter argument.
Implements Rose::BinaryAnalysis::SymbolicExpression::Node.
|
protected |
Appends child
as a new child of this node.
This must only be called from constructors.
|
protected |
Adjust width based on operands.
This must only be called from constructors. The type is needed for certain operations such as convert.
|
protected |
Adjust user-defined bit flags.
This must only be called from constructors. Flags are the union of the operand flags subject to simplification rules, unioned with the specified flags.