Bitstream Interpretation Library (BIL)  0.1
bitcorrelate.cpp
Go to the documentation of this file.
1 
9 #include <cstdlib>
10 #include <cstring>
11 #include <fstream>
12 #include <iostream>
13 #include <bitfile/BitFileData.hpp>
29 #include <xdl/model/Design.hpp>
30 #include <xdl/parser/XDLParser.hpp>
31 #include <xdlrc/model/Device.hpp>
32 
33 using namespace bil;
34 
35 
36 int main(int argc, char** argv)
37 {
38  try
39  {
40  //======================================================================
41  // process given command line
42  std::cout << SPLASH_MSG;
43  parseCommandLine(argc, argv);
44 
45 
46  //======================================================================
47  // parse XDL file
48  Design design;
49  Device device;
50  std::string devicePackageName;
51  {
52  // open XDL file and parse its header
53  std::cout << PARSING_XDL_HEADER_MSG;
54  XDLParser parser;
55  std::ifstream xdlInputStream(xdlFileName.c_str());
56  parser.parseHeader(xdlInputStream, design);
57  devicePackageName = removeSpeed((design.deviceName()).c_str());
58 
59  // load device file of corresponding device
60  std::cout << LOADING_DEVICE1_MSG << devicePackageName << LOADING_DEVICE2_MSG;
61  std::string deviceFileName = dataPathName + devicePackageName + DEVICE_FILE_EXT;
62  std::ifstream deviceInputStream(deviceFileName.c_str(), std::ios::binary);
63  readBinary(device, deviceInputStream);
64 
65  // parse XDL
66  std::cout << PARSING_XDL_MSG;
67  parser.parseBody(device);
68  }
69 
70  //======================================================================
71  // load configuration tile map
72  V5CfgTileMap cfgTileMap;
73  {
74  std::cout << LOADING_CFGTILEMAP_MSG;
75  std::string mapFileName = dataPathName + devicePackageName + MAP_FILE_EXT;
76  std::ifstream mapInputStream(mapFileName.c_str(), std::ios::binary);
77  readBinary(cfgTileMap, mapInputStream);
78  }
79 
80  //======================================================================
81  // get configuration data from bitstream
82  V5AddressLayoutRegistry addressLayoutRegistry;
83  V5PacketProcessor packetProcessor(addressLayoutRegistry);
84  V5Configuration& configuration = packetProcessor.configuration();
85  {
86  // load bitfile
87  std::cout << LOADING_BITFILE_MSG;
88  BitFileData bfd;
89  std::ifstream bitfileStream(bitFileName.c_str(), std::ios::binary);
90  readBitfile(bfd, bitfileStream);
91 
92  // construct bitstream from bitfile raw data
93  std::cout << DECODING_BITSTREAM_MSG;
94  Bitstream bs;
96  bfd.bitstreamWordCount(0);
97 
98  // read in available devices
99  std::cout << LOADING_DEVICELIST_MSG;
100  std::string deviceListFileName = dataPathName + V5DEVICES_FILENAME;
101  std::ifstream lstFileStream(deviceListFileName.c_str(), std::ios::binary);
102  DeviceRegistry deviceRegistry;
103  readBinary(deviceRegistry, lstFileStream);
104 
105  // load address layout
106  std::string deviceName = removePackageAndSpeed(devicePackageName.c_str());
107  std::cout << LOADING_ADDRESSLAYOUT1_MSG << deviceName << LOADING_ADDRESSLAYOUT2_MSG;
108  V5AddressLayout addressLayout;
109  std::string calFileName = dataPathName + deviceName + CAL_FILE_EXT;
110  std::ifstream calFileStream(calFileName.c_str(), std::ios::binary);
111  readBinary(addressLayout, calFileStream);
112  DeviceID::ID_t deviceID = deviceRegistry.lookup(deviceName);
113  addressLayoutRegistry.insert(deviceID, addressLayout);
114 
115  // execute bitstream
116  std::cout << EXECUTING_BITSTREAM_MSG;
117  bs.runVisitor(packetProcessor);
118  }
119 
120 
121  //======================================================================
122  // do correlation
123  DeviceCfgDb cfgDatabase;
124  std::cout << DOING_CORRELATION_MSG;
125  {
126  Correlator correlator;
127  V5CfgExtractor cfgExtractor(configuration, cfgTileMap);
128  correlator.run(cfgDatabase, design, device, cfgExtractor);
129  }
130 
131 
132  //======================================================================
133  // save configuration mapping database
134  std::cout << WRITING_DATABASE_MSG;
135  std::ofstream dbFileStream(dbFileName.c_str(), std::ios::binary);
136  writeBinary(cfgDatabase, dbFileStream);
137 
138 
139  //======================================================================
140  // write out stats
141  std::cout << WRITING_STATS_MSG;
142  {
143  std::ofstream statsFileStream(statsFileName.c_str());
144  DeviceCfgDbStats statsPrinter;
145  statsPrinter.printStats(cfgDatabase, device, statsFileStream);
146  }
147 
148 
149  //======================================================================
150  // finished
151  std::cout << FINISHED_MSG;
152  }
153  catch (const CommandLineException& e)
154  {
155  std::cout << ERROR_MSG << e.what() << INFO_MSG;
156  return EXIT_FAILURE;
157  }
158  catch (...)
159  {
160  std::cout << ERROR_UNKNOWN_MSG;
161  return EXIT_FAILURE;
162  }
163  return EXIT_SUCCESS;
164 }