torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DDB.hpp
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 Header for the DDB class.
18 
19 #ifndef TORC_ARCHITECTURE_DDB_HPP
20 #define TORC_ARCHITECTURE_DDB_HPP
21 
33 #include <string>
34 #include <map>
35 
36 namespace torc {
37 namespace architecture {
38 
39  /// \brief Device database, including complete wiring and logic support.
40  /// \note The DDBConsoleStreams superclass is a utility class that allows for console
41  /// stream redirection.
43  protected:
44  // types
45  typedef std::string string; ///< \brief Imported type name.
46  typedef std::vector<string> StringVector; ///< \brief Imported type name.
47  typedef xilinx::SiteIndex SiteIndex; ///< \brief Imported type name.
48  typedef xilinx::WireIndex WireIndex; ///< \brief Imported type name.
49  typedef xilinx::TileIndex TileIndex; ///< \brief Imported type name.
50  typedef xilinx::TileOffset TileOffset; ///< \brief Imported type name.
51  typedef xilinx::TileTypeIndex TileTypeIndex; ///< \brief Imported type name.
52  // members
53  /// \brief The name of the device.
54  string mDeviceName;
55  /// \brief The name of the family.
56  string mFamilyName;
57  /// \brief the device database path.
59  /// \brief the family database path.
61  /// \brief The device database version.
63  /// \brief The family database version.
65  /// \brief The supported speed grades.
67  /// \brief The device segment data.
69  /// \brief The family and device site data.
71  /// \brief The family and device tile data.
73  /// \brief The design arc usage.
75  /// \brief The design wire usage.
77  // functions
78  /// \brief Reads the family name from a device DigestStream.
79  size_t readFamilyName(class DigestStream& inStream);
80  /// \brief Reads the supported speed grades from a device DigestStream.
81  size_t readSpeedGrades(class DigestStream& inStream);
82  /// \biref Initializes the database.
83  void initialize(const string& inDeviceName, const string& inPackageName);
84  public:
85  // enumerations
86  /// \brief Enumeration to indicate in which directions segments should be expanded.
87  /// \details Segment expansion direction only makes sense when device databases include
88  /// tied wires (or "fake pips"). When tied wires are present, the caller can request
89  /// that segment expansions include no tied wires, include tied wires in the sinkward
90  /// direction, include tied wires in the sourceward direction, or include tied wires in
91  /// both directions.
95  };
96  // types
97  // constructors
98  /// \brief Public constructor.
99  /// \param inDeviceName The name of the device to open. This name should not include any
100  /// package or speed grade information, nor any extension. Examples are xc2vp100,
101  /// xc4vfx60, xc5vlx30, et cetera.
102  /// \param inDDBConsoleStreams The console streams that the database should use.
103  DDB(const string& inDeviceName, DDBConsoleStreams inDDBConsoleStreams = DDBConsoleStreams())
105  { setConsoleStreams(inDDBConsoleStreams); initialize(inDeviceName, string()); }
106  /// \brief Public constructor.
107  /// \param inDeviceName The name of the device to open. This name should not include any
108  /// package or speed grade information, nor any extension. Examples are xc2vp100,
109  /// xc4vfx60, xc5vlx30, et cetera.
110  /// \param inPackageName The name of the package to use.
111  /// \param inDDBConsoleStreams The console streams that the database should use.
112  DDB(const string& inDeviceName, const string& inPackageName,
113  DDBConsoleStreams inDDBConsoleStreams = DDBConsoleStreams())
115  { setConsoleStreams(inDDBConsoleStreams); initialize(inDeviceName, inPackageName); }
116  /// \brief Public constructor.
117  /// \param inDeviceDesignator A designator for the device to open.
118  /// \param inDDBConsoleStreams The console streams that the database should use.
119  DDB(const torc::common::DeviceDesignator& inDeviceDesignator,
120  DDBConsoleStreams inDDBConsoleStreams = DDBConsoleStreams())
122  setConsoleStreams(inDDBConsoleStreams);
123  initialize(inDeviceDesignator.getDeviceName(), inDeviceDesignator.getDevicePackage());
124  }
125  /// \brief Destructor.
126  ~DDB(void) {
128  }
129  // iterators
130  // accessors
131  /// \brief Returns the device name.
132  const string& getDeviceName(void) const { return mDeviceName; }
133  /// \brief Returns the family name.
134  const string& getFamilyName(void) const { return mFamilyName; }
135  /// \brief Returns the device database path.
136  const boost::filesystem::path& getDevicePath(void) const { return mDevicePath; }
137  /// \brief Returns the family database path.
138  const boost::filesystem::path& getFamilyPath(void) const { return mFamilyPath; }
139  /// \brief Returns a constant reference to a vector of speed grades.
140  const StringVector& getSpeedGrades(void) const { return mSpeedGrades; }
141  /// \brief Returns a constant reference to the device segment data.
142  const Segments& getSegments(void) const { return mSegments; }
143  /// \brief Returns a constant reference to the family and device site data.
144  const Sites& getSites(void) const { return mSites; }
145  /// \brief Returns a constant reference to the family and device tile data.
146  const Tiles& getTiles(void) const { return mTiles; }
147  /// \brief Returns a constant reference to the design arc usage.
148  ArcUsage& getArcUsage(void) { return mArcUsage; }
149  /// \brief Returns a constant reference to the design wire usage.
150  WireUsage& getWireUsage(void) { return mWireUsage; }
151  /// \brief Sets all of the database console streams.
152  virtual void setConsoleStreams(DDBConsoleStreams inConsoleStreams) {
153  setConsoleStreams(inConsoleStreams.mIn(), inConsoleStreams.mOut(),
154  inConsoleStreams.mErr(), inConsoleStreams.mLog());
155  }
156  /// \brief Sets all of the database console streams.
157  virtual void setConsoleStreams(istream& inIn, ostream& inOut, ostream& inErr,
158  ostream& inLog) {
159  DDBConsoleStreams::setConsoleStreams(inIn, inOut, inErr, inLog);
160  mSegments.setConsoleStreams(inIn, inOut, inErr, inLog);
161  mSites.setConsoleStreams(inIn, inOut, inErr, inLog);
162  mTiles.setConsoleStreams(inIn, inOut, inErr, inLog);
163  mDeviceVersion.setConsoleStreams(inIn, inOut, inErr, inLog);
164  mFamilyVersion.setConsoleStreams(inIn, inOut, inErr, inLog);
165  }
166  // functions
167  /// \brief Clears all arc and wire usage, effectively restaring with an empty device.
168  void clearUsage(void) {
169  mWireUsage.clear();
170  mArcUsage.clear();
171  }
172  /// \brief Marks the arc and all of its source and sink segment wires as used.
173  void useArc(const Arc& inArc) {
174  mArcUsage.use(inArc);
175  useSegment(inArc.getSourceTilewire());
176  useSegment(inArc.getSinkTilewire());
177  }
178  /// \brief Marks the arc and all of its source and sink segment wires as unused.
179  void releaseArc(const Arc& inArc, bool releaseSource = true, bool releaseSink = true) {
180  mArcUsage.release(inArc);
181  if(releaseSource) releaseSegment(inArc.getSourceTilewire());
182  if(releaseSink) releaseSegment(inArc.getSinkTilewire());
183  }
184  /// \brief Marks all wires on the segment as used.
185  void useSegment(const Tilewire& inTilewire) {
186  TilewireVector segment;
187  expandSegment(inTilewire, segment);
188  TilewireVector::const_iterator p = segment.begin();
189  TilewireVector::const_iterator e = segment.end();
190  while(p < e) mWireUsage.use(*p++);
191  }
192  /// \brief Marks all wires on the segment as unused.
193  void releaseSegment(const Tilewire& inTilewire) {
194  TilewireVector segment;
195  expandSegment(inTilewire, segment);
196  TilewireVector::const_iterator p = segment.begin();
197  TilewireVector::const_iterator e = segment.end();
198  while(p < e) mWireUsage.release(*p++);
199  }
200  /// \brief Expands the given tilewire's segment.
201  /// \details Given a tilewire belonging to a segment, this function populates the supplied
202  /// vector with all of the tilewires on the segment. An optional parameter allows the
203  /// expansion to continue in the sinkward or sourceward directions in cases where tied
204  /// sources or sinks are available.
205  void expandSegment(const Tilewire& inTilewire, TilewireVector& outTilewires,
206  EExpandDirection inExpandDirection = eExpandDirectionNone);
207  /// \brief Expands the given tilewire's arc sinks.
208  /// \details The optional inUseTied, inUseRegular, inUseIrregular, and inUseRoutethrough
209  /// flags determine whether the corresponding arc types will be included. Note that
210  /// tied arcs (or "fake pips") are not currently available in the databases.
211  void expandTilewireSinks(const Tilewire& inTilewire, TilewireVector& outSinks,
212  bool inUseTied = true, bool inUseRegular = true, bool inUseIrregular = true,
213  bool inUseRoutethrough = true);
214  /// \brief Expands the given tilewire's arc sources.
215  /// \details The optional inUseTied, inUseRegular, inUseIrregular, and inUseRoutethrough
216  /// flags determine whether the corresponding arc types will be included. Note that
217  /// tied arcs (or "fake pips") are not currently available in the databases.
218  void expandTilewireSources(const Tilewire& inTilewire, TilewireVector& outSources,
219  bool inUseTied = true, bool inUseRegular = true, bool inUseIrregular = true,
220  bool inUseRoutethrough = true);
221  /// \brief Expands all sink arcs for the given tilewire's segment.
222  /// \details The optional inUseTied, inUseRegular, inUseIrregular, and inUseRoutethrough
223  /// flags determine whether the corresponding arc types will be included. Note that
224  /// tied arcs (or "fake pips") are not currently available in the databases.
225  void expandSegmentSinks(const Tilewire& inTilewire, ArcVector& outSinks,
226  EExpandDirection inExpandDirection = eExpandDirectionNone, bool inUseTied = true,
227  bool inUseRegular = true, bool inUseIrregular = true, bool inUseRoutethrough = true);
228  /// \brief Expands all source arcs for the given tilewire's segment.
229  /// \details The optional inUseTied, inUseRegular, inUseIrregular, and inUseRoutethrough
230  /// flags determine whether the corresponding arc types will be included. Note that
231  /// tied arcs (or "fake pips") are not currently available in the databases.
232  void expandSegmentSources(const Tilewire& inTilewire, ArcVector& outSources,
233  EExpandDirection inExpandDirection = eExpandDirectionNone, bool inUseTied = true,
234  bool inUseRegular = true, bool inUseIrregular = true, bool inUseRoutethrough = true);
235  /// \brief Returns the tilewire for the specified site and pin name pair.
237  const std::string& inPinName) {
238  SiteIndex siteIndex = mSites.findSiteIndex(inSiteName);
239  if(siteIndex.isUndefined()) return Tilewire::sInvalid;
240  return mSites.getSite(siteIndex).getPinTilewire(inPinName);
241  }
242  /// \brief Returns the arc for the specified pip tile and wires.
243  Arc tilePipToArc(const std::string& inTileName, const std::string& inSourceWireName,
244  const std::string& inSinkWireName) {
245  TileIndex tileIndex = mTiles.findTileIndex(inTileName);
246  if(tileIndex.isUndefined()) return Arc();
247  const TileInfo& tileInfo = mTiles.getTileInfo(tileIndex);
248  TileTypeIndex tileTypeIndex = tileInfo.getTypeIndex();
249  WireIndex sourceWireIndex = mTiles.findWireIndex(tileTypeIndex, inSourceWireName);
250  if(sourceWireIndex.isUndefined()) return Arc();
251  WireIndex sinkWireIndex = mTiles.findWireIndex(tileTypeIndex, inSinkWireName);
252  if(sinkWireIndex.isUndefined()) return Arc();
253  return Arc(Tilewire(tileIndex, sourceWireIndex), Tilewire(tileIndex, sinkWireIndex));
254  }
255  /// \brief Returns the tilewire for the specified tile and wire names.
256  /// \todo Add to unit tests.
257  Tilewire lookupTilewire(const std::string& inTileName, const std::string& inWireName) {
258  TileIndex tileIndex = mTiles.findTileIndex(inTileName);
259  if(tileIndex.isUndefined()) return Tilewire::sInvalid;
260  const TileInfo& tileInfo = mTiles.getTileInfo(tileIndex);
261  TileTypeIndex tileTypeIndex = tileInfo.getTypeIndex();
262  WireIndex wireIndex = mTiles.findWireIndex(tileTypeIndex, inWireName);
263  if(wireIndex.isUndefined()) return Tilewire::sInvalid;
264  return Tilewire(tileIndex, wireIndex);
265  }
266  };
267 
268 } // namespace architecture
269 } // namespace torc
270 
271 #endif // TORC_ARCHITECTURE_DDB_HPP
WireUsage & getWireUsage(void)
Returns a constant reference to the design wire usage.
Definition: DDB.hpp:150
static void dissociate(const class DDB &ddb)
Dissociate the given device database from any stream.
Encapsulation of a tile index in an unsigned 32-bit integer.
virtual void setConsoleStreams(istream &inIn, ostream &inOut, ostream &inErr, ostream &inLog)
Sets all of the database console streams.
Definition: DDB.hpp:157
string mDeviceName
The name of the device.
Definition: DDB.hpp:54
Forward declaration of template basic_istream.
EExpandDirection
Enumeration to indicate in which directions segments should be expanded.
Definition: DDB.hpp:92
Encapsulation of an arc between two tilewires.
Definition: Arc.hpp:28
void releaseSegment(const Tilewire &inTilewire)
Marks all wires on the segment as unused.
Definition: DDB.hpp:193
std::vector< Tilewire > TilewireVector
Vector of Tilewire objects.
Definition: Tilewire.hpp:101
Header for the Segments class.
void clear(void)
Marks all arcs as being unused, without releasing the bitset objects.
Definition: ArcUsage.hpp:192
Encapsulation of a device designator and its constituent elements.
const string & getDeviceName(void) const
Returns the device name.
Definition: DDB.hpp:132
Tiles mTiles
The family and device tile data.
Definition: DDB.hpp:72
Header for the WireUsage class.
Device database, including complete wiring and logic support.
Definition: DDB.hpp:42
xilinx::TileOffset TileOffset
Imported type name.
Definition: DDB.hpp:50
const string & getFamilyName(void) const
Returns the family name.
Definition: DDB.hpp:134
Arc tilePipToArc(const std::string &inTileName, const std::string &inSourceWireName, const std::string &inSinkWireName)
Returns the arc for the specified pip tile and wires.
Definition: DDB.hpp:243
const Tiles & getTiles(void) const
Returns a constant reference to the family and device tile data.
Definition: DDB.hpp:146
ArcUsage & getArcUsage(void)
Returns a constant reference to the design arc usage.
Definition: DDB.hpp:148
DDB(const string &inDeviceName, const string &inPackageName, DDBConsoleStreams inDDBConsoleStreams=DDBConsoleStreams())
Public constructor.
Definition: DDB.hpp:112
const TileInfo & getTileInfo(TileIndex inTileIndex) const
Returns the TileInfo object for the specified tile.
Definition: Tiles.hpp:137
Encapsulation the design wire usage.
Definition: WireUsage.hpp:35
xilinx::SiteIndex SiteIndex
Imported type name.
Definition: DDB.hpp:47
Header for the Sites class.
Header for the Arc class.
boost::filesystem::path mDevicePath
the device database path.
Definition: DDB.hpp:58
void releaseArc(const Arc &inArc, bool releaseSource=true, bool releaseSink=true)
Marks the arc and all of its source and sink segment wires as unused.
Definition: DDB.hpp:179
Header for the DeviceDesignator class.
Header for the DDBStreamHelper class.
const Tilewire getPinTilewire(const std::string &inName) const
Returns the Tilewire associated with the specified pin name.
Definition: Site.hpp:70
xilinx::TileIndex TileIndex
Imported type name.
Definition: DDB.hpp:49
Device database console streams class.
ostream & mErr(void)
Returns the database console error stream.
void expandSegmentSinks(const Tilewire &inTilewire, ArcVector &outSinks, EExpandDirection inExpandDirection=eExpandDirectionNone, bool inUseTied=true, bool inUseRegular=true, bool inUseIrregular=true, bool inUseRoutethrough=true)
Expands all sink arcs for the given tilewire's segment.
Definition: DDB.cpp:314
Encapsulation of a wire index in an unsigned 16-bit integer.
void useArc(const Arc &inArc)
Marks the arc and all of its source and sink segment wires as used.
Definition: DDB.hpp:173
Forward declaration of template basic_ostream.
const Sites & getSites(void) const
Returns a constant reference to the family and device site data.
Definition: DDB.hpp:144
std::vector< Arc > ArcVector
Vector of Arc objects.
Definition: Arc.hpp:78
std::string string
const StringVector & getSpeedGrades(void) const
Returns a constant reference to a vector of speed grades.
Definition: DDB.hpp:140
Encapsulation of a tile offset in an unsigned 32-bit integer.
const Tilewire & getSourceTilewire(void) const
Returns the source tilewire.
Definition: Arc.hpp:45
void clear(void)
Marks all wires as being unused, without releasing the bitset objects.
Definition: WireUsage.hpp:121
void expandTilewireSinks(const Tilewire &inTilewire, TilewireVector &outSinks, bool inUseTied=true, bool inUseRegular=true, bool inUseIrregular=true, bool inUseRoutethrough=true)
Expands the given tilewire's arc sinks.
Definition: DDB.cpp:214
Tilewire sitePinToTilewire(const std::string &inSiteName, const std::string &inPinName)
Returns the tilewire for the specified site and pin name pair.
Definition: DDB.hpp:236
void clearUsage(void)
Clears all arc and wire usage, effectively restaring with an empty device.
Definition: DDB.hpp:168
const Tilewire & getSinkTilewire(void) const
Returns the sink tilewire.
Definition: Arc.hpp:47
void use(const Arc &inArc)
Marks the specified arc as being used.
Definition: ArcUsage.hpp:133
Header for the DDBConsoleStreams class.
size_t readFamilyName(class DigestStream &inStream)
Reads the family name from a device DigestStream.
Definition: DDB.cpp:98
Site type and population data for the family and the device.
Definition: Sites.hpp:45
string mFamilyName
The name of the family.
Definition: DDB.hpp:56
Encapsulation of a device tile and wire pair.
Definition: Tilewire.hpp:39
const boost::filesystem::path & getFamilyPath(void) const
Returns the family database path.
Definition: DDB.hpp:138
Encapsulation the design arc usage.
Definition: ArcUsage.hpp:38
Tile map, tile type, and wire information for the family and device.
Definition: Tiles.hpp:36
Header for the Versions class.
const boost::filesystem::path & getDevicePath(void) const
Returns the device database path.
Definition: DDB.hpp:136
std::string string
Imported type name.
Definition: DDB.hpp:45
DDB(const torc::common::DeviceDesignator &inDeviceDesignator, DDBConsoleStreams inDDBConsoleStreams=DDBConsoleStreams())
Public constructor.
Definition: DDB.hpp:119
void expandTilewireSources(const Tilewire &inTilewire, TilewireVector &outSources, bool inUseTied=true, bool inUseRegular=true, bool inUseIrregular=true, bool inUseRoutethrough=true)
Expands the given tilewire's arc sources.
Definition: DDB.cpp:264
void expandSegmentSources(const Tilewire &inTilewire, ArcVector &outSources, EExpandDirection inExpandDirection=eExpandDirectionNone, bool inUseTied=true, bool inUseRegular=true, bool inUseIrregular=true, bool inUseRoutethrough=true)
Expands all source arcs for the given tilewire's segment.
Definition: DDB.cpp:336
Header for the ArcUsage class.
xilinx::TileTypeIndex TileTypeIndex
Imported type name.
Definition: DDB.hpp:51
Encapsulation of a tile within a device tile map.
Definition: TileInfo.hpp:33
SiteIndex findSiteIndex(const string &inName) const
Returns the site index for the given site name.
Definition: Sites.hpp:134
Tilewire lookupTilewire(const std::string &inTileName, const std::string &inWireName)
Returns the tilewire for the specified tile and wire names.
Definition: DDB.hpp:257
boost::filesystem::path path
const TileTypeIndex & getTypeIndex(void) const
Returns the tile type index for this tile.
Definition: TileInfo.hpp:92
void use(const Tilewire &inTilewire)
Marks the specified tilewire as being used.
Definition: WireUsage.hpp:81
ArcUsage mArcUsage
The design arc usage.
Definition: DDB.hpp:74
Header for the ExtendedWireInfo class.
const Site & getSite(SiteIndex inSiteIndex) const
Returns the site for the specified index.
Definition: Sites.hpp:129
xilinx::WireIndex WireIndex
Imported type name.
Definition: DDB.hpp:48
void useSegment(const Tilewire &inTilewire)
Marks all wires on the segment as used.
Definition: DDB.hpp:185
ostream & mOut(void)
Returns the database console output stream.
TileIndex findTileIndex(const string &inName) const
Returns the tile index for the given tile name.
Definition: Tiles.hpp:170
ostream & mLog(void)
Returns the database console log stream.
~DDB(void)
Destructor.
Definition: DDB.hpp:126
Encapsulation of database version information.
Definition: Versions.hpp:37
boost::filesystem::path mFamilyPath
the family database path.
Definition: DDB.hpp:60
Segments mSegments
The device segment data.
Definition: DDB.hpp:68
Encapsulation of a site index in an unsigned 32-bit integer.
WireIndex findWireIndex(TileTypeIndex inTileTypeIndex, const string &inName) const
Returns the wire index for the given wire name in the given tile type.
Definition: Tiles.hpp:182
const string & getDevicePackage(void) const
Returns the device package.
virtual void setConsoleStreams(DDBConsoleStreams inConsoleStreams)
Sets all of the database console streams.
Definition: DDB.hpp:152
Encapsulation of a tile type index in an unsigned 16-bit integer.
void release(const Tilewire &inTilewire)
Marks the specified tilewire as being unused.
Definition: WireUsage.hpp:104
const string & getDeviceName(void) const
Returns the device name.
StringVector mSpeedGrades
The supported speed grades.
Definition: DDB.hpp:66
void release(const Arc &inArc)
Marks the specified arc as being unused.
Definition: ArcUsage.hpp:169
static const Tilewire sInvalid
Definition: Tilewire.hpp:93
Sites mSites
The family and device site data.
Definition: DDB.hpp:70
void initialize(const string &inDeviceName, const string &inPackageName)
Initializes the database.
Definition: DDB.cpp:31
std::vector< string > StringVector
Imported type name.
Definition: DDB.hpp:46
Encapsulation of a device or family digest stream.
Header for the Tiles class.
Segment and irregular arc data for the device.
Definition: Segments.hpp:40
istream & mIn(void)
Returns the database console input stream.
WireUsage mWireUsage
The design wire usage.
Definition: DDB.hpp:76
size_t readSpeedGrades(class DigestStream &inStream)
Reads the supported speed grades from a device DigestStream.
Definition: DDB.cpp:121
virtual void setConsoleStreams(istream &inIn, ostream &inOut, ostream &inErr, ostream &inLog)
Sets all of the database console streams.
Versions mFamilyVersion
The family database version.
Definition: DDB.hpp:64
void expandSegment(const Tilewire &inTilewire, TilewireVector &outTilewires, EExpandDirection inExpandDirection=eExpandDirectionNone)
Expands the given tilewire's segment.
Definition: DDB.cpp:154
const Segments & getSegments(void) const
Returns a constant reference to the device segment data.
Definition: DDB.hpp:142
Versions mDeviceVersion
The device database version.
Definition: DDB.hpp:62