torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Module.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 Header for the Module class.
18 
19 #ifndef TORC_PHYSICAL_MODULE_HPP
20 #define TORC_PHYSICAL_MODULE_HPP
21 
23 #include "torc/physical/Port.hpp"
24 #include <string>
25 
26 namespace torc {
27 namespace physical {
28 
29  /// \brief Hierarchical module.
30  /// \details Modules are used for hard macros in the Xilinx tool flow. For most users, modules
31  /// never appear in XDL netlists, either because the design did not use hard macros, or
32  /// because those hard macros were flattened as instances and nets directly in the design.
33  class Module : public Circuit, protected Progenitor<Module> {
34  // friends
35  /// \brief The Factory class has direct access to our internals.
36  friend class Factory;
37  protected:
38  // types
39  /// \brief Imported type name.
41  // members
42  /// \brief The module anchor instance name.
43  string mAnchor;
44  /// \brief Vector of Port shared pointers for the module
46  // constructors
47  /// \brief Protected constructor.
48  /// \param inName The module name.
49  /// \param inAnchor The anchor instance name for the module. The anchor designates the
50  /// instance in the module relative to which the module will be placed.
51  Module(const string& inName, const string& inAnchor) : Circuit(inName), mAnchor(inAnchor) {}
52  public:
53  // types
54  /// \brief Constant iterator to Port shared pointers.
55  typedef PortSharedPtrVector::const_iterator PortSharedPtrConstIterator;
56  /// \brief Non-constant iterator to Port shared pointers.
57  typedef PortSharedPtrVector::iterator PortSharedPtrIterator;
58  // functions
59  /// \brief Find a port by name.
60  /// \param inName The port name to look for.
61  /// \returns an iterator for the specified port, or portsEnd() if the name was not found.
62  PortSharedPtrIterator findPort(const string& inName) {
63  NameComparator predicate(inName);
64  return std::find_if(portsBegin(), portsEnd(), predicate);
65  }
66  /// \brief Add a port to the module.
67  /// \param inPortPtr The port to add.
68  /// \returns true if the instance was added, or false if an instance with the same name
69  /// already exists in the circuit.
70  bool addPort(PortSharedPtr& inPortPtr) {
71  /// \todo Acquire mutex.
73  PortSharedPtrIterator result = findPort(inPortPtr->getName());
74  if(result != e) return false;
75  mPorts.push_back(inPortPtr);
76  inPortPtr->Progeny<Module>::setParentWeakPtr(Progenitor<Module>::mSelfWeakPtr);
77  return true;
78  /// \todo Release mutex.
79  }
80  bool removePort(PortSharedPtr& inPortPtr) {
81  /// \todo Acquire mutex.
83  PortSharedPtrIterator result = findPort(inPortPtr->getName());
84  if(result == e) return false;
85  mPorts.erase(result);
86  /// \todo Release mutex.
87  return true;
88  }
89  // accessors
90  /// \brief Returns the anchor instance name for this module.
91  const string& getAnchor(void) const { return mAnchor; }
92  /// \brief Sets the anchor instance name for this module.
93  void setAnchor(const string& inAnchor) { mAnchor = inAnchor; }
94  // iterators
95  /// \brief Returns the begin constant iterator for ports.
96  PortSharedPtrConstIterator portsBegin(void) const { return mPorts.begin(); }
97  /// \brief Returns the end constant iterator for ports.
98  PortSharedPtrConstIterator portsEnd(void) const { return mPorts.end(); }
99  /// \brief Returns the begin non-constant iterator for ports.
100  PortSharedPtrIterator portsBegin(void) { return mPorts.begin(); }
101  /// \brief Returns the end non-constant iterator for ports.
102  PortSharedPtrIterator portsEnd(void) { return mPorts.end(); }
103  /// \brief Returns the number of ports in the module.
104  size_t getPortCount(void) const { return mPorts.size(); }
105  // operators
106  /// \brief Equality operator.
107  /// \details This function deems modules equal if their names are identical.
108  /// \param rhs The module to compare against.
109  /// \returns true if both module names are identical, or false otherwise.
110  bool operator ==(const Module& rhs) const { return mName == rhs.mName; }
111  };
112 
113  /// \brief Shared pointer encapsulation of a Module.
114  typedef boost::shared_ptr<Module> ModuleSharedPtr;
115 
116  /// \brief Weak pointer encapsulation of a Module.
117  typedef boost::weak_ptr<Module> ModuleWeakPtr;
118 
119  /// \brief Vector of Module shared pointers.
120  typedef std::vector<ModuleSharedPtr> ModuleSharedPtrVector;
121 
122 } // namespace physical
123 } // namespace torc
124 
125 #endif // TORC_PHYSICAL_MODULE_HPP
PortSharedPtrVector mPorts
Vector of Port shared pointers for the module.
Definition: Module.hpp:45
void setAnchor(const string &inAnchor)
Sets the anchor instance name for this module.
Definition: Module.hpp:93
PortSharedPtrConstIterator portsEnd(void) const
Returns the end constant iterator for ports.
Definition: Module.hpp:98
PortSharedPtrVector::const_iterator PortSharedPtrConstIterator
Constant iterator to Port shared pointers.
Definition: Module.hpp:55
boost::weak_ptr< Module > ModuleWeakPtr
Weak pointer encapsulation of a Module.
Definition: Module.hpp:117
string mAnchor
The module anchor instance name.
Definition: Module.hpp:43
string mName
The name of the object.
Definition: Named.hpp:43
boost::shared_ptr< Port > PortSharedPtr
Shared pointer encapsulation of a Port.
PortSharedPtrIterator findPort(const string &inName)
Find a port by name.
Definition: Module.hpp:62
PortSharedPtrIterator portsBegin(void)
Returns the begin non-constant iterator for ports.
Definition: Module.hpp:100
PortSharedPtrConstIterator portsBegin(void) const
Returns the begin constant iterator for ports.
Definition: Module.hpp:96
const string & getAnchor(void) const
Returns the anchor instance name for this module.
Definition: Module.hpp:91
std::string string
Module(const string &inName, const string &inAnchor)
Protected constructor.
Definition: Module.hpp:51
boost::shared_ptr< Module > ModuleSharedPtr
Shared pointer encapsulation of a Module.
Definition: Module.hpp:114
Comparator class to serve as a predicate when searching for names.
Definition: Named.hpp:61
Header for the Port class.
bool addPort(PortSharedPtr &inPortPtr)
Add a port to the module.
Definition: Module.hpp:70
bool removePort(PortSharedPtr &inPortPtr)
Definition: Module.hpp:80
PortSharedPtrIterator portsEnd(void)
Returns the end non-constant iterator for ports.
Definition: Module.hpp:102
Factory class for physical netlist elements.
Concept for any object that may have children.
Definition: Progenitor.hpp:36
PortSharedPtrVector::iterator PortSharedPtrIterator
Non-constant iterator to Port shared pointers.
Definition: Module.hpp:57
size_t getPortCount(void) const
Returns the number of ports in the module.
Definition: Module.hpp:104
std::string string
Imported type name.
Definition: Module.hpp:40
Header for the Circuit class.
Circuit composed of instances and nets.
Definition: Circuit.hpp:46
std::vector< ModuleSharedPtr > ModuleSharedPtrVector
Vector of Module shared pointers.
Definition: Module.hpp:120
Hierarchical module.
Definition: Module.hpp:33
bool operator==(const Module &rhs) const
Equality operator.
Definition: Module.hpp:110
std::vector< PortSharedPtr > PortSharedPtrVector
Vector of Port shared pointers.