torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Flattening.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 #ifndef TORC_GENERIC_FLATTENING_HPP
17 #define TORC_GENERIC_FLATTENING_HPP
18 
19 #include <boost/function.hpp>
20 
21 #include "torc/generic/Error.hpp"
23 
24 /**
25  * \file Flattening.hpp
26  * \brief Contains functions for flattening a design
27  *
28  * This file contains functions and helpers for flattening a design
29  */
30 
31 namespace torc {
32 namespace generic {
33 
34 /**
35  * @typedef NetNamingFunction
36  * @brief Function to create net names during flattening
37  */
38 typedef boost::function<std::string(const std::string& inParentInstanceName,
39  const NetSharedPtr& inNet, const std::vector<size_t>& inIndicesVector)> NetNamingFunction;
40 
41 /**
42  * @typedef InstanceNamingFunction
43  * @brief Function to create instance names during flattening
44  */
45 typedef boost::function<std::string(const std::string& inParentInstanceName,
46  const InstanceSharedPtr& inInstance, const std::vector<size_t>& inIndicesVector)>
48 
49 /**
50  * @typedef NetRenamingFunction
51  * @brief Function to create names of nets that are set in rename constructs
52  */
53 typedef boost::function<std::string(const InstanceSharedPtr& inParentInstance,
54  const NetSharedPtr& inNet, const std::vector<size_t>& inIndicesVector)> NetRenamingFunction;
55 
56 /**
57  * @typedef InstanceRenamingFunction
58  * @brief Function to create names of nets that are set in rename constructs
59  */
60 typedef boost::function<std::string(const InstanceSharedPtr& inParentInstance,
61  const InstanceSharedPtr& inInstance, const std::vector<size_t>& inIndicesVector)>
63 
64 /**
65  * Generate name for a newly generated object during flattening
66  * This function generates names for objects during flattening. The default generated name is of
67  * the form of parent_child_index. However if the name exceeds 255 characters this will be changed
68  * to N00000001, N00000002 etc. The naming N00000001 etc restart for each object type. Therefore,
69  * there may be both and instance and a net having the name N00000001. This is allowed in EDIF
70  * 2 0 0.
71  */
72 template <typename _Pointer> std::string getModifiedName(const std::string& inInstName,
73  const _Pointer& inNameable, const std::vector<size_t>& inIndicesVector = std::vector<size_t>());
74 
75 /**
76  * Generate original name for a newly generated object during flattening
77  * This function generates original names for objects during flattening. Unlike names these string
78  * do not have a restriction of 255 characters and are stored in the rename construct attached to a
79  * net or instance. The generated name is of the form Parent[index]/Child However the '/' can be
80  * replaced by a custom separator that can be specified as a parameter to the flatten() function.
81  */
82 template <typename _Pointer> std::string getRenamedName(const InstanceSharedPtr& inParentInstance,
83  const _Pointer& inRenamable, const std::vector<size_t>& inIndicesVector =
84  std::vector<size_t>());
85 
86 /**
87  * Flatten a given instance.
88  * Instance flattening is an operation where a given instance is replaced the internals of it's
89  * master in a given view. Instance flattening can be achieved on Single or Array Instances.
90  * However, it is not supported on the elements of an instance array.
91  *
92  * @param[in] inInstance The instance that need to be flattened. This will be removed after the
93  * operation.
94  * @param[in] inFactory The object factory used for cloning components in the instance.
95  *
96  * @param[in] inRecursive If true, Flatten instance hierarchy.
97  * @param[in] inSeparator Use this separator to separate hierarchy elements
98  * @param[in] inInstanceRenameFunc Function used to generate original name of new instances
99  * @param[in] inNetRenamingFunc Function used to generate original name of new rename
100  * @param[in] inInstanceNameFunc Function used to generate name of new instances
101  * @param[in] inNetNamingFunc Function used to generate name of new nets
102  *
103  * @note When connections are made to individual elements of a vector net using for example, say,
104  * the portList construct, the bits of the vectors are appropriately broken up into individual
105  * scalar nets, and connections removed from the vector nets.
106  */
107 void flatten(const InstanceSharedPtr& inInstance, const ObjectFactorySharedPtr& inFactory,
108  bool inRecursive = false, const std::string& inSeparator = "/",
109  const InstanceRenamingFunction& inInstanceRenameFunc
110  = InstanceRenamingFunction(getRenamedName<InstanceSharedPtr>),
111  const NetRenamingFunction& inNetRenameFunc = NetRenamingFunction(getRenamedName<NetSharedPtr>),
112  const InstanceNamingFunction& inInstanceNameFunc
113  = InstanceNamingFunction(getModifiedName<InstanceSharedPtr>),
114  const NetNamingFunction& inNetNameFunc
115  = NetNamingFunction(getModifiedName<NetSharedPtr>)) throw (Error);
116 
117 /**
118  * Flatten all instances in a given view.
119  * Instance flattening is an operation where a given instance is replaced the internals of it's
120  * master in a given view. Instance flattening can be achieved on Single or Array Instances.
121  * However, it is not supported on the elements of an instance array. Difference with the normal
122  * <i>flatten()</i> function is that this will keep flattening all instances in the gien view until
123  * a set of leaf instances is received. A <i>Leaf Instance</i> is an instance where the view has
124  * only interface delcarations and no instantiations of other cells within it.
125  *
126  * @param[in] inView All instances in the given view will be flatten.
127  * @param[in] inFactory The object factory used for cloning components in the instance.
128  *
129  * @param[in] inRecursive If true, Flatten instance hierarchy.
130  * @param[in] inSeparator Use this separator to separate hierarchy elements
131  * @param[in] inInstanceRenameFunc Function used to generate original name of new instances
132  * @param[in] inNetRenamingFunc Function used to generate original name of new rename
133  * @param[in] inInstanceNameFunc Function used to generate name of new instances
134  * @param[in] inNetNamingFunc Function used to generate name of new nets
135  *
136  * @note When connections are made to individual elements of a vector net using for example, say,
137  * the portList construct, the bits of the vectors are appropriately broken up into individual
138  * scalar nets, and conections removed from the vector nets.
139  */
140 void flatten(const ViewSharedPtr& inView, const ObjectFactorySharedPtr& inFactory,
141  bool inRecursive = false, const std::string& inSeparator = "/",
142  const InstanceRenamingFunction& inInstanceRenameFunc
145  const InstanceNamingFunction& inInstanceNameFunc
146  = InstanceNamingFunction(getModifiedName<InstanceSharedPtr>),
147  const NetNamingFunction& inNetNameFunc
148  = NetNamingFunction(getModifiedName<NetSharedPtr>)) throw (Error);
149 /**
150  * Flatten a given design, all NETLIST views owned by the design cell will be flattened.
151  * Instance flattening is an operation where a given instance is replaced the internals of
152  * it's master in a given view. Instance flattening can be achieved on Single or Array
153  * Instances. However, it is not supported on the elements of an instance array.
154  * Difference with the normal <i>flatten()</i> function is that this will keep flattening
155  * all instances in the given design until a set of leaf instances is received. A <i>Leaf
156  * Instance</i> is an instance where the view has only interface delcarations and no
157  * instantiations of other cells within it.
158  *
159  * @param[in] inDesign The design that need to be flattened.
160  * @param[in] inFactory The object factory used for cloning components in the instance.
161  *
162  * @param[in] inRecursive If true, Flatten instance hierarchy.
163  * @param[in] inSeparator Use this separator to separate hierarchy elements
164  * @param[in] inInstanceRenameFunc Function used to generate original name of new instances
165  * @param[in] inNetRenamingFunc Function used to generate original name of new rename
166  * @param[in] inInstanceNameFunc Function used to generate name of new instances
167  * @param[in] inNetNamingFunc Function used to generate name of new nets
168  *
169  * @note When connections are made to individual elements of a vector net using for example, say,
170  * the portList construct, the bits of the vectors are appropriately broken up into individual
171  * scalar nets, and conections removed from the vector nets.
172  */
173 void flatten(const DesignSharedPtr& inDesign, const ObjectFactorySharedPtr& inFactory,
174  bool inRecursive = false, const std::string& inSeparator = "/",
175  const InstanceRenamingFunction& inInstanceRenameFunc
176  = InstanceRenamingFunction(getRenamedName<InstanceSharedPtr>),
177  const NetRenamingFunction& inNetRenameFunc = NetRenamingFunction(getRenamedName<NetSharedPtr>),
178  const InstanceNamingFunction& inInstanceNameFunc
179  = InstanceNamingFunction(getModifiedName<InstanceSharedPtr>),
180  const NetNamingFunction& inNetNameFunc
181  = NetNamingFunction(getModifiedName<NetSharedPtr>)) throw (Error);
182 
183 } //namespace generic
184 } //namespace torc
185 
186 #endif // TORC_GENERIC_FLATTENING_HPP
boost::shared_ptr< Instance > InstanceSharedPtr
std::string getModifiedName(const std::string &inInstName, const _Pointer &inNameable, const std::vector< size_t > &inIndicesVector=std::vector< size_t >())
Definition: Flattening.cpp:707
boost::shared_ptr< ObjectFactory > ObjectFactorySharedPtr
std::string string
boost::shared_ptr< Design > DesignSharedPtr
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
boost::shared_ptr< Net > NetSharedPtr
boost::function< std::string(const InstanceSharedPtr &inParentInstance, const NetSharedPtr &inNet, const std::vector< size_t > &inIndicesVector)> NetRenamingFunction
Function to create names of nets that are set in rename constructs.
Definition: Flattening.hpp:54
boost::function< std::string(const InstanceSharedPtr &inParentInstance, const InstanceSharedPtr &inInstance, const std::vector< size_t > &inIndicesVector)> InstanceRenamingFunction
Function to create names of nets that are set in rename constructs.
Definition: Flattening.hpp:62
std::string getRenamedName(const InstanceSharedPtr &inParentInstance, const _Pointer &inRenamable, const std::vector< size_t > &inIndicesVector=std::vector< size_t >())
Definition: Flattening.cpp:713
boost::shared_ptr< View > ViewSharedPtr
boost::function< std::string(const std::string &inParentInstanceName, const NetSharedPtr &inNet, const std::vector< size_t > &inIndicesVector)> NetNamingFunction
Function to create net names during flattening.
Definition: Flattening.hpp:39
void flatten(const InstanceSharedPtr &inInstance, const ObjectFactorySharedPtr &inFactory, bool inRecursive, const std::string &inSeparator, const InstanceRenamingFunction &inInstanceRenameFunc, const NetRenamingFunction &inNetRenameFunc, const InstanceNamingFunction &inInstanceNameFunc, const NetNamingFunction &inNetNameFunc)
Definition: Flattening.cpp:739
boost::function< std::string(const std::string &inParentInstanceName, const InstanceSharedPtr &inInstance, const std::vector< size_t > &inIndicesVector)> InstanceNamingFunction
Function to create instance names during flattening.
Definition: Flattening.hpp:47