torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ArchitectureBrowser.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 ArchitectureBrowser class for exploring database contents.
18 
19 #ifndef TORC_UTILS_ARCHITECTUREBROWSER_HPP
20 #define TORC_UTILS_ARCHITECTUREBROWSER_HPP
21 
22 #include <iostream>
23 #include <iomanip>
24 #include <map>
25 #include <sstream>
29 #include <boost/regex.hpp>
30 #include <boost/lexical_cast.hpp>
31 #include <boost/algorithm/string/case_conv.hpp>
32 
33 
34 namespace torc {
35 
36 /// \brief Utility class for exploring database contents.
38 
39 protected:
40  /// \brief Imported type name.
42  /// \brief Imported type name.
44  /// \brief Imported type name.
46  /// \brief Imported type name.
48  /// \brief Imported type name.
50  /// \brief Imported type name.
52  /// \brief Imported type name.
54  /// \brief Imported type name.
56  /// \brief Imported type name.
58  /// \brief Imported type name.
60  /// \brief Imported type name.
62  /// \brief Imported type name.
64  /// \brief Imported type name.
66  /// \brief Imported type name.
68  /// \brief Imported type name.
70  /// \brief Imported type name.
72  /// \brief Type for member function pointers.
73  typedef void (ArchitectureBrowser::*BrowserFunction)(const std::string& x);
74 
75  /// \brief Database Reference.
76  DDB& mDB;
77  /// \brief Segments reference from the database.
79  /// \brief Site data reference from the database.
80  const Sites& mSites;
81  /// \brief Tile data reference from the database.
82  const Tiles& mTiles;
83  /// \brief Pip usage information from the database.
85  /// \brief Wire usage information from the database.
87 
88  /// \brief Regular expression for Tilewire form.
89  static boost::regex sTilewireRegEx;
90  /// \brief Regular expression for nonnegative integers.
91  static boost::regex sIndexRegEx;
92  /// \brief Regular expression for a name.
93  static boost::regex sNameRegEx;
94 
95  /// \brief Enumeration of menu selection options.
96  enum EFunctionMap {
100  };
101 
102  /// \brief Mapping from function to index.
103  std::map<string, EFunctionMap> mFunctionMap;
104 
105 
106 
107 public:
108  /// \brief Constructor.
109  ArchitectureBrowser(DDB& inDB) : mDB(inDB), mSegments(inDB.getSegments()),
110  mSites(inDB.getSites()), mTiles(inDB.getTiles()),
111  mArcUsage(inDB.getArcUsage()), mWireUsage(inDB.getWireUsage()) {
113  }
114  /// \brief Destructor.
116 public:
117  /// \brief Function to begin an interactive browsing session.
118  void browse() {
119  using std::cout;
120  using std::cin;
121  using std::endl;
122 
132 
133  string function;
134  string userinput;
135  Tilewire tw;
136  while (true) {
137  printFullMenu();
138  cin >> function;
139  switch (mFunctionMap[function]) {
140  case eQuit:
141  cout << "Bye!" << endl << endl;
142  return;
143  break;
144  case eDeviceSummary:
145  cout << "Device Summary." << endl;
146  deviceSummary();
147  break;
148  case eTiles:
149  //cout << "Tile List." << endl;
150  functionPrompt("Enter regexp filter (\".*\" to match all tiles), q to quit",
151  getFilteredTileListRef);
152  break;
153  case eWires:
154  functionPrompt("Enter tile type index, tile type name or tile name, q to quit",
155  getWireListForTileTypeRef);
156  break;
157  case eDetail:
158  functionPrompt("Enter wire@tile, q to quit", getTilewireDetailRef);
159  break;
160  case eSegment:
161  functionPrompt("Enter wire@tile, q to quit", displayFullSegmentRef);
162  break;
163  case eSources:
164  functionPrompt("Enter wire@tile, q to quit", displaySegmentSourcesRef);
165  break;
166  case eSinks:
167  functionPrompt("Enter wire@tile, q to quit", displaySegmentSinksRef);
168  break;
169  case eSites:
170  //cout << "Site List." << endl;
171  functionPrompt("Enter regexp filter (\".*\" to match all sites), q to quit",
172  getFilteredSiteListRef);
173  break;
174  case eSiteDetail:
175  functionPrompt("Enter site name or index, q to quit", getSiteDetailRef);
176  break;
177  case eSiteTypes:
178  cout << "List site types: " << endl;
180  break;
181  case eSitesOfType:
182  functionPrompt("Enter site type name, q to quit", displaySitesOfTypeRef);
183  break;
184 
185 
186 
187  case eBit:
188  cout << "Bit - Nothing here yet." << endl;
189  break;
190  case eClear:
191  cout << "Clear - Nothing here yet." << endl;
192  break;
193  case eFind:
194  cout << "Enter tile index: ";
195  cin >> userinput;
196  //findIndexInformation(userinput);
197  break;
198  case eGoto:
199  cout << "Enter wire@tile: " << endl;
200  cin >> userinput;
201  //enumerateTileWireSinks(userinput);
202  break;
203  case eInstances:
204  cout << "Enter tile type: ";
205  cin >> userinput;
206  //enumerateTileInstances(userinput);
207  break;
208  case eRoute:
209  cout << "Route - Not yet supported" << endl;
210  //cout << "Route - Supports routing to a single sink." << endl;
211  //routeToSingleSink();
212  break;
213  case eTypes:
214  cout << "Available tile types:" << endl;
215  //enumerateTileTypes();
216  break;
217  case eEquations:
218  cout << "Equations - Nothing here yet." << endl;
219  break;
220  case eeXtent:
221  cout << "Enter wire@tile: ";
222  cin >> userinput;
223  //enumerateTilewireReach(userinput);
224  break;
225  case eMap:
226  cout << "Displaying tilemap:" << endl;
227  //displayTilemap();
228  break;
229  case eSitePins:
230  cout << "Enter site: ";
231  cin >> userinput;
232  //enumerateSitePins(userinput);
233  break;
234  default:
235  cout << "Invalid Function: " << function << endl;
236  }
237  }
238  }
239  /// \brief Secondary menu loop to remain in a particular function.
240  void functionPrompt(const char* inPrompt, BrowserFunction f) {
241  using std::cout;
242  using std::endl;
243  using std::cin;
244  string userinput;
245  while (true) {
246  cout << endl << inPrompt << "> ";
247  cin >> userinput;
248  switch (mFunctionMap[userinput]) {
249  case eQuit:
250  return;
251  default:
252  (this->*f)(userinput);
253  break;
254  }
255  }
256  }
257  /// \brief A brief summary of device information.
258  void deviceSummary() {
259  using std::cout;
260  using std::endl;
261  cout << "Name: " << mDB.getDeviceName() << endl;
262  cout << "Family: " << mDB.getFamilyName() << endl;
263  cout << "Speed grades:";
264  for (unsigned int i =0; i < mDB.getSpeedGrades().size(); i++) {
265  cout << " " << mDB.getSpeedGrades()[i];
266  }
267  cout << endl;
268 
269  cout << "Total tiles: " << mTiles.getTileCount() << endl;
270  cout << "Family tile type count: " << mTiles.getTileTypeCount() << endl;
271  cout << "Tilemap dimensions: " << mTiles.getRowCount() << " "
272  << mTiles.getColCount() << endl;
273  cout << "Wire use: " << mWireUsage.getWireUsageCount() << endl;
274  cout << "Arc use: " << mArcUsage.getArcUsageCount() << endl;
275  }
276  /// \brief List all tiles.
277  void getTileList() {
278  using std::cout;
279  using std::endl;
280  std::ios_base::fmtflags saveflags = cout.flags();
281 
282  for (TileIndex i(0); i < mTiles.getTileCount(); i++) {
284  cout << std::setw(6) << i << " type " << std::setw(3) << ti.getTypeIndex() << " "
285  << "(" << std::setw(3) << ti.getRow() << "," << std::setw(3) << ti.getCol()
286  << ") " << ti.getName() << endl;
287  }
288  cout.flags(saveflags);
289  }
290  /// \brief Filtered list of all tiles.
291  void getFilteredTileList(const string& inString) {
292  using std::cout;
293  using std::endl;
294  std::ios_base::fmtflags saveflags = cout.flags();
295 
296  // Replace all asterisks in the input string with regex wildcards (".*")
297  std::string userPattern = regex_replace(inString, boost::regex("(?<!\\.)\\*"), ".*");
298 
299  // Build regex
300  boost::regex sTileNameRegEx(userPattern, boost::regex::perl | boost::regex::icase
301  | boost::regex::no_except);
302  // Check regex syntax
303  if (sTileNameRegEx.empty()) {
304  cout << "Bad regular expression. Try again." << endl;
305  return;
306  }
307 
308  // Print matching sites
309  boost::smatch smatches;
310  int matchCount = 0;
311  for (TileIndex i(0); i < mTiles.getTileCount(); i++) {
313  if (regex_match(std::string(ti.getName()), smatches, sTileNameRegEx)) {
314  matchCount++;
315  cout << std::setw(6) << i << " type " << std::setw(3) << ti.getTypeIndex() << " "
316  << "(" << std::setw(3) << ti.getRow() << "," << std::setw(3) << ti.getCol()
317  << ") " << ti.getName() << endl;
318  }
319  }
320 
321  // Output # matches
322  cout << endl << matchCount << " match" << (matchCount == 1 ? "." : "es.") << endl;
323 
324  cout.flags(saveflags);
325  }
326  /// \brief List of all sites.
327  void getSiteList() {
328  using std::cout;
329  using std::endl;
330  std::ios_base::fmtflags saveflags = cout.flags();
331 
332  for (SiteIndex i(0); i < mSites.getSiteCount(); i++) {
333  const architecture::Site& site = mSites.getSite(i);
334  cout << std::setw(7) << i << " " << site.getName() << endl;
335  }
336  cout.flags(saveflags);
337  }
338  /// \brief Filtered list of all sites.
339  void getFilteredSiteList(const string& inString) {
340  using std::cout;
341  using std::endl;
342  std::ios_base::fmtflags saveflags = cout.flags();
343 
344  // Replace all asterisks in the input string with regex wildcards (".*")
345  std::string userPattern = regex_replace(inString, boost::regex("(?<!\\.)\\*"), ".*");
346 
347  // Build regex
348  boost::regex sSiteNameRegEx(userPattern, boost::regex::perl | boost::regex::icase
349  | boost::regex::no_except);
350  // Check regex syntax
351  if (sSiteNameRegEx.empty()) {
352  cout << "Bad regular expression. Try again." << endl;
353  return;
354  }
355 
356  // Print matching sites
357  boost::smatch smatches;
358  int matchCount = 0;
359  for (SiteIndex i(0); i < mSites.getSiteCount(); i++) {
360  const architecture::Site& site = mSites.getSite(i);
361  if (regex_match(site.getName(), smatches, sSiteNameRegEx)) {
362  matchCount++;
363  cout << std::setw(7) << i << " " << site.getName() << endl;
364  }
365  }
366 
367  // Output # matches
368  cout << endl << matchCount << " match" << (matchCount == 1 ? "." : "es.") << endl;
369 
370  cout.flags(saveflags);
371  }
372  /// brief Site detail function.
373  void getSiteDetail(const string& inString) {
374  using std::cout;
375  using std::endl;
376  std::ios_base::fmtflags saveflags = cout.flags();
377  SiteIndex siteIndex(0);
378  std::string siteName;
379  boost::smatch smatches;
380  if (regex_match(inString, smatches, ArchitectureBrowser::sIndexRegEx)) {
381  siteIndex = boost::lexical_cast<SiteIndex>(smatches[1]);
382  if (siteIndex >= mSites.getSiteCount()) {
383  cout << "Site index " << siteIndex << " out of range! "
384  << mSites.getSiteCount() << endl;
385  return;
386  }
387  } else if (regex_match(inString, smatches, ArchitectureBrowser::sNameRegEx)) {
388  siteIndex = mSites.findSiteIndex(inString);
389  if (siteIndex == SiteIndex(-1)) {
390  cout << "Site not found: " << inString << endl;
391  return;
392  }
393  } else {
394  cout << "Input invalid: " << inString << endl;
395  return;
396  }
397  const architecture::Site& site = mSites.getSite(siteIndex);
398  cout << "Site: " << site.getName() << endl;
399  cout << "\tTile: " << mTiles.getTileInfo(site.getTileIndex()).getName()
400  << " (" << site.getTileIndex() << ") " << endl;
401  cout << "\tFlags: " << std::hex << site.getFlags() << endl;
402  cout << std::dec << "\tPinMapPtr" << endl << "\t\t";
403  for (unsigned int i = 0; i < (site.getPinMapPtr())->getSize(); i++) {
404  cout << " " << (*site.getPinMapPtr())[i];
405  }
406  cout << endl;
407  const PrimitiveDef& primDef = *site.getPrimitiveDefPtr();
408  cout << "\tPrimitive Definition: " << primDef.getName() << endl;
409  cout.flags(saveflags);
410 
411  }
412  /// brief Sites of a particular type function.
413  void displaySitesOfType(const string& inString) {
414  using std::cout;
415  using std::endl;
416  std::ios_base::fmtflags saveflags = cout.flags();
417 
418  for (SiteIndex i(0); i < mSites.getSiteCount(); i++) {
419  const architecture::Site& site = mSites.getSite(i);
420  const PrimitiveDef* siteTypePtr = site.getPrimitiveDefPtr();
421  if (siteTypePtr->getName() == inString)
422  cout << std::setw(7) << i << " " << site.getName() << endl;
423  }
424 
425  cout.flags(saveflags);
426  }
427  /// \brief Tilewire detail function.
428  void getTilewireDetail(const string& inString) {
429  using std::cout;
430  using std::endl;
431  Tilewire tw = stringToTilewire(inString);
432  if (tw == Tilewire::sInvalid) {
433  cout << "Specified tilewire not found: " << inString << endl;
434  return;
435  }
436  TileTypeIndex tti = mTiles.getTileInfo(tw.getTileIndex()).getTypeIndex();
438  cout << ewi << endl;
439  const architecture::WireInfo& wireinfo = mTiles.getWireInfo(tti, tw.getWireIndex());
440  cout << "\toffset: " << wireinfo.getArcOffset() << endl;
441  cout << "\tattributes: ";
442  cout << (wireinfo.isHidden() ? "HIDDEN " : "");
443  cout << (wireinfo.isInput() ? "INPUT " : "");
444  cout << (wireinfo.isOutput() ? "OUTPUT " : "");
445  cout << (wireinfo.isRemote() ? "REMOTE " : "");
446  cout << (wireinfo.isGlobal() ? "GLOBAL " : "");
447  cout << (wireinfo.isRemoteNodeCapable() ? "REMOTE_NODE_CAPABLE " : "");
448  cout << (wireinfo.isRemoteArcCapable() ? "REMOTE_ARC_CAPABLE " : "") << endl;
449  const architecture::WireArray& sinks = wireinfo.getSinks();
450  cout << "\tsinks: ";
451  for (uint32_t i = 0; i < sinks.getSize(); i++) cout << sinks[i] << " "; cout << endl;
452 
453  const architecture::WireArray& sources = wireinfo.getSources();
454  cout << "\tsources: ";
455  for (uint32_t i = 0; i < sources.getSize(); i++) cout << sources[i] << " "; cout << endl;
456 
457  const architecture::WireArray& isinks = wireinfo.getIrregularSinks();
458  cout << "\tirregular sinks: ";
459  for (uint32_t i = 0; i < isinks.getSize(); i++) cout << isinks[i] << " "; cout << endl;
460 
461  const architecture::WireArray& isources = wireinfo.getIrregularSources();
462  cout << "\tirregular sources: ";
463  for (uint32_t i = 0; i < isources.getSize(); i++) cout << isources[i] << " "; cout << endl;
464 
465  const architecture::WireArray& tsinks = wireinfo.getTiedSinks();
466  cout << "\ttied sinks: ";
467  for (uint32_t i = 0; i < tsinks.getSize(); i++) cout << tsinks[i] << " "; cout << endl;
468 
469  const architecture::WireArray& tsources = wireinfo.getTiedSources();
470  cout << "\ttied sources: ";
471  for (uint32_t i = 0; i < tsources.getSize(); i++) cout << tsources[i] << " "; cout << endl;
472 
473  /// \todo SegmentReference with internal segment data?
474 
475  architecture::TilewireVector segmentwires;
476  mDB.expandSegment(tw, segmentwires);
477  cout << "\t";
478  for (uint32_t i = 0; i < segmentwires.size(); i++) cout << segmentwires[i] << " ";
479  cout << endl;
480  }
481  /// \brief Display source Tilewires of a segment.
482  void displaySegmentSources(const string& inString) {
483  using std::cout;
484  using std::endl;
485 
486  Tilewire tw = stringToTilewire(inString);
487  if (tw == Tilewire::sInvalid) {
488  cout << inString << " is not a valid Tilewire" << endl;
489  return;
490  }
491  architecture::TilewireVector segmentWires;
492  architecture::TilewireVector sourceWires;
493  cout << "Sources for segment containing: " << inString << endl;
494  mDB.expandSegment(tw, segmentWires);
495  for (uint32_t i = 0; i < segmentWires.size(); i++) {
496  architecture::ExtendedWireInfo ewi(mDB, segmentWires[i]);
497  cout << "|\t" << ewi << endl;
498  sourceWires.clear();
499  mDB.expandTilewireSources(segmentWires[i], sourceWires, false, true, false, false);
500  for (uint32_t j = 0; j < sourceWires.size(); j++) {
501  architecture::ExtendedWireInfo ewi2(mDB, sourceWires[j]);
502  cout << "|<--\t\t" << ewi2 << endl;
503  }
504  sourceWires.clear();
505  mDB.expandTilewireSources(segmentWires[i], sourceWires, false, false, true, false);
506  for (uint32_t j = 0; j < sourceWires.size(); j++) {
507  architecture::ExtendedWireInfo ewi2(mDB, sourceWires[j]);
508  cout << "|<--\t\t" << ewi2 << " - IRREGULAR" << endl;
509  }
510  sourceWires.clear();
511  mDB.expandTilewireSources(segmentWires[i], sourceWires, false, false, false, true);
512  for (uint32_t j = 0; j < sourceWires.size(); j++) {
513  architecture::ExtendedWireInfo ewi2(mDB, sourceWires[j]);
514  cout << "|<--\t\t" << ewi2 << " - ROUTETHROUGH" << endl;
515  }
516  }
517  }
518  /// \brief Display sink Tilewires of a segment.
519  void displaySegmentSinks(const string& inString) {
520  using std::cout;
521  using std::endl;
522 
523  Tilewire tw = stringToTilewire(inString);
524  if (tw == Tilewire::sInvalid) {
525  cout << inString << " is not a valid Tilewire" << endl;
526  return;
527  }
528  architecture::TilewireVector segmentWires;
530  cout << "Sinks for segment containing: " << inString << endl;
531  mDB.expandSegment(tw, segmentWires);
532  for (uint32_t i = 0; i < segmentWires.size(); i++) {
533  architecture::ExtendedWireInfo ewi(mDB, segmentWires[i]);
534  cout << "|\t" << ewi << endl;
535  sinkWires.clear();
536  mDB.expandTilewireSinks(segmentWires[i], sinkWires, false, true, false, false);
537  for (uint32_t j = 0; j < sinkWires.size(); j++) {
538  architecture::ExtendedWireInfo ewi2(mDB, sinkWires[j]);
539  cout << "|-->\t\t" << ewi2 << endl;
540  }
541  sinkWires.clear();
542  mDB.expandTilewireSinks(segmentWires[i], sinkWires, false, false, true, false);
543  for (uint32_t j = 0; j < sinkWires.size(); j++) {
544  architecture::ExtendedWireInfo ewi2(mDB, sinkWires[j]);
545  cout << "|-->\t\t" << ewi2 << " - IRREGULAR" << endl;
546  }
547  sinkWires.clear();
548  mDB.expandTilewireSinks(segmentWires[i], sinkWires, false, false, false, true);
549  for (uint32_t j = 0; j < sinkWires.size(); j++) {
550  architecture::ExtendedWireInfo ewi2(mDB, sinkWires[j]);
551  cout << "|-->\t\t" << ewi2 << " - ROUTETHROUGH" << endl;
552  }
553  }
554  }
555  /// \brief Display segment connectivity.
556  void displayFullSegment(const string& inString) {
557  using std::cout;
558  using std::endl;
559 
560  std::map<string, std::vector<string> > sourcemap;
561  std::map<string, std::vector<string> > sinkmap;
562  std::vector<string> segmentstrings;
563 
564  Tilewire tw = stringToTilewire(inString);
565  if (tw == Tilewire::sInvalid) {
566  cout << inString << " is not a valid Tilewire" << std::endl;
567  return;
568  }
569  architecture::TilewireVector segmentwires;
571  mDB.expandSegment(tw, segmentwires);
572  for (uint32_t i = 0; i < segmentwires.size(); i++) {
573  architecture::ExtendedWireInfo ewi(mDB, segmentwires[i]);
574  std::stringstream segwire;
575  segwire << ewi;
576  string segwirestring = segwire.str();
577  segmentstrings.push_back(segwirestring);
578 
579  sinkmap[segwirestring] = std::vector<string>();
580  sourcemap[segwirestring] = std::vector<string>();
581 
582  arcwires.clear();
583  mDB.expandTilewireSinks(segmentwires[i], arcwires);
584  for (uint32_t j = 0; j < arcwires.size(); j++) {
585  architecture::ExtendedWireInfo ewi2(mDB, arcwires[j]);
586  std::stringstream arcwire;
587  arcwire << ewi2;
588 
589  sinkmap[segwirestring].push_back(arcwire.str());
590  }
591  arcwires.clear();
592  mDB.expandTilewireSources(segmentwires[i], arcwires);
593  for (uint32_t j = 0; j < arcwires.size(); j++) {
594  architecture::ExtendedWireInfo ewi2(mDB, arcwires[j]);
595  std::stringstream arcwire;
596  arcwire << ewi2;
597 
598  sourcemap[segwirestring].push_back(arcwire.str());
599  }
600  }
601  cout << "Displaying segment containing: " << inString << endl;
602  /*for (uint32_t i = 0; i < segmentstrings.size(); i++) {
603  //cout << "\t\t" << segmentstrings[i] << endl;
604  for (uint32_t j = 0; j < sourcemap[segmentstrings[i]].size(); j++) {
605  cout << "|<--\t" << sourcemap[segmentstrings[i]][j] << endl;
606  }
607  cout << "|\t\t" << segmentstrings[i] << endl;
608  for (uint32_t j = 0; j < sinkmap[segmentstrings[i]].size(); j++) {
609  cout << "|-->\t\t\t" << sinkmap[segmentstrings[i]][j] << endl;
610  }
611  }*/
612  for (uint32_t i = 0; i < segmentstrings.size(); i++) {
613  cout << "|" << endl << "| " << segmentstrings[i] << endl;
614 
615  for (uint32_t j = 0; j < sourcemap[segmentstrings[i]].size(); j++) {
616  cout << "| <--- " << sourcemap[segmentstrings[i]][j] << endl;
617  }
618  for (uint32_t j = 0; j < sinkmap[segmentstrings[i]].size(); j++) {
619  cout << "| ---> " << sinkmap[segmentstrings[i]][j] << endl;
620  }
621  }
622 
623  }
624  /// \brief Display segment connectivity.
625  void displayFullSegmentFANCY(const string& inString) {
626  using std::cout;
627  using std::endl;
628 
629  std::map<string, std::vector<string> > sourcemap;
630  std::map<string, std::vector<string> > sinkmap;
631  std::vector<string> segmentstrings;
632 
633  Tilewire tw = stringToTilewire(inString);
634  architecture::TilewireVector segmentwires;
636  mDB.expandSegment(tw, segmentwires);
637  for (uint32_t i = 0; i < segmentwires.size(); i++) {
638  architecture::ExtendedWireInfo ewi(mDB, segmentwires[i]);
639  std::stringstream segwire;
640 
641  segwire << ewi;
642  string segwirestring = segwire.str();
643  segmentstrings.push_back(segwirestring);
644 
645  sinkmap[segwirestring] = std::vector<string>();
646  sourcemap[segwirestring] = std::vector<string>();
647 
648  arcwires.clear();
649  mDB.expandTilewireSinks(segmentwires[i], arcwires);
650  for (uint32_t j = 0; j < arcwires.size(); j++) {
651  architecture::ExtendedWireInfo ewi2(mDB, arcwires[j]);
652  std::stringstream arcwire;
653 
654  arcwire << ewi2;
655 
656  sinkmap[segwirestring].push_back(arcwire.str());
657  }
658  arcwires.clear();
659  mDB.expandTilewireSources(segmentwires[i], arcwires);
660  for (uint32_t j = 0; j < arcwires.size(); j++) {
661  architecture::ExtendedWireInfo ewi2(mDB, arcwires[j]);
662  std::stringstream arcwire;
663 
664  arcwire << ewi2;
665 
666  sourcemap[segwirestring].push_back(arcwire.str());
667  }
668  }
669 
670  uint32_t sourcewidth = 0;
671  uint32_t segwidth = 0;
672  uint32_t sinkwidth = 0;
673 
674  std::map<string, std::vector<string> >::iterator e;
675  std::map<string, std::vector<string> >::iterator p;
676 
677  e = sourcemap.end();
678  for (p = sourcemap.begin(); p != e; p++) {
679  // get length of longest string
680  for (uint32_t j = 0; j < p->second.size(); j++) {
681  if (p->second[j].size() > sourcewidth) sourcewidth = p->second[j].size();
682  }
683  }
684  e = sinkmap.end();
685  for (p = sinkmap.begin(); p != e; p++) {
686  // get length of longest string
687  for (uint32_t j = 0; j < p->second.size(); j++) {
688  if (p->second[j].size() > sinkwidth) sinkwidth = p->second[j].size();
689  }
690  }
691  for (uint32_t i = 0; i < segmentstrings.size(); i++) {
692  if (segmentstrings[i].size() > segwidth) segwidth = segmentstrings[i].size();
693  }
694  sourcewidth += 2;
695  segwidth += 2;
696  sinkwidth += 2;
697 
698  for (uint32_t i = 0; i < segmentstrings.size(); i++) {
699  std::map<string, std::vector<string> >::iterator p;
700  p = sourcemap.find(segmentstrings[i]);
701  if (p != sourcemap.end() && p->second.size() > 0) {
702  for (uint32_t j = 0; j < p->second.size() - 1; j++) {
703  cout << " " << p->second[j];
704  for (uint32_t k = p->second[j].size(); k < sourcewidth; k++) cout << " ";
705  cout << "|" << endl;
706  }
707  cout << " " << p->second[p->second.size() - 1];
708  for (uint32_t k = p->second[p->second.size() - 1].size();
709  k < sourcewidth; k++) cout << " ";
710  cout << "+ ";
711  } else {
712  for (uint32_t k = 0; k < sourcewidth + 3; k++) cout << " ";
713  }
714 
715  cout << segmentstrings[i];
716  for (uint32_t k = segmentstrings[i].size(); k < segwidth; k++) cout << " ";
717  p = sinkmap.find(segmentstrings[i]);
718  if (p != sinkmap.end()) {
719  if (p->second.size() > 0) cout << " + " << p->second[0] << endl;
720  else cout << endl;
721  for (uint32_t j = 1; j < p->second.size(); j++) {
722  for (uint32_t k = 0; k < sourcewidth + segwidth + 4; k++) cout << " ";
723  cout << "| " << p->second[j] << endl;
724  }
725  }
726  }
727 
728  }
729  /// \brief List all wires for a given tile type.
730  void getWireListForTileType(const string& inString) {
731  using std::cout;
732  using std::endl;
733 
734  TileTypeIndex tileType(0);
735  TileIndex tileIndex(0);
736  string tileTypeName;
737  string tileName;
738 
739  boost::smatch smatches;
740  if (regex_match(inString, smatches, ArchitectureBrowser::sIndexRegEx)) {
741  tileType = boost::lexical_cast<TileTypeIndex>(smatches[1]);
742  if (tileType >= mTiles.getTileTypeCount()) {
743  cout << "Type index " << tileType << " out of range! "
744  << mTiles.getTileTypeCount() << endl;
745  return;
746  }
747  tileTypeName = mTiles.getTileTypeName(tileType);
748  } else if (regex_match(inString, smatches, ArchitectureBrowser::sNameRegEx)) {
749  bool flag = false;
750  tileTypeName = smatches[1];
751  for ( ; tileType < mTiles.getTileTypeCount(); tileType++) {
752  if (tileTypeName == mTiles.getTileTypeName(tileType)) {
753  flag = true;
754  break;
755  }
756  }
757  tileName = tileTypeName;
758  for ( ; tileIndex < mTiles.getTileCount(); tileIndex++) {
759  const architecture::TileInfo& tileInfo = mTiles.getTileInfo(tileIndex);
760  if (tileTypeName == tileInfo.getName()) {
761  tileType = tileInfo.getTypeIndex();
762  tileTypeName = mTiles.getTileTypeName(tileType);
763  flag = true;
764  break;
765  }
766  }
767  if (!flag) {
768  cout << inString << " not found." << endl;
769  return;
770  }
771  } else {
772  cout << "Input invalid: " << inString << endl;
773  return;
774  }
775 
777  mTiles.getWireInfo(tileType);
778 
779  cout << "Wires for tile type: " << tileTypeName << " (" << tileType << ")" << endl;
780  for (uint32_t i = 0; i < wireInfoArray.getSize(); i++) {
781  const WireInfo& wireInfo = wireInfoArray[i];
782  cout << "\t" << i << ": " << wireInfo.getName();
783  cout << (wireInfo.isHidden() ? " (HIDDEN) " : "");
784  cout << (wireInfo.isInput() ? " (INPUT) " : "");
785  cout << (wireInfo.isOutput() ? " (OUTPUT) " : "");
786  cout << (wireInfo.isRemote() ? " (REMOTE) " : "");
787  cout << (wireInfo.isGlobal() ? " (GLOBAL) " : "");
788  cout << (wireInfo.isRemoteNodeCapable() ? " (REMOTE_NODE_CAPABLE) " : "");
789  cout << (wireInfo.isRemoteArcCapable() ? " (REMOTE_ARC_CAPABLE) " : "");
790  cout << endl;
791  }
792  }
794  using std::cout;
795  using std::endl;
796  cout << "Device Site Types:" << endl;
797 
799  for (uint32_t i = 0; i < siteTypes.getSize(); i++) {
800  cout << siteTypes[i].getName() << endl;
801  }
802  }
803 public:
804  /// \brief Convert user input to a Tilewire.
805  Tilewire stringToTilewire(const string& inString) {
806  TileIndex tile;
807  WireIndex wire;
808 
809  boost::smatch smatches;
810  boost::smatch smatches2;
811  if (regex_match(inString, smatches, ArchitectureBrowser::sTilewireRegEx)) {
812  // wire@tile form
813  string tilePart = smatches[2];
814  boost::to_upper(tilePart);
815  if (regex_match(tilePart, smatches2, ArchitectureBrowser::sIndexRegEx)) {
816  tile = boost::lexical_cast<TileIndex>(smatches2[1]);
817  } else if (regex_match(tilePart, smatches2, ArchitectureBrowser::sNameRegEx)) {
818  tile = mTiles.findTileIndex(tilePart);
819  } else {
820  return Tilewire::sInvalid;
821  }
822  if (tile >= mTiles.getTileCount()) return Tilewire::sInvalid;
824  string wirePart = smatches[1];
825  boost::to_upper(wirePart);
826  if (regex_match(wirePart, smatches2, ArchitectureBrowser::sIndexRegEx)) {
827  wire = boost::lexical_cast<WireIndex>(smatches2[1]);
828  } else if (regex_match(wirePart, smatches2, ArchitectureBrowser::sNameRegEx)) {
829  wire = mTiles.findWireIndex(tti, wirePart);
830  } else {
831  return Tilewire::sInvalid;
832  }
833  if (wire >= mTiles.getWireInfo(tti).getSize()) return Tilewire::sInvalid;
834  return Tilewire(tile, wire);
835  }
836  else {
837  return Tilewire::sInvalid;
838  }
839  }
840  /// \brief Print the full menu of browser functions.
841  void printFullMenu();
842  /// \brief Prepare function map to lookup what the user asks for.
843  void setupFunctionMap();
844 
845 };
846 
847 } // namespace torc
848 
849 #endif // TORC_UTILS_ARCHITECTUREBROWSER_HPP
const Sites & mSites
Site data reference from the database.
const WireIndex & getWireIndex(void) const
Returns the wire index.
Definition: Tilewire.hpp:66
architecture::xilinx::TileCount TileCount
Imported type name.
SiteCount getSiteCount(void) const
Returns the site count for this device.
Definition: Sites.hpp:121
Encapsulation of a tile index in an unsigned 32-bit integer.
const TileCol & getCol(void) const
Returns the column for this tile.
Definition: TileInfo.hpp:96
void displayFullSegmentFANCY(const string &inString)
Display segment connectivity.
bool isOutput(void) const
Returns true if the wire is a logic output.
Definition: WireInfo.hpp:132
architecture::xilinx::SiteIndex SiteIndex
Imported type name.
std::vector< Tilewire > TilewireVector
Vector of Tilewire objects.
Definition: Tilewire.hpp:101
const TileRow & getRow(void) const
Returns the row for this tile.
Definition: TileInfo.hpp:94
Utility class for exploring database contents.
architecture::xilinx::TileIndex TileIndex
Imported type name.
const string & getDeviceName(void) const
Returns the device name.
Definition: DDB.hpp:132
architecture::Tilewire Tilewire
Imported type name.
const PrimitiveDef * getPrimitiveDefPtr(void) const
Returns a pointer to the associated primitive definition.
Definition: Site.hpp:81
Device database, including complete wiring and logic support.
Definition: DDB.hpp:42
TileTypeCount getTileTypeCount(void) const
Returns the tile type count for this device.
Definition: Tiles.hpp:151
TileRow getRowCount(void) const
Returns the row count for this device.
Definition: Tiles.hpp:153
bool isGlobal(void) const
Returns true if the wire is a global wire (a what!?).
Definition: WireInfo.hpp:136
Array of wire indexes.
Definition: WireInfo.hpp:31
const string & getFamilyName(void) const
Returns the family name.
Definition: DDB.hpp:134
void getFilteredSiteList(const string &inString)
Filtered list of all sites.
void getFilteredTileList(const string &inString)
Filtered list of all tiles.
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
Encapsulation of primitive site definition, with associated connections, elements, and pins.
const uint16_t getArcOffset(void) const
Returns this wire's offset into the arc usage bitset.
Definition: WireInfo.hpp:105
bool isInput(void) const
Returns true if the wire is a logic input.
Definition: WireInfo.hpp:130
void getWireListForTileType(const string &inString)
List all wires for a given tile type.
static boost::regex sTilewireRegEx
Regular expression for Tilewire form.
const WireArray & getIrregularSinks(void) const
Returns the irregular sink array for this wire.
Definition: WireInfo.hpp:119
uint32_t getArcUsageCount(void) const
Returns the number of arcs in use.
Definition: ArcUsage.hpp:228
Header for the DDBStreamHelper class.
ArchitectureBrowser(DDB &inDB)
Constructor.
architecture::Sites Sites
Imported type name.
const Array< const WireInfo > & getWireInfo(TileTypeIndex inTileTypeIndex) const
Returns the WireInfo array for the specified tile type.
Definition: Tiles.hpp:140
const WireArray & getSources(void) const
Returns the source array for this wire.
Definition: WireInfo.hpp:117
architecture::DDB DDB
Imported type name.
bool isHidden(void) const
Returns true if the wire is hidden in traces.
Definition: WireInfo.hpp:128
Encapsulation of a wire index in an unsigned 16-bit integer.
void displaySitesOfType(const string &inString)
brief Sites of a particular type function.
TileCount getTileCount(void) const
Returns the tile count for this device.
Definition: Tiles.hpp:149
ArcUsage & mArcUsage
Pip usage information from the database.
std::string string
const StringVector & getSpeedGrades(void) const
Returns a constant reference to a vector of speed grades.
Definition: DDB.hpp:140
uint32_t getWireUsageCount(void) const
Returns the number of wires in use.
Definition: WireUsage.hpp:151
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
architecture::WireInfo WireInfo
Imported type name.
void getTileList()
List all tiles.
architecture::PrimitiveDef PrimitiveDef
Imported type name.
const Array< const PrimitiveDef > & getSiteTypes(void) const
Returns the site types for this family.
Definition: Sites.hpp:125
const WireArray & getTiedSources(void) const
Returns the tied source array for this wire.
Definition: WireInfo.hpp:113
SiteFlags getFlags(void) const
Returns the flags associated with this site.
Definition: Site.hpp:85
DDB & mDB
Database Reference.
Header for torc::physical output stream helpers.
Encapsulation of a device logic site.
Definition: Site.hpp:30
const WireArray & getIrregularSources(void) const
Returns the irregular source array for this wire.
Definition: WireInfo.hpp:121
bool isRemoteArcCapable(void) const
Returns true if the wire may be referenced by a remote arc.
Definition: WireInfo.hpp:140
Site type and population data for the family and the device.
Definition: Sites.hpp:45
void browse()
Function to begin an interactive browsing session.
Encapsulation of a device tile and wire pair.
Definition: Tilewire.hpp:39
const string & getName(void) const
Returns the site name.
Definition: Site.hpp:79
void displaySegmentSources(const string &inString)
Display source Tilewires of a segment.
architecture::Segments Segments
Imported type name.
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
Encapsulation of a tile count in an unsigned 32-bit integer.
const WireArray & getSinks(void) const
Returns the sink array for this wire.
Definition: WireInfo.hpp:115
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
Encapsulation of a tile within a device tile map.
Definition: TileInfo.hpp:33
const char * getTileTypeName(TileTypeIndex inTileTypeIndex) const
Returns the tile type name for the given tile type index.
Definition: Tiles.hpp:164
Verbose encapsulation of a wire's information.
SiteIndex findSiteIndex(const string &inName) const
Returns the site index for the given site name.
Definition: Sites.hpp:134
architecture::ArcUsage ArcUsage
Imported type name.
TileIndex getTileIndex(void) const
Returns the index of the containing tile.
Definition: Site.hpp:83
const TileTypeIndex & getTypeIndex(void) const
Returns the tile type index for this tile.
Definition: TileInfo.hpp:92
void displaySegmentSinks(const string &inString)
Display sink Tilewires of a segment.
void getSiteDetail(const string &inString)
brief Site detail function.
architecture::xilinx::TileTypeIndex TileTypeIndex
Imported type name.
const Site & getSite(SiteIndex inSiteIndex) const
Returns the site for the specified index.
Definition: Sites.hpp:129
EFunctionMap
Enumeration of menu selection options.
TileIndex findTileIndex(const string &inName) const
Returns the tile index for the given tile name.
Definition: Tiles.hpp:170
void setupFunctionMap()
Prepare function map to lookup what the user asks for.
void getSiteList()
List of all sites.
void(ArchitectureBrowser::* BrowserFunction)(const std::string &x)
Type for member function pointers.
TileCol getColCount(void) const
Returns the column count for this device.
Definition: Tiles.hpp:155
Encapsulation of a site index in an unsigned 32-bit integer.
architecture::WireUsage WireUsage
Imported type name.
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
Tilewire stringToTilewire(const string &inString)
Convert user input to a Tilewire.
Encapsulation of a tile type index in an unsigned 16-bit integer.
void functionPrompt(const char *inPrompt, BrowserFunction f)
Secondary menu loop to remain in a particular function.
const char * getName(void) const
Returns the name for this tile.
Definition: TileInfo.hpp:98
const WireArray & getTiedSinks(void) const
Returns the tied sink array for this wire.
Definition: WireInfo.hpp:111
Header for the DDB class.
static boost::regex sNameRegEx
Regular expression for a name.
const TileIndex & getTileIndex(void) const
Returns the tile index.
Definition: Tilewire.hpp:64
Encapsulation of a wire within a tile type.
Definition: WireInfo.hpp:36
static const Tilewire sInvalid
Definition: Tilewire.hpp:93
static boost::regex sIndexRegEx
Regular expression for nonnegative integers.
std::string string
Imported type name.
void displayFullSegment(const string &inString)
Display segment connectivity.
Segment and irregular arc data for the device.
Definition: Segments.hpp:40
const Segments & mSegments
Segments reference from the database.
void printFullMenu()
Print the full menu of browser functions.
const char * getName(void) const
Returns the name for this wire.
Definition: WireInfo.hpp:109
architecture::TilewireVector TilewireVector
Imported type name.
WireUsage & mWireUsage
Wire usage information from the database.
std::map< string, EFunctionMap > mFunctionMap
Mapping from function to index.
const WireIndexArray * getPinMapPtr(void) const
Returns the pin to wire map for this site.
Definition: Site.hpp:87
void deviceSummary()
A brief summary of device information.
bool isRemote(void) const
Returns true if the wire is a remote wire.
Definition: WireInfo.hpp:134
architecture::Tiles Tiles
Imported type name.
architecture::xilinx::WireIndex WireIndex
Imported type name.
bool isRemoteNodeCapable(void) const
Returns true if the wire may be referenced by a remote wire.
Definition: WireInfo.hpp:138
Encapsulation of a static array.
Definition: Array.hpp:39
void expandSegment(const Tilewire &inTilewire, TilewireVector &outTilewires, EExpandDirection inExpandDirection=eExpandDirectionNone)
Expands the given tilewire's segment.
Definition: DDB.cpp:154
uint32_t getSize(void) const
Returns the array size.
Definition: Array.hpp:104
void getTilewireDetail(const string &inString)
Tilewire detail function.
const Tiles & mTiles
Tile data reference from the database.
const string & getName(void) const
Returns the name of the primitive.