torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
torc::bitstream::DeviceInfoHelper Class Reference

Xilinx bitstream base class. More...

#include <DeviceInfoHelper.hpp>

Static Public Member Functions

static void buildFamilyDeviceInfo (const std::string &inFamilyName, const std::string &inTemplateName, const std::string &inOutputName, const torc::common::DeviceVector &inDeviceNames, Bitstream &inBitstream)
 Build the static device information for the specified family. More...
 

Detailed Description

Xilinx bitstream base class.

Definition at line 29 of file DeviceInfoHelper.hpp.

Member Function Documentation

void torc::bitstream::DeviceInfoHelper::buildFamilyDeviceInfo ( const std::string &  inFamilyName,
const std::string &  inTemplateName,
const std::string &  inOutputName,
const torc::common::DeviceVector inDeviceNames,
Bitstream inBitstream 
)
static

Build the static device information for the specified family.

Todo:
Reinstate check for existing static device information file.

Definition at line 31 of file DeviceInfoHelper.cpp.

33  {
34 
35  // preflight and open the output file
36  boost::filesystem::path outputPath
37  = torc::common::DirectoryTree::getWorkingPath() / "torc" / "bitstream" / inOutputName;
38 /// \todo Reinstate check for existing static device information file.
39 // if(boost::filesystem::exists(outputPath)) {
40 // std::cerr << "Existing static device information file will not be replaced: "
41 // << outputPath.string() << std::endl;
42 // return;
43 // }
44  std::ofstream outputStream(outputPath.string().c_str(), std::ios::out | std::ios::binary);
45  if(!outputStream.is_open()) {
46  std::cerr << "Output static device information file could not be opened: "
47  << outputPath.string() << std::endl;
48  return;
49  }
50 
51  // read the device info template
53  / "torc" / "bitstream" / "build" / inTemplateName;
54  std::ifstream templateStream(templatePath.string().c_str(),
55  std::ios::in | std::ios::binary | std::ios::ate);
56  if(!templateStream.is_open()) {
57  std::cerr << "Input static device information template could not be opened: "
58  << outputPath.string() << std::endl;
59  return;
60  }
61  std::string templateString;
62  // resize the string according to the file length
63  std::ifstream::pos_type size = templateStream.tellg();
64  templateString.resize(size);
65  // rewind to the beginning and read the entire file directly into the string
66  templateStream.seekg(0, std::ios::beg);
67  templateStream.read(const_cast<char*>(templateString.data()), size);
68  // close close file
69  templateStream.close();
70 
71  // iterate over all devices
72  std::stringstream allDeviceInfo;
73  torc::common::DeviceVector::const_iterator dp = inDeviceNames.begin();
74  torc::common::DeviceVector::const_iterator de = inDeviceNames.end();
75  while(dp < de) {
76  const std::string& device = *dp++;
77  if(device.empty()) break;
78  inBitstream.setDevice(device);
79  inBitstream.initializeDeviceInfo(device);
80  inBitstream.writeDeviceInfo(allDeviceInfo, device);
81  if(dp < de) allDeviceInfo << std::endl;
82  }
83 
84  // define the substitutions
85  typedef std::map<std::string, std::string> SubstitutionMap;
86  SubstitutionMap substitutions;
87  substitutions["%%ARCHITECTURE%%"] = inFamilyName;
88  substitutions["%%DEVICES%%"] = allDeviceInfo.str();
89  substitutions["%%GENERATED%%"] = __FILE__;
90 
91  // replace all substitution strings in the template
92  SubstitutionMap::iterator p = substitutions.begin();
93  SubstitutionMap::iterator e = substitutions.end();
94  while(p != e) {
95  // create the regular expression, and prepare to replace
96  boost::regex re(p->first);
97  std::stringstream stringStream;
98  std::ostream_iterator<char, char> stringIterator(stringStream);
99  // replace all occurrences of the current substitution pattern
100  boost::regex_replace(stringIterator, templateString.begin(), templateString.end(), re,
101  p->second, boost::match_default);
102  // copy the results back into place
103  templateString = stringStream.str();
104  p++;
105  }
106 
107  // write the output file
108  outputStream << templateString;
109  outputStream.close();
110 
111  }
std::string string
boost::filesystem::path path
static const boost::filesystem::path & getWorkingPath(void)
Returns the absolute path to the working directory.

+ Here is the call graph for this function:


The documentation for this class was generated from the following files: