VIS
|
00001 00035 #include "hrcInt.h" 00036 #include "io.h" 00037 00038 static char rcsid[] UNUSED = "$Id: hrcInOut.c,v 1.6 2005/04/28 14:16:09 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 00075 /*---------------------------------------------------------------------------*/ 00076 /* Definition of exported functions */ 00077 /*---------------------------------------------------------------------------*/ 00114 boolean 00115 Hrc_NodeAddApplInfo( 00116 Hrc_Node_t *node, 00117 char * key, 00118 Hrc_ApplInfoFreeFn freeFn, 00119 Hrc_ApplInfoChangeFn changeFn, 00120 void * data) 00121 { 00122 ApplInfo_t *applInfo; 00123 boolean status; 00124 00125 if (st_lookup(node->applInfoTable, key, &applInfo)) { 00126 (*applInfo->freeFn)(applInfo->data); 00127 status = TRUE; 00128 } 00129 else { 00130 char *keyCopy = util_strsav(key); 00131 00132 applInfo = ALLOC(ApplInfo_t, 1); 00133 st_insert(node->applInfoTable, keyCopy, applInfo); 00134 status = FALSE; 00135 } 00136 applInfo->freeFn = freeFn; 00137 applInfo->changeFn = changeFn; 00138 applInfo->data = data; 00139 return status; 00140 } 00141 00142 00155 void * 00156 Hrc_NodeReadApplInfo( 00157 Hrc_Node_t *node, 00158 char * key) 00159 { 00160 int status; 00161 ApplInfo_t *applInfo; 00162 00163 status = st_lookup(node->applInfoTable, key, &applInfo); 00164 if (status == 1) { 00165 return (applInfo->data); 00166 } 00167 else { 00168 return (NIL(void)); 00169 } 00170 } 00171 00172 00190 boolean 00191 Hrc_NodeFreeApplInfo( 00192 Hrc_Node_t *node, 00193 char * key) 00194 { 00195 int status; 00196 ApplInfo_t *applInfo; 00197 00198 status = st_lookup(node->applInfoTable, key, &applInfo); 00199 00200 if (status == 1) { 00201 st_delete(node->applInfoTable, &key, &applInfo); 00202 (*applInfo->freeFn)(applInfo->data); 00203 FREE(key); /* frees the string contained in the table */ 00204 FREE(applInfo); 00205 } 00206 00207 return ((status) ? TRUE : FALSE); 00208 } 00209 00225 void 00226 Hrc_ModelWriteBlifMv( 00227 FILE *fp, 00228 Hrc_Model_t *model, 00229 boolean isRootModel, 00230 char *rootInstanceName) 00231 { 00232 Hrc_Node_t *hnode, *subcktHnode; 00233 Hrc_Model_t *subcktModel; 00234 int i, is_enum, range; 00235 Var_Variable_t *var, *actualVar; 00236 Hrc_Latch_t *latch; 00237 Hrc_Subckt_t *subckt; 00238 Tbl_Table_t *table; 00239 char *varName, *latchName, *instanceName; 00240 st_generator *gen; 00241 array_t *subcktActualInputVars, *subcktActualOutputVars; 00242 00243 (void)fprintf(fp,".model %s\n",Hrc_ModelReadName(model)); 00244 if (isRootModel){ 00245 (void)fprintf(fp,".root %s\n",rootInstanceName); 00246 } 00247 hnode = Hrc_ModelReadMasterNode(model); 00248 00249 /* .inputs */ 00250 if (Hrc_NodeReadNumFormalInputs(hnode) != 0){ 00251 (void)fprintf(fp,".inputs "); 00252 Hrc_NodeForEachFormalInput(hnode,i,var){ 00253 (void)fprintf(fp,"%s ",Var_VariableReadName(var)); 00254 } 00255 (void)fprintf(fp,"\n"); 00256 } 00257 00258 /* .outputs */ 00259 if (Hrc_NodeReadNumFormalOutputs(hnode) != 0){ 00260 (void)fprintf(fp,".outputs "); 00261 Hrc_NodeForEachFormalOutput(hnode,i,var){ 00262 (void)fprintf(fp,"%s ",Var_VariableReadName(var)); 00263 } 00264 (void)fprintf(fp,"\n"); 00265 } 00266 00267 /* .mv */ 00268 Hrc_NodeForEachVariable(hnode,gen,varName,var){ 00269 is_enum = Var_VariableTestIsEnumerative(var); 00270 range = Var_VariableReadNumValues(var); 00271 00272 if (is_enum == 1){ 00273 if (range == 2){ 00274 /* Boolean enumerative variables need no .mv declaration. */ 00275 continue; 00276 } 00277 else { 00278 (void)fprintf(fp,".mv %s %d\n",Var_VariableReadName(var),range); 00279 } 00280 } 00281 else { 00282 /* variable var is symbolic */ 00283 (void)fprintf(fp,".mv %s %d ",Var_VariableReadName(var),range); 00284 for (i=0; i < range; i++){ 00285 (void)fprintf(fp,"%s ",Var_VariableReadSymbolicValueFromIndex(var,i)); 00286 } 00287 (void)fprintf(fp,"\n"); 00288 } 00289 } 00290 00291 /* .latches */ 00292 Hrc_NodeForEachLatch(hnode,gen,latchName,latch){ 00293 (void)fprintf(fp,".latch %s %s\n", 00294 Var_VariableReadName(Hrc_LatchReadInput(latch)), 00295 Var_VariableReadName(Hrc_LatchReadOutput(latch))); 00296 Tbl_TableWriteBlifMvToFile(Hrc_LatchReadResetTable(latch),1,fp); 00297 } 00298 00299 /* .subckt */ 00300 Hrc_ModelForEachSubckt(model,gen,instanceName,subckt){ 00301 subcktModel = Hrc_SubcktReadModel(subckt); 00302 subcktHnode = Hrc_ModelReadMasterNode(subcktModel); 00303 subcktActualInputVars = Hrc_SubcktReadActualInputVars(subckt); 00304 subcktActualOutputVars = Hrc_SubcktReadActualOutputVars(subckt); 00305 00306 (void)fprintf(fp,".subckt %s %s ", 00307 Hrc_ModelReadName(subcktModel), Hrc_SubcktReadInstanceName(subckt)); 00308 Hrc_NodeForEachFormalInput(subcktHnode,i,var){ 00309 actualVar = array_fetch(Var_Variable_t *,subcktActualInputVars,i); 00310 (void)fprintf(fp,"%s = %s ",Var_VariableReadName(var),Var_VariableReadName(actualVar)); 00311 } 00312 Hrc_NodeForEachFormalOutput(subcktHnode,i,var){ 00313 actualVar = array_fetch(Var_Variable_t *,subcktActualOutputVars,i); 00314 (void)fprintf(fp,"%s = %s ",Var_VariableReadName(var),Var_VariableReadName(actualVar)); 00315 } 00316 (void)fprintf(fp,"\n"); 00317 } 00318 00319 /* .names */ 00320 Hrc_NodeForEachNameTable(hnode,i,table){ 00321 Tbl_TableWriteBlifMvToFile(table,0,fp); 00322 } 00323 00324 (void)fprintf(fp,".end\n"); 00325 } 00326 00327 00343 void 00344 Hrc_ModelWriteSmv( 00345 FILE *fp, 00346 Hrc_Model_t *model, 00347 boolean isRootModel, 00348 char *rootInstanceName) 00349 { 00350 Hrc_Node_t *hnode, *subcktHnode; 00351 Hrc_Model_t *subcktModel; 00352 int i, is_enum, range; 00353 Var_Variable_t *var, *actualVar; 00354 Hrc_Latch_t *latch; 00355 Hrc_Subckt_t *subckt; 00356 Tbl_Table_t *table; 00357 char *varName, *latchName, *instanceName; 00358 st_generator *gen; 00359 array_t *subcktActualInputVars, *subcktActualOutputVars; 00360 00361 hnode = Hrc_ModelReadMasterNode(model); 00362 00363 if (isRootModel){ 00364 (void)fprintf(fp,"\n\nMODULE main --("); 00365 if (Hrc_NodeReadNumFormalInputs(hnode) != 0){ 00366 fprintf(stderr, 00367 "Warning: ignored %d input parameter(s) in the main module (root model)\n", 00368 Hrc_NodeReadNumFormalInputs(hnode)); 00369 } 00370 if (Hrc_NodeReadNumFormalOutputs(hnode) != 0){ 00371 fprintf(stderr, 00372 "Warning: ignored %d output parameter(s) in the main module (root model)\n", 00373 Hrc_NodeReadNumFormalOutputs(hnode)); 00374 } 00375 } else { 00376 (void)fprintf(fp,"\n\nMODULE %s (",Hrc_ModelReadName(model)); 00377 } 00378 00379 /* Input parameters */ 00380 if (Hrc_NodeReadNumFormalInputs(hnode) != 0){ 00381 Hrc_NodeForEachFormalInput(hnode,i,var){ 00382 Io_SmvPrintVar(fp, var); 00383 if(i < Hrc_NodeReadNumFormalInputs(hnode)-1 || 00384 Hrc_NodeReadNumFormalOutputs(hnode) > 0) { 00385 (void)fprintf(fp,", "); 00386 } 00387 } 00388 } 00389 /* Output parameters */ 00390 if (Hrc_NodeReadNumFormalOutputs(hnode) != 0){ 00391 Hrc_NodeForEachFormalOutput(hnode,i,var){ 00392 Io_SmvPrintVar(fp, var); 00393 if(i < Hrc_NodeReadNumFormalOutputs(hnode)-1) { 00394 (void)fprintf(fp,", "); 00395 } 00396 } 00397 } 00398 (void)fprintf(fp,")\n"); 00399 00400 /* Variables */ 00401 Hrc_NodeForEachVariable(hnode,gen,varName,var){ 00402 if (!isRootModel && (Var_VariableTestIsPI(var) || Var_VariableTestIsPO(var))) { 00403 fprintf(fp,"-- PI or PO: "); 00404 } 00405 00406 is_enum = Var_VariableTestIsEnumerative(var); 00407 range = Var_VariableReadNumValues(var); 00408 00409 (void)fprintf(fp,"VAR "); 00410 Io_SmvPrintVar(fp, var); 00411 if (is_enum == 1){ 00412 if (range == 2){ 00413 (void)fprintf(fp," : boolean;\n"); 00414 } 00415 else { 00416 (void)fprintf(fp," : 0..%d;\n",range-1); 00417 } 00418 } 00419 else { 00420 /* variable var is symbolic */ 00421 (void)fprintf(fp," : {"); 00422 for (i=0; i < range; i++){ 00423 (void)fprintf(fp,"%s",Var_VariableReadSymbolicValueFromIndex(var,i)); 00424 if(i < range-1) 00425 (void)fprintf(fp, ", "); 00426 } 00427 (void)fprintf(fp,"};\n"); 00428 } 00429 } 00430 00431 /* Subcircuits */ 00432 Hrc_ModelForEachSubckt(model,gen,instanceName,subckt){ 00433 subcktModel = Hrc_SubcktReadModel(subckt); 00434 subcktHnode = Hrc_ModelReadMasterNode(subcktModel); 00435 subcktActualInputVars = Hrc_SubcktReadActualInputVars(subckt); 00436 subcktActualOutputVars = Hrc_SubcktReadActualOutputVars(subckt); 00437 00438 /* Note: mv uses named parameters; we do not check that there are 00439 enough parameters or that they occur in the correct order. This 00440 doesn't seem to matter at the moment. */ 00441 (void)fprintf(fp,"VAR %s : %s(", 00442 Hrc_SubcktReadInstanceName(subckt), Hrc_ModelReadName(subcktModel)); 00443 Hrc_NodeForEachFormalInput(subcktHnode,i,var){ 00444 actualVar = array_fetch(Var_Variable_t *,subcktActualInputVars,i); 00445 Io_SmvPrintVar(fp, actualVar); 00446 if(i < Hrc_NodeReadNumFormalInputs(subcktHnode)-1 || 00447 Hrc_NodeReadNumFormalOutputs(subcktHnode) > 0) { 00448 (void)fprintf(fp,", "); 00449 } 00450 } 00451 Hrc_NodeForEachFormalOutput(subcktHnode,i,var){ 00452 actualVar = array_fetch(Var_Variable_t *,subcktActualOutputVars,i); 00453 Io_SmvPrintVar(fp, actualVar); 00454 if(i < Hrc_NodeReadNumFormalOutputs(subcktHnode)-1) { 00455 (void)fprintf(fp,", "); 00456 } 00457 } 00458 (void)fprintf(fp,");\n"); 00459 } 00460 00461 /* .latches */ 00462 (void)fprintf(fp,"\nASSIGN\n"); 00463 Hrc_NodeForEachLatch(hnode,gen,latchName,latch){ 00464 (void)fprintf(fp,"next("); 00465 Io_SmvPrintVar(fp, Hrc_LatchReadOutput(latch)); 00466 (void)fprintf(fp,") := "); 00467 Io_SmvPrintVar(fp, Hrc_LatchReadInput(latch)); 00468 (void)fprintf(fp,";\ninit("); 00469 Io_SmvPrintVar(fp, Hrc_LatchReadOutput(latch)); 00470 (void)fprintf(fp,") := "); 00471 Tbl_TableWriteSmvToFile(Hrc_LatchReadResetTable(latch),1,fp); 00472 (void)fprintf(fp,"\n"); 00473 } 00474 00475 /* .names */ 00476 Hrc_NodeForEachNameTable(hnode,i,table){ 00477 Tbl_TableWriteSmvToFile(table,0,fp); 00478 } 00479 00480 } 00481 00494 Hrc_Node_t * 00495 Hrc_ManagerReadRootNode( 00496 Hrc_Manager_t *manager) 00497 { 00498 return manager->rootNode; 00499 } 00500 00513 Hrc_Node_t * 00514 Hrc_ManagerReadCurrentNode( 00515 Hrc_Manager_t *manager) 00516 { 00517 return manager->currentNode; 00518 } 00519 00533 st_table * 00534 Hrc_ManagerReadModelTable( 00535 Hrc_Manager_t *manager) 00536 { 00537 return manager->modelTable; 00538 } 00539 00553 Hrc_Model_t * 00554 Hrc_ManagerFindModelByName( 00555 Hrc_Manager_t *manager, 00556 char *modelName) 00557 { 00558 Hrc_Model_t *model; 00559 00560 if(st_lookup(manager->modelTable, modelName, &model)) { 00561 return model; 00562 } 00563 else { 00564 return NIL(Hrc_Model_t); 00565 } 00566 } 00567 00577 Hrc_Node_t * 00578 Hrc_ModelReadMasterNode( 00579 Hrc_Model_t *model) 00580 { 00581 return model->masterNode; 00582 } 00583 00596 char * 00597 Hrc_ModelReadName( 00598 Hrc_Model_t *model) 00599 { 00600 return model->modelName; 00601 } 00602 00616 st_table * 00617 Hrc_ModelReadSubcktTable( 00618 Hrc_Model_t *model) 00619 { 00620 return model->subcktTable; 00621 } 00622 00635 Hrc_Model_t * 00636 Hrc_SubcktReadModel( 00637 Hrc_Subckt_t *subckt) 00638 { 00639 return subckt->model; 00640 } 00641 00654 char * 00655 Hrc_SubcktReadInstanceName( 00656 Hrc_Subckt_t *subckt) 00657 { 00658 return subckt->instanceName; 00659 } 00660 00674 array_t * 00675 Hrc_SubcktReadActualInputVars( 00676 Hrc_Subckt_t *subckt) 00677 { 00678 return subckt->actualInputVars; 00679 } 00680 00694 array_t * 00695 Hrc_SubcktReadActualOutputVars( 00696 Hrc_Subckt_t *subckt) 00697 { 00698 return subckt->actualOutputVars; 00699 } 00700 00712 Hrc_Manager_t * 00713 Hrc_NodeReadManager( 00714 Hrc_Node_t *node) 00715 { 00716 return node->manager; 00717 } 00718 00732 char * 00733 Hrc_NodeReadModelName( 00734 Hrc_Node_t *node) 00735 { 00736 return node->modelName; 00737 } 00738 00752 char * 00753 Hrc_NodeReadInstanceName( 00754 Hrc_Node_t *node) 00755 { 00756 return node->instanceName; 00757 } 00758 00770 Hrc_Node_t * 00771 Hrc_NodeReadParentNode( 00772 Hrc_Node_t *node) 00773 { 00774 return node->parentNode; 00775 } 00776 00788 int 00789 Hrc_NodeReadNumFormalInputs( 00790 Hrc_Node_t *node) 00791 { 00792 return array_n(node->formalInputs); 00793 } 00794 00806 int 00807 Hrc_NodeReadNumFormalOutputs( 00808 Hrc_Node_t *node) 00809 { 00810 return array_n(node->formalOutputs); 00811 } 00812 00822 int 00823 Hrc_NodeReadNumVariables( 00824 Hrc_Node_t *node) 00825 { 00826 return st_count(node->varTable); 00827 } 00828 00838 int 00839 Hrc_NodeReadNumTables( 00840 Hrc_Node_t *node) 00841 { 00842 return array_n(node->nameTables); 00843 } 00844 00854 int 00855 Hrc_NodeReadNumLatches( 00856 Hrc_Node_t *node) 00857 { 00858 return st_count(node->latchTable); 00859 } 00860 00870 int 00871 Hrc_NodeReadNumChildren( 00872 Hrc_Node_t *node) 00873 { 00874 return st_count(node->childTable); 00875 } 00876 00890 array_t * 00891 Hrc_NodeReadFormalInputs( 00892 Hrc_Node_t *node) 00893 { 00894 return node->formalInputs; 00895 } 00896 00910 array_t * 00911 Hrc_NodeReadFormalOutputs( 00912 Hrc_Node_t *node) 00913 { 00914 return node->formalOutputs; 00915 } 00916 00930 array_t * 00931 Hrc_NodeReadActualInputs( 00932 Hrc_Node_t *node) 00933 { 00934 return node->actualInputs; 00935 } 00936 00950 array_t * 00951 Hrc_NodeReadActualOutputs( 00952 Hrc_Node_t *node) 00953 { 00954 return node->actualOutputs; 00955 } 00956 00970 array_t * 00971 Hrc_NodeReadNameTables( 00972 Hrc_Node_t *node) 00973 { 00974 return node->nameTables; 00975 } 00976 00990 st_table * 00991 Hrc_NodeReadChildTable( 00992 Hrc_Node_t *node) 00993 { 00994 return node->childTable; 00995 } 00996 01010 st_table * 01011 Hrc_NodeReadLatchTable( 01012 Hrc_Node_t *node) 01013 { 01014 return node->latchTable; 01015 } 01016 01030 st_table * 01031 Hrc_NodeReadVariableTable( 01032 Hrc_Node_t *node) 01033 { 01034 return node->varTable; 01035 } 01036 01046 void * 01047 Hrc_NodeReadUndef( 01048 Hrc_Node_t *node) 01049 { 01050 return node->undef; 01051 } 01065 Hrc_Latch_t * 01066 Hrc_NodeFindLatchByName( 01067 Hrc_Node_t *node, 01068 char *latchName) 01069 { 01070 Hrc_Latch_t *latch; 01071 01072 if(st_lookup(node->latchTable, latchName, &latch)) { 01073 return latch; 01074 } 01075 else { 01076 return NIL(Hrc_Latch_t); 01077 } 01078 } 01079 01093 Var_Variable_t * 01094 Hrc_NodeFindVariableByName( 01095 Hrc_Node_t *node, 01096 char *varName) 01097 { 01098 Var_Variable_t *var; 01099 01100 if(st_lookup(node->varTable, varName, &var)) { 01101 return var; 01102 } 01103 else { 01104 return NIL(Var_Variable_t); 01105 } 01106 } 01107 01122 Hrc_Node_t * 01123 Hrc_NodeFindChildByName( 01124 Hrc_Node_t *node, 01125 char *instanceName) 01126 { 01127 Hrc_Node_t *childNode; 01128 01129 if(st_lookup(node->childTable, instanceName, &childNode)) { 01130 return childNode; 01131 } 01132 else { 01133 return NIL(Hrc_Node_t); 01134 } 01135 } 01136 01146 Var_Variable_t * 01147 Hrc_LatchReadInput( 01148 Hrc_Latch_t *latch) 01149 { 01150 return latch->latchInput; 01151 } 01152 01162 Var_Variable_t * 01163 Hrc_LatchReadOutput( 01164 Hrc_Latch_t *latch) 01165 { 01166 return latch->latchOutput; 01167 } 01168 01178 Tbl_Table_t * 01179 Hrc_LatchReadResetTable( 01180 Hrc_Latch_t *latch) 01181 { 01182 return latch->resetTable; 01183 } 01184 01194 void * 01195 Hrc_LatchReadUndef( 01196 Hrc_Latch_t *latch) 01197 { 01198 return latch->undef; 01199 } 01200 01210 void 01211 Hrc_ManagerSetRootNode( 01212 Hrc_Manager_t *manager, 01213 Hrc_Node_t *node) 01214 { 01215 manager->rootNode = node; 01216 } 01217 01227 void 01228 Hrc_ManagerSetCurrentNode( 01229 Hrc_Manager_t *manager, 01230 Hrc_Node_t *currentNode) 01231 { 01232 manager->currentNode = currentNode; 01233 } 01234 01249 boolean 01250 Hrc_NodeAddFormalInput( 01251 Hrc_Node_t *node, 01252 Var_Variable_t *var) 01253 { 01254 char *name = Var_VariableReadName(var); 01255 01256 if(!Var_VariableTestIsPI(var)) { 01257 array_insert_last(Var_Variable_t *, node->formalInputs, var); 01258 st_insert(node->varTable, name, (char *) var); 01259 (void)Var_VariableSetPI(var); 01260 return TRUE; 01261 } 01262 else { 01263 return FALSE; 01264 } 01265 } 01266 01281 boolean 01282 Hrc_NodeAddFormalOutput( 01283 Hrc_Node_t *node, 01284 Var_Variable_t *var) 01285 { 01286 char *name = Var_VariableReadName(var); 01287 01288 if(!Var_VariableTestIsPO(var)) { 01289 array_insert_last(Var_Variable_t *, node->formalOutputs, var); 01290 st_insert(node->varTable, name, (char *) var); 01291 (void)Var_VariableSetPO(var); 01292 return TRUE; 01293 } 01294 else { 01295 return FALSE; 01296 } 01297 } 01298 01308 void 01309 Hrc_NodeAddNameTable( 01310 Hrc_Node_t *node, 01311 Tbl_Table_t *nameTable) 01312 { 01313 array_insert_last(Tbl_Table_t *, node->nameTables, nameTable); 01314 } 01315 01325 void 01326 Hrc_NodeSetUndef( 01327 Hrc_Node_t *node, 01328 void *value) 01329 { 01330 node->undef = value; 01331 } 01332 01346 boolean 01347 Hrc_LatchSetResetTable( 01348 Hrc_Latch_t *latch, 01349 Tbl_Table_t *table) 01350 { 01351 if (latch->resetTable != NIL(Tbl_Table_t)){ 01352 return FALSE; 01353 } 01354 latch->resetTable = table; 01355 return TRUE; 01356 } 01357 01367 void 01368 Hrc_LatchSetUndef( 01369 Hrc_Latch_t *latch, 01370 void *value) 01371 { 01372 latch->undef = value; 01373 } 01374 01375 01376 /*---------------------------------------------------------------------------*/ 01377 /* Definition of internal functions */ 01378 /*---------------------------------------------------------------------------*/ 01379 01380 01381 /*---------------------------------------------------------------------------*/ 01382 /* Definition of static functions */ 01383 /*---------------------------------------------------------------------------*/ 01384 01385 01386 01387 01388 01389 01390 01391 01392 01393 01394 01395 01396 01397 01398 01399 01400 01401 01402 01403 01404 01405 01406 01407 01408