torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MarkExtracter.hpp
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 PhysicalDiff class for comparing physical netlists.
18 
19 #ifndef TORC_UTILS_MARKEXTRACTER_HPP
20 #define TORC_UTILS_MARKEXTRACTER_HPP
21 
22 #include <iostream>
23 #include "torc/Physical.hpp"
25 #include <vector>
26 #include <boost/regex.hpp>
27 
28 namespace torc {
29 
30 /*namespace physical_diff {
31  // forward declarations of unit test classes within their namespace.
32  class diff_design;
33  class diff_module;
34  class diff_circuit;
35  class diff_config_map;
36  class diff_instance;
37  class diff_net;
38 }*/
39 
40 
41 /// \brief Diff utility class for comparing physical netlists.
42 /// \details This class takes two design pointers and compares them.
44 protected:
45  /// \brief Imported type name.
47  /// \brief Imported type name.
49  /// \brief Imported type name.
51  /// \brief Imported type name.
52  typedef std::vector<ModuleSharedPtr> ModuleSharedPtrVector;
53  /// \brief Imported type name.
55  /// \brief Imported type name.
57  /// \brief Imported type name.
58  typedef std::vector<InstanceSharedPtr> InstanceSharedPtrVector;
59  /// \brief Imported type name.
61  /// \brief Imported type name.
62  typedef std::vector<NetSharedPtr> NetSharedPtrVector;
63  /// \brief Imported type name.
65  /// \brief Imported type name.
67  /// \brief Imported type name.
69  /// \brief Imported type name.
71  /// \brief Imported type name.
73  /// \brief Imported type name.
75  /// \brief Imported type name.
77  /// \brief Imported type name.
79  /// \brief Imported type name.
82  /// \brief Imported type name.
84  /// \brief Imported type name.
85  typedef boost::shared_ptr<torc::physical::Named> NamedSharedPtr;
86  /// \brief Imported type name.
87  typedef boost::shared_ptr<torc::physical::ConfigMap> ConfigMapSharedPtr;
88  /// \brief Imported type name.
90  /// \brief Imported type name.
92  /// \brief Imported type name.
96 
97  /// \brief Output stream to use for comparison results.
98  std::ostream& mStream;
101  const string mPattern;
102  boost::regex mRegex;
103 
104 public:
105  MarkExtracter(std::ostream& inOutStream, const DesignSharedPtr& inDesign,
106  string inPattern) : mStream(inOutStream), mDesign(inDesign), mPattern(inPattern) {
107  mStream << "Searching for '" << mPattern << "'" << std::endl;
108  mStream << "NEAT" << std::endl;
109  mRegex.assign(mPattern);
110  }
111 
112  /// \brief Top level call to diff two designs.
114 
115  std::cout << "### " << mPattern << " ###" << std::endl;
116 
118  for (p = mDesign->modulesBegin(); p!= mDesign->modulesEnd(); p++) {
119  std::cout << "MODULES ARE NOT CURRENTLY SUPPORTED!" << std::endl;
120  }
121  mNewDesign = physical::Factory::newDesignPtr(mDesign->getName(), mDesign->getDevice(),
122  mDesign->getPackage(), mDesign->getSpeedGrade(), mDesign->getXdlVersion());
123 
125  //filterOnPips(mDesign);
126 
127  return mNewDesign;
128  }
131  NetSharedPtrIterator net_i;
132 
133  std::map<InstanceSharedPtr, bool> instanceMap;
134  std::map<NetSharedPtr, bool> netMap;
135 
136  boost::smatch smatches;
137 
138  for (inst_i = circuit->instancesBegin(); inst_i != circuit->instancesEnd(); inst_i++) {
139  bool test = regex_match((*inst_i)->getName(), smatches, mRegex);
140  std::multimap<std::string, physical::Config>::const_iterator p;
141  for (p = (*inst_i)->configBegin(); p != (*inst_i)->configEnd(); p++) {
142  test = test || regex_match((*p).first, smatches, mRegex);
143  test = test || regex_match((*p).second.getName(), smatches, mRegex);
144  test = test || regex_match((*p).second.getValue(), smatches, mRegex);
145  }
146  //std::cout << "INSTANCE: " << (*inst_i)->getName() << " -- " << test << std::endl;
147  instanceMap[*inst_i] = test;
148  }
149  for (net_i = circuit->netsBegin(); net_i != circuit->netsEnd(); net_i++) {
150  bool test = regex_match((*net_i)->getName(), smatches, mRegex);
151  //std::cout << "NET: " << (*net_i)->getName() << " -- " << test << std::endl;
152  netMap[*net_i] = test;
153  if (!test) continue;
155  for (pin_i = (*net_i)->sourcesBegin(); pin_i != (*net_i)->sourcesEnd(); pin_i++) {
156  std::cout << "NET INST source: " << ((*pin_i)->getInstancePtr().lock())->getName()
157  << " -- " << true << std::endl;
158  instanceMap[(*pin_i)->getInstancePtr().lock()] = true;
159  }
160  for (pin_i = (*net_i)->sinksBegin(); pin_i != (*net_i)->sinksEnd(); pin_i++) {
161  std::cout << "NET INST sink: " << ((*pin_i)->getInstancePtr().lock())->getName()
162  << " -- " << true << std::endl;
163  instanceMap[(*pin_i)->getInstancePtr().lock()] = true;
164  }
165  }
166 
167  std::map<InstanceSharedPtr, bool>::iterator imap_i;
168  std::map<NetSharedPtr, bool>::iterator nmap_i;
169  std::cout << "Copying marked instances and nets..." << std::endl;
170  for (imap_i = instanceMap.begin(); imap_i != instanceMap.end(); imap_i++) {
171  //std::cout << "check INST: " << (*(imap_i->first)).getName()
172  // << " -- " << imap_i->second << std::endl;
173  if (imap_i->second) { // this is inverted for removing!
174  InstanceSharedPtr isp = imap_i->first;
175  mNewDesign->addInstance(isp);
176  }
177  }
178  for (nmap_i = netMap.begin(); nmap_i != netMap.end(); nmap_i++) {
179  //std::cout << "check NET: " << (*(nmap_i->first)).getName()
180  // << " -- " << nmap_i->second << std::endl;
181  if (nmap_i->second) {
182  NetSharedPtr nsp = nmap_i->first;
183  mNewDesign->addNet(nsp);
184  }
185  }
186 
187  }
190  NetSharedPtrIterator net_i;
191 
192  std::map<InstanceSharedPtr, bool> instanceMap;
193  std::map<NetSharedPtr, bool> netMap;
194 
195  boost::smatch smatches;
196 
197  for (inst_i = circuit->instancesBegin(); inst_i != circuit->instancesEnd(); inst_i++) {
198  instanceMap[*inst_i] = false;
199  }
200  for (net_i = circuit->netsBegin(); net_i != circuit->netsEnd(); net_i++) {
201  bool test = false;
202  for (PipIterator pip_i = (*net_i)->pipsBegin(); pip_i != (*net_i)->pipsEnd(); pip_i++) {
203  test = test || regex_match(pip_i->getTileName(), smatches, mRegex);
204  test = test || regex_match(pip_i->getSourceWireName(), smatches, mRegex);
205  test = test || regex_match(pip_i->getSinkWireName(), smatches, mRegex);
206  }
207  //bool test = regex_match((*net_i)->getName(), smatches, mRegex);
208  //std::cout << "NET: " << (*net_i)->getName() << " -- " << test << std::endl;
209  netMap[*net_i] = test;
210  if (!test) continue;
212  for (pin_i = (*net_i)->sourcesBegin(); pin_i != (*net_i)->sourcesEnd(); pin_i++) {
213  std::cout << "NET INST source: " << ((*pin_i)->getInstancePtr().lock())->getName()
214  << " -- " << true << std::endl;
215  instanceMap[(*pin_i)->getInstancePtr().lock()] = true;
216  }
217  for (pin_i = (*net_i)->sinksBegin(); pin_i != (*net_i)->sinksEnd(); pin_i++) {
218  std::cout << "NET INST sink: " << ((*pin_i)->getInstancePtr().lock())->getName()
219  << " -- " << true << std::endl;
220  instanceMap[(*pin_i)->getInstancePtr().lock()] = true;
221  }
222  }
223 
224  std::map<InstanceSharedPtr, bool>::iterator imap_i;
225  std::map<NetSharedPtr, bool>::iterator nmap_i;
226  std::cout << "Copying marked instances and nets..." << std::endl;
227  for (imap_i = instanceMap.begin(); imap_i != instanceMap.end(); imap_i++) {
228  //std::cout << "check INST: " << (*(imap_i->first)).getName()
229  // << " -- " << imap_i->second << std::endl;
230  if (imap_i->second) { // this is inverted for removing!
231  InstanceSharedPtr isp = imap_i->first;
232  mNewDesign->addInstance(isp);
233  }
234  }
235  for (nmap_i = netMap.begin(); nmap_i != netMap.end(); nmap_i++) {
236  //std::cout << "check NET: " << (*(nmap_i->first)).getName()
237  // << " -- " << nmap_i->second << std::endl;
238  if (nmap_i->second) {
239  NetSharedPtr nsp = nmap_i->first;
240  mNewDesign->addNet(nsp);
241  }
242  }
243 
244  }
245 
246 };
247 
248 } // namespace torc
249 
250 #endif // TORC_UTILS_MARKEXTRACTER_HPP
MarkExtracter(std::ostream &inOutStream, const DesignSharedPtr &inDesign, string inPattern)
DesignSharedPtr mNewDesign
torc::physical::PipVector PipVector
torc::physical::InstanceSharedPtr InstanceSharedPtr
Imported type name.
torc::physical::NetSharedPtr NetSharedPtr
Imported type name.
torc::physical::Circuit::NetSharedPtrIterator NetSharedPtrIterator
Imported type name.
void filterOnPips(CircuitSharedPtr circuit)
PortSharedPtrVector::const_iterator PortSharedPtrConstIterator
Constant iterator to Port shared pointers.
Definition: Module.hpp:55
DesignSharedPtr mDesign
torc::physical::Circuit::InstanceSharedPtrConstIterator InstanceSharedPtrConstIterator
Imported type name.
std::vector< ModuleSharedPtr > ModuleSharedPtrVector
Imported type name.
torc::physical::Design::ModuleSharedPtrConstIterator ModuleSharedPtrConstIterator
Imported type name.
boost::shared_ptr< torc::physical::ConfigMap > ConfigMapSharedPtr
Imported type name.
PipVector::const_iterator PipConstIterator
Constant iterator to Pip objects.
Diff utility class for comparing physical netlists.
InstancePinSharedPtrVector::iterator InstancePinSharedPtrIterator
Non-constant iterator to InstancePin shared pointer objects.
InstanceSharedPtrVector::const_iterator InstanceSharedPtrConstIterator
Constant iterator to Instance shared pointers.
Definition: Circuit.hpp:72
torc::physical::Circuit::NetSharedPtrConstIterator NetSharedPtrConstIterator
Imported type name.
ModuleSharedPtrVector::const_iterator ModuleSharedPtrConstIterator
Constant iterator for Module shared pointers.
std::ostream & mStream
Output stream to use for comparison results.
DesignSharedPtr extract()
Top level call to diff two designs.
std::string string
torc::physical::ModuleSharedPtr ModuleSharedPtr
Imported type name.
const_iterator const_iterator
Constant iterator to {setting,Config} pairs.
Definition: ConfigMap.hpp:52
void pruneCircuit(CircuitSharedPtr circuit)
torc::physical::DesignSharedPtr DesignSharedPtr
Imported type name.
torc::physical::Net::PipIterator PipIterator
torc::physical::Pip Pip
Imported type name.
boost::shared_ptr< Module > ModuleSharedPtr
Shared pointer encapsulation of a Module.
Definition: Module.hpp:114
Main torc::physical namespace header.
torc::physical::Net::InstancePinSharedPtrConstIterator InstancePinSharedPtrConstIterator
Imported type name.
Header for torc::physical output stream helpers.
boost::shared_ptr< Net > NetSharedPtr
Shared pointer encapsulation of a Net.
boost::shared_ptr< Circuit > CircuitSharedPtr
Shared pointer encapsulation of a Circuit.
Definition: Circuit.hpp:219
torc::physical::ConfigMap::const_iterator ConfigMapConstIterator
Imported type name.
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.
boost::shared_ptr< Design > DesignSharedPtr
Shared pointer encapsulation of a Design.
std::vector< NetSharedPtr > NetSharedPtrVector
Imported type name.
torc::physical::Module::PortSharedPtrConstIterator PortSharedPtrConstIterator
Imported type name.
std::vector< InstanceSharedPtr > InstanceSharedPtrVector
Imported type name.
InstancePinSharedPtrVector::const_iterator InstancePinSharedPtrConstIterator
Constant iterator to InstancePin shared pointer objects.
NetSharedPtrVector::iterator NetSharedPtrIterator
Non-constant iterator to Net shared pointers.
Definition: Circuit.hpp:78
Physical design programmable interconnect point.
Definition: Pip.hpp:34
torc::physical::Circuit::InstanceSharedPtrIterator InstanceSharedPtrIterator
Imported type name.
torc::physical::InstanceWeakPtr InstanceWeakPtr
Imported type name.
static DesignSharedPtr newDesignPtr(const string &inName, const string &inDevice, const string &inPackage, const string &inSpeedGrade, const string &inXdlVersion)
Create and return a new Design shared pointer.
ModuleSharedPtrVector::iterator ModuleSharedPtrIterator
Non-constant iterator for Module shared pointers.
torc::physical::Net::InstancePinSharedPtrIterator InstancePinSharedPtrIterator
Imported type name.
std::string string
Imported type name.
boost::weak_ptr< Instance > InstanceWeakPtr
Weak pointer encapsulation of an Instance.
boost::shared_ptr< torc::physical::Named > NamedSharedPtr
Imported type name.
NetSharedPtrVector::const_iterator NetSharedPtrConstIterator
Constant iterator to Net shared pointers.
Definition: Circuit.hpp:76
torc::physical::Net::PipConstIterator PipConstIterator
Imported type name.
PipVector::iterator PipIterator
Non-constant iterator to Pip objects.
InstanceSharedPtrVector::iterator InstanceSharedPtrIterator
Non-constant iterator to Instance shared pointers.
Definition: Circuit.hpp:74
torc::physical::Design::ModuleSharedPtrIterator ModuleSharedPtrIterator
Imported type name.
std::vector< Pip > PipVector
Vector of pips.
Definition: Pip.hpp:95
torc::physical::CircuitSharedPtr CircuitSharedPtr
Imported type name.