-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
67 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,98 @@ | ||
.. _`sec:InstructionAST.h`: | ||
|
||
InstructionAST.h | ||
================ | ||
################ | ||
|
||
.. cpp:namespace:: Dyninst::InstructionAPI | ||
|
||
InstructionAST Class | ||
-------------------- | ||
.. cpp:enum:: formatStyle | ||
|
||
The InstructionAST class is the base class for all nodes in the ASTs | ||
used by the Operand class. It defines the necessary interfaces for | ||
traversing and searching an abstract syntax tree representing an | ||
operand. For the purposes of searching an InstructionAST, we provide two | ||
related interfaces. The first, ``getUses``, will return the registers | ||
that appear in a given tree. The second, ``isUsed``, will take as input | ||
another tree and return true if that tree is a (not necessarily proper) | ||
subtree of this one. ``isUsed`` requires us to define an equality | ||
relation on these abstract syntax trees, and the equality operator is | ||
provided by the InstructionAST, with the details implemented by the | ||
classes derived from InstructionAST. Two AST nodes are equal if the | ||
following conditions hold: | ||
.. cpp:enumerator:: defaultStyle | ||
.. cpp:enumerator:: memoryAccessStyle | ||
|
||
- They are of the same type | ||
.. cpp:class:: InstructionAST : public boost::enable_shared_from_this<InstructionAST> | ||
|
||
- If leaf nodes, they represent the same immediate value or the same | ||
register | ||
**The base class for all nodes in the ASTs used by the Operand class** | ||
|
||
- If non-leaf nodes, they represent the same operation and their | ||
corresponding children are equal | ||
.. cpp:type:: boost::shared_ptr<InstructionAST> Ptr | ||
|
||
.. code-block:: cpp | ||
A reference-counted pointer to an ``InstructionAST``. | ||
|
||
typedef boost::shared_ptr<InstructionAST> Ptr | ||
.. cpp:function:: bool operator==(const InstructionAST &rhs) const | ||
|
||
A type definition for a reference-counted pointer to an | ||
``InstructionAST``. | ||
Checks if this :cpp:class::`AST` node is equal to ``rhs``. | ||
|
||
.. code-block:: cpp | ||
bool operator==(const InstructionAST &rhs) const | ||
Non-leaf nodes are equal if they are of the same type and their children are equal. | ||
|
||
Compare two AST nodes for equality. | ||
.. cpp:function:: virtual void getChildren(vector<InstructionAST::Ptr> & children) const | ||
|
||
Non-leaf nodes are equal if they are of the same type and their children | ||
are equal. ``RegisterAST``\ s are equal if they represent the same | ||
register. ``Immediate``\ s are equal if they represent the same value. | ||
Note that it is not safe to compare two ``InstructionAST::Ptr`` | ||
variables, as those are pointers. Instead, test the underlying | ||
``InstructionAST`` objects. | ||
Children of this node are appended to the vector ``children``. | ||
|
||
.. code-block:: cpp | ||
.. cpp:function:: virtual void getUses(set<InstructionAST::Ptr> & uses) | ||
|
||
virtual void getChildren(vector<InstructionAPI::Ptr> & children) const | ||
Appends the set of expressions used. | ||
|
||
Children of this node are appended to the vector ``children``. | ||
See :ref:`sec:instructionast-use-sets` for details. | ||
|
||
.. code-block:: cpp | ||
.. cpp:function:: virtual bool isUsed(InstructionAST::Ptr i) const | ||
|
||
virtual void getUses(set<InstructionAPI::Ptr> & uses) | ||
Checks if ``i`` is used by this node. | ||
|
||
The use set of an ``InstructionAST`` is defined as follows: | ||
Unlike :cpp:func:`getUses`, this looks for ``i`` as a subtree of the | ||
current tree. ``getUses`` is designed to return a minimal set of | ||
registers used in this tree, whereas ``isUsed`` is designed to allow | ||
searches for arbitrary subexpressions. | ||
|
||
See :ref:`sec:instructionast-use-sets` for details. | ||
|
||
.. cpp:function:: virtual std::string format(formatStyle how = defaultStyle) const | ||
|
||
Returns a string representation of the :cpp:class:`AST` node. | ||
|
||
- A ``RegisterAST`` uses itself | ||
Produces assembly language by default. | ||
|
||
- A ``BinaryFunction`` uses the use sets of its children | ||
virtual std::string format(Architecture arch, formatStyle how = defaultStyle) const = 0 | ||
|
||
- A ``Immediate`` uses nothing | ||
.. cpp:function:: protected virtual bool isStrictEqual(const InstructionAST& rhs) const= 0 | ||
.. cpp:function:: protected virtual bool checkRegID(MachRegister, unsigned int = 0, unsigned int = 0) const | ||
.. cpp:function:: protected virtual const Result& eval() const = 0 | ||
|
||
- A ``Dereference uses the use set of its child`` | ||
.. _`sec:instructionast-notes`: | ||
|
||
The use set oft his node is appended to the vector ``uses``. | ||
Notes | ||
===== | ||
|
||
.. code-block:: cpp | ||
InstructionAST defines the necessary interfaces for | ||
traversing and searching an abstract syntax tree representing an | ||
operand. For the purposes of searching an InstructionAST, we provide two | ||
related interfaces. The first, ``getUses``, will return the registers | ||
that appear in a given tree. The second, ``isUsed``, will take as input | ||
another tree and return true if that tree is a (not necessarily proper) | ||
subtree of this one. ``isUsed`` requires us to define an equality | ||
relation on these abstract syntax trees, and the equality operator is | ||
provided by the InstructionAST, with the details implemented by the | ||
classes derived from InstructionAST. Two AST nodes are equal if the | ||
following conditions hold: | ||
|
||
- They are of the same type | ||
|
||
- If leaf nodes, they represent the same immediate value or the same | ||
register | ||
|
||
virtual bool isUsed(InstructionAPI::Ptr findMe) const | ||
- If non-leaf nodes, they represent the same operation and their | ||
corresponding children are equal | ||
|
||
Unlike ``getUses``, ``isUsed`` looks for ``findMe`` as a subtree of the | ||
current tree. ``getUses`` is designed to return a minimal set of | ||
registers used in this tree, whereas ``isUsed`` is designed to allow | ||
searches for arbitrary subexpressions. ``findMe`` is the AST node to | ||
find in the use set of this node. | ||
.. _`sec:instructionast-use-sets`: | ||
|
||
Use Sets | ||
^^^^^^^^ | ||
|
||
The use set of an ``InstructionAST`` is defined as follows: | ||
|
||
Returns ``true`` if ``findMe`` is used by this AST node. | ||
- A ``RegisterAST`` uses itself | ||
|
||
.. code-block:: cpp | ||
- A ``BinaryFunction`` uses the use sets of its children | ||
|
||
virtual std::string format(formatStyle how == defaultStyle) const | ||
- A ``Immediate`` uses nothing | ||
|
||
The ``format`` interface returns the contents of an ``InstructionAPI`` | ||
object as a string. By default, ``format`` produces assembly language. | ||
- A ``Dereference`` uses the use set of its child |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters