VIS

src/hrc/hrcHierarchy.c

Go to the documentation of this file.
00001 
00036 #include "hrcInt.h"
00037 
00038 static char rcsid[] UNUSED = "$Id: hrcHierarchy.c,v 1.4 2005/04/16 04:23:47 fabio Exp $";
00039 
00040 /*---------------------------------------------------------------------------*/
00041 /* Constant declarations                                                     */
00042 /*---------------------------------------------------------------------------*/
00043 
00044 
00045 /*---------------------------------------------------------------------------*/
00046 /* Type declarations                                                         */
00047 /*---------------------------------------------------------------------------*/
00048 
00049 
00050 /*---------------------------------------------------------------------------*/
00051 /* Stucture declarations                                                     */
00052 /*---------------------------------------------------------------------------*/
00053 
00054 
00055 /*---------------------------------------------------------------------------*/
00056 /* Variable declarations                                                     */
00057 /*---------------------------------------------------------------------------*/
00058 
00059 
00060 /*---------------------------------------------------------------------------*/
00061 /* Macro declarations                                                        */
00062 /*---------------------------------------------------------------------------*/
00063 
00064 
00067 /*---------------------------------------------------------------------------*/
00068 /* Static function prototypes                                                */
00069 /*---------------------------------------------------------------------------*/
00070 
00071 static Hrc_Node_t * _HrcCreateHierarchyAux(Hrc_Manager_t *hmgr, Hrc_Model_t *model, char *instanceName, st_table *pathTable);
00072 static int _HrcConnectParentChild(Hrc_Node_t *parent, Hrc_Node_t *child, Hrc_Subckt_t *subckt);
00073 
00077 /*---------------------------------------------------------------------------*/
00078 /* Definition of exported functions                                          */
00079 /*---------------------------------------------------------------------------*/
00080 
00096 Hrc_Node_t *
00097 Hrc_ModelCreateHierarchy(
00098   Hrc_Manager_t *hmgr,
00099   Hrc_Model_t *model,
00100   char *instanceName)
00101 {
00102   st_table *pathTable = st_init_table(st_ptrcmp,st_ptrhash);
00103   Hrc_Node_t *rootNode = _HrcCreateHierarchyAux(hmgr,model,instanceName,pathTable);
00104   st_free_table(pathTable);
00105   return rootNode;
00106 }
00107     
00108 
00109 /*---------------------------------------------------------------------------*/
00110 /* Definition of internal functions                                          */
00111 /*---------------------------------------------------------------------------*/
00112 
00113 /*---------------------------------------------------------------------------*/
00114 /* Definition of static functions                                            */
00115 /*---------------------------------------------------------------------------*/
00129 static Hrc_Node_t *
00130 _HrcCreateHierarchyAux(
00131   Hrc_Manager_t *hmgr,
00132   Hrc_Model_t *model,
00133   char *instanceName,
00134   st_table *pathTable)
00135 {
00136   Hrc_Node_t *rootNode, *childNode;
00137   Hrc_Model_t *modelToBeInstantiated;
00138   Hrc_Subckt_t *subckt;
00139   st_generator *gen;
00140 
00141   if (st_is_member(pathTable,(char *)model) == 1){
00142     error_append("Model ");
00143     error_append(Hrc_ModelReadName(model));
00144     error_append(" is defined by using itself.\n");
00145     return NIL(Hrc_Node_t);
00146   }
00147   rootNode = Hrc_NodeDup(Hrc_ModelReadMasterNode(model),instanceName);
00148   (void)st_insert(pathTable,model,NULL);
00149 
00150   Hrc_ModelForEachSubckt(model,gen,instanceName,subckt){
00151     modelToBeInstantiated = Hrc_SubcktReadModel(subckt);
00152     childNode = _HrcCreateHierarchyAux(hmgr,modelToBeInstantiated,Hrc_SubcktReadInstanceName(subckt),pathTable);
00153     if (childNode == NIL(Hrc_Node_t)){
00154       return NIL(Hrc_Node_t);
00155     }
00156     if (_HrcConnectParentChild(rootNode,childNode,subckt) == 0){
00157       return NIL(Hrc_Node_t);
00158     }
00159   }
00160   (void)st_delete(pathTable,&model,NULL);
00161   return rootNode;
00162 }
00163 
00164 
00178 static int
00179 _HrcConnectParentChild(
00180   Hrc_Node_t *parent, 
00181   Hrc_Node_t *child,
00182   Hrc_Subckt_t *subckt)
00183 {
00184   array_t *actualInputVars, *actualOutputVars;
00185   array_t *realActualInputVars, *realActualOutputVars;
00186   int i;
00187   Var_Variable_t *var, *realVar;
00188 
00189   /* actual inputs and outputs in the master hnode corresponsing to the parent */
00190   actualInputVars = Hrc_SubcktReadActualInputVars(subckt);
00191   actualOutputVars = Hrc_SubcktReadActualOutputVars(subckt);
00192 
00193   /* collect all the actual inputs in the parent */
00194   realActualInputVars = array_alloc(Var_Variable_t *,0);
00195   for (i=0; i < array_n(actualInputVars); i++){
00196     var = array_fetch(Var_Variable_t *,actualInputVars,i);
00197     realVar = Hrc_NodeFindVariableByName(parent,Var_VariableReadName(var)); 
00198     array_insert_last(Var_Variable_t *,realActualInputVars,realVar);
00199   }
00200   /* collect all the actual outputs in the parent */
00201   realActualOutputVars = array_alloc(Var_Variable_t *,0);
00202   for (i=0; i < array_n(actualOutputVars); i++){
00203     var = array_fetch(Var_Variable_t *,actualOutputVars,i);
00204     realVar = Hrc_NodeFindVariableByName(parent,Var_VariableReadName(var)); 
00205     array_insert_last(Var_Variable_t *,realActualOutputVars,realVar);
00206   }
00207   /* connects the parent and the child using an hrc function */
00208   if (Hrc_NodeAddChild(parent,child,realActualInputVars,realActualOutputVars) == 0){
00209      return 0;
00210   }
00211   return 1;
00212 }
00213   
00214 
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 
00223 
00224 
00225 
00226 
00227 
00228