torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bitstream/Factory.cpp
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 Source for the Factory class.
18 
30 #include <fstream>
31 
32 namespace torc {
33 namespace bitstream {
34 
36 
37  BitstreamSharedPtr Factory::newBitstreamPtr(const char* inFileName) {
38  // open the file as a stream
39  BitstreamSharedPtr bitstreamPtr;
40  std::fstream fileStream(inFileName, std::ios::binary | std::ios::in);
41  if(!fileStream.good()) return bitstreamPtr;
42 
43  // read the header and determine the device family
44  Bitstream bitstream;
45  bitstream.readHeader(fileStream);
46  DeviceDesignator designator(bitstream.getDeviceName());
47 
48  // instantiate the appropriate bitstream
49  switch(designator.getFamily()) {
51  bitstreamPtr = BitstreamSharedPtr(new Virtex()); break;
53  bitstreamPtr = BitstreamSharedPtr(new VirtexE()); break;
55  bitstreamPtr = BitstreamSharedPtr(new Virtex2()); break;
57  bitstreamPtr = BitstreamSharedPtr(new Virtex2P()); break;
59  bitstreamPtr = BitstreamSharedPtr(new Virtex4()); break;
61  bitstreamPtr = BitstreamSharedPtr(new Virtex5()); break;
63  bitstreamPtr = BitstreamSharedPtr(new Virtex6()); break;
68  bitstreamPtr = BitstreamSharedPtr(new Virtex7()); break;
70  bitstreamPtr = BitstreamSharedPtr(new Spartan3E()); break;
72  bitstreamPtr = BitstreamSharedPtr(new Spartan6()); break;
73  default:
74  return bitstreamPtr;
75  }
76 
77  // rewind the stream
78  fileStream.seekg(0, std::ios::beg);
79  bitstreamPtr->read(fileStream);
80 
81  // return the newly created bitstream
82  return bitstreamPtr;
83  }
84 
85 } // namespace bitstream
86 } // namespace torc
Header for the VirtexE class.
static bool readHeader(std::istream &inStream, string &outDesignName, string &outDeviceName, string &outDesignDate, string &outDesignTime, uint32_t &outBitstreamLength, uint32_t &outHeaderLength)
Read a bitstream header, and return its fields.
Encapsulation of a device designator and its constituent elements.
torc::common::DeviceDesignator DeviceDesignator
Header for the Virtex4 class.
Header for the Virtex2P class.
Virtex6 bitstream.
Definition: Virtex6.hpp:41
Header for the Virtex6 class.
Header for the Virtex5 class.
const string & getDeviceName(void) const
Return the device name.
Virtex2 bitstream.
Definition: Virtex2.hpp:40
Header for the Factory class.
Header for the Spartan6 class.
Virtex5 bitstream.
Definition: Virtex5.hpp:41
Xilinx bitstream base class.
Spartan6 bitstream.
Definition: Spartan6.hpp:31
Virtex4 bitstream.
Definition: Virtex4.hpp:40
static BitstreamSharedPtr newBitstreamPtr(const boost::filesystem::path &inPath)
Header for the Virtex class.
Virtex bitstream.
Definition: Virtex.hpp:40
Virtex7 bitstream.
Definition: Virtex7.hpp:40
VirtexE bitstream inherited from Virtex bitstream.
Definition: VirtexE.hpp:37
Header for the Virtex2 class.
Header for the Spartan3E class.
Spartan3E bitstream.
Definition: Spartan3E.hpp:38
boost::shared_ptr< Bitstream > BitstreamSharedPtr
Virtex2P bitstream inherited from Virtex2 bitstream.
Definition: Virtex2P.hpp:37
Header for the Virtex7 class.