OpenASIP 2.2
Loading...
Searching...
No Matches
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
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
51namespace ProGe {
52
54
56
57void
59 const BaseNetlistBlock& root, std::ostream& streamOut) {
60 printBlock(root, "", streamOut);
61 printBlockTree(root, "", streamOut);
62}
63
64void
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
102void
104 const BaseNetlistBlock& block, std::ostream& streamOut) {
105 listNetlistDescriptors(block.netlist(), streamOut);
106}
107
108void
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
122void
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
144void
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
152void
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
160void
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
169std::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
183std::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 */
static std::string toString(const T &source)
virtual const BaseNetlistBlock & subBlock(size_t index) const
virtual size_t parameterCount() const
virtual size_t subBlockCount() const
virtual const Parameter & parameter(const std::string &name) const
virtual const NetlistPort & port(size_t index) const
const std::string & instanceName() const
virtual size_t portCount() const
const std::string & moduleName() const
virtual const Netlist & netlist() const
bool realWidthAvailable() const
std::string widthFormula() const
DataType dataType() const
const BaseNetlistBlock & parentBlock() const
Direction direction() const
std::string name() const
int realWidth() const
static void listNetlistDescriptors(const BaseNetlistBlock &block, std::ostream &streamOut)
static void visualizeBlockTree(const BaseNetlistBlock &root, std::ostream &streamOut)
static void printBlock(const BaseNetlistBlock &root, const std::string &prefix, std::ostream &streamOut)
static void printBlockTree(const BaseNetlistBlock &node, std::string prefix, std::ostream &streamOut)
static void printPort(const NetlistPort &port, const std::string &prefix, std::ostream &streamOut)
static std::string portWidthToString(const NetlistPort &port)
static void listConnections(const BaseNetlistBlock &block, std::ostream &streamOut)
static std::string toString(Direction dir)
static void printParameter(const Parameter &parameter, const std::string &prefix, std::ostream &streamOut)
descriptor_iterator descriptorBegin()
Definition Netlist.cc:463
iterator end()
Definition Netlist.cc:448
boost::graph_traits< constNetlist >::edge_iterator const_iterator
Definition Netlist.hh:126
DescriptorMap::const_iterator const_descriptor_iterator
Definition Netlist.hh:133
iterator begin()
Definition Netlist.cc:443
descriptor_iterator descriptorEnd()
Definition Netlist.cc:468
const TCEString & value() const
Definition Parameter.cc:143
const TCEString & type() const
Definition Parameter.cc:138
const TCEString & name() const
Definition Parameter.cc:133
static std::string applyIf(bool expression, stringCRef ifTrue, stringCRef ifFalse)
Definition TCEString.cc:229
Definition FUGen.hh:54
@ BIT
One bit.
Definition ProGeTypes.hh:47
@ BIT_VECTOR
Several bits.
Definition ProGeTypes.hh:48
Direction
Direction of the port.
Definition ProGeTypes.hh:52
@ OUT
Output port.
Definition ProGeTypes.hh:54
@ IN
Input port.
Definition ProGeTypes.hh:53
@ BIDIR
Bidirectional port.
Definition ProGeTypes.hh:55