torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DeviceDesignator.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 DeviceDesignator class.
18 
20 #include <boost/algorithm/string.hpp>
21 #include <boost/regex.hpp>
22 
23 namespace torc {
24 namespace common {
25 
27  "(x?c?2s[0-9]+)" /* device */
28  "((?:cs|fg|pq|tq|vq)[0-9]+)?" /* package */
29  "(-[0-9]+Q?)?", /* speed */
30  boost::regex_constants::icase
31  );
32 
34  "(x?c?2s[0-9]+e)" /* device */
35  "((?:fg|ft|pq)[0-9]+)?" /* package */
36  "(-[0-9]+Q?)?", /* speed */
37  boost::regex_constants::icase
38  );
39 
41  "(x?c?3s[0-9]+l?)" /* device */
42  "((?:cp|fg|ft|pq|tq|vq)[0-9]+)?" /* package */
43  "(-[0-9]+)?", /* speed */
44  boost::regex_constants::icase
45  );
46 
48  "(x?c?3s[0-9]+an?)" /* device */
49  "((?:fg|fgg|ft|tq|tqg)[0-9]+)?" /* package */
50  "(-[0-9]+)?", /* speed */
51  boost::regex_constants::icase
52  );
53 
55  "(x?c?3s[0-9]+e)" /* device */
56  "((?:cp|fg|ft|pq|tq|vq)[0-9]+)?" /* package */
57  "(-[0-9]+)?", /* speed */
58  boost::regex_constants::icase
59  );
60 
62  "(x?c?6s[l]x[0-9]+t?l?)" /* device */
63  "((?:cpg|csg|fgg|ftg|tqg)[0-9]+)?" /* package */
64  "(-[0-9]+)?", /* speed */
65  boost::regex_constants::icase
66  );
67 
68  boost::regex DeviceDesignator::sVirtexRegEx(
69  "(x?c?v[0-9]+)" /* device */
70  "((?:bg|cs|fg|hq|pq|tq)[0-9]+)?" /* package */
71  "(-[0-9]+)?", /* speed */
72  boost::regex_constants::icase
73  );
74 
76  "(x?c?v[0-9]+e)" /* device */
77  "((?:bg|cs|fg|hq|pq)[0-9]+)?" /* package */
78  "(-[0-9]+)?", /* speed */
79  boost::regex_constants::icase
80  );
81 
83  "(x?c?2v[0-9]+)" /* device */
84  "((?:bf|bg|cs|ff|fg)[0-9]+)?" /* package */
85  "(-[0-9]+)?", /* speed */
86  boost::regex_constants::icase
87  );
88 
90  "(x?c?2vpx?[0-9]+)" /* device */
91  "((?:ff|fg)[0-9]+)?" /* package */
92  "(-[0-9]+)?", /* speed */
93  boost::regex_constants::icase
94  );
95 
97  "(x?c?4v[fls]x[0-9]+)" /* device */
98  "((?:ff|sf)[0-9]+)?" /* package */
99  "(-[0-9]+)?", /* speed */
100  boost::regex_constants::icase
101  );
102 
103  boost::regex DeviceDesignator::sVirtex5RegEx(
104  "(x?c?5v[flst]x[0-9]+t?)" /* device */
105  "((?:ff)[0-9]+)?" /* package */
106  "(-[0-9]+)?", /* speed */
107  boost::regex_constants::icase
108  );
109 
110  boost::regex DeviceDesignator::sVirtex6RegEx(
111  "(x?c?6v[chls]x[0-9]+t?l?)" /* device */
112  "((?:ff)[0-9]+)?" /* package */
113  "(-[0-9]+L?)?", /* speed */
114  boost::regex_constants::icase
115  );
116 
117  boost::regex DeviceDesignator::sArtix7RegEx(
118  "(x?c?7a[0-9]+t?)" /* device */
119  "((?:cpg|csg|fbg|ffg|fgg|ftg)[0-9]+)?" /* package */
120  "(-[0-9]+L?)?", /* speed */
121  boost::regex_constants::icase
122  );
123 
124  boost::regex DeviceDesignator::sKintex7RegEx(
125  "(x?c?7k[0-9]+tl?)" /* device */
126  "((?:fbg|ffg|sbg)[0-9]+)?" /* package */
127  "(-[0-9]+L?)?", /* speed */
128  boost::regex_constants::icase
129  );
130 
131  boost::regex DeviceDesignator::sVirtex7RegEx(
132  "(x?c?7v[hx]?[0-9]+tl?)" /* device */
133  "((?:ffg|fhg)[0-9]+)?" /* package */
134  "(-[0-9]+L?)?", /* speed */
135  boost::regex_constants::icase
136  );
137 
139  "(x?c?7z[0-9]+)" /* device */
140  "((?:clg|fbg|ffg)[0-9]+|die)?" /* package */
141  "(-[0-9]+)?", /* speed */
142  boost::regex_constants::icase
143  );
144 
145  DeviceDesignator::DeviceDesignator(const string& inDeviceDesignator) {
146  mDeviceDesignator = inDeviceDesignator;
147  if(parse(inDeviceDesignator, sSpartan2RegEx)) { mFamily = eFamilySpartan2; } else
148  if(parse(inDeviceDesignator, sSpartan2ERegEx)) { mFamily = eFamilySpartan2E; } else
149  if(parse(inDeviceDesignator, sSpartan3RegEx)) { mFamily = eFamilySpartan3; } else
150  if(parse(inDeviceDesignator, sSpartan3ARegEx)) { mFamily = eFamilySpartan3A; } else
151  if(parse(inDeviceDesignator, sSpartan3ERegEx)) { mFamily = eFamilySpartan3E; } else
152  if(parse(inDeviceDesignator, sSpartan6RegEx)) { mFamily = eFamilySpartan6; } else
153  if(parse(inDeviceDesignator, sVirtexRegEx)) { mFamily = eFamilyVirtex; } else
154  if(parse(inDeviceDesignator, sVirtexERegEx)) { mFamily = eFamilyVirtexE; } else
155  if(parse(inDeviceDesignator, sVirtex2RegEx)) { mFamily = eFamilyVirtex2; } else
156  if(parse(inDeviceDesignator, sVirtex2PRegEx)) { mFamily = eFamilyVirtex2P; } else
157  if(parse(inDeviceDesignator, sVirtex4RegEx)) { mFamily = eFamilyVirtex4; } else
158  if(parse(inDeviceDesignator, sVirtex5RegEx)) { mFamily = eFamilyVirtex5; } else
159  if(parse(inDeviceDesignator, sVirtex6RegEx)) { mFamily = eFamilyVirtex6; } else
160  if(parse(inDeviceDesignator, sArtix7RegEx)) { mFamily = eFamilyArtix7; } else
161  if(parse(inDeviceDesignator, sKintex7RegEx)) { mFamily = eFamilyKintex7; } else
162  if(parse(inDeviceDesignator, sVirtex7RegEx)) { mFamily = eFamilyVirtex7; } else
163  if(parse(inDeviceDesignator, sZynq7000RegEx)) { mFamily = eFamilyZynq7000; } else
164  { mFamily = eFamilyUnknown; }
165  }
166 
167  bool DeviceDesignator::parse(const string& inDeviceDesignator, const boost::regex& inRegEx) {
168  boost::smatch what;
169  string designator = inDeviceDesignator;
170  boost::to_lower(designator);
171  if(boost::regex_match(designator, what, inRegEx, boost::match_default)) {
172  if(what[1].matched) mDeviceName = std::string(what[1].first, what[1].second);
173  if(what[2].matched) mDevicePackage = std::string(what[2].first, what[2].second);
174  if(what[3].matched) mDeviceSpeedGrade = std::string(what[3].first, what[3].second);
175  if(what[1].matched) {
176  // this will have to change when we support other Xilinx and non-Xilinx devices
177  mDeviceName = boost::regex_replace(mDeviceName, boost::regex("^x?c?"), "xc");
178  }
179  return true;
180  } else {
181  return false;
182  }
183  }
184 
185  std::ostream& operator<< (std::ostream& os, const DeviceDesignator& rhs) {
186  os << rhs.getDeviceName();
187  if(rhs.getDevicePackage().length()) os << rhs.getDevicePackage();
188  if(rhs.getDeviceSpeedGrade().length()) os << rhs.getDeviceSpeedGrade();
189  return os;
190  }
191 
192 } // namespace common
193 } // namespace torc
static boost::regex sArtix7RegEx
Regular expression for Artix7 devices.
Encapsulation of a device designator and its constituent elements.
string mDevicePackage
The device package.
static boost::regex sVirtexERegEx
Regular expression for VirtexE devices.
string mDeviceSpeedGrade
The device speed grade.
static boost::regex sVirtex4RegEx
Regular expression for Virtex4 devices.
static boost::regex sSpartan6RegEx
Regular expression for Spartan3E devices.
static boost::regex sKintex7RegEx
Regular expression for Kintex7 devices.
std::ostream & operator<<(std::ostream &os, const DeviceDesignator &rhs)
bool parse(const string &inDeviceDesignator, const boost::regex &inRegEx)
Parses the device name into constituent device, package, and speed components.
string mDeviceDesignator
The full device designator.
Header for the DeviceDesignator class.
static boost::regex sSpartan3RegEx
Regular expression for Spartan3 devices.
static boost::regex sVirtex6RegEx
Regular expression for Virtex6 devices.
std::string string
static boost::regex sSpartan2RegEx
Regular expression for Spartan2 devices.
const string & getDeviceSpeedGrade(void) const
Returns the device speed grade.
static boost::regex sVirtexRegEx
Regular expression for Virtex devices.
static boost::regex sSpartan3ERegEx
Regular expression for Spartan3E devices.
static boost::regex sSpartan3ARegEx
Regular expression for Spartan3A devices.
static boost::regex sVirtex2PRegEx
Regular expression for Virtex2P devices.
static boost::regex sVirtex7RegEx
Regular expression for Virtex7 devices.
static boost::regex sVirtex5RegEx
Regular expression for Virtex5 devices.
const string & getDevicePackage(void) const
Returns the device package.
const string & getDeviceName(void) const
Returns the device name.
static boost::regex sZynq7000RegEx
Regular expression for Zynq7000 devices.
DeviceDesignator(const string &inDeviceDesignator)
Basic constructor.
static boost::regex sSpartan2ERegEx
Regular expression for Spartan2E devices.
static boost::regex sVirtex2RegEx
Regular expression for Virtex2 devices.