OpenASIP
2.0
|
#include <OperationDAGBuilder.hh>
Public Member Functions | |
OperationDAGBuilder (const OperationPimpl &operation, OperationDAG &dag, const TokenizerData::TokenTreeNode &root) | |
void | parse () |
Private Types | |
typedef std::pair< OperationDAGNode *, int > | VariableBinding |
Node and operand which is referred by a variable. More... | |
typedef std::pair< TerminalNode *, unsigned int > | TerminalBinding |
Information of object and index of operand of a variable. More... | |
Private Member Functions | |
void | parseNode (const TokenizerData::TokenTreeNode *node) |
void | createOperationNode (const std::string &operation) |
void | connectOperandToNode (const TokenizerData::TokenTreeNode *var, unsigned int operandIndex) |
void | finalize () |
void | declareVariable (const TokenizerData::TokenTreeNode *var) |
void | assignVariable (const TokenizerData::TokenTreeNode *dst, VariableBinding &src) |
void | assignVariable (const TokenizerData::TokenTreeNode *dst, const TokenizerData::TokenTreeNode *src) |
std::string | getVariableName (const TokenizerData::TokenTreeNode *var) |
VariableBinding & | getBinding (const TokenizerData::TokenTreeNode *var) |
VariableBinding & | getBinding (std::string varName) |
VariableBinding & | getBinding (unsigned int operandIndex) |
VariableBinding & | getConstantBinding (long value) |
unsigned int | getIOOperand (const TokenizerData::TokenTreeNode *var) |
Private Attributes | |
OperationDAG * | dag_ |
DAG where all nodes and edges are added. More... | |
const TokenizerData::TokenTreeNode & | rootNode_ |
Root of tokenized data parsed from OSAL DAG source code. More... | |
OperationNode * | currentOperation_ |
Currently created handled operation. More... | |
std::map< std::string, VariableBinding > | variableBindings_ |
Node and operand which are referred by IO(x) or declared variable. More... | |
std::map< long, VariableBinding > | constantBindings_ |
Node representing constant value. More... | |
std::map< std::string, TerminalBinding > | ioVariables_ |
IO(x) variables and corresponding TerminalNodes and operand indices. More... | |
const OperationPimpl & | operation_ |
Builds OperationDAG from parsed and tokenized OSAL code.
Definition at line 47 of file OperationDAGBuilder.hh.
|
private |
Information of object and index of operand of a variable.
Definition at line 61 of file OperationDAGBuilder.hh.
|
private |
Node and operand which is referred by a variable.
Definition at line 58 of file OperationDAGBuilder.hh.
OperationDAGBuilder::OperationDAGBuilder | ( | const OperationPimpl & | operation, |
OperationDAG & | dag, | ||
const TokenizerData::TokenTreeNode & | root | ||
) |
Constructor.
dag | OperationDAG where to create DAG representation of operation. |
root | Tokenized OSAL DAG Language code. |
Definition at line 53 of file OperationDAGBuilder.cc.
|
private |
Assign binding of destination variable to be same than source.
src | Tree node variable whose binding is set to destination. |
dst | Tree node variable whose binding is set to same that source's. |
Definition at line 311 of file OperationDAGBuilder.cc.
References getBinding(), getVariableName(), and variableBindings_.
|
private |
Assign binding of destination variable to be source binding.
src | Tree node variable whose binding is set to destination. |
dst | Binding that is set to source's binding. |
Definition at line 289 of file OperationDAGBuilder.cc.
References __func__, getVariableName(), ioVariables_, TokenizerData::Token::stringValue(), TokenizerData::TokenTreeNode::token(), and variableBindings_.
Referenced by connectOperandToNode(), and parseNode().
|
private |
Connects a variable node to given operand index of last created operation node.
var | Variable to connect to operand of created operation node. |
operandIndex | Index of operand to which variable is connected. |
IllegalParameters | Operand with requested index doesn't exist. |
Definition at line 162 of file OperationDAGBuilder.cc.
References __func__, assignVariable(), BoostGraph< GraphNode, GraphEdge >::connectNodes(), currentOperation_, dag_, getBinding(), BoostGraph< GraphNode, GraphEdge >::hasNode(), Operand::isInput(), Operand::isOutput(), OperationPimpl::name(), Operation::operand(), Operation::operandCount(), operation_, OperationNode::referencedOperation(), Conversion::toString(), and OperationNode::toString().
Referenced by parseNode().
|
private |
Starts creation of new operation node.
operation | Name of operation which is referred by this node. |
IllegalParameters | Operation by requested name doesn't exist. |
Definition at line 141 of file OperationDAGBuilder.cc.
References __func__, BoostGraph< GraphNode, GraphEdge >::addNode(), currentOperation_, dag_, NullOperation::instance(), and OperationPool::operation().
Referenced by parseNode().
|
private |
Declared new variable which can be used for temporary storage of IO() variables.
var | Token tree node containing variable name. |
IllegalParameters | If variable already exists. |
Definition at line 270 of file OperationDAGBuilder.cc.
References __func__, getVariableName(), TokenizerData::Token::stringValue(), TokenizerData::TokenTreeNode::token(), and variableBindings_.
Referenced by parseNode().
|
private |
Finalizes DAG by creating output terminals.
TerminalNode objects are created for Those IO() operands, which are referred, but doesn't already have TerminalNode objects.
Definition at line 218 of file OperationDAGBuilder.cc.
References __func__, BoostGraph< GraphNode, GraphEdge >::addNode(), BoostGraph< GraphNode, GraphEdge >::connectNodes(), dag_, getBinding(), ioVariables_, OperationPimpl::name(), OperationPimpl::numberOfInputs(), OperationPimpl::numberOfOutputs(), operation_, and Conversion::toString().
Referenced by parse().
|
private |
Returns node and operand index of any existing variable, IO() call or constant.
var | Funcion call or single identifier type of token tree node. |
IllegalParameter | Parameter isn't function call or variable name. |
Definition at line 363 of file OperationDAGBuilder.cc.
References __func__, getConstantBinding(), getIOOperand(), getVariableName(), TokenizerData::TokenTreeNode::intValue(), TokenizerData::TokenTreeNode::isFunctionCall(), TokenizerData::Token::isIdentifier(), TokenizerData::TokenTreeNode::isInteger(), TokenizerData::Token::stringValue(), and TokenizerData::TokenTreeNode::token().
Referenced by assignVariable(), connectOperandToNode(), finalize(), and getBinding().
|
private |
Returns node and operand index of any existing variable.
varName | Name of the variable whose current binding is requested. |
IllegalParameters | Variable is not declared. |
Definition at line 393 of file OperationDAGBuilder.cc.
References __func__, and variableBindings_.
|
private |
Returns node and operand index of IO() variable.
If called first time creates TerminalNode and binds IO() to that node with operand index 1.
operandIndex | Number of IO whose current binding is requested. |
Definition at line 430 of file OperationDAGBuilder.cc.
References BoostGraph< GraphNode, GraphEdge >::addNode(), dag_, getBinding(), ioVariables_, Conversion::toString(), and variableBindings_.
|
private |
Returns node and operand index of any existing variable.
varName | Name of the variable whose current binding is requested. |
IllegalParameters | Variable is not declared. |
Definition at line 410 of file OperationDAGBuilder.cc.
References BoostGraph< GraphNode, GraphEdge >::addNode(), constantBindings_, and dag_.
Referenced by getBinding().
|
private |
Returns operand's number of tree node, which contains reference to IO() variable.
var | Token tree node, which contains parsed IO(x) call. |
IllegalParameters | If var isn't parsed IO() call. |
Definition at line 462 of file OperationDAGBuilder.cc.
References __func__, TokenizerData::Token::intValue(), TokenizerData::Token::isIntegerLiteral(), TokenizerData::TokenTreeNode::leaf(), TokenizerData::TokenTreeNode::leafCount(), TokenizerData::Token::stringValue(), and TokenizerData::TokenTreeNode::token().
Referenced by getBinding(), and getVariableName().
|
private |
Retuns name of variable, for token tree node containing IO() call or variable name.
var | IO() call or variable name. |
IllegalParameter | Parameter is not variable.. |
Definition at line 327 of file OperationDAGBuilder.cc.
References __func__, getIOOperand(), ioVariables_, TokenizerData::TokenTreeNode::isFunctionCall(), TokenizerData::Token::isIdentifier(), TokenizerData::Token::stringValue(), TokenizerData::TokenTreeNode::token(), and Conversion::toString().
Referenced by assignVariable(), declareVariable(), and getBinding().
void OperationDAGBuilder::parse | ( | ) |
Parses token tree presentation of OSAL DAG language to OperationDAG.
Definition at line 64 of file OperationDAGBuilder.cc.
References finalize(), TokenizerData::TokenTreeNode::leaf(), TokenizerData::TokenTreeNode::leafCount(), parseNode(), and rootNode_.
Referenced by OperationDAGConverter::createDAG().
|
private |
Parses one token tree node to DAG representation.
node | Node to parse. |
Definition at line 84 of file OperationDAGBuilder.cc.
References TokenizerData::ASSIGNMENT_EXPRESSION, assignVariable(), connectOperandToNode(), createOperationNode(), TokenizerData::DECLARATION, declareVariable(), TokenizerData::EXPRESSION_STATEMENT, TokenizerData::TokenTreeNode::isAssignment(), TokenizerData::TokenTreeNode::isFunctionCall(), TokenizerData::TokenTreeNode::leaf(), TokenizerData::TokenTreeNode::leafCount(), TokenizerData::Token::stringValue(), TokenizerData::TokenTreeNode::token(), TokenizerData::TokenTreeNode::toStr(), and TokenizerData::Token::type_.
Referenced by parse().
|
private |
Node representing constant value.
Definition at line 101 of file OperationDAGBuilder.hh.
Referenced by getConstantBinding().
|
private |
Currently created handled operation.
Definition at line 95 of file OperationDAGBuilder.hh.
Referenced by connectOperandToNode(), and createOperationNode().
|
private |
DAG where all nodes and edges are added.
Definition at line 89 of file OperationDAGBuilder.hh.
Referenced by connectOperandToNode(), createOperationNode(), finalize(), getBinding(), and getConstantBinding().
|
private |
IO(x) variables and corresponding TerminalNodes and operand indices.
Definition at line 104 of file OperationDAGBuilder.hh.
Referenced by assignVariable(), finalize(), getBinding(), and getVariableName().
|
private |
Definition at line 106 of file OperationDAGBuilder.hh.
Referenced by connectOperandToNode(), and finalize().
|
private |
Root of tokenized data parsed from OSAL DAG source code.
Definition at line 92 of file OperationDAGBuilder.hh.
Referenced by parse().
|
private |
Node and operand which are referred by IO(x) or declared variable.
Definition at line 98 of file OperationDAGBuilder.hh.
Referenced by assignVariable(), declareVariable(), and getBinding().