VIS
|
00001 00036 #include "hrcInt.h" 00037 00038 static char rcsid[] UNUSED = "$Id: hrcCmd.c,v 1.6 2002/09/08 21:54:25 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 int CommandCd(Hrc_Manager_t **hmgr, int argc, char **argv); 00072 static int CommandLs(Hrc_Manager_t **hmgr, int argc, char **argv); 00073 static int CommandPwd(Hrc_Manager_t **hmgr, int argc, char **argv); 00074 static void NodeListChildren(Hrc_Node_t *hnode, boolean recursiveFlag, int depth); 00075 static void PrintSpace(int depth); 00076 static int CommandPrintModels(Hrc_Manager_t **hmgr, int argc, char **argv); 00077 static int CommandPrintHierarchyStats(Hrc_Manager_t **hmgr, int argc, char **argv); 00078 static void PrintNodeStats(Hrc_Node_t *node, boolean isHnode); 00079 static void PrintNodeStatsRecursively(Hrc_Node_t *node); 00080 static int CommandPrintIo(Hrc_Manager_t **hmgr, int argc, char **argv); 00081 static int CommandPrintLatches(Hrc_Manager_t **hmgr, int argc, char **argv); 00082 static int _HrcStringCmp(const void * s1, const void * s2); 00083 00087 /*---------------------------------------------------------------------------*/ 00088 /* Definition of exported functions */ 00089 /*---------------------------------------------------------------------------*/ 00090 00100 void 00101 Hrc_Init(void) 00102 { 00103 Cmd_CommandAdd("cd", CommandCd, 0); 00104 Cmd_CommandAdd("ls", CommandLs, 0); 00105 Cmd_CommandAdd("pwd", CommandPwd, 0); 00106 Cmd_CommandAdd("print_models", CommandPrintModels, 0); 00107 Cmd_CommandAdd("print_hierarchy_stats", CommandPrintHierarchyStats, 0); 00108 Cmd_CommandAdd("print_io", CommandPrintIo, 0); 00109 Cmd_CommandAdd("print_latches", CommandPrintLatches, 0); 00110 } 00111 00121 void 00122 Hrc_End(void) 00123 { 00124 } 00125 /*---------------------------------------------------------------------------*/ 00126 /* Definition of internal functions */ 00127 /*---------------------------------------------------------------------------*/ 00128 00129 00130 /*---------------------------------------------------------------------------*/ 00131 /* Definition of static functions */ 00132 /*---------------------------------------------------------------------------*/ 00133 00162 static int 00163 CommandCd( 00164 Hrc_Manager_t **hmgr, 00165 int argc, 00166 char **argv) 00167 { 00168 Hrc_Node_t *currentNode, *parent, *child; 00169 int c; 00170 00171 util_getopt_reset(); 00172 while ((c = util_getopt(argc, argv, "h")) != EOF) { 00173 switch(c){ 00174 case 'h': 00175 goto usage; 00176 default: 00177 goto usage; 00178 } 00179 } 00180 00181 if (argc != 2){ 00182 goto usage; 00183 } 00184 00185 currentNode = Hrc_ManagerReadCurrentNode(*hmgr); 00186 if (currentNode == NIL(Hrc_Node_t)){ 00187 (void)fprintf(vis_stdout,"No file has been read in.\n"); 00188 return 1; 00189 } 00190 /* go to the parent node */ 00191 if (strcmp(*(++argv),"..") == 0){ 00192 if ((parent = Hrc_NodeReadParentNode(currentNode)) == NIL(Hrc_Node_t)){ 00193 (void)fprintf(vis_stderr,"You are at the root node. Can't cd to a parent.\n"); 00194 return 1; 00195 } 00196 Hrc_ManagerSetCurrentNode(*hmgr,parent); 00197 return 0; 00198 } 00199 00200 if ((child = Hrc_NodeFindChildByName(currentNode,*argv)) == NIL(Hrc_Node_t)){ 00201 (void)fprintf(vis_stderr,"No child node whose name is %s exists in the current node.\n",*argv); 00202 return 1; 00203 } 00204 Hrc_ManagerSetCurrentNode(*hmgr,child); 00205 return 0; 00206 00207 usage: 00208 (void)fprintf(vis_stderr,"usage: cd [-h] child_name or cd ..\n"); 00209 (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); 00210 return 1; 00211 } 00212 00240 static int 00241 CommandLs( 00242 Hrc_Manager_t **hmgr, 00243 int argc, 00244 char **argv) 00245 { 00246 int recursiveFlag = 0; 00247 int c; 00248 Hrc_Node_t *currentNode; 00249 00250 util_getopt_reset(); 00251 while ((c = util_getopt(argc, argv, "hR")) != EOF) { 00252 switch(c){ 00253 case 'h': 00254 goto usage; 00255 case 'R': 00256 recursiveFlag = 1; 00257 break; 00258 default: 00259 goto usage; 00260 } 00261 } 00262 /* if there are some arguments for ls */ 00263 if (argc != util_optind){ 00264 goto usage; 00265 } 00266 00267 currentNode = Hrc_ManagerReadCurrentNode(*hmgr); 00268 if (currentNode == NIL(Hrc_Node_t)){ 00269 (void)fprintf(vis_stdout,"No file has been read in.\n"); 00270 return 1; 00271 } 00272 NodeListChildren(currentNode, recursiveFlag, 0); 00273 return 0; 00274 00275 usage: 00276 (void)fprintf(vis_stderr,"usage: ls [-h] [-R]\n"); 00277 (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); 00278 (void) fprintf(vis_stderr, " -R \t\tprint recursive tree\n"); 00279 00280 return 1; 00281 } 00282 00311 static int 00312 CommandPwd( 00313 Hrc_Manager_t **hmgr, 00314 int argc, 00315 char **argv) 00316 { 00317 Hrc_Node_t *currentNode; 00318 Hrc_Node_t *rootNode; 00319 char *separator, *hierarchicalName; 00320 int c; 00321 00322 util_getopt_reset(); 00323 while ((c = util_getopt(argc, argv, "h")) != EOF) { 00324 switch(c){ 00325 case 'h': 00326 goto usage; 00327 default: 00328 goto usage; 00329 } 00330 } 00331 if (argc != 1){ 00332 goto usage; 00333 } 00334 00335 currentNode = Hrc_ManagerReadCurrentNode(*hmgr); 00336 if (currentNode == NIL(Hrc_Node_t)){ 00337 (void)fprintf(vis_stdout,"No file has been read in.\n"); 00338 return 1; 00339 } 00340 rootNode = Hrc_ManagerReadRootNode(*hmgr); 00341 separator = (char *) ((rootNode == currentNode) ? "" : "."); 00342 hierarchicalName = Hrc_NodeFindHierarchicalName(currentNode, FALSE); 00343 (void)fprintf(vis_stdout,"%s%s%s\n", Hrc_NodeReadInstanceName(rootNode), 00344 separator, hierarchicalName); 00345 FREE(hierarchicalName); 00346 return 0; 00347 00348 usage: 00349 (void)fprintf(vis_stderr,"usage: pwd [-h]\n"); 00350 (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); 00351 return 1; 00352 } 00353 00366 static void 00367 NodeListChildren( 00368 Hrc_Node_t *hnode, 00369 boolean recursiveFlag, 00370 int depth) 00371 { 00372 st_generator *gen; 00373 char *childName; 00374 Hrc_Node_t *child; 00375 int newDepth, i; 00376 array_t *tmpArray; 00377 00378 newDepth = depth + 1; 00379 tmpArray = array_alloc(char *,0); 00380 Hrc_NodeForEachChild(hnode,gen,childName,child){ 00381 array_insert_last(char *,tmpArray,childName); 00382 } 00383 array_sort(tmpArray,_HrcStringCmp); 00384 for (i=0; i < array_n(tmpArray); i++){ 00385 PrintSpace(depth); 00386 childName = array_fetch(char *,tmpArray,i); 00387 (void)fprintf(vis_stdout,"%s\n",childName); 00388 if (recursiveFlag == 1){ 00389 NodeListChildren(Hrc_NodeFindChildByName(hnode,childName),recursiveFlag,newDepth); 00390 } 00391 } 00392 array_free(tmpArray); 00393 } 00394 00395 00405 static void 00406 PrintSpace(int depth) 00407 { 00408 int i; 00409 for (i=0; i < depth; i++){ 00410 (void)fprintf(vis_stdout," "); 00411 } 00412 } 00413 00441 static int 00442 CommandPrintModels( 00443 Hrc_Manager_t **hmgr, 00444 int argc, 00445 char **argv) 00446 { 00447 st_generator *gen; 00448 char *name; 00449 Hrc_Model_t *model; 00450 Hrc_Node_t *node; 00451 int c; 00452 00453 util_getopt_reset(); 00454 while ((c = util_getopt(argc, argv, "h")) != EOF) { 00455 switch(c){ 00456 case 'h': 00457 goto usage; 00458 default: 00459 goto usage; 00460 } 00461 } 00462 if(argc != 1) { 00463 goto usage; 00464 } 00465 00466 node = Hrc_ManagerReadCurrentNode(*hmgr); 00467 if (node == NIL(Hrc_Node_t)){ 00468 (void)fprintf(vis_stderr,"No file has been read in.\n"); 00469 return 1; 00470 } 00471 00472 Hrc_ManagerForEachModel(*hmgr, gen, name, model) { 00473 PrintNodeStats(Hrc_ModelReadMasterNode(model), FALSE); 00474 (void) fprintf(vis_stdout, "subckts = %d\n", 00475 st_count(Hrc_ModelReadSubcktTable(model))); 00476 } 00477 return 0; 00478 00479 usage: 00480 (void) fprintf(vis_stderr, "usage: print_models [-h]\n"); 00481 (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); 00482 return 1; 00483 } 00484 00514 static int 00515 CommandPrintHierarchyStats( 00516 Hrc_Manager_t **hmgr, 00517 int argc, 00518 char **argv) 00519 { 00520 int c; 00521 int recursiveFlag = 0; 00522 Hrc_Node_t *node; 00523 00524 util_getopt_reset(); 00525 while ((c = util_getopt(argc, argv, "hR")) != EOF) { 00526 switch(c){ 00527 case 'h': 00528 goto usage; 00529 case 'R': 00530 recursiveFlag = 1; 00531 break; 00532 default: 00533 goto usage; 00534 } 00535 } 00536 /* if there are some arguments left */ 00537 if (argc != util_optind){ 00538 goto usage; 00539 } 00540 00541 node = Hrc_ManagerReadCurrentNode(*hmgr); 00542 if (node == NIL(Hrc_Node_t)){ 00543 (void)fprintf(vis_stderr,"No file has been read in.\n"); 00544 return 1; 00545 } 00546 00547 if(recursiveFlag) { 00548 PrintNodeStatsRecursively(node); 00549 } 00550 else { 00551 PrintNodeStats(node, TRUE); 00552 } 00553 return 0; 00554 usage: 00555 (void) fprintf(vis_stderr,"usage: print_hierarchy_stats [-h][-R]\n"); 00556 (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); 00557 (void) fprintf(vis_stderr, " -R \t\tprint recursive tree\n"); 00558 return 1; 00559 } 00560 00570 static void 00571 PrintNodeStats( 00572 Hrc_Node_t *node, 00573 boolean isHnode) 00574 { 00575 (void) fprintf(vis_stdout, "Model name = %s", Hrc_NodeReadModelName(node)); 00576 if(isHnode) { 00577 (void) fprintf(vis_stdout, ", Instance name = %s\n", 00578 Hrc_NodeReadInstanceName(node)); 00579 } 00580 else { 00581 (void) fprintf(vis_stdout, "\n"); 00582 } 00583 (void) fprintf(vis_stdout, "inputs = %d,", Hrc_NodeReadNumFormalInputs(node)); 00584 (void) fprintf(vis_stdout, " outputs = %d,", Hrc_NodeReadNumFormalOutputs(node)); 00585 (void) fprintf(vis_stdout, " variables = %d,", Hrc_NodeReadNumVariables(node)); 00586 (void) fprintf(vis_stdout, " tables = %d,", Hrc_NodeReadNumTables(node)); 00587 (void) fprintf(vis_stdout, " latches = %d", Hrc_NodeReadNumLatches(node)); 00588 if(isHnode) { 00589 (void) fprintf(vis_stdout, ", children = %d\n", Hrc_NodeReadNumChildren(node)); 00590 } 00591 else { 00592 (void) fprintf(vis_stdout, "\n"); 00593 } 00594 } 00595 00606 static void 00607 PrintNodeStatsRecursively( 00608 Hrc_Node_t *node) 00609 { 00610 Hrc_Node_t *childNode; 00611 st_generator *gen; 00612 char *name; 00613 00614 PrintNodeStats(node, TRUE); 00615 Hrc_NodeForEachChild(node, gen, name, childNode) { 00616 PrintNodeStatsRecursively(childNode); 00617 } 00618 } 00619 00644 static int 00645 CommandPrintIo( 00646 Hrc_Manager_t **hmgr, 00647 int argc, 00648 char **argv) 00649 { 00650 int c, i; 00651 Hrc_Node_t *node; 00652 Var_Variable_t *var; 00653 array_t *tmpArray; 00654 00655 util_getopt_reset(); 00656 while ((c = util_getopt(argc, argv, "h")) != EOF) { 00657 switch(c){ 00658 case 'h': 00659 goto usage; 00660 default: 00661 goto usage; 00662 } 00663 } 00664 /* if there are some arguments left */ 00665 if (argc != util_optind){ 00666 goto usage; 00667 } 00668 node = Hrc_ManagerReadCurrentNode(*hmgr); 00669 if (node == NIL(Hrc_Node_t)){ 00670 (void)fprintf(vis_stderr,"No file has been read in.\n"); 00671 return 1; 00672 } 00673 00674 if (Hrc_NodeReadNumFormalInputs(node) == 0){ 00675 fprintf(vis_stdout,"No inputs\n"); 00676 } 00677 else { 00678 tmpArray = array_alloc(char *,0); 00679 Hrc_NodeForEachFormalInput(node,i,var){ 00680 array_insert_last(char *,tmpArray,Var_VariableReadName(var)); 00681 } 00682 array_sort(tmpArray,_HrcStringCmp); 00683 fprintf(vis_stdout,"inputs:"); 00684 for (i=0; i < array_n(tmpArray); i++){ 00685 fprintf(vis_stdout," %s",array_fetch(char *,tmpArray,i)); 00686 } 00687 fprintf(vis_stdout,"\n"); 00688 array_free(tmpArray); 00689 } 00690 00691 if (Hrc_NodeReadNumFormalOutputs(node) == 0){ 00692 fprintf(vis_stdout,"No outputs\n"); 00693 } 00694 else { 00695 tmpArray = array_alloc(char *,0); 00696 Hrc_NodeForEachFormalOutput(node,i,var){ 00697 array_insert_last(char *,tmpArray,Var_VariableReadName(var)); 00698 } 00699 array_sort(tmpArray,_HrcStringCmp); 00700 fprintf(vis_stdout,"outputs:"); 00701 for (i=0; i < array_n(tmpArray); i++){ 00702 fprintf(vis_stdout," %s",array_fetch(char *,tmpArray,i)); 00703 } 00704 fprintf(vis_stdout,"\n"); 00705 array_free(tmpArray); 00706 } 00707 return 0; 00708 00709 usage: 00710 (void) fprintf(vis_stderr,"usage: print_io [-h]\n"); 00711 (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); 00712 return 1; 00713 } 00714 00739 static int 00740 CommandPrintLatches( 00741 Hrc_Manager_t **hmgr, 00742 int argc, 00743 char **argv) 00744 { 00745 int c, i; 00746 Hrc_Node_t *node; 00747 st_generator *gen; 00748 char *latchName; 00749 Hrc_Latch_t *latch; 00750 array_t *tmpArray; 00751 00752 util_getopt_reset(); 00753 while ((c = util_getopt(argc, argv, "h")) != EOF) { 00754 switch(c){ 00755 case 'h': 00756 goto usage; 00757 default: 00758 goto usage; 00759 } 00760 } 00761 /* if there are some arguments left */ 00762 if (argc != util_optind){ 00763 goto usage; 00764 } 00765 node = Hrc_ManagerReadCurrentNode(*hmgr); 00766 if (node == NIL(Hrc_Node_t)){ 00767 (void)fprintf(vis_stderr,"No file has been read in.\n"); 00768 return 1; 00769 } 00770 00771 if (Hrc_NodeReadNumLatches(node) == 0){ 00772 fprintf(vis_stdout,"No latches\n"); 00773 } 00774 else { 00775 tmpArray = array_alloc(char *,0); 00776 Hrc_NodeForEachLatch(node,gen,latchName,latch){ 00777 array_insert_last(char *,tmpArray,latchName); 00778 } 00779 array_sort(tmpArray,_HrcStringCmp); 00780 for (i=0; i < array_n(tmpArray); i++){ 00781 fprintf(vis_stdout,"%s ",array_fetch(char *,tmpArray,i)); 00782 } 00783 fprintf(vis_stdout,"\n"); 00784 array_free(tmpArray); 00785 } 00786 return 0; 00787 00788 usage: 00789 (void) fprintf(vis_stderr,"usage: print_latches [-h]\n"); 00790 (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); 00791 return 1; 00792 } 00793 00805 static int 00806 _HrcStringCmp( 00807 const void * s1, 00808 const void * s2) 00809 { 00810 return(strcmp(*(char **)s1, *(char **)s2)); 00811 } 00812