OpenASIP  2.0
OperationDAGBuilder.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file OperationDAGBuilder.hh
26  *
27  * Declaration of OperationDAGBuilder class.
28  *
29  * @author Mikael Lepistö 2007 (tmlepist-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #ifndef TTA_OPERATION_DAG_BUILDER_HH
34 #define TTA_OPERATION_DAG_BUILDER_HH
35 
37 
38 class OperationNode;
39 class TerminalNode;
40 class OperationPimpl;
41 class OperationDAG;
42 class OperationDAGNode;
43 
44 /**
45  * Builds OperationDAG from parsed and tokenized OSAL code.
46  */
48 public:
50  const OperationPimpl& operation,
51  OperationDAG& dag,
52  const TokenizerData::TokenTreeNode& root);
53 
54  void parse();
55 
56 private:
57  /// Node and operand which is referred by a variable.
58  typedef std::pair<OperationDAGNode*, int> VariableBinding;
59 
60  /// Information of object and index of operand of a variable.
61  typedef std::pair<TerminalNode*, unsigned int> TerminalBinding;
62 
63  void parseNode(const TokenizerData::TokenTreeNode* node);
64  void createOperationNode(const std::string& operation);
65 
67  const TokenizerData::TokenTreeNode* var, unsigned int operandIndex);
68 
69  void finalize();
70 
72 
73  void assignVariable(
75  void assignVariable(
77  const TokenizerData::TokenTreeNode* src);
78 
79  std::string getVariableName(const TokenizerData::TokenTreeNode* var);
80 
82  VariableBinding& getBinding(std::string varName);
83  VariableBinding& getBinding(unsigned int operandIndex);
85 
86  unsigned int getIOOperand(const TokenizerData::TokenTreeNode* var);
87 
88  /// DAG where all nodes and edges are added.
90 
91  /// Root of tokenized data parsed from OSAL DAG source code.
93 
94  /// Currently created handled operation.
96 
97  /// Node and operand which are referred by IO(x) or declared variable.
98  std::map<std::string, VariableBinding> variableBindings_;
99 
100  /// Node representing constant value.
101  std::map<long, VariableBinding> constantBindings_;
102 
103  /// IO(x) variables and corresponding TerminalNodes and operand indices.
104  std::map<std::string, TerminalBinding> ioVariables_;
105 
107 };
108 
109 #endif
OperationDAGLanguageParser.hh
OperationDAGBuilder::VariableBinding
std::pair< OperationDAGNode *, int > VariableBinding
Node and operand which is referred by a variable.
Definition: OperationDAGBuilder.hh:58
OperationPimpl
Definition: OperationPimpl.hh:54
OperationDAGBuilder::currentOperation_
OperationNode * currentOperation_
Currently created handled operation.
Definition: OperationDAGBuilder.hh:95
TerminalNode
Definition: TerminalNode.hh:47
OperationDAGBuilder::variableBindings_
std::map< std::string, VariableBinding > variableBindings_
Node and operand which are referred by IO(x) or declared variable.
Definition: OperationDAGBuilder.hh:98
OperationDAGBuilder::rootNode_
const TokenizerData::TokenTreeNode & rootNode_
Root of tokenized data parsed from OSAL DAG source code.
Definition: OperationDAGBuilder.hh:92
OperationNode
Definition: OperationNode.hh:47
OperationDAGBuilder::constantBindings_
std::map< long, VariableBinding > constantBindings_
Node representing constant value.
Definition: OperationDAGBuilder.hh:101
OperationDAGBuilder::parse
void parse()
Definition: OperationDAGBuilder.cc:64
OperationDAGBuilder::ioVariables_
std::map< std::string, TerminalBinding > ioVariables_
IO(x) variables and corresponding TerminalNodes and operand indices.
Definition: OperationDAGBuilder.hh:104
OperationDAGBuilder::getConstantBinding
VariableBinding & getConstantBinding(long value)
Definition: OperationDAGBuilder.cc:410
OperationDAGBuilder::OperationDAGBuilder
OperationDAGBuilder(const OperationPimpl &operation, OperationDAG &dag, const TokenizerData::TokenTreeNode &root)
Definition: OperationDAGBuilder.cc:53
OperationDAGNode
Definition: OperationDAGNode.hh:45
TokenizerData::TokenTreeNode
Definition: OperationDAGLanguageParser.hh:397
OperationDAG
Definition: OperationDAG.hh:43
OperationDAGBuilder
Definition: OperationDAGBuilder.hh:47
OperationDAGBuilder::assignVariable
void assignVariable(const TokenizerData::TokenTreeNode *dst, VariableBinding &src)
Definition: OperationDAGBuilder.cc:289
OperationDAGBuilder::connectOperandToNode
void connectOperandToNode(const TokenizerData::TokenTreeNode *var, unsigned int operandIndex)
Definition: OperationDAGBuilder.cc:162
OperationDAGBuilder::operation_
const OperationPimpl & operation_
Definition: OperationDAGBuilder.hh:106
OperationDAGBuilder::dag_
OperationDAG * dag_
DAG where all nodes and edges are added.
Definition: OperationDAGBuilder.hh:89
OperationDAGBuilder::getVariableName
std::string getVariableName(const TokenizerData::TokenTreeNode *var)
Definition: OperationDAGBuilder.cc:327
OperationDAGBuilder::parseNode
void parseNode(const TokenizerData::TokenTreeNode *node)
Definition: OperationDAGBuilder.cc:84
OperationDAGBuilder::createOperationNode
void createOperationNode(const std::string &operation)
Definition: OperationDAGBuilder.cc:141
OperationDAGBuilder::declareVariable
void declareVariable(const TokenizerData::TokenTreeNode *var)
Definition: OperationDAGBuilder.cc:270
OperationDAGBuilder::finalize
void finalize()
Definition: OperationDAGBuilder.cc:218
OperationDAGBuilder::getIOOperand
unsigned int getIOOperand(const TokenizerData::TokenTreeNode *var)
Definition: OperationDAGBuilder.cc:462
OperationDAGBuilder::TerminalBinding
std::pair< TerminalNode *, unsigned int > TerminalBinding
Information of object and index of operand of a variable.
Definition: OperationDAGBuilder.hh:61
OperationDAGBuilder::getBinding
VariableBinding & getBinding(const TokenizerData::TokenTreeNode *var)
Definition: OperationDAGBuilder.cc:363