OpenASIP  2.0
NetlistPortGroup.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2015 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 NetlistPortGroup.cc
26  *
27  * Implementation of NetlistPortGroup class.
28  *
29  * Created on: 24.4.2015
30  * @author: Henry Linjamäki (henry.linjamaki-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #include "NetlistPortGroup.hh"
35 
36 #include <cassert>
37 #include <iterator>
38 
39 #include "BaseNetlistBlock.hh"
40 #include "NetlistPort.hh"
41 
42 #include "SequenceTools.hh"
43 
44 namespace ProGe {
45 
47  : parent_(nullptr), ports_(), signalGroup_() {}
48 
49 /**
50  * Copy constructor. Copies everything except parent block reference.
51  */
53  const NetlistPortGroup& other, bool asMirrored)
54  : parent_(nullptr), ports_(), signalGroup_(other.signalGroup_) {
55  std::insert_iterator<PortContainerType> portInserter(
56  ports_, ports_.begin());
57  for (size_t i = 0; i < other.portCount(); i++) {
58  portInserter = other.portAt(i).clone(asMirrored);
59  }
60 }
61 
62 /**
63  * Constructs empty port group with given SignalGroup.
64  */
66  : parent_(nullptr), ports_(), signalGroup_(signalGroup) {}
67 
69  if (!hasParent()) {
71  }
72 }
73 
74 /**
75  * Returns number of ports in the group.
76  */
77 size_t
79  return ports_.size();
80 }
81 
82 const NetlistPort&
83 NetlistPortGroup::portAt(size_t index) const {
84  return *ports_.at(index);
85 }
86 
88 NetlistPortGroup::portAt(size_t index) {
89  return *ports_.at(index);
90 }
91 
92 void
94  ports_.push_back(&port);
95 }
96 
97 bool
99  for (const NetlistPort* p : *this) {
100  if (p->assignedSignal() == type) {
101  return true;
102  }
103  }
104  return false;
105 }
106 
107 /**
108  * Returns first found port by given signal type.
109  */
110 const NetlistPort&
112  for (const NetlistPort* p : *this) {
113  if (p->assignedSignal() == type) {
114  return *p;
115  }
116  }
119  "The port group does not have port by given signal type.");
120 }
121 
122 /**
123  * Clears all ports associated to the port group.
124  *
125  * The Ports are deleted and detached from the parent block.
126  */
127 void
130 }
131 
132 bool
134  return parent_ != nullptr;
135 }
136 
137 const BaseNetlistBlock&
139  assert(hasParent());
140  return *parent_;
141 }
142 
145  assert(hasParent());
146  return *parent_;
147 }
148 
149 void
151  parent_ = newParent;
152 }
153 
154 void
156  signalGroup_ = signalGroup;
157 }
158 
161  return signalGroup_;
162 }
163 
164 /**
165  * Clones the NetlistPort and and its ports without parent block reference
166  * since it would break unique port name constraint.
167  */
169 NetlistPortGroup::clone(bool asMirrored) const {
170  NetlistPortGroup* newGroup = new NetlistPortGroup(*this, asMirrored);
171  assert(this->portCount() == newGroup->portCount());
172  for (size_t i = 0; i < portCount(); i++) {
173  assert(
174  this->portAt(i).assignedSignal().type() ==
175  newGroup->portAt(i).assignedSignal().type());
176  }
177  return newGroup;
178 }
179 
182  return ports_.begin();
183 }
184 
187  return ports_.end();
188 }
189 
191 NetlistPortGroup::begin() const {
192  return ports_.begin();
193 }
194 
196 NetlistPortGroup::end() const {
197  return ports_.end();
198 }
199 
202  return ports_.rbegin();
203 }
204 
207  return ports_.rend();
208 }
209 
211 NetlistPortGroup::rbegin() const {
212  return ports_.rbegin();
213 }
214 
216 NetlistPortGroup::rend() const {
217  return ports_.rend();
218 }
219 
220 } /* namespace ProGe */
ProGe::BaseNetlistBlock
Definition: BaseNetlistBlock.hh:59
ProGe::NetlistPortGroup::end
iterator end()
Definition: NetlistPortGroup.cc:186
ProGe::NetlistPortGroup::clone
virtual NetlistPortGroup * clone(bool asMirrored=false) const
Definition: NetlistPortGroup.cc:169
ProGe::NetlistPortGroup::parent_
BaseNetlistBlock * parent_
The parent block where the group belongs to.
Definition: NetlistPortGroup.hh:110
ProGe::NetlistPortGroup::clear
void clear()
Definition: NetlistPortGroup.cc:128
SequenceTools.hh
ProGe::NetlistPortGroup::portAt
const NetlistPort & portAt(size_t index) const
Definition: NetlistPortGroup.cc:83
ProGe::NetlistPortGroup::setParent
void setParent(BaseNetlistBlock *newParent)
Definition: NetlistPortGroup.cc:150
ProGe::NetlistPortGroup::hasParent
bool hasParent() const
Definition: NetlistPortGroup.cc:133
ProGe::NetlistPortGroup::rend
reverse_iterator rend()
Definition: NetlistPortGroup.cc:206
ProGe::NetlistPortGroup::const_reverse_iterator
PortContainerType::const_reverse_iterator const_reverse_iterator
Definition: NetlistPortGroup.hh:88
ProGe::NetlistPortGroup::reverse_iterator
PortContainerType::reverse_iterator reverse_iterator
Definition: NetlistPortGroup.hh:87
ProGe::NetlistPortGroup::assignSignalGroup
void assignSignalGroup(SignalGroup signalGroup)
Definition: NetlistPortGroup.cc:155
NetlistPortGroup.hh
ProGe::SignalGroup
Definition: SignalGroup.hh:48
assert
#define assert(condition)
Definition: Application.hh:86
ProGe::NetlistPortGroup
Definition: NetlistPortGroup.hh:53
SequenceTools::deleteAllItems
static void deleteAllItems(SequenceType &aSequence)
THROW_EXCEPTION
#define THROW_EXCEPTION(exceptionType, message)
Exception wrapper macro that automatically includes file name, line number and function name where th...
Definition: Exception.hh:39
NetlistPort.hh
ProGe::NetlistPortGroup::addPort
void addPort(NetlistPort &port)
Definition: NetlistPortGroup.cc:93
ProGe::NetlistPortGroup::iterator
PortContainerType::iterator iterator
Definition: NetlistPortGroup.hh:85
ProGe::NetlistPortGroup::begin
iterator begin()
Definition: NetlistPortGroup.cc:181
ProGe::NetlistPortGroup::NetlistPortGroup
NetlistPortGroup()
Definition: NetlistPortGroup.cc:46
ProGe::NetlistPort::clone
virtual NetlistPort * clone(bool asMirrored=false) const
Definition: NetlistPort.cc:258
ProGe::NetlistPortGroup::assignedSignalGroup
SignalGroup assignedSignalGroup() const
Definition: NetlistPortGroup.cc:160
ProGe::SignalType
SignalType
Definition: SignalTypes.hh:42
ProGe::NetlistPortGroup::parent
const BaseNetlistBlock & parent() const
Definition: NetlistPortGroup.cc:138
ProGe::NetlistPortGroup::signalGroup_
SignalGroup signalGroup_
The usage/implemented interface of the group.
Definition: NetlistPortGroup.hh:114
ProGe::Signal::type
SignalType type() const
Definition: Signal.cc:55
ProGe
Definition: FUGen.hh:54
BaseNetlistBlock.hh
ProGe::NetlistPortGroup::portBySignal
const NetlistPort & portBySignal(SignalType type) const
Definition: NetlistPortGroup.cc:111
ProGe::NetlistPort
Definition: NetlistPort.hh:70
ProGe::NetlistPortGroup::portCount
size_t portCount() const
Definition: NetlistPortGroup.cc:78
ProGe::NetlistPort::assignedSignal
Signal assignedSignal() const
Definition: NetlistPort.cc:455
ProGe::NetlistPortGroup::rbegin
reverse_iterator rbegin()
Definition: NetlistPortGroup.cc:201
ProGe::NetlistPortGroup::hasPortBySignal
bool hasPortBySignal(SignalType type) const
Definition: NetlistPortGroup.cc:98
ProGe::NetlistPortGroup::~NetlistPortGroup
virtual ~NetlistPortGroup()
Definition: NetlistPortGroup.cc:68
ProGe::NetlistPortGroup::const_iterator
PortContainerType::const_iterator const_iterator
Definition: NetlistPortGroup.hh:86
InstanceNotFound
Definition: Exception.hh:304
ProGe::NetlistPortGroup::ports_
PortContainerType ports_
The ports belonging to this group by reference.
Definition: NetlistPortGroup.hh:112