[14] | 1 | /**CFile*********************************************************************** |
---|
| 2 | |
---|
| 3 | FileName [hrcHierarchy.c] |
---|
| 4 | |
---|
| 5 | PackageName [hrc] |
---|
| 6 | |
---|
| 7 | Synopsis [Creates a hierarchy from model definitions.] |
---|
| 8 | |
---|
| 9 | Description [] |
---|
| 10 | |
---|
| 11 | SeeAlso [] |
---|
| 12 | |
---|
| 13 | Author [Yuji Kukimoto] |
---|
| 14 | |
---|
| 15 | Copyright [Copyright (c) 1994-1996 The Regents of the Univ. of California. |
---|
| 16 | All rights reserved. |
---|
| 17 | |
---|
| 18 | Permission is hereby granted, without written agreement and without license |
---|
| 19 | or royalty fees, to use, copy, modify, and distribute this software and its |
---|
| 20 | documentation for any purpose, provided that the above copyright notice and |
---|
| 21 | the following two paragraphs appear in all copies of this software. |
---|
| 22 | |
---|
| 23 | IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR |
---|
| 24 | DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT |
---|
| 25 | OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF |
---|
| 26 | CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 27 | |
---|
| 28 | THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, |
---|
| 29 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
---|
| 30 | FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN |
---|
| 31 | "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE |
---|
| 32 | MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.] |
---|
| 33 | |
---|
| 34 | ******************************************************************************/ |
---|
| 35 | |
---|
| 36 | #include "hrcInt.h" |
---|
| 37 | |
---|
| 38 | static char rcsid[] UNUSED = "$Id: hrcHierarchy.c,v 1.4 2005/04/16 04:23:47 fabio Exp $"; |
---|
| 39 | |
---|
| 40 | /*---------------------------------------------------------------------------*/ |
---|
| 41 | /* Constant declarations */ |
---|
| 42 | /*---------------------------------------------------------------------------*/ |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | /*---------------------------------------------------------------------------*/ |
---|
| 46 | /* Type declarations */ |
---|
| 47 | /*---------------------------------------------------------------------------*/ |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | /*---------------------------------------------------------------------------*/ |
---|
| 51 | /* Stucture declarations */ |
---|
| 52 | /*---------------------------------------------------------------------------*/ |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | /*---------------------------------------------------------------------------*/ |
---|
| 56 | /* Variable declarations */ |
---|
| 57 | /*---------------------------------------------------------------------------*/ |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | /*---------------------------------------------------------------------------*/ |
---|
| 61 | /* Macro declarations */ |
---|
| 62 | /*---------------------------------------------------------------------------*/ |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | /**AutomaticStart*************************************************************/ |
---|
| 66 | |
---|
| 67 | /*---------------------------------------------------------------------------*/ |
---|
| 68 | /* Static function prototypes */ |
---|
| 69 | /*---------------------------------------------------------------------------*/ |
---|
| 70 | |
---|
| 71 | static Hrc_Node_t * _HrcCreateHierarchyAux(Hrc_Manager_t *hmgr, Hrc_Model_t *model, char *instanceName, st_table *pathTable); |
---|
| 72 | static int _HrcConnectParentChild(Hrc_Node_t *parent, Hrc_Node_t *child, Hrc_Subckt_t *subckt); |
---|
| 73 | |
---|
| 74 | /**AutomaticEnd***************************************************************/ |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | /*---------------------------------------------------------------------------*/ |
---|
| 78 | /* Definition of exported functions */ |
---|
| 79 | /*---------------------------------------------------------------------------*/ |
---|
| 80 | |
---|
| 81 | /**Function******************************************************************** |
---|
| 82 | |
---|
| 83 | Synopsis [Creates a hierarchy from model definitinos.] |
---|
| 84 | |
---|
| 85 | Description [Creates a hierarchy from model definitinos. The second |
---|
| 86 | argument is a pointer to the root model. The last argument is the name |
---|
| 87 | of the root node. A hash table pathTable is used to check to see if |
---|
| 88 | there is no cyclic model definition.] |
---|
| 89 | |
---|
| 90 | SideEffects [] |
---|
| 91 | |
---|
| 92 | SeeAlso [_HrcCreateHierarchyAux] |
---|
| 93 | |
---|
| 94 | ******************************************************************************/ |
---|
| 95 | |
---|
| 96 | Hrc_Node_t * |
---|
| 97 | Hrc_ModelCreateHierarchy( |
---|
| 98 | Hrc_Manager_t *hmgr, |
---|
| 99 | Hrc_Model_t *model, |
---|
| 100 | char *instanceName) |
---|
| 101 | { |
---|
| 102 | st_table *pathTable = st_init_table(st_ptrcmp,st_ptrhash); |
---|
| 103 | Hrc_Node_t *rootNode = _HrcCreateHierarchyAux(hmgr,model,instanceName,pathTable); |
---|
| 104 | st_free_table(pathTable); |
---|
| 105 | return rootNode; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | /*---------------------------------------------------------------------------*/ |
---|
| 110 | /* Definition of internal functions */ |
---|
| 111 | /*---------------------------------------------------------------------------*/ |
---|
| 112 | |
---|
| 113 | /*---------------------------------------------------------------------------*/ |
---|
| 114 | /* Definition of static functions */ |
---|
| 115 | /*---------------------------------------------------------------------------*/ |
---|
| 116 | /**Function******************************************************************** |
---|
| 117 | |
---|
| 118 | Synopsis [Recursively creates a hierarchy from model definitinos.] |
---|
| 119 | |
---|
| 120 | Description [] |
---|
| 121 | |
---|
| 122 | SideEffects [pathTable is updated to keep track of the models used |
---|
| 123 | from the root to the current node.] |
---|
| 124 | |
---|
| 125 | SeeAlso [Hrc_CreateHierarchy] |
---|
| 126 | |
---|
| 127 | ******************************************************************************/ |
---|
| 128 | |
---|
| 129 | static Hrc_Node_t * |
---|
| 130 | _HrcCreateHierarchyAux( |
---|
| 131 | Hrc_Manager_t *hmgr, |
---|
| 132 | Hrc_Model_t *model, |
---|
| 133 | char *instanceName, |
---|
| 134 | st_table *pathTable) |
---|
| 135 | { |
---|
| 136 | Hrc_Node_t *rootNode, *childNode; |
---|
| 137 | Hrc_Model_t *modelToBeInstantiated; |
---|
| 138 | Hrc_Subckt_t *subckt; |
---|
| 139 | st_generator *gen; |
---|
| 140 | |
---|
| 141 | if (st_is_member(pathTable,(char *)model) == 1){ |
---|
| 142 | error_append("Model "); |
---|
| 143 | error_append(Hrc_ModelReadName(model)); |
---|
| 144 | error_append(" is defined by using itself.\n"); |
---|
| 145 | return NIL(Hrc_Node_t); |
---|
| 146 | } |
---|
| 147 | rootNode = Hrc_NodeDup(Hrc_ModelReadMasterNode(model),instanceName); |
---|
| 148 | (void)st_insert(pathTable,model,NULL); |
---|
| 149 | |
---|
| 150 | Hrc_ModelForEachSubckt(model,gen,instanceName,subckt){ |
---|
| 151 | modelToBeInstantiated = Hrc_SubcktReadModel(subckt); |
---|
| 152 | childNode = _HrcCreateHierarchyAux(hmgr,modelToBeInstantiated,Hrc_SubcktReadInstanceName(subckt),pathTable); |
---|
| 153 | if (childNode == NIL(Hrc_Node_t)){ |
---|
| 154 | return NIL(Hrc_Node_t); |
---|
| 155 | } |
---|
| 156 | if (_HrcConnectParentChild(rootNode,childNode,subckt) == 0){ |
---|
| 157 | return NIL(Hrc_Node_t); |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | (void)st_delete(pathTable,&model,NULL); |
---|
| 161 | return rootNode; |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | /**Function******************************************************************** |
---|
| 166 | |
---|
| 167 | Synopsis [Connects a parent node and a child node using Hrc_Subckt_t |
---|
| 168 | information.] |
---|
| 169 | |
---|
| 170 | Description [] |
---|
| 171 | |
---|
| 172 | SideEffects [The parent node and the child node are connected together |
---|
| 173 | in the hierarchy.] |
---|
| 174 | |
---|
| 175 | SeeAlso [Hrc_NodeAddChild] |
---|
| 176 | |
---|
| 177 | ******************************************************************************/ |
---|
| 178 | static int |
---|
| 179 | _HrcConnectParentChild( |
---|
| 180 | Hrc_Node_t *parent, |
---|
| 181 | Hrc_Node_t *child, |
---|
| 182 | Hrc_Subckt_t *subckt) |
---|
| 183 | { |
---|
| 184 | array_t *actualInputVars, *actualOutputVars; |
---|
| 185 | array_t *realActualInputVars, *realActualOutputVars; |
---|
| 186 | int i; |
---|
| 187 | Var_Variable_t *var, *realVar; |
---|
| 188 | |
---|
| 189 | /* actual inputs and outputs in the master hnode corresponsing to the parent */ |
---|
| 190 | actualInputVars = Hrc_SubcktReadActualInputVars(subckt); |
---|
| 191 | actualOutputVars = Hrc_SubcktReadActualOutputVars(subckt); |
---|
| 192 | |
---|
| 193 | /* collect all the actual inputs in the parent */ |
---|
| 194 | realActualInputVars = array_alloc(Var_Variable_t *,0); |
---|
| 195 | for (i=0; i < array_n(actualInputVars); i++){ |
---|
| 196 | var = array_fetch(Var_Variable_t *,actualInputVars,i); |
---|
| 197 | realVar = Hrc_NodeFindVariableByName(parent,Var_VariableReadName(var)); |
---|
| 198 | array_insert_last(Var_Variable_t *,realActualInputVars,realVar); |
---|
| 199 | } |
---|
| 200 | /* collect all the actual outputs in the parent */ |
---|
| 201 | realActualOutputVars = array_alloc(Var_Variable_t *,0); |
---|
| 202 | for (i=0; i < array_n(actualOutputVars); i++){ |
---|
| 203 | var = array_fetch(Var_Variable_t *,actualOutputVars,i); |
---|
| 204 | realVar = Hrc_NodeFindVariableByName(parent,Var_VariableReadName(var)); |
---|
| 205 | array_insert_last(Var_Variable_t *,realActualOutputVars,realVar); |
---|
| 206 | } |
---|
| 207 | /* connects the parent and the child using an hrc function */ |
---|
| 208 | if (Hrc_NodeAddChild(parent,child,realActualInputVars,realActualOutputVars) == 0){ |
---|
| 209 | return 0; |
---|
| 210 | } |
---|
| 211 | return 1; |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | |
---|
| 215 | |
---|
| 216 | |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | |
---|
| 220 | |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | |
---|
| 225 | |
---|
| 226 | |
---|
| 227 | |
---|
| 228 | |
---|