00001 // Torc - Copyright 2011 University of Southern California. All Rights Reserved. 00002 // $HeadURL: https://svn.east.isi.edu/torc/trunk/src/torc/physical/Module.hpp $ 00003 // $Id: Module.hpp 380 2011-02-23 04:05:26Z nsteiner $ 00004 00005 // This program is free software: you can redistribute it and/or modify it under the terms of the 00006 // GNU General Public License as published by the Free Software Foundation, either version 3 of the 00007 // License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 00010 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 00011 // the GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License along with this program. If 00014 // not, see <http://www.gnu.org/licenses/>. 00015 00016 /// \file 00017 /// \brief Header for the Module class. 00018 00019 #ifndef TORC_PHYSICAL_MODULE_HPP 00020 #define TORC_PHYSICAL_MODULE_HPP 00021 00022 #include "torc/physical/Circuit.hpp" 00023 #include "torc/physical/Port.hpp" 00024 #include <string> 00025 00026 namespace torc { 00027 namespace physical { 00028 00029 /// \brief Hierarchical module. 00030 /// \details Modules are used for hard macros in the Xilinx tool flow. For most users, modules 00031 /// never appear in XDL netlists, either because the design did not use hard macros, or 00032 /// because those hard macros were flattened as instances and nets directly in the design. 00033 class Module : public Circuit, protected Progenitor<Module> { 00034 // friends 00035 /// \brief The Factory class has direct access to our internals. 00036 friend class Factory; 00037 protected: 00038 // types 00039 /// \brief Imported type name. 00040 typedef std::string string; 00041 // members 00042 /// \brief The module anchor instance name. 00043 string mAnchor; 00044 /// \brief Vector of Port shared pointers for the module 00045 PortSharedPtrVector mPorts; 00046 // constructors 00047 /// \brief Protected constructor. 00048 /// \param inName The module name. 00049 /// \param inAnchor The anchor instance name for the module. The anchor designates the 00050 /// instance in the module relative to which the module will be placed. 00051 Module(const string& inName, const string& inAnchor) : Circuit(inName), mAnchor(inAnchor) {} 00052 public: 00053 // types 00054 /// \brief Constant iterator to Port shared pointers. 00055 typedef PortSharedPtrVector::const_iterator PortSharedPtrConstIterator; 00056 /// \brief Non-constant iterator to Port shared pointers. 00057 typedef PortSharedPtrVector::iterator PortSharedPtrIterator; 00058 // functions 00059 /// \brief Find a port by name. 00060 /// \param inName The port name to look for. 00061 /// \returns an iterator for the specified port, or portsEnd() if the name was not found. 00062 PortSharedPtrIterator findPort(const string& inName) { 00063 NameComparator predicate(inName); 00064 return std::find_if(portsBegin(), portsEnd(), predicate); 00065 } 00066 /// \brief Add a port to the module. 00067 /// \param inPortPtr The port to add. 00068 /// \returns true if the instance was added, or false if an instance with the same name 00069 /// already exists in the circuit. 00070 bool addPort(PortSharedPtr& inPortPtr) { 00071 /// \todo Acquire mutex. 00072 PortSharedPtrIterator e = portsEnd(); 00073 PortSharedPtrIterator result = findPort(inPortPtr->getName()); 00074 if(result != e) return false; 00075 mPorts.push_back(inPortPtr); 00076 inPortPtr->Progeny<Module>::setParentWeakPtr(Progenitor<Module>::mSelfWeakPtr); 00077 return true; 00078 /// \todo Release mutex. 00079 } 00080 bool removePort(PortSharedPtr& inPortPtr) { 00081 /// \todo Acquire mutex. 00082 PortSharedPtrIterator e = portsEnd(); 00083 PortSharedPtrIterator result = findPort(inPortPtr->getName()); 00084 if(result == e) return false; 00085 mPorts.erase(result); 00086 /// \todo Release mutex. 00087 return true; 00088 } 00089 // accessors 00090 /// \brief Returns the anchor instance name for this module. 00091 const string& getAnchor(void) const { return mAnchor; } 00092 /// \brief Sets the anchor instance name for this module. 00093 void setAnchor(const string& inAnchor) { mAnchor = inAnchor; } 00094 // iterators 00095 /// \brief Returns the begin constant iterator for ports. 00096 PortSharedPtrConstIterator portsBegin(void) const { return mPorts.begin(); } 00097 /// \brief Returns the end constant iterator for ports. 00098 PortSharedPtrConstIterator portsEnd(void) const { return mPorts.end(); } 00099 /// \brief Returns the begin non-constant iterator for ports. 00100 PortSharedPtrIterator portsBegin(void) { return mPorts.begin(); } 00101 /// \brief Returns the end non-constant iterator for ports. 00102 PortSharedPtrIterator portsEnd(void) { return mPorts.end(); } 00103 /// \brief Returns the number of ports in the module. 00104 size_t getPortCount(void) const { return mPorts.size(); } 00105 // operators 00106 /// \brief Equality operator. 00107 /// \details This function deems modules equal if their names are identical. 00108 /// \param rhs The module to compare against. 00109 /// \returns true if both module names are identical, or false otherwise. 00110 bool operator ==(const Module& rhs) const { return mName == rhs.mName; } 00111 }; 00112 00113 /// \brief Shared pointer encapsulation of a Module. 00114 typedef boost::shared_ptr<Module> ModuleSharedPtr; 00115 00116 /// \brief Weak pointer encapsulation of a Module. 00117 typedef boost::weak_ptr<Module> ModuleWeakPtr; 00118 00119 /// \brief Vector of Module shared pointers. 00120 typedef std::vector<ModuleSharedPtr> ModuleSharedPtrVector; 00121 00122 } // namespace physical 00123 } // namespace torc 00124 00125 #endif // TORC_PHYSICAL_MODULE_HPP