OpenASIP  2.0
NetlistPort.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 NetlistPort.hh
26  *
27  * Declaration of NetlistPort class.
28  *
29  * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30  * @author Otto Esko 2010 (otto.esko-no.spam-tut.fi)
31  * @author Henry Linjamäki 2015 (henry.linjamaki-no.spam-tut.fi)
32  * @note rating: red
33  */
34 
35 #ifndef TTA_NETLIST_PORT_HH
36 #define TTA_NETLIST_PORT_HH
37 
38 #include <string>
39 
40 #include "ProGeTypes.hh"
41 #include "Exception.hh"
42 #include "Signal.hh"
43 #include "NetlistTools.hh"
44 
45 namespace ProGe {
46 
47 class StaticSignal {
48 public:
49  enum State {
50  GND, ///< All port signals set to low.
51  VCC, ///< All port signals set to high.
52  MIXED, ///< Port has signals both the low and high states.
53  OPEN ///< Port is left open/unused.
54  };
55 
56  StaticSignal(State state) : state_(state) {}
57  bool is(State state) { return state_ == state; }
58 private:
60 };
61 
62 class NetlistBlock;
63 class BaseNetlistBlock;
64 
65 /**
66  * Represents a port in the netlist. Ports are the vertices of the graph
67  * that represents the netlist. From the ports, it is possible to reach the
68  * parent netlist blocks.
69  */
70 class NetlistPort {
71 public:
72  friend class BaseNetlistBlock;
73 
75  const std::string& name,
76  const std::string& widthFormula,
77  int realWidth,
80  BaseNetlistBlock& parent,
81  Signal signal = Signal());
83  const std::string& name,
84  int realWidth,
87  BaseNetlistBlock& parent,
88  Signal signal = Signal());
90  const std::string& name,
91  const std::string& widthFormula,
94  BaseNetlistBlock& parent,
95  Signal signal = Signal());
97  const std::string& name,
98  const std::string& widthFormula,
101  Signal signal = Signal());
102  virtual ~NetlistPort();
103 
104  bool resolveRealWidth(int& width) const;
106  BaseNetlistBlock& newParent,
107  std::string newName="") const;
108  virtual NetlistPort* clone(bool asMirrored = false) const;
109 
110  std::string name() const;
111  void rename(const std::string& newname);
112  std::string widthFormula() const;
113  void setWidthFormula(const std::string& newFormula);
114  bool realWidthAvailable() const;
115  int realWidth() const;
116  DataType dataType() const;
117  Direction direction() const;
119 
120  bool hasParentBlock() const;
121  const BaseNetlistBlock& parentBlock() const;
123 
124  void setToStatic(StaticSignal value) const;
125  void unsetStatic() const;
126  bool hasStaticValue() const;
127  StaticSignal staticValue() const;
128 
129  void assignSignal(Signal signal);
130  Signal assignedSignal() const;
131 
132 private:
133 
134  void setParent(BaseNetlistBlock* parent);
135  NetlistPort(const NetlistPort& other, bool asMirrored = false);
136 
137  /// Name of the port.
138  std::string name_;
139  /// Formula for the width of the port.
140  std::string widthFormula_;
141  /// Real width of the port.
143  /// Data type of the port.
145  /// Direction of the port.
147  /// The parent netlist block.
149  /// Indicates if port is connected to vcc or gnd
150  mutable bool hasStaticValue_;
151  /// Static signal value
153  /// Assigned port usage.
155 };
156 
157 /// Convenience class for output ports.
158 class OutPort : public NetlistPort {
159 public:
160  OutPort(
161  const std::string& name,
162  const std::string& widthFormula,
163  int realWidth,
165  BaseNetlistBlock& parent,
166  Signal signal = Signal());
167  OutPort(
168  const std::string& name,
169  const std::string& widthFormula,
171  BaseNetlistBlock& parent,
172  Signal signal = Signal());
173  OutPort(
174  const std::string& name,
175  const std::string& widthFormula,
177  Signal signal = Signal());
178 };
179 
180 /// Convenience class for output bit ports.
181 class OutBitPort : public NetlistPort {
182 public:
183  OutBitPort(
184  const std::string& name,
185  BaseNetlistBlock& parent,
186  Signal signal = Signal());
187  OutBitPort(
188  const std::string& name,
189  Signal signal = Signal());
190 };
191 
192 /// Convenience class for input ports.
193 class InPort : public NetlistPort {
194 public:
195  InPort(
196  const std::string& name,
197  const std::string& widthFormula,
198  int realWidth,
200  BaseNetlistBlock& parent,
201  Signal signal = Signal());
202  InPort(
203  const std::string& name,
204  const std::string& widthFormula,
206  BaseNetlistBlock& parent,
207  Signal signal = Signal());
208  InPort(
209  const std::string& name,
210  const std::string& widthFormula,
212  Signal signal = Signal());
213 };
214 
215 /// Convenience class for input bit ports.
216 class InBitPort : public NetlistPort {
217 public:
218  InBitPort(
219  const std::string& name,
220  BaseNetlistBlock& parent,
221  Signal signal = Signal());
222  InBitPort(
223  const std::string& name,
224  Signal signal = Signal());
225 };
226 
227 }
228 
229 #endif
ProGe::NetlistPort::hasStaticValue_
bool hasStaticValue_
Indicates if port is connected to vcc or gnd.
Definition: NetlistPort.hh:150
ProGe::NetlistPort::dataType_
DataType dataType_
Data type of the port.
Definition: NetlistPort.hh:144
ProGe::NetlistPort::widthFormula_
std::string widthFormula_
Formula for the width of the port.
Definition: NetlistPort.hh:140
ProGe::StaticSignal::GND
@ GND
All port signals set to low.
Definition: NetlistPort.hh:50
ProGe::BaseNetlistBlock
Definition: BaseNetlistBlock.hh:59
ProGe::NetlistPort::NetlistPort
NetlistPort(const std::string &name, const std::string &widthFormula, int realWidth, DataType dataType, Direction direction, BaseNetlistBlock &parent, Signal signal=Signal())
Definition: NetlistPort.cc:64
ProGe::NetlistPort::parentBlock
const BaseNetlistBlock & parentBlock() const
Definition: NetlistPort.cc:400
ProGe::NetlistBlock
Definition: NetlistBlock.hh:61
ProGe::StaticSignal::OPEN
@ OPEN
Port is left open/unused.
Definition: NetlistPort.hh:53
ProGe::OutBitPort::OutBitPort
OutBitPort(const std::string &name, BaseNetlistBlock &parent, Signal signal=Signal())
Definition: NetlistPort.cc:487
Exception.hh
ProGe::BIT_VECTOR
@ BIT_VECTOR
Several bits.
Definition: ProGeTypes.hh:48
ProGe::NetlistPort::widthFormula
std::string widthFormula() const
Definition: NetlistPort.cc:316
ProGe::OutBitPort
Convenience class for output bit ports.
Definition: NetlistPort.hh:181
ProGe::NetlistPort::setDirection
void setDirection(Direction direction)
Definition: NetlistPort.cc:381
ProGe::NetlistPort::direction
Direction direction() const
Definition: NetlistPort.cc:373
ProGe::NetlistPort::unsetStatic
void unsetStatic() const
Definition: NetlistPort.cc:417
ProGe::InBitPort::InBitPort
InBitPort(const std::string &name, BaseNetlistBlock &parent, Signal signal=Signal())
Definition: NetlistPort.cc:528
ProGe::NetlistPort::setToStatic
void setToStatic(StaticSignal value) const
Definition: NetlistPort.cc:410
ProGe::NetlistPort::direction_
Direction direction_
Direction of the port.
Definition: NetlistPort.hh:146
ProGe::NetlistPort::assignSignal
void assignSignal(Signal signal)
Definition: NetlistPort.cc:447
ProGe::StaticSignal::VCC
@ VCC
All port signals set to high.
Definition: NetlistPort.hh:51
ProGe::InPort::InPort
InPort(const std::string &name, const std::string &widthFormula, int realWidth, DataType dataType, BaseNetlistBlock &parent, Signal signal=Signal())
Definition: NetlistPort.cc:500
ProGe::OutPort::OutPort
OutPort(const std::string &name, const std::string &widthFormula, int realWidth, DataType dataType, BaseNetlistBlock &parent, Signal signal=Signal())
Definition: NetlistPort.cc:459
ProGe::NetlistPort::staticValue
StaticSignal staticValue() const
Definition: NetlistPort.cc:429
ProGe::NetlistPort::~NetlistPort
virtual ~NetlistPort()
Definition: NetlistPort.cc:270
ProGe::StaticSignal::is
bool is(State state)
Definition: NetlistPort.hh:57
ProGe::NetlistPort::signal_
Signal signal_
Assigned port usage.
Definition: NetlistPort.hh:154
ProGe::NetlistPort::realWidthAvailable
bool realWidthAvailable() const
Definition: NetlistPort.cc:334
ProGe::NetlistPort::copyTo
NetlistPort * copyTo(BaseNetlistBlock &newParent, std::string newName="") const
Definition: NetlistPort.cc:231
ProGe::InPort
Convenience class for input ports.
Definition: NetlistPort.hh:193
ProGe::StaticSignal
Definition: NetlistPort.hh:47
NetlistTools.hh
ProGe::NetlistPort::hasParentBlock
bool hasParentBlock() const
Definition: NetlistPort.cc:390
ProGeTypes.hh
ProGe::NetlistPort::name
std::string name() const
Definition: NetlistPort.cc:283
Signal.hh
ProGe::NetlistPort::realWidth_
int realWidth_
Real width of the port.
Definition: NetlistPort.hh:142
ProGe::NetlistPort::clone
virtual NetlistPort * clone(bool asMirrored=false) const
Definition: NetlistPort.cc:258
ProGe::NetlistPort::dataType
DataType dataType() const
Definition: NetlistPort.cc:362
ProGe::NetlistPort::name_
std::string name_
Name of the port.
Definition: NetlistPort.hh:138
ProGe::NetlistPort::realWidth
int realWidth() const
Definition: NetlistPort.cc:348
ProGe::NetlistPort::setParent
void setParent(BaseNetlistBlock *parent)
Definition: NetlistPort.cc:439
ProGe::NetlistPort::setWidthFormula
void setWidthFormula(const std::string &newFormula)
Definition: NetlistPort.cc:324
ProGe::StaticSignal::state_
State state_
Definition: NetlistPort.hh:59
ProGe::NetlistPort::resolveRealWidth
bool resolveRealWidth(int &width) const
Definition: NetlistPort.cc:204
ProGe
Definition: FUGen.hh:54
ProGe::DataType
DataType
Data types of hardware ports.
Definition: ProGeTypes.hh:46
ProGe::NetlistPort::hasStaticValue
bool hasStaticValue() const
Definition: NetlistPort.cc:423
ProGe::NetlistPort
Definition: NetlistPort.hh:70
ProGe::NetlistPort::assignedSignal
Signal assignedSignal() const
Definition: NetlistPort.cc:455
ProGe::StaticSignal::MIXED
@ MIXED
Port has signals both the low and high states.
Definition: NetlistPort.hh:52
ProGe::NetlistPort::parentBlock_
BaseNetlistBlock * parentBlock_
The parent netlist block.
Definition: NetlistPort.hh:148
ProGe::StaticSignal::State
State
Definition: NetlistPort.hh:49
ProGe::NetlistPort::rename
void rename(const std::string &newname)
Definition: NetlistPort.cc:294
ProGe::Signal
Definition: Signal.hh:46
ProGe::Direction
Direction
Direction of the port.
Definition: ProGeTypes.hh:52
ProGe::InBitPort
Convenience class for input bit ports.
Definition: NetlistPort.hh:216
ProGe::OutPort
Convenience class for output ports.
Definition: NetlistPort.hh:158
ProGe::NetlistPort::staticValue_
StaticSignal staticValue_
Static signal value.
Definition: NetlistPort.hh:152
ProGe::StaticSignal::StaticSignal
StaticSignal(State state)
Definition: NetlistPort.hh:56