torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XdlExporter.cpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 /// \file
17 /// \brief Source for the XdlExporter class.
18 
20 #include <iosfwd>
21 
22 namespace torc {
23 namespace physical {
24 
25  void XdlExporter::operator() (const DesignSharedPtr& inDesignPtr) {
26  // std::cout << "Design " << inDesignPtr->getName() << std::endl;
27  // std::cout << " module count: " << inDesignPtr->getModuleCount() << std::endl;
28  // std::cout << " instance count: " << inDesignPtr->getInstanceCount() << std::endl;
29  // std::cout << " net count: " << inDesignPtr->getNetCount() << std::endl;
30 
31  /// \todo Acquire mutex.
32 
33  // export the design statement
34  DesignSharedPtr designPtr(inDesignPtr);
35  const Design& design = *designPtr;
36  write(design);
37 
38  /// \todo Release mutex.
39  }
40 
41  void XdlExporter::write(const Circuit& circuit) {
42  // export the instances
45  while(pi < ei) write(**pi++);
46 
47  // export the nets
50  while(pn < en) write(**pn++);
51  }
52 
53  void XdlExporter::write(const Design& design) {
54  indent();
55  mStream << "design \"" << design.getName() << "\" " << design.getDevice()
56  << design.getPackage() << design.getSpeedGrade() << " " << design.getXdlVersion();
57  if(!design.configIsEmpty())
58  { mStream << ", "; write(static_cast<const ConfigMap&>(design)); }
59  mStream << ";" << std::endl;
60  // export the modules
63  while(p < e) write(**p++);
64  // export the instances and nets
65  write(static_cast<Circuit>(design));
66 
67  }
68 
69  void XdlExporter::write(const Module& module) {
70  indent();
71  mStream << "module \"" << module.getName() << "\" \"" << module.getAnchor() << "\"";
72  if(!module.configIsEmpty())
73  { mStream << ", "; write(static_cast<const ConfigMap&>(module)); }
74  mStream << ";" << std::endl;
75  // increment the indent
76  mIndentCount++;
77  // export the ports
80  while(p < e) write(**p++);
81  // export the instances and nets
82  write(static_cast<Circuit>(module));
83  // decrement the indent
84  mIndentCount--;
85  // close out the module
86  indent();
87  mStream << "endmodule \"" << module.getName() << "\";" << std::endl;
88  }
89 
90  void XdlExporter::write(const Port& port) {
91  indent();
92  std::string instanceName = port.getInstancePtr().expired()
93  ? "[expired instance]" : port.getInstancePtr().lock()->getName();
94  mStream << "port \"" << port.getName() << "\" \"" << instanceName << "\" \""
95  << port.getPinName() << "\";" << std::endl;
96  }
97 
98  void XdlExporter::write(const ConfigMap& configMap) {
99  // nothing to do if the configMap is empty
100  if(configMap.configIsEmpty()) return;
101  // write the config keyword and double quotes
102  mStream << "cfg \"";
103  // iterate through the config settings
104  ConfigMap::const_iterator p = configMap.configBegin();
105  ConfigMap::const_iterator e = configMap.configEnd();
106  while(p != e) {
107  const std::string& setting = p->first;
108  const Config& config = p->second;
109  mStream << setting << ":" << config.getName() << ":" << config.getValue();
110  p++;
111  if(p != e) mStream << " ";
112  }
113  // close the double quotes
114  mStream << "\"";
115  }
116 
117  void XdlExporter::write(const Instance& instance) {
118  indent();
119  mStream << "inst \"" << instance.getName() << "\" \"" << instance.getType() << "\", ";
120  const std::string& site = instance.getSite();
121  std::string tile = instance.getTile();
122  EInstanceBonding bonding = instance.getBonding();
123  if(site.empty()) {
124  mStream << "unplaced";
125  // bonding may be specified for unplaced IOBs, but is ignored for unplaced instances of
126  // other types, and is illegal for placed instances of any type
127  if(bonding != eInstanceBondingUnknown) {
128  mStream << " " << (bonding == eInstanceBondingUnbonded ? "unbonded" : "bonded");
129  }
130  } else {
131  if(tile.empty()) tile = "unknown";
132  mStream << "placed " << tile << " " << site;
133  }
134  InstanceReferenceSharedPtr instanceReferencePtr = instance.getInstanceReferencePtr();
135  if(instanceReferencePtr.get() != 0) {
136  const InstanceReference& instanceReference = *instanceReferencePtr;
137  std::string moduleName = instanceReference.getModulePtr().expired()
138  ? "[expired module]" : instanceReference.getModulePtr().lock()->getName();
139  std::string instanceName = instanceReference.getInstancePtr().expired()
140  ? "[expired instance]" : instanceReference.getInstancePtr().lock()->getName();
141  mStream << ", module \"" << instanceReference.getInstantiationName() << "\" \""
142  << moduleName << "\" \"" << instanceName << "\"";
143  }
144  if(!instance.configIsEmpty())
145  { mStream << ", "; write(static_cast<const ConfigMap&>(instance)); }
146  mStream << ";" << std::endl;
147  }
148 
149  void XdlExporter::write(const Net& net) {
150  indent();
151  // write the header
152  mStream << "net \"" << net.getName() << "\"";
153  switch(net.getNetType()) {
154  case eNetTypePower: mStream << " power"; break;
155  case eNetTypeGround: mStream << " ground"; break;
156  default: break;
157  }
158  size_t left = net.getSourceCount() + net.getSinkCount() + net.getPipCount()
159  + (net.configIsEmpty() ? 0 : 1);
160  bool empty = (left == 0);
161  mStream << (empty ? "" : ",") << std::endl;
162  // write the sources
165  while(sop < soe) write(**sop++, ePinDirectionOutpin, --left > 0);
166  // write the sinks
169  while(sip < sie) write(**sip++, ePinDirectionInpin, --left > 0);
170  // write the pips
171  Net::PipConstIterator pip = net.pipsBegin();
172  Net::PipConstIterator pie = net.pipsEnd();
173  while(pip < pie) write(*pip++, --left > 0);
174  // write the config string if there is one
175  if(!net.configIsEmpty()) {
176  indent();
178  write(static_cast<const ConfigMap&>(net));
179  mStream << std::endl;
180  }
181  // indent before the closing semicolon if the net was not completely empty
182  if(!empty) { indent(); mStream << mIndentString; }
183  mStream << ";" << std::endl;
184  }
185 
186  void XdlExporter::write(const InstancePin& instancePin, EPinDirection pinDirection,
187  bool comma) {
188  indent();
189  std::string instanceName = instancePin.getInstancePtr().expired()
190  ? "[expired instance]" : instancePin.getInstancePtr().lock()->getName();
191  mStream << mIndentString << (pinDirection == ePinDirectionInpin ? "inpin" : "outpin")
192  << " \"" << instanceName << "\" " << instancePin.getPinName() << (comma ? "," : "")
193  << std::endl;
194  }
195 
196  void XdlExporter::write(const Pip& pip, bool comma) {
197  indent();
199  << "pip " << pip.getTileName() << " " << pip.getSourceWireName()
200  << " " << pip.getDirectionString() << " " << pip.getSinkWireName()
201  << (comma ? "," : "");
202  if(pip.isRoutethrough()) write(*pip.getRoutethroughPtr());
203  mStream << std::endl;
204  }
205 
206  void XdlExporter::write(const Routethrough& routethrough) {
207  std::string instanceName = routethrough.getInstancePtr().expired()
208  ? "[expired instance]" : routethrough.getInstancePtr().lock()->getName();
209  mStream << " # " << routethrough.getSetting() << ":" << routethrough.getName() << ":"
210  << routethrough.getValue() << " \"" << instanceName << "\" "
211  << routethrough.getSourceWireName() << " -> " << routethrough.getSinkWireName();
212  }
213 
214 } // namespace physical
215 } // namespace torc
InstancePinSharedPtrConstIterator sinksBegin(void) const
Returns the begin constant iterator for sink instance pins.
const WireName & getSinkWireName(void) const
Returns the instance sink wire name.
size_t getPipCount(void) const
Returns the number of pips on the net.
InstancePinSharedPtrConstIterator sourcesEnd(void) const
Returns the end constant iterator for source instance pins.
EInstanceBonding
Enumeration of pad bonding types.
PortSharedPtrConstIterator portsEnd(void) const
Returns the end constant iterator for ports.
Definition: Module.hpp:98
const string & getSetting(void) const
Returns the _ROUTETHROUGH setting.
InstanceReferenceSharedPtr getInstanceReferencePtr(void) const
Returns the instance reference for this instance, if any.
const string & getPackage(void) const
Returns the device package for this design.
ENetType getNetType(void) const
Returns the net power type. See ENetPowerType.
InstancePinSharedPtrConstIterator sinksEnd(void) const
Returns the end constant iterator for sink instance pins.
const string & getType(void) const
Returns the logic type for this instance.
PortSharedPtrVector::const_iterator PortSharedPtrConstIterator
Constant iterator to Port shared pointers.
Definition: Module.hpp:55
const PinName & getPinName(void) const
Returns the pin name.
void write(const Circuit &circuit)
Writes the given Circuit.
Definition: XdlExporter.cpp:41
std::ostream & mStream
The output stream.
Definition: XdlExporter.hpp:34
PipVector::const_iterator PipConstIterator
Constant iterator to Pip objects.
InstanceSharedPtrVector::const_iterator InstanceSharedPtrConstIterator
Constant iterator to Instance shared pointers.
Definition: Circuit.hpp:72
Physical netlist design.
const string & getSite(void) const
Returns the placement site for this instance.
PortSharedPtrConstIterator portsBegin(void) const
Returns the begin constant iterator for ports.
Definition: Module.hpp:96
const string & getAnchor(void) const
Returns the anchor instance name for this module.
Definition: Module.hpp:91
ModuleSharedPtrVector::const_iterator ModuleSharedPtrConstIterator
Constant iterator for Module shared pointers.
const PinName & getPinName(void) const
Returns the pin name.
size_t getSinkCount(void) const
Returns the number of sinks on the net.
const ModuleWeakPtr & getModulePtr(void) const
Returns the weak module pointer.
ModuleSharedPtrConstIterator modulesEnd(void) const
Returns the end constant iterator for modules.
InstancePinSharedPtrConstIterator sourcesBegin(void) const
Returns the begin constant iterator for source instance pins.
const InstanceWeakPtr & getInstancePtr(void) const
Returns the weak instance pointer.
std::string string
const_iterator const_iterator
Constant iterator to {setting,Config} pairs.
Definition: ConfigMap.hpp:52
ModuleSharedPtrConstIterator modulesBegin(void) const
Returns the begin constant iterator for modules.
const_iterator configBegin(void) const
Returns the begin constant iterator for configurations.
Definition: ConfigMap.hpp:58
const WireName & getSinkWireName(void) const
Returns the pip sink wire.
Definition: Pip.hpp:77
Header for the XdlExport class.
Physical design instance.
Configuration. A {name:value} pair.
Definition: Config.hpp:39
Physical design net.
PipConstIterator pipsBegin(void) const
Returns the begin constant iterator for pips.
NetSharedPtrConstIterator netsEnd(void) const
Returns the end constant iterator for nets.
Definition: Circuit.hpp:209
RoutethroughSharedPtr getRoutethroughPtr(void) const
Returns the pip's routethrough pointer.
Definition: Pip.hpp:83
void operator()(const DesignSharedPtr &inDesignPtr)
Top level design exporter operator.
Definition: XdlExporter.cpp:25
size_t getSourceCount(void) const
Returns the number of sources on the net.
const string & getName(void) const
Returns the object name.
Definition: Named.hpp:51
const WireName & getSourceWireName(void) const
Returns the instance source wire name.
Physical design instance-pin pair, suitable for specifying a net endpoint.
const string & getValue(void) const
Return the configuration value.
Definition: Config.hpp:86
void indent(void) const
Indent the current line.
Definition: XdlExporter.hpp:41
boost::shared_ptr< Design > DesignSharedPtr
Shared pointer encapsulation of a Design.
InstancePinSharedPtrVector::const_iterator InstancePinSharedPtrConstIterator
Constant iterator to InstancePin shared pointer objects.
const TileName & getTileName(void) const
Returns the pip tile.
Definition: Pip.hpp:73
const string & getTile(void) const
Returns the placement tile for this instance.
int mIndentCount
The indent count.
Definition: XdlExporter.hpp:36
Physical design programmable interconnect point.
Definition: Pip.hpp:34
const WireName & getSourceWireName(void) const
Returns the pip source wire.
Definition: Pip.hpp:75
Configuration setting map.
Definition: ConfigMap.hpp:39
const string & getXdlVersion(void) const
Returns the XDL version for this design.
bool configIsEmpty(void) const
Returns true if the configuration map is empty.
Definition: ConfigMap.hpp:65
PipConstIterator pipsEnd(void) const
Returns the end constant iterator for pips.
Module input or output port.
const InstanceWeakPtr & getInstancePtr(void) const
Returns the weak instance pointer.
const string & getSpeedGrade(void) const
Returns the device speed grade for this design.
const InstanceWeakPtr & getInstancePtr(void) const
Returns a weak instance pointer.
const string & getDevice(void) const
Returns the target device for this design.
Instantiation of a module instance.
EInstanceBonding getBonding(void) const
Returns the IO bonding for this instance.
Circuit composed of instances and nets.
Definition: Circuit.hpp:46
Hierarchical module.
Definition: Module.hpp:33
const_iterator configEnd(void) const
Returns the end constant iterator for configurations.
Definition: ConfigMap.hpp:60
InstanceSharedPtrConstIterator instancesBegin(void) const
Returns the begin constant iterator for instances.
Definition: Circuit.hpp:197
boost::shared_ptr< InstanceReference > InstanceReferenceSharedPtr
Shared pointer encapsulation of an InstanceReference.
EPinDirection
Enumeration of instance pin directionality.
static const char * getDirectionString(EPipDirection inPipDirection)
Returns the pip directionality as a string.
Definition: Pip.cpp:36
NetSharedPtrVector::const_iterator NetSharedPtrConstIterator
Constant iterator to Net shared pointers.
Definition: Circuit.hpp:76
bool isRoutethrough(void) const
Indicates whether or not the pip has an associated routethrough.
Definition: Pip.hpp:86
std::string mIndentString
The indent string.
Definition: XdlExporter.hpp:38
const string & getInstantiationName(void) const
Returns the instantiation name.
NetSharedPtrConstIterator netsBegin(void) const
Returns the begin constant iterator for nets.
Definition: Circuit.hpp:207
const InstanceWeakPtr & getInstancePtr(void) const
Returns the instance weak pointer.
InstanceSharedPtrConstIterator instancesEnd(void) const
Returns the end constant iterator for instances.
Definition: Circuit.hpp:199