torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LogicXdlGenerator.cpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL: https://svn.east.isi.edu/torc/trunk/src/torc/packer/Virtex5PrimitiveStructureUnitTest.cpp $
3 // $Id: Virtex5PrimitiveStructureUnitTest.cpp 768 2011-08-24 19:44:37Z nsteiner $
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 XDL generator for supported logic sites. Generates an XDL for each config and also
18 /// an harness XDL for each BEL or as required.
19 
22 #include <iostream>
23 #include <fstream>
24 #include <map>
25 #include "iomanip"
27 #include "torc/Physical.hpp"
28 #include "SharedFunctions.hpp"
29 
30 using namespace torc::architecture;
31 using namespace torc::packer;
32 using namespace torc::physical;
33 
34 // Constants
35 static const std::string kXDLReferenceFolder = "reference";
36 
37 // Globals
40 static std::map<std::string, std::string> gElementReferenceConfigMap;
41 
42 // Some elements generate 1 bit when configured to #OFF, which is not good for generating compressed bitstream.
43 // This map stores those configs which generate 0 bit in the bitstream.
45 
46  gElementReferenceConfigMap["LFSR_EN_SET"] = "SET";
47  gElementReferenceConfigMap["TEST_SET_P"] = "SET";
48  gElementReferenceConfigMap["MASK"] = "000000000000";
49  gElementReferenceConfigMap["PATTERN"] = "000000000000";
50 }
51 
52 // For most element #OFF is the reference config. But for some elements, #OFF generates 1 bit in bitstream.
53 // For such elements, the reference config is one which generates 0 bit in bitstream.
55  std::string configValue;
56  // if element present in the map of Element->ReferenceConfig, return it.
57  std::map<std::string, std::string>::const_iterator pElementConfigMap;
58  std::map<std::string, std::string>::const_iterator eElementConfigMap =
60  pElementConfigMap = gElementReferenceConfigMap.find(elementName);
61  if(pElementConfigMap != eElementConfigMap) {
62  return pElementConfigMap->second;
63  }
64 
65  return kConfigOff;
66 }
67 
68 // \brief Generates a custom reference XDL for the element.
69 void GenerateReferenceXDLForTheElement(const std::string &elementName, DesignSharedPtr harnessDesignPtr,
70  const std::string &xdlFileName) {
71  // We know harness XDL design has only one instance
72  InstanceSharedPtr instancePtr = *(harnessDesignPtr->instancesBegin());
73  // If no instance found, just return
74  if(!instancePtr) {
75  std::cerr << "No instance found in the harness " << harnessDesignPtr->getName() << std::endl;
76  return;
77  }
78 
79  // Set config value to #OFF for the given element
80  std::string configValue = GetReferenceConfigValueForElement(elementName);
81  instancePtr->setConfig(elementName, "", configValue);
82 
83  /* Generate an reference XDL file for this element's custom harness */
84  boost::filesystem::path referenceXDLFilePath = gXDLReferenceGenerationFolder / xdlFileName;
85 
86  std::ofstream fileStream(referenceXDLFilePath.string().c_str());
87  if(!fileStream.good()) {
88  std::cerr << "Could not open file " << referenceXDLFilePath.string() << std::endl;
89  return;
90  }
91 
92  // Export design as XDL
93  torc::physical::XdlExporter exporter(fileStream);
94  exporter(harnessDesignPtr);
95  fileStream.close();
96 
97  std::cout << "\tGenerated reference XDL " << referenceXDLFilePath.string() << std::endl;
98 }
99 
100 // Given a site type and harness folder, return XDL design shared pointer for harness of the site type
102  const boost::filesystem::path &harnessFolderPath) {
103 
104  boost::filesystem::path harnessFilePath(harnessFolderPath);
105 
106  torc::physical::DesignSharedPtr harnessDesignPtr;
107  std::stringstream ssHarnessFileName;
108  // ssHarnessFileName << "Virtex5_" << siteType << ".xdl";
109  ssHarnessFileName << kArchitectureName << kNameSeparator << siteType << ".xdl";
110 
111  harnessFilePath = harnessFilePath / ssHarnessFileName.str();
112 
113  std::ifstream fileStream(harnessFilePath.string().c_str());
114  if(!fileStream.good()) {
115  std::cerr << "Could not open file " << harnessFilePath.string() << std::endl;
116  return harnessDesignPtr;
117  }
119  importer(fileStream, ssHarnessFileName.str());
120 
121  fileStream.close();
122 
123  // Return the design pointer
124  harnessDesignPtr = importer.getDesignPtr();
125  return harnessDesignPtr;
126 }
127 
128 // Given element name, return the index of the element in PrimitiveElementArray
129 int FindPrimitiveElementByName(std::string elementName, PrimitiveStructureSharedPtr const primitiveStructurePtr) {
130 
131  int elementIndex = -1, index = 0;
132  const PrimitiveElementArray& elementsArray = primitiveStructurePtr->getPrimitiveDefPtr()->getElements();
133  PrimitiveElementArray::const_iterator pElements = elementsArray.begin();
134  PrimitiveElementArray::const_iterator eElements = elementsArray.end();
135 
136  // For every primitive element (BEL) in the site
137  while(pElements != eElements) {
138  if(pElements->getName().compare(elementName) == 0) {
139  elementIndex = index;
140  break;
141  }
142  pElements++; index++;
143  }
144  return elementIndex;
145 }
146 
147 // Sets given elemnt to given config and generates XDL
148 void SetConfigAndGenerateXDL(const std::string &elementName, const std::string & configVal,
149  const std::string & xdlFileName, torc::physical::DesignSharedPtr designPtr) {
150 
151  torc::physical::InstanceSharedPtr instancePtr = *(designPtr->instancesBegin());
152 
153  instancePtr->setConfig(elementName, "", configVal);
154  // create the appropriate file paths
155  boost::filesystem::path xdlFilePath = gXDLGenerationFolder / xdlFileName.c_str();
156 
157  // Export the design as XDL
158  std::fstream xdlExport(xdlFilePath.string().c_str(), std::ios_base::out);
159  torc::physical::XdlExporter fileExporter(xdlExport);
160  fileExporter(designPtr);
161  std::cout << "\tGenerated XDL file " << xdlFileName << std::endl;
162 }
163 
164 // Some elements do not require harness. Use empty design for such elements, but same metadata.
166  DesignSharedPtr emptyDesign = Factory::newDesignPtr(designPtr->getName(),
167  designPtr->getDevice(), designPtr->getPackage(), designPtr->getSpeedGrade(),
168  designPtr->getXdlVersion());
169 
170  return emptyDesign;
171 }
172 
173 // Some elements together affect the bitstream. Their combined settings decide which bits should be set in bitstream.
174 // Eg. In DSP48E, ACASCREG and AREG together affect the bitstream.
175 static void GenerateXdlForCompoundSettings(const PrimitiveElement &element1, std::string siteType,
176  PrimitiveStructureSharedPtr const primitiveStructurePtr, torc::physical::DesignSharedPtr designPtr) {
177 
178  std::vector<std::string> compoundElements = gCompoundSettingsMap[element1.getName()];
179  // For now assume there is only on element in the vector, i.e. there is a compound
180  // setting with only two elements.
181  if(compoundElements.size() != 1) {
182  std::cout << "Compound setting with more than two elements not handled currently"
183  << std::endl;
184  } else {
185 
186  // Generate XDLs with all permutations of configs of the two elements
187  // The two element names will be concatenated to form a compound element name Element1Element2.
188  // Similarly two config settings will be concatenated to form a compound config name.
189  std::string element1Name = element1.getName();
190  std::string element2Name = compoundElements[0];
191  std::string compoundElementName = element1Name + element2Name;
192 
193  // Get the other element
194  int elementIndex = FindPrimitiveElementByName(element2Name, primitiveStructurePtr);
195 
196  if(elementIndex == -1) {
197  std::cout << "Primitive element " << element2Name << " not found" << std::endl;
198  return;
199  }
200 
201  const PrimitiveElement &element2 = primitiveStructurePtr->getPrimitiveDefPtr()->getElements()[elementIndex];
202 
203  // Get the first instance
204  InstanceSharedPtr instancePtr = *(designPtr->instancesBegin());
205 
206  // Store the 2nd elements harness config
207  std::string harnessConfig2Val, harnessConfig2Name;
208  instancePtr->getConfig(element2Name, harnessConfig2Name, harnessConfig2Val);
209 
210  // Set element1 OFF and generate harness
211  std::string referenceXdlFileName = siteType + kNameSeparator + compoundElementName + kXDLExtension;
212  instancePtr->setConfig(element1Name, "", kConfigOff);
213  GenerateReferenceXDLForTheElement(element2Name, designPtr, referenceXdlFileName);
214 
215  // Iterate over configs of 1st element
216  const PrimitiveElement::StringSet &configs1 = element1.getCfgs();
217  PrimitiveElement::StringSet::const_iterator pConfigs1 = configs1.begin();
218  PrimitiveElement::StringSet::const_iterator eConfigs1 = configs1.end();
219 
220  while(pConfigs1 != eConfigs1) {
221 
222  // Iterate over configs of 2nd element.
223  const PrimitiveElement::StringSet &configs2 = element2.getCfgs();
224  PrimitiveElement::StringSet::const_iterator pConfigs2 = configs2.begin();
225  PrimitiveElement::StringSet::const_iterator eConfigs2 = configs2.end();
226 
227  while(pConfigs2 != eConfigs2) {
228 
229  // Form the XDL file name
230  std::string compoundConfigName = *pConfigs1 + *pConfigs2;
231  std::string xdlFileName = siteType + kNameSeparator + compoundElementName
232  + kNameSeparator + compoundConfigName + kXDLExtension;
233 
234  // Set element1 config and generate primary XDL
235  instancePtr->setConfig(element1Name, "", *pConfigs1);
236  SetConfigAndGenerateXDL(element2Name, *pConfigs2, xdlFileName, designPtr);
237  pConfigs2++;
238  }
239 
240  pConfigs1++;
241  }
242 
243  // Set original value of element2
244  instancePtr->setConfig(element2Name, harnessConfig2Name, harnessConfig2Val);
245  }
246 }
247 
248 void GenerateXdlForDSPMaskAndPattern(const std::string &elementName, std::string siteType,
250 
251  // We know for Virtex 5 DSP's mask and pattern have 12 hex characters as config value.
252  long long configValNumber = 1;
253 
254  std::string siteTypeAndElement = siteType + kNameSeparator + elementName;
255 
256  std::stringstream xdlReferenceFileName;
257  xdlReferenceFileName << siteTypeAndElement << kXDLExtension;
258  GenerateReferenceXDLForTheElement(elementName, designPtr, xdlReferenceFileName.str());
259 
260  for(int bitPosition = 0; bitPosition < 48; bitPosition++) {
261  std::stringstream ssConfigVal;
262  ssConfigVal << std::setfill('0') << std::setw(12) << std::hex << configValNumber;
263 
264  std::stringstream xdlFileName;
265  xdlFileName << siteTypeAndElement << kNameSeparator << bitPosition << kXDLExtension;
266 
267  SetConfigAndGenerateXDL(elementName, ssConfigVal.str(), xdlFileName.str(), designPtr);
268 
269  configValNumber = configValNumber << 1;
270 
271  }
272 
273  // Set the config to default again
274  InstanceSharedPtr instancePtr = *(designPtr->instancesBegin());
275  instancePtr->setConfig(elementName, "", GetReferenceConfigValueForElement(elementName));
276 }
277 
278 void GenerateXdlForLUT(const PrimitiveElement &elem, const std::string &xdlFileNamePartial,
280 
281  std::string elementName = elem.getName();
282 
283  std::cout << "Found a LUT " << elementName << std::endl;
284 
285  DesignSharedPtr emptyDesign = GetEmptyDesignWithSameMetadata(designPtr);
286  InstanceSharedPtr instancePtr = *(designPtr->instancesBegin());
287  InstanceSharedPtr emptyInstance = Factory::newInstancePtr(instancePtr->getName(),
288  instancePtr->getType(), instancePtr->getTile(), instancePtr->getSite(),
289  instancePtr->getBonding());
290  emptyDesign->addInstance(emptyInstance);
291 
292  const PrimitiveElementPinArray &pins = elem.getPins();
295 
296  // Generate reference XDL for LUT
297  std::string referenceXdlFileName = xdlFileNamePartial + kXDLExtension;
298  GenerateReferenceXDLForTheElement(elementName, emptyDesign, referenceXdlFileName);
299 
300  //For every output-input pin combination
301  while(pPins != ePins) {
302 
303  if(pPins->isOutput()) {
304 
307 
308  while(pPinsIn != ePinsIn) {
309  if(pPinsIn->isInput()) {
310 
311  std::string configVal = "#LUT:" + pPins->getName() + "=" + pPinsIn->getName();
312  std::stringstream xdlFileName;
313  xdlFileName << xdlFileNamePartial << kNameSeparator << configVal << ".xdl";
314 // GenerateReferenceXDLForTheElement(elementName, emptyDesign, xdlFileName.str());
315  SetConfigAndGenerateXDL(elementName, configVal, xdlFileName.str(), emptyDesign);
316  }
317  pPinsIn++;
318  }
319 
320  // Generate XDLs for output 1 also
321  std::string configVal = "#LUT:" + pPins->getName() + "=" + "1";
322  std::stringstream xdlFileName1;
323  xdlFileName1 << xdlFileNamePartial << kNameSeparator << configVal << ".xdl";
324 // GenerateReferenceXDLForTheElement(elementName, emptyDesign, xdlFileName1.str());
325  SetConfigAndGenerateXDL(elementName, configVal, xdlFileName1.str(), emptyDesign);
326 
327  configVal = "#LUT:" + pPins->getName() + "=" + "0";
328  std::stringstream xdlFileName0;
329  xdlFileName0 << xdlFileNamePartial << kNameSeparator << configVal << ".xdl";
330 // GenerateReferenceXDLForTheElement(elementName, emptyDesign, xdlFileName0.str());
331  SetConfigAndGenerateXDL(elementName, configVal, xdlFileName0.str(), emptyDesign);
332  }
333  pPins++;
334  }
335 
336 }
337 
338 void GenerateXdlForGenericElement(const PrimitiveElement &elem, const std::string &configVal,
339  const std::string &xdlFileNamePartial, torc::physical::DesignSharedPtr designPtr) {
340 
341  std::stringstream xdlFileName;
342  xdlFileName << xdlFileNamePartial << kNameSeparator << configVal << ".xdl";
343 
344 // GenerateReferenceXDLForTheElement(elem.getName(), designPtr, xdlFileName.str());
345 
346  SetConfigAndGenerateXDL(elem.getName(), configVal, xdlFileName.str(), designPtr);
347 
348 }
349 
351  const std::string &siteType, torc::physical::DesignSharedPtr designPtr) {
352 
353  std::cout << " Found a Orphan element " << elem.getName() << std::endl;
354 
355  std::string elementName = elem.getName();
356  std::string siteTypeAndElem = siteType + kNameSeparator + elementName;
357 
358  // Get and empty design with same metadata
359  DesignSharedPtr emptyDesign = GetEmptyDesignWithSameMetadata(designPtr);
360 
361  // Add an empty instance of same site type and location
362  InstanceSharedPtr instancePtr = *(designPtr->instancesBegin());
363 
364  InstanceSharedPtr emptyInstance = Factory::newInstancePtr(instancePtr->getName(),
365  instancePtr->getType(), instancePtr->getTile(), instancePtr->getSite(),
366  instancePtr->getBonding());
367 
368  emptyDesign->addInstance(emptyInstance);
369 
370  std::string referenceXdlFileName = siteTypeAndElem + kXDLExtension;
371  GenerateReferenceXDLForTheElement(elementName, emptyDesign, referenceXdlFileName);
372 
373  // Go over all the configs
374  const PrimitiveElement::StringSet &configs = elem.getCfgs();
375  PrimitiveElement::StringSet::const_iterator pConfigs = configs.begin();
376  PrimitiveElement::StringSet::const_iterator eConfigs = configs.end();
377 
378  // Iterate over configs of the primitive
379  while(pConfigs != eConfigs) {
380  GenerateXdlForGenericElement(elem, *pConfigs, siteTypeAndElem, emptyDesign);
381  pConfigs++;
382  }
383 }
384 
386  PrimitiveStructureSharedPtr const primitiveStructurePtr, const std::string &siteType,
387  DesignSharedPtr designPtr) {
388 
389  std::cout << "Found a " << elem.getName() << std::endl;
390 
391  std::string elementName = elem.getName();
392 
394  GenerateXdlForCompoundSettings(elem, siteType, primitiveStructurePtr, designPtr);
395  } else if(primitiveStructurePtr->isOrphan(elem) && elem.getName() != "SYNC_ATTR") {
396  GenerateXdlForOrphanElements(elem, siteType, designPtr);
397  } else {
398 
399  std::string siteTypeAndElem = siteType + kNameSeparator + elementName;
400 
401  const PrimitiveElement::StringSet &configs = elem.getCfgs();
402  PrimitiveElement::StringSet::const_iterator pConfigs = configs.begin();
403  PrimitiveElement::StringSet::const_iterator eConfigs = configs.end();
404 
405  // Iterate over configs of the primitive
406  while(pConfigs != eConfigs) {
407 
408  if(primitiveStructurePtr->isLUT(elem, *pConfigs)) {
409  GenerateXdlForLUT(elem, siteTypeAndElem, designPtr);
410  } else {
411  GenerateXdlForGenericElement(elem, *pConfigs, siteTypeAndElem, designPtr);
412  }
413 
414  pConfigs++;
415  }
416  }
417 }
418 
419 /// \brief Returns true if the library supports the site type.
420 bool LibrarySupportForSiteType(const std::string& siteType) {
421  std::cout << "Site type: " << siteType << std::endl;
422  return ( siteType.compare("SLICEM") == 0 ||
423  siteType.compare("SLICEL") == 0 ||
424  siteType.compare("RAMB36_EXP") == 0 ||
425  siteType.compare("DSP48E") == 0 ||
426  siteType.compare("BUFGCTRL") == 0 ||
427  siteType.compare("BUFDS") == 0 ||
428  siteType.compare("BUFR") == 0 ||
429  siteType.compare("BUFG") == 0);
430  // return 1; //Generate library files for all types just for information.
431 }
432 
433 // Returns true if the site is some form of RAMB site.
434 bool IsRAMBSite(const std::string &siteType) {
435  if(siteType.length() > 3) {
436  return siteType.substr(0, 4).compare("RAMB") == 0;
437  }
438  return false;
439 }
440 
441 // Returns true if it DSP site
442 bool IsDSPSite(const std::string &siteType) {
443  if(siteType.length() > 3) {
444  return siteType.substr(0, 3).compare("DSP") == 0;
445  }
446  return false;
447 }
448 
449 // This function generates an XDL with designPtr in libraryPath and another empty design in tempFolderPath
450 void GenerateRAMBBaseFile(const std::string &primitiveDefName,
452 
453  /* Generate XDL for designPtr in libraryPath */
454 
455  // Create XDL file name of the pattern <Architecture>-<SiteType>-<Element>-<Config>.xdl
456  std::stringstream ssXDLFileName;
457  ssXDLFileName << kArchitectureName << kNameSeparator << primitiveDefName << kNameSeparator
458  << primitiveDefName << kNameSeparator << "BASE.xdl";
459  boost::filesystem::path xdlFilePath = gXDLGenerationFolder / ssXDLFileName.str();
460  std::fstream xdlExport(xdlFilePath.string().c_str(), std::ios::out);
461  torc::physical::XdlExporter fileExporter(xdlExport);
462  fileExporter(designPtr);
463  xdlExport.close();
464 
465  /* Generate XDL for an empty design in tempFolderPath */
466 
467  // Get empty design
468  DesignSharedPtr emptyDesign = GetEmptyDesignWithSameMetadata(designPtr);
469  // Get empty design XDL path and open the file
470  boost::filesystem::path emptyDesignPath = gXDLReferenceGenerationFolder / ssXDLFileName.str();
471  std::fstream emptyDesignStream(emptyDesignPath.string().c_str(), std::ios::out);
472  // Get XDL exporter and export the empty design
473  torc::physical::XdlExporter emptyDesignExporter(emptyDesignStream);
474  emptyDesignExporter(emptyDesign);
475  emptyDesignStream.close();
476 
477  return;
478 
479 }
480 
481 /// \brief Generates XDLs for various site types. An XDL is generated for each
482 // config setting of each element. All the XDLs are generated with reference to
483 // a 'harness' XDL. Two sets of XDLs are generated for each config value - one with the config OFF
484 // and other with the config value set.
485 int main(int argc, char **argv) {
486 
487  if(argc != 3) {
488  std::cerr << "Invalid arguments. Usage: " << argv[0] <<
489  " <harness_folder> <xdl_generation_folder>" << std::endl;
490  exit (-1);
491  }
492  // get the part number
493  std::string partNumber = "xc5vfx130t";
494  // Initialize the DirectoryTree class
495  torc::common::DirectoryTree directoryTree(argv[0]);
496 
497  // Check if Harness folder path exists.
498  boost::filesystem::path harnessFolderPath = argv[1];
499  if(!boost::filesystem::exists(harnessFolderPath)) {
500  std::cout << "Folder " << harnessFolderPath.string() << " does not exist" << std::endl;
501  exit (-1);
502  }
503 
504  // Create the xdl generation folder if it doesn't exits
505  gXDLGenerationFolder = argv[2];
506  if(!boost::filesystem::exists(gXDLGenerationFolder))
507  boost::filesystem::create_directory(gXDLGenerationFolder);
509  if(!boost::filesystem::exists(gXDLReferenceGenerationFolder))
510  boost::filesystem::create_directory(gXDLReferenceGenerationFolder);
511 
512  // Initialize the map of element to reference config map
515 
516  // open and initialize a database
517  DDB ddb(partNumber);
518  // look up the logic sites in the device
519  const Sites& sites = ddb.getSites();
520  // define a vector of PrimitiveStructure objects
521  typedef std::map<std::string, PrimitiveStructureSharedPtr> PrimitiveStructuresSharedPtrMap;
522  PrimitiveStructuresSharedPtrMap primitiveStructures;
523  // look up the primitive def types
524  typedef const Array<const PrimitiveDef> PrimitiveDefArray;
525  PrimitiveDefArray& primitiveDefs = sites.getSiteTypes();
526  PrimitiveDefArray::const_iterator p = primitiveDefs.begin();
527  PrimitiveDefArray::const_iterator e = primitiveDefs.end();
528  // Store the corresponding primitive structures in a map.
529  while(p < e) {
530  // create a PrimitiveStructure object for this PrimitiveDef
531  PrimitiveStructureSharedPtr primitiveStructurePtr(new Virtex5PrimitiveStructure(&*p++));
532  const torc::architecture::PrimitiveDef* primitiveDefPtr =
533  primitiveStructurePtr->getPrimitiveDefPtr();
534  const std::string& primitiveDefName = primitiveDefPtr->getName();
535  // insert the PrimitiveStructure into the map
536  primitiveStructures[primitiveDefName] = primitiveStructurePtr;
537  }
538 
539  // iterate through the PrimitiveStructure entries in the map
540  PrimitiveStructuresSharedPtrMap::iterator psp = primitiveStructures.begin();
541  PrimitiveStructuresSharedPtrMap::iterator pse = primitiveStructures.end();
542 
543  // For every site type
544  while(psp != pse) {
545 
546  // look up the PrimitiveDef name and the PrimitiveStructureSharedPtr
547  std::string primitiveDefName = psp->first;
548  PrimitiveStructureSharedPtr primitiveStructurePtr = psp->second;
549 
550  psp++;
551  // If the site type is to be supported
552  if(LibrarySupportForSiteType(primitiveDefName)) {
553 
554  // Get the designPtr for test harness for this site type
556  primitiveDefName, harnessFolderPath);
557 
558  if(!designPtr) {
559  std::cout << "No test harness for site type " << primitiveDefName << std::endl;
560  continue;
561  }
562 
563  std::cout << "Working on site type " << primitiveDefName << std::endl;
564 
565  // Create the XDL file name (partial)
566  std::stringstream ssXdlFileName;
567  ssXdlFileName << kArchitectureName << kNameSeparator << primitiveDefName;
568 
569  if(IsRAMBSite(primitiveDefName)) {
570  GenerateRAMBBaseFile(primitiveDefName, designPtr);
571  }
572 
573  if(IsDSPSite(primitiveDefName)) {
574  GenerateXdlForDSPMaskAndPattern("MASK", ssXdlFileName.str(), designPtr);
575  GenerateXdlForDSPMaskAndPattern("PATTERN", ssXdlFileName.str(), designPtr);
576  }
577 
578  // We know the design has only one instance. So, get the first one in the iterator.
579  torc::physical::InstanceSharedPtr instancePtr = *(designPtr->instancesBegin());
580 
581  const torc::architecture::PrimitiveDef* primitiveDefPtr =
582  primitiveStructurePtr->getPrimitiveDefPtr();
583 
584  const PrimitiveElementArray& elements = primitiveDefPtr->getElements();
585 
586  PrimitiveElementArray::const_iterator pElements = elements.begin();
587  PrimitiveElementArray::const_iterator eElements = elements.end();
588 
589  // For every primitive element (BEL) in the site
590  while(pElements != eElements) {
591  const PrimitiveElement &elem = *pElements;
592  // Ignore the route through elements
593  if(!primitiveStructurePtr->isRoutethrough(elem)) {
594 
595  // Cache the current setting of the element
596  std::string harnessConfigName;
597  std::string harnessConfigVal;
598  instancePtr->getConfig(elem.getName(), harnessConfigName, harnessConfigVal);
599 
600 
601  // Generate XDLs only if the element has a config to be set.
602  if(elem.getCfgs().size() > 0) {
603  // First generate a generic reference XDL for all configs of the element, so that the special elements have option of over writing this harness
604  std::stringstream ssReferenceXdlFileName;
605  ssReferenceXdlFileName << ssXdlFileName.str() << kNameSeparator << elem.getName() << kXDLExtension;
606  GenerateReferenceXDLForTheElement(elem.getName(), designPtr, ssReferenceXdlFileName.str());
607 
608  // Generate XDL for each config of the element.
609  GenerateXdlForElement(elem, primitiveStructurePtr, ssXdlFileName.str(),
610  designPtr);
611  }
612 
613  // Store back the previous setting of the element
614  instancePtr->setConfig(elem.getName(), harnessConfigName, harnessConfigVal);
615  }
616 
617  pElements++;
618  }
619  }
620  }
621  return 0;
622 }
623 
void GenerateXdlForGenericElement(const PrimitiveElement &elem, const std::string &configVal, const std::string &xdlFileNamePartial, torc::physical::DesignSharedPtr designPtr)
const std::string kConfigOff
const std::string kXDLExtension
const const PrimitiveElement * const_iterator
Constant T iterator type.
Definition: Array.hpp:83
DesignSharedPtr GetEmptyDesignWithSameMetadata(torc::physical::DesignSharedPtr designPtr)
Device database, including complete wiring and logic support.
Definition: DDB.hpp:42
bool LibrarySupportForSiteType(const std::string &siteType)
Returns true if the library supports the site type.
Header for the Virtex5PrimitiveStructure class.
DesignSharedPtr getDesignPtr(void)
Returns a shared pointer for the design.
Header for the DirectoryTree class.
void InitializeElementReferenceConfigMap()
void SetConfigAndGenerateXDL(const std::string &elementName, const std::string &configVal, const std::string &xdlFileName, torc::physical::DesignSharedPtr designPtr)
std::string GetReferenceConfigValueForElement(std::string elementName)
Encapsulation of primitive site definition, with associated connections, elements, and pins.
T * end(void)
Returns the non-constant end iterator.
Definition: Array.hpp:97
void GenerateXdlForLUT(const PrimitiveElement &elem, const std::string &xdlFileNamePartial, torc::physical::DesignSharedPtr designPtr)
bool ElementNeedsCompoundSetting(std::string elementName)
const std::string kArchitectureName
void InitializeCompoundSettingsMap()
const Sites & getSites(void) const
Returns a constant reference to the family and device site data.
Definition: DDB.hpp:144
std::string string
const string & getName(void) const
Returns the name of the element.
PrimitiveElementPinArray & getPins(void)
Returns a non-constant array of element pins. This function should only be used by the Sites class d...
static boost::filesystem::path gXDLGenerationFolder
const Array< const PrimitiveDef > & getSiteTypes(void) const
Returns the site types for this family.
Definition: Sites.hpp:125
Main torc::physical namespace header.
Site type and population data for the family and the device.
Definition: Sites.hpp:45
int main(int argc, char **argv)
Generates XDLs for various site types. An XDL is generated for each.
Encapsulation of filesystem paths that are used by the library.
bool IsRAMBSite(const std::string &siteType)
boost::filesystem::path path
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.
static void GenerateXdlForCompoundSettings(const PrimitiveElement &element1, std::string siteType, PrimitiveStructureSharedPtr const primitiveStructurePtr, torc::physical::DesignSharedPtr designPtr)
static const std::string kXDLReferenceFolder
void GenerateRAMBBaseFile(const std::string &primitiveDefName, torc::physical::DesignSharedPtr designPtr)
boost::shared_ptr< Design > DesignSharedPtr
Shared pointer encapsulation of a Design.
const std::string kNameSeparator
const PrimitiveElementArray & getElements(void) const
Returns a constant array of primitive elements.
void GenerateXdlForElement(const PrimitiveElement &elem, PrimitiveStructureSharedPtr const primitiveStructurePtr, const std::string &siteType, DesignSharedPtr designPtr)
static std::map< std::string, std::string > gElementReferenceConfigMap
Encapsulation of a primitive site element. Primitive elements are subcomponents of logic primitive s...
void GenerateXdlForOrphanElements(const PrimitiveElement &elem, const std::string &siteType, torc::physical::DesignSharedPtr designPtr)
CompoundSettingMap gCompoundSettingsMap
T * begin(void)
Returns the non-constant begin iterator.
Definition: Array.hpp:95
static boost::filesystem::path gXDLReferenceGenerationFolder
std::set< std::string > StringSet
A set of configuration values.
boost::shared_ptr< PrimitiveStructure > PrimitiveStructureSharedPtr
Shared pointer encapsulation of a PrimitiveStructure.
Header for the DDB class.
const StringSet & getCfgs(void) const
Returns the set of allowable configuration values.
void GenerateXdlForDSPMaskAndPattern(const std::string &elementName, std::string siteType, torc::physical::DesignSharedPtr designPtr)
Importer from XDL format into a physical design.
torc::physical::DesignSharedPtr GetTestHarnessDesignForSiteType(std::string siteType, const boost::filesystem::path &harnessFolderPath)
int FindPrimitiveElementByName(std::string elementName, PrimitiveStructureSharedPtr const primitiveStructurePtr)
bool IsDSPSite(const std::string &siteType)
Subclass of PrimitiveStructure for Virtex5.
Physical design exporter for XDL.
Definition: XdlExporter.hpp:31
void GenerateReferenceXDLForTheElement(const std::string &elementName, DesignSharedPtr harnessDesignPtr, const std::string &xdlFileName)
const string & getName(void) const
Returns the name of the primitive.