torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Sites.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 Sites class.
18 
20 #include <iostream>
21 
22 namespace torc {
23 namespace architecture {
24 
25  size_t Sites::readPackages(DigestStream& inStream) {
26  // prepare to read from the stream
27  size_t bytesReadOffset = inStream.getBytesRead();
28  char scratch[1 << 10]; // scratch read buffer
29  uint16_t nameLength = 0; // length of tile type name
30  PackageCount packageCount; // number of packages
31  PadCount padCount; // number of pads
32  SiteFlags siteFlags; // site attribute flags
33  SiteIndex siteIndex; // pad site index
34 
35  // read the section header
36  string sectionName;
37  inStream.readSectionHeader(sectionName);
38  /// \todo Throw a proper exception.
39  if(sectionName != ">>>>Packages>>>>") throw -1;
40 
41  // initialize the package array
42  inStream.read(packageCount);
43  mPackages.setSize(packageCount);
44  mOut() << "\tReading " << packageCount << " package" << (packageCount != 1 ? "s" : "")
45  << " (";
46  // loop through each package
47  for(PackageIndex i; i < packageCount; i++) {
48  // look up the current package
49  Package& package = const_cast<Package&>(mPackages[i]);
50  // read the package name
51  inStream.read(nameLength);
52  /// \todo Throw a proper exception.
53  if(nameLength > sizeof(scratch)) throw -1;
54  inStream.read(scratch, nameLength);
55  scratch[nameLength] = 0;
56  // update the package
57  package.mName = scratch;
58  mPackageNameToPackageIndex[scratch] = i;
59  mOut() << scratch << (i + 1 < packageCount ? ", " : "");
60  // read the pad count
61  inStream.read(padCount);
62  package.mPads.setSize(padCount);
63  // loop through each pad
64  for(PadCount j; j < padCount; j++) {
65  // look up the current pad
66  Pad& pad = const_cast<Pad&>(package.mPads[j]);
67  // read the site index
68  inStream.read(siteIndex);
69  // read the site flags
70  inStream.read(siteFlags);
71  // read the pad name
72  inStream.read(nameLength);
73  /// \todo Throw a proper exception.
74  if(nameLength > sizeof(scratch)) throw -1;
75  inStream.read(scratch, nameLength);
76  scratch[nameLength] = 0;
77  // update the package pad
78  pad.mSiteIndex = siteIndex;
79  pad.mFlags = siteFlags;
80  pad.mName = scratch;
81  package.mPadNameToPadIndex[scratch] = xilinx::PadIndex(j);
82  }
83  }
84  mOut() << ") ..." << std::endl;
85 
86  // return the number of bytes read
87  return inStream.getBytesRead() - bytesReadOffset;
88  }
89 
91  // prepare to read from the stream
92  size_t bytesReadOffset = inStream.getBytesRead();
93  char scratch[1 << 10]; // scratch read buffer
94  uint16_t nameLength = 0; // length of site type name
95  SiteTypeCount siteTypeCount; // number of site types
96  uint32_t elementCount; // number of site elements
97  PinCount pinCount; // number of pins
98  PinFlags pinFlags; // pin attribute flags
99  uint32_t elementIndex; // connection element index
100  uint32_t pinIndex; // connection pin index
101 
102  // read the section header
103  string sectionName;
104  inStream.readSectionHeader(sectionName);
105  /// \todo Throw a proper exception.
106  if(sectionName != ">>>>PrimDefs>>>>") throw -1;
107 
108  // initialize the tile type array
109  inStream.read(siteTypeCount);
110  mSiteTypes.setSize(siteTypeCount);
111  mOut() << "\tReading " << siteTypeCount << " site types..." << std::endl;
112  // loop through each site type
113  for(SiteTypeIndex i; i < siteTypeCount; i++) {
114  // look up the current site definition
115  PrimitiveDef& primitiveDef = const_cast<PrimitiveDef&>(mSiteTypes[i]);
116  // read the site type name
117  inStream.read(nameLength);
118  /// \todo Throw a proper exception.
119  if(nameLength > sizeof(scratch)) throw -1;
120  inStream.read(scratch, nameLength);
121  scratch[nameLength] = 0;
122 //mOut() << "\t\t" << i << ": " << scratch << std::endl;
123 //mOut().flush();
124  // read the pin count
125  inStream.read(pinCount);
126  // update the site definition
127  primitiveDef.mName = scratch;
128  primitiveDef.mPins.setSize(pinCount);
129  // loop through each pin
130  for(PinCount j; j < pinCount; j++) {
131  // look up the current pin
132  PrimitivePin& primitivePin = const_cast<PrimitivePin&>(primitiveDef.mPins[j]);
133  // read the pin flags
134  inStream.read(pinFlags);
135  // read the pin name
136  inStream.read(nameLength);
137  /// \todo Throw a proper exception.
138  if(nameLength > sizeof(scratch)) throw -1;
139  inStream.read(scratch, nameLength);
140  scratch[nameLength] = 0;
141  // update the site pin
142  primitivePin.mFlags = pinFlags;
143  primitivePin.mName = scratch;
144  primitiveDef.mPinNameToPinIndex[scratch] = xilinx::PinIndex(j);
145  }
146  // read the number of site elements
147  inStream.read(elementCount);
148  // update the site definition
149  primitiveDef.mElements.setSize(elementCount);
150  // loop through each element
151  for(uint32_t j = 0; j < elementCount; j++) {
152  // look up the current element
153  PrimitiveElement& element
154  = const_cast<PrimitiveElement&>(primitiveDef.mElements[j]);
155  // read the element name
156  inStream.read(nameLength);
157  /// \todo Throw a proper exception.
158  if(nameLength > sizeof(scratch)) throw -1;
159  inStream.read(scratch, nameLength);
160  scratch[nameLength] = 0;
161  // update the element name
162  element.mName = scratch;
163 //mOut() << primitiveDef.getName() << " - " << element.getName() << ":" << std::endl;
164 //mOut() << " ";
165  // read the BEL flag
166  uint16_t isBel;
167  inStream.read(isBel);
168  // read the pin count
169  inStream.read(pinCount);
170  // update the element
171  element.mIsBel = isBel != 0;
172  element.mPins.setSize(pinCount);
173  // loop through each pin
174  for(PinCount k; k < pinCount; k++) {
175  // look up the current pin
176  PrimitiveElementPin& elementPin =
177  const_cast<PrimitiveElementPin&>(element.mPins[k]);
178  // read the pin flags
179  inStream.read(pinFlags);
180  // read the pin name
181  inStream.read(nameLength);
182  /// \todo Throw a proper exception.
183  if(nameLength > sizeof(scratch)) throw -1;
184  inStream.read(scratch, nameLength);
185  scratch[nameLength] = 0;
186  // update the site pin
187  elementPin.mElementPtr = &element;
188 //mOut() << elementPin.mElementPtr->getName() << "." << scratch << " ";
189 //if(elementPin.mElementPtr == 0) {
190 // mOut() << "Element pin " << scratch << " has NULL element" << std::endl;
191 // mOut().flush();
192 //}
193  elementPin.mFlags = pinFlags;
194  elementPin.mName = scratch;
195  element.mPinNameToPinIndex[scratch] = xilinx::PinIndex(k);
196  }
197 //mOut() << std::endl;
198  // read the config count
199  uint32_t cfgCount;
200  inStream.read(cfgCount);
201  // loop through each cfg value
202 //bool debug = cfgCount > 0;
203 //if(debug) mOut() << "\t\t\t" << j << " \"" << scratch << "\": ";
204  for(uint32_t k = 0; k < cfgCount; k++) {
205  // read the cfg value
206  inStream.read(nameLength);
207  /// \todo Throw a proper exception.
208  if(nameLength > sizeof(scratch)) throw -1;
209  inStream.read(scratch, nameLength);
210  scratch[nameLength] = 0;
211 //if(debug) mOut() << scratch << " ";
212  // update the cfg values
213  element.mCfgs.insert(scratch);
214  }
215 //if(debug) mOut() << std::endl;
216  }
217  // read the conn count
218  uint32_t connCount;
219  inStream.read(connCount);
220 //mOut() << primitiveDef.mName << ": " << connCount << std::endl;
221  // update the site definition
222  primitiveDef.mConnections.setSize(connCount);
223  // loop through each conn
224  const PrimitiveElementArray& elements = primitiveDef.getElements();
225  for(uint32_t j = 0; j < connCount; j++) {
226  // look up the current connection
227  PrimitiveConnSharedPtr& connectionPtr = primitiveDef.mConnections[j];
228  connectionPtr = boost::shared_ptr<PrimitiveConn>(new PrimitiveConn());
229  PrimitiveConn& connection = const_cast<PrimitiveConn&>(*connectionPtr);
230  // read the source count
231  uint16_t sourceCount;
232  inStream.read(sourceCount);
233  /// \todo Throw a proper exception
234  if(sourceCount != 1) throw -1;
235  // read the source element and pin
236  inStream.read(elementIndex);
237  inStream.read(pinIndex);
238  const PrimitiveElement* elementPtr = elements.begin() + elementIndex;
239  PrimitiveElement& element = const_cast<PrimitiveElement&>(*elementPtr);
240  const PrimitiveElementPinArray& pins = element.getPins();
241  PrimitiveElementPin& pin = const_cast<PrimitiveElementPin&>(pins[pinIndex]);
242  connection.mSourcePtr = &pin;
243  const_cast<PrimitiveConnSharedPtr&>(pin.mPrimitiveConn) = connectionPtr;
244  // read the sink count
245  uint16_t sinkCount;
246  inStream.read(sinkCount);
247  // loop through each sink
248  for(uint32_t k = 0; k < sinkCount; k++) {
249  // read the sink element and pin
250  inStream.read(elementIndex);
251  inStream.read(pinIndex);
252  elementPtr = elements.begin() + elementIndex;
253  PrimitiveElement& element = const_cast<PrimitiveElement&>(*elementPtr);
254  const PrimitiveElementPinArray& pins = element.getPins();
255  PrimitiveElementPin& pin = const_cast<PrimitiveElementPin&>(pins[pinIndex]);
256  connection.mSinks.push_back(&pin);
257  const_cast<PrimitiveConnSharedPtr&>(pin.mPrimitiveConn) = connectionPtr;
258  }
259  }
260 //mOut() << primitiveDef.getName() << " - " << element.getName() << ":" << std::endl;
261  }
262 
263  // return the number of bytes read
264  return inStream.getBytesRead() - bytesReadOffset;
265  }
266 
268  // prepare to read from the stream
269  size_t bytesReadOffset = inStream.getBytesRead();
270  uint16_t primitivePinMapCount = 0; // number of pin maps
271  PinCount pinCount; // number of pins
272  WireIndex wireIndex; // pin index
273 
274  // read the section header
275  string sectionName;
276  inStream.readSectionHeader(sectionName);
277  /// \todo Throw a proper exception.
278  if(sectionName != ">>>>Pin Maps>>>>") throw -1;
279 
280  // initialize the site pin map array
281  inStream.read(primitivePinMapCount);
282  mPrimitivePinMaps.setSize(primitivePinMapCount);
283  mOut() << "\tReading " << primitivePinMapCount << " primitive pin maps..." << std::endl;
284  // loop through each pin map
285  for(uint16_t i = 0; i < primitivePinMapCount; i++) {
286  // read the pin count
287  inStream.read(pinCount);
288  mPrimitivePinMaps[i].setSize(pinCount);
289  // get a reference to this map's pin array
291  // loop through each pin
292  for(PinCount j; j < pinCount; j++) {
293  // look up a reference to the pin and discard the const trait
294  WireIndex& pin = const_cast<WireIndex&>(pins[j]);
295  // read the pin
296  inStream.read(wireIndex);
297  pin = wireIndex;
298  }
299  }
300 
301  // return the number of bytes read
302  return inStream.getBytesRead() - bytesReadOffset;
303  }
304 
305  size_t Sites::readSites(DigestStream& inStream) {
306  // prepare to read from the stream
307  size_t bytesReadOffset = inStream.getBytesRead();
308  char scratch[1 << 10]; // scratch read buffer
309  uint16_t nameLength = 0; // length of tile type name
310  SiteCount siteCount; // number of sites
311  SiteTypeIndex siteTypeIndex; // site type index
312  TileIndex tileIndex; // site tile index
313  SiteFlags flags; // site flags
314  uint16_t pinMap = 0; // site pin map
315 
316  // read the section header
317  string sectionName;
318  inStream.readSectionHeader(sectionName);
319  /// \todo Throw a proper exception.
320  if(sectionName != ">>>> Sites >>>>") throw -1;
321 
322  // initialize the site array
323  inStream.read(siteCount);
324  mSites.setSize(siteCount);
325  mOut() << "\tReading " << siteCount << " sites..." << std::endl;
326  // loop through each site
327  for(SiteIndex i; i < siteCount; i++) {
328  // read the site name
329  inStream.read(nameLength);
330  /// \todo Throw a proper exception.
331  if(nameLength > sizeof(scratch)) throw -1;
332  inStream.read(scratch, nameLength);
333  scratch[nameLength] = 0;
334  // read the site type index, tile index, flags, and pin map
335  inStream.read(siteTypeIndex);
336  inStream.read(tileIndex);
337  inStream.read(flags);
338  inStream.read(pinMap);
339  // look up a reference for the site, and discard the const trait
340  Site& site = const_cast<Site&>(mSites[i]);
341  site = Site(scratch, mSiteTypes[siteTypeIndex], tileIndex, flags,
342  mPrimitivePinMaps[pinMap]);
343  mSiteNameToSiteIndex[scratch] = i;
344  }
345 
346  // return the number of bytes read
347  return inStream.getBytesRead() - bytesReadOffset;
348  }
349 
350 } // namespace architecture
351 } // namespace torc
PrimitiveElementPinArray mPins
The array of pins.
Encapsulation of the site index, pin name, and pin flags for a package.
Definition: Pad.hpp:33
Encapsulation of a physical device package and its pins.
Definition: Package.hpp:33
SiteIndex mSiteIndex
The index of the site corresponding to this pad.
Definition: Pad.hpp:47
Encapsulation of a tile index in an unsigned 32-bit integer.
PinNameToPinIndexMap mPinNameToPinIndex
The map of pin names to pin indexes.
string mName
The name of the pad in its physical package.
Definition: Pad.hpp:49
std::istream & read(uint8_t &outValue)
Read and return a uint8_t.
SiteNameToSiteIndexMap mSiteNameToSiteIndex
The mapping from site name to site index for this device.
Definition: Sites.hpp:77
Encapsulation of a pad count in an unsigned 32-bit integer.
PinNameToPinIndexMap mPinNameToPinIndex
The map of pin names to pin indexes.
const PrimitiveElement * mElementPtr
The primitive element that owns this pin.
Encapsulation of a pin count in an unsigned 32-bit integer.
Encapsulation of primitive site definition, with associated connections, elements, and pins.
Header for the Sites class.
std::string mName
The primitive name.
Encapsulation of a site count in an unsigned 32-bit integer.
Array< const PrimitiveDef > mSiteTypes
The site types for this family.
Definition: Sites.hpp:71
const PrimitiveConnSharedPtr mPrimitiveConn
The primitive connection that includes this pin.
PinFlags mFlags
The pin direction flags.
PrimitiveElementArray mElements
The primitive elements.
Encapsulation of a pin index in an unsigned 32-bit integer.
Encapsulation of a wire index in an unsigned 16-bit integer.
Array< const Package > mPackages
The packages for this device.
Definition: Sites.hpp:79
Encapsulation of a package count in an unsigned 16-bit integer.
Encapsulation of a site type index in an unsigned 16-bit integer.
PrimitiveElementPinArray & getPins(void)
Returns a non-constant array of element pins. This function should only be used by the Sites class d...
PinFlags mFlags
The pin direction flags.
StringSet mCfgs
The set of allowable configuration values.
Array< const Site > mSites
The logic sites for this device.
Definition: Sites.hpp:75
Encapsulation of a device logic site.
Definition: Site.hpp:30
Encapsulation of a PrimitiveDef internal connection. This class is analogous to a permanent net with...
PrimitiveConnSharedPtrArray mConnections
The primitive internal connections.
size_t readPrimitivePinMaps(DigestStream &inStream)
Read the site pin mappings for the family.
Definition: Sites.cpp:267
PackageNameToPackageIndexMap mPackageNameToPackageIndex
The mapping from package name to package index for this device.
Definition: Sites.hpp:81
SiteFlags mFlags
The site flags for this pad, specifically including bonding.
Definition: Pad.hpp:51
Encapsulation of a package index in an unsigned 16-bit integer.
Encapsulation of pin attribute flags in an unsigned 16-bit integer.
Encapsulation of a site type count in an unsigned 16-bit integer.
Encapsulation of a primitive pin's name and flags. Primitive pins are logic site inputs or outputs...
boost::shared_ptr< const PrimitiveConn > PrimitiveConnSharedPtr
void readSectionHeader(string &outHeader)
Read and return a section header.
ostream & mOut(void)
Returns the database console output stream.
const PrimitiveElementArray & getElements(void) const
Returns a constant array of primitive elements.
Encapsulation of site attribute flags in an unsigned 16-bit integer.
Encapsulation of a primitive site element. Primitive elements are subcomponents of logic primitive s...
Encapsulation of a primitive element pin's name, flags, and element pointer. Primitive element pins ...
PrimitivePinArray mPins
The primitive pins.
Encapsulation of a site index in an unsigned 32-bit integer.
Array2D< const WireIndex > mPrimitivePinMaps
The site pin maps for this family.
Definition: Sites.hpp:73
T * begin(void)
Returns the non-constant begin iterator.
Definition: Array.hpp:95
size_t readPackages(DigestStream &inStream)
Read the packages for the device.
Definition: Sites.cpp:25
void setSize(uint32_t inSize)
Discards all contents and resizes the array.
Definition: Array.hpp:107
Encapsulation of a device or family digest stream.
size_t getBytesRead(void) const
Returns the number of bytes read.
size_t readPrimitiveTypes(DigestStream &inStream)
Read the primitive types for the family.
Definition: Sites.cpp:90
Encapsulation of a pad index in an unsigned 32-bit integer.
bool mIsBel
A flag indicating whether or not this element is a BEL (Basic ELement).
size_t readSites(DigestStream &inStream)
Read the sites for the device.
Definition: Sites.cpp:305