OpenASIP  2.0
MoveNode.icc
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 MoveNode.icc
26  *
27  * Inline method implementation of MoveNode class.
28  *
29  * Nodes are the minimum independent unit of information in a
30  * minimally-ordered program representation. Typically, but not necessarily,
31  * the nodes in a program representation are linked together by dependences
32  * and thus form a graph.
33  *
34  * @author Heikki Kultala 2009 (hkultala-no.spam-cs.tut.fi)
35  * @note rating: red
36  */
37 
38 #include "Conversion.hh"
39 
40 /**
41  * Tells whether the destination of the node (move) belongs to an operation.
42  *
43  * @return True if the destination of the node is an operation input.
44  */
45 inline bool
46 MoveNode::isDestinationOperation() const {
47  if (move_ == NULL) {
48  return false;
49  }
50  return dstOps_.size() != 0;
51 }
52 
53 /**
54  * Tells how many operations this movenode is an operand to(operand sharing)
55  *
56  */
57 inline unsigned int
58 MoveNode::destinationOperationCount() const {
59  if (move_ == NULL) {
60  return 0;
61  }
62  return dstOps_.size();
63 }
64 
65 /**
66  * Access Move inside MoveNode, casting constantness away
67  *
68  * @return reference to Move inside MoveNode
69  */
70 inline TTAProgram::Move&
71 MoveNode::move(){
72  if (move_ == NULL) {
73  throw NotAvailable(__FILE__,__LINE__,__func__,
74  "Move of MoveNode is NULL");
75  }
76  return const_cast<TTAProgram::Move&> (*move_);
77 }
78 
79 /**
80  * Access Move inside MoveNode, const version.
81  *
82  * @return reference to Move inside MoveNode
83  */
84 inline const TTAProgram::Move&
85 MoveNode::move() const {
86  if (move_ == NULL) {
87  throw NotAvailable(__FILE__,__LINE__,__func__,
88  "Move of MoveNode is NULL");
89  }
90  return *move_;
91 }
92 
93 /**
94  * Access Move inside MoveNode, casting constantness away
95  *
96  * @return reference to Move inside MoveNode
97  */
98 inline std::shared_ptr<TTAProgram::Move>
99 MoveNode::movePtr(){
100  if (move_ == NULL) {
101  throw NotAvailable(__FILE__,__LINE__,__func__,
102  "Move of MoveNode is NULL");
103  }
104  return move_;
105 }
106 
107 /**
108  * Access Move inside MoveNode, const version.
109  *
110  * @return reference to Move inside MoveNode
111  */
112 inline std::shared_ptr<const TTAProgram::Move>
113 MoveNode::movePtr() const {
114  if (move_ == NULL) {
115  throw NotAvailable(__FILE__,__LINE__,__func__,
116  "Move of MoveNode is NULL");
117  }
118  return move_;
119 }
120 
121 /**
122  * Returns true if it's a real move, not a pseudo move such as entry node.
123  */
124 inline bool
125 MoveNode::isMove() const {
126  return move_ != NULL;
127 }
128 
129 /**
130  * Returns the instance of operation in the program whose input is the
131  * destination of this node.
132  *
133  * @return A program operation.
134  * @exception InvalidData if the given node does not write an operation
135  * input.
136  */
137 inline ProgramOperation&
138 MoveNode::destinationOperation(unsigned int index) const {
139  return *dstOps_[index].get();
140 }
141 
142 inline ProgramOperationPtr
143 MoveNode::destinationOperationPtr(unsigned int index) const {
144  if (!isDestinationOperation()){
145  std::string msg = "MoveNode destination is not Operation.";
146  throw InvalidData(__FILE__, __LINE__, __func__, msg);
147  } else {
148  if (index >= dstOps_.size()) {
149  std::string msg =
150  "MoveNode does not have dst Operation of index" +
151  Conversion::toString(index);
152  throw InvalidData(__FILE__, __LINE__, __func__, msg);
153  }
154  return dstOps_[index];
155  }
156 }
157 
158 inline bool
159 MoveNode::isFinalized() const {
160  return finalized_;
161 }
162 
163 inline void
164 MoveNode::finalize() {
165  finalized_ = true;
166 }
167 
168 inline bool
169 MoveNode::isInFrontier() const {
170  return isInFrontier_;
171 }
172 
173 inline void
174 MoveNode::setIsInFrontier(bool isInFrontier) {
175  isInFrontier_ = isInFrontier;
176 }