Bitstream Interpretation Library (BIL)  0.1
bitextract.cpp
Go to the documentation of this file.
1 
8 #include <cstdlib>
9 #include <fstream>
10 #include <iostream>
13 #include <bitfile/BitFileData.hpp>
23 
24 
25 int main(int argc, char** argv)
26 {
27  using namespace bil;
28 
29  try
30  {
31  // process command line
32  std::cout << SPLASH_MSG;
33  parseCommandLine(argc, argv);
34 
35  // load bitfile
36  std::cout << LOADING_BITFILE_MSG;
37  BitFileData bfd;
38  std::ifstream bitfileStream(bitFileName.c_str(), std::ios::binary);
39  readBitfile(bfd, bitfileStream);
40 
41  // construct bitstream from bitfile raw data
42  std::cout << DECODING_BITSTREAM_MSG;
43  Bitstream bs;
45  bfd.bitstreamWordCount(0);
46 
47  // read in available devices
48  std::cout << LOADING_DEVICELIST_MSG;
49  std::string s = dataPathName + V5DEVICES_FILENAME;
50  std::ifstream lstFileStream(s.c_str(), std::ios::binary);
51  DeviceRegistry deviceRegistry;
52  readBinary(deviceRegistry, lstFileStream);
53 
54  // detect target device type
55  std::cout << DETECTING_TARGETDEVICE_MSG;
56  DeviceID::ID_t deviceID = detectV5DeviceType(bs);
57  s = deviceRegistry.lookup(deviceID);
58  if (s.empty()) throw Exception();
59 
60  // load address layout
62  V5AddressLayout addressLayout;
63  s = dataPathName + s + CAL_FILE_EXT;
64  std::ifstream calFileStream(s.c_str(), std::ios::binary);
65  readBinary(addressLayout, calFileStream);
66  V5AddressLayoutRegistry addressLayoutRegistry;
67  addressLayoutRegistry.insert(deviceID, addressLayout);
68 
69  // execute bitstream
70  std::cout << EXECUTING_BITSTREAM_MSG;
71  V5PacketProcessor packetProcessor(addressLayoutRegistry);
72  bs.runVisitor(packetProcessor);
73 
74  // write configuration data
75  std::cout << WRITING_CFG_MSG;
76  std::ofstream cfgFileStream(outCfgFile.c_str(), std::ios::binary);
77  std::ofstream indexFileStream(outIndexFile.c_str());
78  indexFileStream << INDEX_FILE_HEADER;
79  dumpConfiguration(packetProcessor.configuration(), cfgFileStream, indexFileStream);
80 
81  // finished
82  std::cout << FINISHED_MSG;
83  }
84  catch (const CommandLineException& e)
85  {
86  std::cout << ERROR_MSG << e.what() << INFO_MSG;
87  return EXIT_FAILURE;
88  }
89  catch (...)
90  {
91  std::cout << ERROR_UNKNOWN_MSG;
92  return EXIT_FAILURE;
93  }
94  return EXIT_SUCCESS;
95 }