OpenASIP  2.0
NetlistVisualization.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 NetlistVisualization.cc
26  *
27  * Implementation of NetlistVisualization class.
28  *
29  * Created on: 23.4.2015
30  * @author: Henry Linjamäki (henry.linjamaki-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #include "NetlistVisualization.hh"
35 
36 #include <iostream>
37 #include <string>
38 #include <set>
39 #include <utility>
40 #include <boost/graph/graph_traits.hpp>
41 
42 #include "BaseNetlistBlock.hh"
43 #include "NetlistPort.hh"
44 #include "Netlist.hh"
45 #include "Parameter.hh"
46 #include "NetlistTools.hh"
47 
48 #include "Conversion.hh"
49 #include "TCEString.hh"
50 
51 namespace ProGe {
52 
54 
56 
57 void
59  const BaseNetlistBlock& root, std::ostream& streamOut) {
60  printBlock(root, "", streamOut);
61  printBlockTree(root, "", streamOut);
62 }
63 
64 void
66  const BaseNetlistBlock& block, std::ostream& streamOut) {
67  // typedef boost::graph_traits<Netlist>::edge_iterator EdgeIterator;
68  // typedef std::pair<EdgeIterator, EdgeIterator> EdgePair;
69  typedef std::pair<std::string, std::string> PortNamePair;
70  typedef std::set<PortNamePair> ConnectionSet;
71 
72  ConnectionSet connections;
73  // EdgePair edge_it;
74 
76  for (edge_it = block.netlist().begin(); edge_it != block.netlist().end();
77  edge_it++) {
78  const NetlistPort* port_a =
79  block.netlist()[boost::source(*edge_it, block.netlist())];
80  const NetlistPort* port_b =
81  block.netlist()[boost::target(*edge_it, block.netlist())];
82  std::string port_a_name(port_a->parentBlock().instanceName());
83  port_a_name += ":" + port_a->name();
84  std::string port_b_name(port_b->parentBlock().instanceName());
85  port_b_name += ":" + port_b->name();
86 
87  if (port_a_name < port_b_name) {
88  connections.insert(std::make_pair(port_a_name, port_b_name));
89  } else {
90  connections.insert(std::make_pair(port_b_name, port_a_name));
91  }
92  }
93 
94  ConnectionSet::const_iterator conn_it;
95  for (conn_it = connections.begin(); conn_it != connections.end();
96  conn_it++) {
97  streamOut << conn_it->first << " <-> " << conn_it->second
98  << std::endl;
99  }
100 }
101 
102 void
104  const BaseNetlistBlock& block, std::ostream& streamOut) {
105  listNetlistDescriptors(block.netlist(), streamOut);
106 }
107 
108 void
110  const Netlist& netlist, std::ostream& streamOut) {
112  for (desc_it = netlist.descriptorBegin();
113  desc_it != netlist.descriptorEnd(); desc_it++) {
114  const NetlistPort* port = desc_it->first;
115  const BaseNetlistBlock* parent = &port->parentBlock();
116  size_t descriptor = desc_it->second;
117  streamOut << parent->instanceName() << ":" << port->name() << ":"
118  << descriptor << std::endl;
119  }
120 }
121 
122 void
124  const BaseNetlistBlock& blockNode, std::string prefix,
125  std::ostream& streamOut) {
126  for (size_t i = 0; i < blockNode.parameterCount(); i++) {
127  printParameter(blockNode.parameter(i), prefix + "|- ", streamOut);
128  }
129 
130  for (size_t i = 0; i < blockNode.portCount(); i++) {
131  printPort(blockNode.port(i), prefix + "|- ", streamOut);
132  }
133 
134  for (size_t i = 0; i < blockNode.subBlockCount(); i++) {
135  printBlock(blockNode.subBlock(i), prefix + "+- ", streamOut);
137  blockNode.subBlock(i),
138  prefix + TCEString::applyIf(
139  i < blockNode.subBlockCount() - 1, "| ", " "),
140  streamOut);
141  }
142 }
143 
144 void
146  const BaseNetlistBlock& blockNode, const std::string& prefix,
147  std::ostream& streamOut) {
148  streamOut << prefix << "Blk: " << blockNode.instanceName() << " : "
149  << blockNode.moduleName() << std::endl;
150 }
151 
152 void
154  const Parameter& parameter, const std::string& prefix,
155  std::ostream& streamOut) {
156  streamOut << prefix << "Prm: " << parameter.name() << " : "
157  << parameter.type() << " := " << parameter.value() << std::endl;
158 }
159 
160 void
162  const NetlistPort& port, const std::string& prefix,
163  std::ostream& streamOut) {
164  streamOut << prefix << "Prt: " << port.name() << " "
165  << toString(port.direction()) << " " << portWidthToString(port)
166  << std::endl;
167 }
168 
169 std::string
171  switch (dir) {
172  case IN:
173  return "in";
174  case OUT:
175  return "out";
176  case BIDIR:
177  return "bidir";
178  default:
179  return "N/A";
180  }
181 }
182 
183 std::string
185  if (port.dataType() == BIT) {
186  return "1";
187  } else if (port.dataType() == BIT_VECTOR) {
188  if (port.realWidthAvailable()) {
189  return std::string("[") + Conversion::toString(port.realWidth()) +
190  "-1:0]";
191  } else {
192  return std::string("[") + port.widthFormula() + "-1:0]";
193  }
194  } else {
195  return "N/A";
196  }
197 }
198 
199 } /* namespace ProGe */
ProGe::BaseNetlistBlock
Definition: BaseNetlistBlock.hh:59
Netlist.hh
ProGe::NetlistPort::parentBlock
const BaseNetlistBlock & parentBlock() const
Definition: NetlistPort.cc:400
ProGe::NetlistVisualization::printPort
static void printPort(const NetlistPort &port, const std::string &prefix, std::ostream &streamOut)
Definition: NetlistVisualization.cc:161
ProGe::BIT_VECTOR
@ BIT_VECTOR
Several bits.
Definition: ProGeTypes.hh:48
TCEString::applyIf
static std::string applyIf(bool expression, stringCRef ifTrue, stringCRef ifFalse)
Definition: TCEString.cc:229
ProGe::BaseNetlistBlock::parameterCount
virtual size_t parameterCount() const
Definition: BaseNetlistBlock.cc:231
ProGe::Parameter::type
const TCEString & type() const
Definition: Parameter.cc:138
ProGe::NetlistVisualization::listNetlistDescriptors
static void listNetlistDescriptors(const BaseNetlistBlock &block, std::ostream &streamOut)
Definition: NetlistVisualization.cc:103
ProGe::NetlistPort::widthFormula
std::string widthFormula() const
Definition: NetlistPort.cc:316
ProGe::NetlistPort::direction
Direction direction() const
Definition: NetlistPort.cc:373
ProGe::BaseNetlistBlock::instanceName
const std::string & instanceName() const
Definition: BaseNetlistBlock.cc:135
ProGe::NetlistVisualization::printBlock
static void printBlock(const BaseNetlistBlock &root, const std::string &prefix, std::ostream &streamOut)
Definition: NetlistVisualization.cc:145
ProGe::BIDIR
@ BIDIR
Bidirectional port.
Definition: ProGeTypes.hh:55
ProGe::NetlistVisualization::printParameter
static void printParameter(const Parameter &parameter, const std::string &prefix, std::ostream &streamOut)
Definition: NetlistVisualization.cc:153
ProGe::Netlist::end
iterator end()
Definition: Netlist.cc:448
ProGe::NetlistVisualization::printBlockTree
static void printBlockTree(const BaseNetlistBlock &node, std::string prefix, std::ostream &streamOut)
Definition: NetlistVisualization.cc:123
ProGe::Netlist::descriptorEnd
descriptor_iterator descriptorEnd()
Definition: Netlist.cc:468
ProGe::Netlist
Definition: Netlist.hh:63
ProGe::BaseNetlistBlock::netlist
virtual const Netlist & netlist() const
Definition: BaseNetlistBlock.cc:348
Conversion::toString
static std::string toString(const T &source)
ProGe::NetlistVisualization::~NetlistVisualization
virtual ~NetlistVisualization()
Definition: NetlistVisualization.cc:55
TCEString.hh
ProGe::NetlistVisualization::portWidthToString
static std::string portWidthToString(const NetlistPort &port)
Definition: NetlistVisualization.cc:184
ProGe::NetlistPort::realWidthAvailable
bool realWidthAvailable() const
Definition: NetlistPort.cc:334
ProGe::Netlist::descriptorBegin
descriptor_iterator descriptorBegin()
Definition: Netlist.cc:463
ProGe::BaseNetlistBlock::parameter
virtual const Parameter & parameter(const std::string &name) const
Definition: BaseNetlistBlock.cc:198
NetlistTools.hh
ProGe::Netlist::const_descriptor_iterator
DescriptorMap::const_iterator const_descriptor_iterator
Definition: Netlist.hh:133
Conversion.hh
ProGe::Parameter
Definition: Parameter.hh:62
NetlistPort.hh
ProGe::BaseNetlistBlock::portCount
virtual size_t portCount() const
Definition: BaseNetlistBlock.cc:248
ProGe::NetlistVisualization::visualizeBlockTree
static void visualizeBlockTree(const BaseNetlistBlock &root, std::ostream &streamOut)
Definition: NetlistVisualization.cc:58
ProGe::Parameter::name
const TCEString & name() const
Definition: Parameter.cc:133
ProGe::Parameter::value
const TCEString & value() const
Definition: Parameter.cc:143
ProGe::BIT
@ BIT
One bit.
Definition: ProGeTypes.hh:47
ProGe::NetlistVisualization::NetlistVisualization
NetlistVisualization()
Definition: NetlistVisualization.cc:53
ProGe::NetlistPort::name
std::string name() const
Definition: NetlistPort.cc:283
ProGe::OUT
@ OUT
Output port.
Definition: ProGeTypes.hh:54
ProGe::NetlistPort::dataType
DataType dataType() const
Definition: NetlistPort.cc:362
ProGe::NetlistVisualization::listConnections
static void listConnections(const BaseNetlistBlock &block, std::ostream &streamOut)
Definition: NetlistVisualization.cc:65
ProGe::NetlistPort::realWidth
int realWidth() const
Definition: NetlistPort.cc:348
ProGe::NetlistVisualization::toString
static std::string toString(Direction dir)
Definition: NetlistVisualization.cc:170
ProGe
Definition: FUGen.hh:54
BaseNetlistBlock.hh
NetlistVisualization.hh
ProGe::Netlist::const_iterator
boost::graph_traits< const Netlist >::edge_iterator const_iterator
Definition: Netlist.hh:126
ProGe::NetlistPort
Definition: NetlistPort.hh:70
ProGe::BaseNetlistBlock::moduleName
const std::string & moduleName() const
Definition: BaseNetlistBlock.cc:140
ProGe::BaseNetlistBlock::subBlock
virtual const BaseNetlistBlock & subBlock(size_t index) const
Definition: BaseNetlistBlock.cc:155
ProGe::Direction
Direction
Direction of the port.
Definition: ProGeTypes.hh:52
Parameter.hh
ProGe::IN
@ IN
Input port.
Definition: ProGeTypes.hh:53
ProGe::Netlist::begin
iterator begin()
Definition: Netlist.cc:443
ProGe::BaseNetlistBlock::subBlockCount
virtual size_t subBlockCount() const
Definition: BaseNetlistBlock.cc:150
ProGe::BaseNetlistBlock::port
virtual const NetlistPort & port(size_t index) const
Definition: BaseNetlistBlock.cc:253