InsnSemanticsExpr::TreeNode Class Reference

#include <InsnSemanticsExpr.h>

Inheritance diagram for InsnSemanticsExpr::TreeNode:

Inheritance graph
[legend]
List of all members.

Detailed Description

Any node of an expression tree for instruction semantics, from which the InternalNode and LeafNode classes are derived.

Every node has a specified number of significant bits that is constant over the life of the node.

In order that subtrees can be freely assigned as children of other nodes (provided the structure as a whole remains a lattice and not a graph with cycles), each tree node maintains a counter (nrefs) of the number of times it is referenced. Each time a subtree is added as a child to another node, the reference count for the root node of the subtree is incremented. Likewise, when a child is removed the reference count for the root of the child is decremented. The delete operator must only be invoked on nodes with a zero reference count.


Public Member Functions

 TreeNode (size_t nbits)
virtual ~TreeNode ()
 Shallow delete.
virtual void deleteDeeply ()
 Deletes this node and all children, provided the children aren't also children of other nodes.
virtual void print (std::ostream &, RenameMap *rmap=NULL) const =0
 Print the expression to a stream.
virtual bool equal_to (const TreeNode *other, SMTSolver *) const =0
 Tests two expressions for equality using an optional satisfiability modulo theory (SMT) solver.
virtual bool is_known () const =0
 Returns true if the expression is a known value.
virtual uint64_t get_value () const =0
 Returns the integer value of a node for which is_known() returns true.
size_t get_nbits () const
 Returns the number of significant bits.
size_t get_nrefs () const
 Returns the number of times this node is referenced.
size_t inc_nrefs () const
 Increments the reference count by one and returns the new reference count.
size_t dec_nrefs () const
 Decrements the reference count by one and returns the new reference count.
virtual void depth_first_visit (Visitor *) const =0
 Traverse the expression.
std::set< const LeafNode * > get_variables () const
 Returns the variables appearing in the expression.

Protected Attributes

size_t nbits
 Number of significant bits.
size_t nrefs
 Number of parent nodes.


Constructor & Destructor Documentation

InsnSemanticsExpr::TreeNode::TreeNode ( size_t  nbits  )  [inline]

virtual InsnSemanticsExpr::TreeNode::~TreeNode (  )  [inline, virtual]

Shallow delete.

Deletes only this node, decrementing reference counts in any children. It is an error to delete a node whose reference count is nonzero.


Member Function Documentation

virtual void InsnSemanticsExpr::TreeNode::deleteDeeply (  )  [virtual]

Deletes this node and all children, provided the children aren't also children of other nodes.

If the reference count of the root node (this) is nonzero then nothing happens.

Reimplemented in InsnSemanticsExpr::InternalNode.

virtual void InsnSemanticsExpr::TreeNode::print ( std::ostream &  ,
RenameMap rmap = NULL 
) const [pure virtual]

Print the expression to a stream.

The output is an S-expression with no line-feeds. If rmap is non-null then it will be used to rename free variables for readability. If the expression contains N variables, then the new names will be numbered from the set M = (i | 0 <= i <= N-1).

Implemented in InsnSemanticsExpr::InternalNode, and InsnSemanticsExpr::LeafNode.

virtual bool InsnSemanticsExpr::TreeNode::equal_to ( const TreeNode other,
SMTSolver  
) const [pure virtual]

Tests two expressions for equality using an optional satisfiability modulo theory (SMT) solver.

Returns true if the inequality is not satisfiable.

Implemented in InsnSemanticsExpr::InternalNode, and InsnSemanticsExpr::LeafNode.

virtual bool InsnSemanticsExpr::TreeNode::is_known (  )  const [pure virtual]

Returns true if the expression is a known value.

FIXME: The current implementation returns true only when this node is leaf node with a known value. Since InsnSemanticsExpr does not do constant folding, this is of limited use. [RPM 2010-06-08].

Implemented in InsnSemanticsExpr::InternalNode, and InsnSemanticsExpr::LeafNode.

virtual uint64_t InsnSemanticsExpr::TreeNode::get_value (  )  const [pure virtual]

Returns the integer value of a node for which is_known() returns true.

The high-order bits, those beyond the number of significant bits returned by get_nbits(), are guaranteed to be zero.

Implemented in InsnSemanticsExpr::InternalNode, and InsnSemanticsExpr::LeafNode.

size_t InsnSemanticsExpr::TreeNode::get_nbits (  )  const [inline]

Returns the number of significant bits.

An expression with a known value is guaranteed to have all higher-order bits cleared.

size_t InsnSemanticsExpr::TreeNode::get_nrefs (  )  const [inline]

Returns the number of times this node is referenced.

Reference counting happens automatically when a node is used as a child of an internal node, but users may also forcibly increment and decrement the reference counter for other reasons. See also, documentation for the class.

size_t InsnSemanticsExpr::TreeNode::inc_nrefs (  )  const [inline]

Increments the reference count by one and returns the new reference count.

It is not necessary to increment the reference count when a node is used as a child of an InternalNode since this happens automatically. However, the user may want to increment the reference count for other reasons. See also, documentation for the class.

size_t InsnSemanticsExpr::TreeNode::dec_nrefs (  )  const [inline]

Decrements the reference count by one and returns the new reference count.

It is not necessary to decrement the reference count when a node is removed as a child of an InternalNode since this happens automatically. However, the user may want to decrement the reference count for other reasons. The dec_nrefs() method should be called the same number of times that inc_nrefs() was called. See also, documentation for the class.

virtual void InsnSemanticsExpr::TreeNode::depth_first_visit ( Visitor  )  const [pure virtual]

Traverse the expression.

The expression is traversed in a depth-first visit, invoking the functor at each node of the expression tree.

Implemented in InsnSemanticsExpr::InternalNode, and InsnSemanticsExpr::LeafNode.

std::set<const LeafNode*> InsnSemanticsExpr::TreeNode::get_variables (  )  const

Returns the variables appearing in the expression.


Member Data Documentation

size_t InsnSemanticsExpr::TreeNode::nbits [protected]

Number of significant bits.

Constant over the life of the node.

size_t InsnSemanticsExpr::TreeNode::nrefs [mutable, protected]

Number of parent nodes.

Zero implies this node can be deleted.


The documentation for this class was generated from the following file:
Generated on Tue Jan 31 05:46:13 2012 for ROSE by  doxygen 1.4.7