VIS
|
00001 00036 #include "ioInt.h" 00037 00038 static char rcsid[] UNUSED = "$Id: ioParse.c,v 1.4 2002/08/16 17:35:01 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 void _IoParserAddSubckt(array_t **subcktArray, char *modelName, char *instanceName, array_t *formalNameArray, array_t *actualNameArray); 00072 static int _IoIOProcess(Hrc_Node_t *hnode, char *name, int type); 00073 static IoPTable_t * _IoPTableCreate(array_t *inputArray, array_t *outputArray, array_t *defaultArray, array_t *symCubeArray); 00074 static void _IoPTableFree(IoPTable_t *pTable); 00075 00079 /*---------------------------------------------------------------------------*/ 00080 /* Definition of exported functions */ 00081 /*---------------------------------------------------------------------------*/ 00082 00083 00084 /*---------------------------------------------------------------------------*/ 00085 /* Definition of internal functions */ 00086 /*---------------------------------------------------------------------------*/ 00087 00102 Var_Variable_t * 00103 IoVariableFindOrAllocByName( 00104 Hrc_Node_t *hnode, 00105 char *name) 00106 { 00107 Var_Variable_t *var; 00108 00109 if ((var = Hrc_NodeFindVariableByName(hnode,name)) != NIL(Var_Variable_t)){ 00110 return var; 00111 } 00112 var = Var_VariableAlloc(hnode,name); 00113 return var; 00114 } 00115 00128 int 00129 IoAtoi(char *string) 00130 { 00131 char *s; 00132 for (s=string; *s!='\0'; s++) { 00133 if (isdigit((int) *s)==0){ 00134 return -1; 00135 } 00136 } 00137 return atoi(string); 00138 } 00139 00152 void 00153 IoStringArrayFree(array_t *array) 00154 { 00155 int i; 00156 char *symbol; 00157 00158 for (i=0; i < array_n(array); i++) { 00159 symbol = array_fetch(char *, array, i); 00160 FREE(symbol); 00161 } 00162 array_free(array); 00163 } 00164 00165 00179 void 00180 IoNameInsertInArray(array_t **arrayPtrPtr, char *name) 00181 { 00182 if (*arrayPtrPtr == NIL(array_t)){ 00183 *arrayPtrPtr = array_alloc(char *, 0); 00184 } 00185 array_insert_last(char *, *arrayPtrPtr, name); 00186 } 00187 00200 void 00201 IoSymValueInsertInArray(array_t **arrayPtrPtr, IoSymValue_t *value) 00202 { 00203 if (*arrayPtrPtr == NIL(array_t)){ 00204 *arrayPtrPtr = array_alloc(IoSymValue_t *, 0); 00205 } 00206 array_insert_last(IoSymValue_t *, *arrayPtrPtr, value); 00207 } 00208 00220 void 00221 IoSymCubeInsertInArray(array_t **arrayPtrPtr, array_t *symCube) 00222 { 00223 if (*arrayPtrPtr == NIL(array_t)){ 00224 *arrayPtrPtr = array_alloc(array_t *, 0); 00225 } 00226 array_insert_last(array_t *, *arrayPtrPtr, symCube); 00227 } 00228 00240 boolean 00241 IoInputProcess( 00242 Hrc_Node_t *hnode, 00243 char *name) 00244 { 00245 return _IoIOProcess(hnode, name, 0); 00246 } 00247 00259 boolean 00260 IoOutputProcess( 00261 Hrc_Node_t *hnode, 00262 char *name) 00263 { 00264 return _IoIOProcess(hnode, name, 1); 00265 } 00266 00278 boolean 00279 IoMvProcess( 00280 Hrc_Model_t *model, 00281 Hrc_Node_t *hnode, 00282 array_t *varNames, 00283 int range, 00284 array_t *symValues) 00285 { 00286 int i; 00287 char *varName; 00288 Var_Variable_t *var; 00289 00290 if (range == -1) { 00291 error_append("Invalid .mv specification of "); 00292 error_append(array_fetch(char *,varNames,0)); 00293 error_append(" in model "); 00294 error_append(Hrc_ModelReadName(model)); 00295 error_append("\n- Range should be an integer.\n"); 00296 return 0; 00297 } 00298 00299 for (i=0; i < array_n(varNames); i++){ 00300 varName = array_fetch(char *,varNames,i); 00301 if ((var = Hrc_NodeFindVariableByName(hnode,varName)) != NIL(Var_Variable_t)) { 00302 if (Var_VariableAddRangeInfo(var,range,symValues) == 0){ 00303 error_append("Invalid .mv specification of "); 00304 error_append(varName); 00305 error_append(" in model "); 00306 error_append(Hrc_ModelReadName(model)); 00307 error_append("\n- You are trying to redefine the above variable.\n"); 00308 return 0; 00309 } 00310 } 00311 else { 00312 var = Var_VariableAlloc(hnode,varName); 00313 (void)Var_VariableAddRangeInfo(var,range,symValues); 00314 } 00315 } 00316 return 1; 00317 } 00318 00330 boolean 00331 IoLatchProcess( 00332 Hrc_Model_t *model, 00333 Hrc_Node_t *hnode, 00334 char *latchInput, 00335 char *latchOutput) 00336 { 00337 Var_Variable_t *varIn, *varOut; 00338 00339 varIn = IoVariableFindOrAllocByName(hnode,latchInput); 00340 varOut = IoVariableFindOrAllocByName(hnode,latchOutput); 00341 if (varIn == NIL(Var_Variable_t) || varOut == NIL(Var_Variable_t)){ 00342 return 0; 00343 } 00344 if ((Hrc_LatchCreate(model,varIn,varOut)) == NIL(Hrc_Latch_t)){ 00345 return 0; 00346 } 00347 (void)Var_VariableSetNS(varIn); 00348 /* a latch can have only one fanin */ 00349 if (Var_VariableSetPS(varOut) == 0){ 00350 error_append("Variable "); 00351 error_append(latchOutput); 00352 error_append(" are fed by more than one latch\n"); 00353 return 0; 00354 } 00355 return 1; 00356 } 00357 00369 boolean 00370 IoTableProcess( 00371 Hrc_Model_t *model, 00372 Hrc_Node_t *hnode, 00373 array_t *inputArray, 00374 array_t *outputArray, 00375 array_t *defaultArray, 00376 array_t *symCubeArray) 00377 { 00378 IoPTable_t *pTable; 00379 Tbl_Table_t *table; 00380 00381 pTable = _IoPTableCreate(inputArray,outputArray,defaultArray,symCubeArray); 00382 00383 if ((table = IoPTableTransformToTable(model, hnode, pTable)) == NIL(Tbl_Table_t)){ 00384 _IoPTableFree(pTable); 00385 return 0; 00386 } 00387 _IoPTableFree(pTable); 00388 Hrc_ModelAddNameTable(model,table); 00389 return 1; 00390 } 00391 00403 boolean 00404 IoResetProcess( 00405 array_t **resetArray, 00406 Hrc_Model_t *model, 00407 Hrc_Node_t *hnode, 00408 array_t *inputArray, 00409 array_t *outputArray, 00410 array_t *defaultArray, 00411 array_t *symCubeArray) 00412 { 00413 IoPTable_t *pTable; 00414 Tbl_Table_t *table; 00415 00416 pTable = _IoPTableCreate(inputArray,outputArray,defaultArray,symCubeArray); 00417 if ((table = IoPTableTransformToTable(model,hnode,pTable)) == NIL(Tbl_Table_t)){ 00418 _IoPTableFree(pTable); 00419 return 0; 00420 } 00421 _IoPTableFree(pTable); 00422 00423 if (*resetArray == NIL(array_t)){ 00424 *resetArray = array_alloc(Tbl_Table_t *,0); 00425 } 00426 array_insert_last(Tbl_Table_t *,*resetArray,table); 00427 return 1; 00428 } 00429 00430 00442 boolean 00443 IoSubcktProcess( 00444 array_t **subcktArray, 00445 Hrc_Model_t *model, 00446 Hrc_Node_t *hnode, 00447 char *modelName, 00448 char *instanceName, 00449 array_t *formalNameArray, 00450 array_t *actualNameArray) 00451 { 00452 int i; 00453 char *actual; 00454 Var_Variable_t *var; 00455 00456 for (i=0; i < array_n(actualNameArray); i++){ 00457 actual = array_fetch(char *,actualNameArray,i); 00458 var = IoVariableFindOrAllocByName(hnode,actual); 00459 if (var == NIL(Var_Variable_t)){ 00460 error_append("Problem in defining variable "); 00461 error_append(actual); 00462 error_append(" found in subckt "); 00463 error_append(instanceName); 00464 error_append(" in model "); 00465 error_append(Hrc_ModelReadName(model)); 00466 error_append("\n"); 00467 return 0; 00468 } 00469 } 00470 00471 _IoParserAddSubckt(subcktArray,modelName,instanceName,formalNameArray,actualNameArray); 00472 return 1; 00473 } 00474 00475 00476 /*---------------------------------------------------------------------------*/ 00477 /* Definition of static functions */ 00478 /*---------------------------------------------------------------------------*/ 00479 00492 static void 00493 _IoParserAddSubckt( 00494 array_t **subcktArray, 00495 char *modelName, 00496 char *instanceName, 00497 array_t *formalNameArray, 00498 array_t *actualNameArray) 00499 { 00500 IoSubckt_t *subckt; 00501 00502 subckt = ALLOC(IoSubckt_t,1); 00503 subckt->modelName = modelName; 00504 subckt->instanceName = instanceName; 00505 subckt->formalNameArray = formalNameArray; 00506 subckt->actualNameArray = actualNameArray; 00507 00508 if (*subcktArray == NIL(array_t)){ 00509 *subcktArray = array_alloc(IoSubckt_t *,0); 00510 } 00511 array_insert_last(IoSubckt_t *, *subcktArray, subckt); 00512 } 00513 00527 static int 00528 _IoIOProcess( 00529 Hrc_Node_t *hnode, 00530 char *name, 00531 int type) 00532 { 00533 Var_Variable_t *var; 00534 00535 if (Hrc_NodeFindVariableByName(hnode, name) != NIL(Var_Variable_t)) { 00536 error_append("Variable "); 00537 error_append(name); 00538 error_append(" is tried to be set to PI and PO in model "); 00539 error_append(Hrc_NodeReadModelName(hnode)); 00540 error_append("\n"); 00541 return 0; 00542 } 00543 var = Var_VariableAlloc(hnode,name); 00544 switch(type){ 00545 case 0: /* PI */ 00546 Hrc_NodeAddFormalInput(hnode,var); 00547 /* the following is now a part of Hrc_NodeAddFormalInput */ 00548 /*(void)Var_VariableSetPI(var);*/ 00549 break; 00550 case 1: /* PO */ 00551 Hrc_NodeAddFormalOutput(hnode,var); 00552 /* the following is now a part of Hrc_NodeAddFormalOutput */ 00553 /*(void)Var_VariableSetPO(var);*/ 00554 break; 00555 default: 00556 fail("Strange argument is given to variable type in IOProcess\n"); 00557 } 00558 return 1; 00559 } 00560 00561 00573 static IoPTable_t * 00574 _IoPTableCreate( 00575 array_t *inputArray, 00576 array_t *outputArray, 00577 array_t *defaultArray, 00578 array_t *symCubeArray) 00579 { 00580 IoPTable_t *pTable; 00581 00582 pTable = ALLOC(IoPTable_t,1); 00583 if (inputArray == NIL(array_t)){ 00584 pTable->inputs = array_alloc(char *,0); 00585 } 00586 else { 00587 pTable->inputs = inputArray; 00588 } 00589 assert(outputArray != NIL(array_t)); 00590 pTable->outputs = outputArray; 00591 pTable->defaultOutput = defaultArray; 00592 pTable->cubes = symCubeArray; 00593 00594 return pTable; 00595 } 00596 00609 static void 00610 _IoPTableFree(IoPTable_t *pTable) 00611 { 00612 int i; 00613 array_t *symValueArray; 00614 00615 IoStringArrayFree(pTable->inputs); 00616 IoStringArrayFree(pTable->outputs); 00617 if (pTable->defaultOutput != NIL(array_t)){ 00618 IoSymValueArrayFree(pTable->defaultOutput); 00619 } 00620 if (pTable->cubes != NIL(array_t)){ 00621 for (i=0; i < array_n(pTable->cubes); i++){ 00622 symValueArray = array_fetch(array_t *,pTable->cubes,i); 00623 IoSymValueArrayFree(symValueArray); 00624 } 00625 array_free(pTable->cubes); 00626 } 00627 FREE(pTable); 00628 } 00629 00630 00631 00632 00633 00634 00635 00636 00637 00638 00639