VIS
|
00001 00019 #include "absInt.h" 00020 00021 static char rcsid[] UNUSED = "$Id: absCatalog.c,v 1.8 2005/04/16 04:22:21 fabio Exp $"; 00022 00023 00024 /*---------------------------------------------------------------------------*/ 00025 /* Structure declarations */ 00026 /*---------------------------------------------------------------------------*/ 00027 00037 struct AbsVertexCatalog { 00038 lsList fixedPoints; 00039 lsList booleanOps; 00040 lsList negations; 00041 lsList preImages; 00042 lsList identifiers; 00043 lsList variables; 00044 }; 00045 00046 /*---------------------------------------------------------------------------*/ 00047 /* Macro declarations */ 00048 /*---------------------------------------------------------------------------*/ 00049 00060 #define AbsVertexCatalogReadFixedPoints(\ 00061 /* AbsVertexCatalog_t * */ cPtr \ 00062 ) \ 00063 (cPtr->fixedPoints) 00064 00075 #define AbsVertexCatalogReadBooleanOps(\ 00076 /* AbsVertexCatalog_t * */ cPtr \ 00077 ) \ 00078 (cPtr->booleanOps) 00079 00090 #define AbsVertexCatalogReadNegations(\ 00091 /* AbsVertexCatalog_t * */ cPtr \ 00092 ) \ 00093 (cPtr->negations) 00094 00105 #define AbsVertexCatalogReadPreImages(\ 00106 /* AbsVertexCatalog_t * */ cPtr \ 00107 ) \ 00108 (cPtr->preImages) 00109 00120 #define AbsVertexCatalogReadIdentifiers(\ 00121 /* AbsVertexCatalog_t * */ cPtr \ 00122 ) \ 00123 (cPtr->identifiers) 00124 00135 #define AbsVertexCatalogReadVariables(\ 00136 /* AbsVertexCatalog_t * */ cPtr \ 00137 ) \ 00138 (cPtr->variables) 00139 00150 #define AbsVertexCatalogSetFixedPoints(\ 00151 /* AbsVertexCatalog_t * */ cPtr, \ 00152 /* lsList */ data \ 00153 ) \ 00154 (cPtr->fixedPoints) = (data) 00155 00166 #define AbsVertexCatalogSetBooleanOps(\ 00167 /* AbsVertexCatalog_t * */ cPtr, \ 00168 /* lsList */ data \ 00169 ) \ 00170 (cPtr->booleanOps) = (data) 00171 00182 #define AbsVertexCatalogSetNegations(\ 00183 /* AbsVertexCatalog_t * */ cPtr, \ 00184 /* lsList */ data \ 00185 ) \ 00186 (cPtr->negations) = (data) 00187 00198 #define AbsVertexCatalogSetPreImages(\ 00199 /* AbsVertexCatalog_t * */ cPtr, \ 00200 /* lsList */ data \ 00201 ) \ 00202 (cPtr->preImages) = (data) 00203 00214 #define AbsVertexCatalogSetIdentifiers(\ 00215 /* AbsVertexCatalog_t * */ cPtr, \ 00216 /* lsList */ data \ 00217 ) \ 00218 (cPtr->identifiers) = (data) 00219 00230 #define AbsVertexCatalogSetVariables(\ 00231 /* AbsVertexCatalog_t * */ cPtr, \ 00232 /* lsList */ data \ 00233 ) \ 00234 (cPtr->variables) = (data) 00235 00238 /*---------------------------------------------------------------------------*/ 00239 /* Static function prototypes */ 00240 /*---------------------------------------------------------------------------*/ 00241 00242 static AbsVertexInfo_t * LookUpBooleanOp(lsList vertexList, AbsVertex_t type, boolean polarity, AbsVertexInfo_t *leftKid, AbsVertexInfo_t *rightKid); 00243 static AbsVertexInfo_t * LookUpFixedPoint(lsList vertexList, boolean polarity, AbsVertexInfo_t *leftKid, int localId); 00244 static AbsVertexInfo_t * LookUpIdentifier(lsList vertexList, boolean polarity, char *name, char *value); 00245 static AbsVertexInfo_t * LookUpPreImage(lsList vertexList, boolean polarity, AbsVertexInfo_t *leftKid); 00246 static AbsVertexInfo_t * LookUpVariable(lsList vertexList, boolean polarity, int localId); 00247 00251 /*---------------------------------------------------------------------------*/ 00252 /* Definition of exported functions */ 00253 /*---------------------------------------------------------------------------*/ 00254 00255 /*---------------------------------------------------------------------------*/ 00256 /* Definition of internal functions */ 00257 /*---------------------------------------------------------------------------*/ 00258 00268 AbsVertexCatalog_t * 00269 AbsVertexCatalogInitialize(void) 00270 { 00271 AbsVertexCatalog_t *result; 00272 00273 result = ALLOC(AbsVertexCatalog_t, 1); 00274 00275 AbsVertexCatalogSetFixedPoints(result, lsCreate()); 00276 AbsVertexCatalogSetBooleanOps(result, lsCreate()); 00277 AbsVertexCatalogSetNegations(result, lsCreate()); 00278 AbsVertexCatalogSetPreImages(result, lsCreate()); 00279 AbsVertexCatalogSetIdentifiers(result, lsCreate()); 00280 AbsVertexCatalogSetVariables(result, lsCreate()); 00281 00282 return result; 00283 } /* End of AbsVertexCatalogInitialize */ 00284 00294 void 00295 AbsVertexCatalogFree( 00296 AbsVertexCatalog_t *c) 00297 { 00298 lsDestroy(AbsVertexCatalogReadFixedPoints(c), (void (*)(lsGeneric))0); 00299 lsDestroy(AbsVertexCatalogReadBooleanOps(c), (void (*)(lsGeneric))0); 00300 lsDestroy(AbsVertexCatalogReadNegations(c), (void (*)(lsGeneric))0); 00301 lsDestroy(AbsVertexCatalogReadPreImages(c), (void (*)(lsGeneric))0); 00302 lsDestroy(AbsVertexCatalogReadIdentifiers(c), (void (*)(lsGeneric))0); 00303 lsDestroy(AbsVertexCatalogReadVariables(c), (void (*)(lsGeneric))0); 00304 00305 FREE(c); 00306 00307 return; 00308 } /* End of AbsVertexCatalogFree */ 00309 00320 AbsVertexInfo_t * 00321 AbsVertexCatalogFindOrAdd( 00322 AbsVertexCatalog_t *catalog, 00323 AbsVertex_t type, 00324 boolean polarity, 00325 AbsVertexInfo_t *leftKid, 00326 AbsVertexInfo_t *rightKid, 00327 int localId, 00328 char *idName, 00329 char *idValue 00330 ) 00331 { 00332 if (type == fixedPoint_c) { 00333 return LookUpFixedPoint(AbsVertexCatalogReadFixedPoints(catalog), 00334 polarity, leftKid, localId); 00335 } 00336 00337 if (type == and_c || type == xor_c || type == xnor_c) { 00338 return LookUpBooleanOp(AbsVertexCatalogReadBooleanOps(catalog), 00339 type, polarity, leftKid, rightKid); 00340 } 00341 00342 if (type == not_c) { 00343 return LookUpPreImage(AbsVertexCatalogReadNegations(catalog), 00344 polarity, leftKid); 00345 } 00346 00347 if (type == preImage_c) { 00348 return LookUpPreImage(AbsVertexCatalogReadPreImages(catalog), 00349 polarity, leftKid); 00350 } 00351 00352 if (type == identifier_c) { 00353 return LookUpIdentifier(AbsVertexCatalogReadIdentifiers(catalog), 00354 polarity, idName, idValue); 00355 } 00356 00357 if (type == variable_c) { 00358 return LookUpVariable(AbsVertexCatalogReadVariables(catalog), 00359 polarity, localId); 00360 } 00361 00362 (void) fprintf(vis_stderr, "** abs error: Unknown vertex type in function "); 00363 (void) fprintf(vis_stderr, "AbsVertexCatalogFindOrAdd.\n"); 00364 00365 return NIL(AbsVertexInfo_t); 00366 00367 } /* End of AbsVertexCatalogFindOrAdd */ 00368 00378 void 00379 AbsCatalogDelete( 00380 AbsVertexCatalog_t *catalog, 00381 AbsVertexInfo_t *vertex) 00382 { 00383 AbsVertex_t type; 00384 AbsVertexInfo_t *result; 00385 lsList vertexList; 00386 lsGen listGen; 00387 lsHandle item; 00388 lsGeneric userData; 00389 00390 vertexList = 0; 00391 type = AbsVertexReadType(vertex); 00392 00393 /* Select the proper list from the catalog */ 00394 if (type == fixedPoint_c) { 00395 vertexList = AbsVertexCatalogReadFixedPoints(catalog); 00396 } 00397 00398 if (type == and_c || type == xor_c || type == xnor_c) { 00399 vertexList = AbsVertexCatalogReadBooleanOps(catalog); 00400 } 00401 00402 if (type == not_c) { 00403 vertexList = AbsVertexCatalogReadNegations(catalog); 00404 } 00405 00406 if (type == preImage_c) { 00407 vertexList = AbsVertexCatalogReadPreImages(catalog); 00408 } 00409 00410 if (type == identifier_c) { 00411 vertexList = AbsVertexCatalogReadIdentifiers(catalog); 00412 } 00413 00414 if (type == variable_c) { 00415 vertexList = AbsVertexCatalogReadVariables(catalog); 00416 } 00417 00418 listGen = lsStart(vertexList); 00419 while(lsNext(listGen, &result, &item) == LS_OK) { 00420 if (result == vertex) { 00421 lsRemoveItem(item, &userData); 00422 assert(vertex == (AbsVertexInfo_t *)userData); 00423 lsFinish(listGen); 00424 return; 00425 } 00426 } 00427 00428 (void) fprintf(vis_stderr, "** abs error: Removing non-existent vertex from"); 00429 (void) fprintf(vis_stderr, " catalog\n"); 00430 00431 return; 00432 } /* End of AbsCatalogDelete */ 00433 00434 /*---------------------------------------------------------------------------*/ 00435 /* Definition of static functions */ 00436 /*---------------------------------------------------------------------------*/ 00437 00447 static AbsVertexInfo_t * 00448 LookUpBooleanOp( 00449 lsList vertexList, 00450 AbsVertex_t type, 00451 boolean polarity, 00452 AbsVertexInfo_t *leftKid, 00453 AbsVertexInfo_t *rightKid) 00454 { 00455 lsGen listGen; 00456 AbsVertexInfo_t *result; 00457 00458 /* Start the generator and traverse the list */ 00459 listGen = lsStart(vertexList); 00460 while(lsNext(listGen, &result, NIL(lsHandle)) == LS_OK) { 00461 if (AbsVertexReadType(result) == type && 00462 AbsVertexReadLeftKid(result) == leftKid && 00463 AbsVertexReadRightKid(result) == rightKid && 00464 AbsVertexReadPolarity(result) == polarity) { 00465 AbsVertexReadRefs(result)++; 00466 lsFinish(listGen); 00467 return result; 00468 } 00469 } 00470 00471 /* Item has not been found */ 00472 lsFinish(listGen); 00473 result = AbsVertexInitialize(); 00474 lsNewBegin(vertexList, (lsGeneric)result, NIL(lsHandle)); 00475 00476 return result; 00477 } /* End of LookUpBooleanOp */ 00478 00488 static AbsVertexInfo_t * 00489 LookUpFixedPoint( 00490 lsList vertexList, 00491 boolean polarity, 00492 AbsVertexInfo_t *leftKid, 00493 int localId) 00494 { 00495 lsGen listGen; 00496 AbsVertexInfo_t *result; 00497 00498 /* Start the generator and traverse the list */ 00499 listGen = lsStart(vertexList); 00500 while(lsNext(listGen, &result, NIL(lsHandle)) == LS_OK) { 00501 if (AbsVertexReadLeftKid(result) == leftKid && 00502 AbsVertexReadPolarity(result) == polarity && 00503 AbsVertexReadVarId(AbsVertexReadFpVar(result)) == localId) { 00504 AbsVertexReadRefs(result)++; 00505 lsFinish(listGen); 00506 return result; 00507 } 00508 } 00509 00510 /* Item has not been found */ 00511 lsFinish(listGen); 00512 result = AbsVertexInitialize(); 00513 lsNewBegin(vertexList, (lsGeneric)result, NIL(lsHandle)); 00514 00515 return result; 00516 } /* End of LookUpFixedPoint */ 00517 00527 static AbsVertexInfo_t * 00528 LookUpIdentifier( 00529 lsList vertexList, 00530 boolean polarity, 00531 char *name, 00532 char *value) 00533 { 00534 lsGen listGen; 00535 AbsVertexInfo_t *result; 00536 00537 /* Start the generator and traverse the list */ 00538 listGen = lsStart(vertexList); 00539 while(lsNext(listGen, &result, NIL(lsHandle)) == LS_OK) { 00540 if (AbsVertexReadPolarity(result) == polarity && 00541 strcmp(AbsVertexReadName(result), name) == 0 && 00542 strcmp(AbsVertexReadValue(result), value) == 0) { 00543 AbsVertexReadRefs(result)++; 00544 lsFinish(listGen); 00545 return result; 00546 } 00547 } 00548 00549 /* Item has not been found */ 00550 lsFinish(listGen); 00551 result = AbsVertexInitialize(); 00552 lsNewBegin(vertexList, (lsGeneric)result, NIL(lsHandle)); 00553 00554 return result; 00555 } /* End of LookUpIdentifier */ 00556 00566 static AbsVertexInfo_t * 00567 LookUpPreImage( 00568 lsList vertexList, 00569 boolean polarity, 00570 AbsVertexInfo_t *leftKid) 00571 { 00572 lsGen listGen; 00573 AbsVertexInfo_t *result; 00574 00575 /* Start the generator and traverse the list */ 00576 listGen = lsStart(vertexList); 00577 while(lsNext(listGen, &result, NIL(lsHandle)) == LS_OK) { 00578 if (AbsVertexReadLeftKid(result) == leftKid && 00579 AbsVertexReadPolarity(result) == polarity) { 00580 AbsVertexReadRefs(result)++; 00581 lsFinish(listGen); 00582 return result; 00583 } 00584 } 00585 00586 /* Item has not been found */ 00587 lsFinish(listGen); 00588 result = AbsVertexInitialize(); 00589 lsNewBegin(vertexList, (lsGeneric)result, NIL(lsHandle)); 00590 00591 return result; 00592 } /* End of LookUpPreImage */ 00593 00603 static AbsVertexInfo_t * 00604 LookUpVariable( 00605 lsList vertexList, 00606 boolean polarity, 00607 int localId) 00608 { 00609 lsGen listGen; 00610 AbsVertexInfo_t *result; 00611 00612 /* Start the generator and traverse the list */ 00613 listGen = lsStart(vertexList); 00614 while(lsNext(listGen, &result, NIL(lsHandle)) == LS_OK) { 00615 if (AbsVertexReadPolarity(result) == polarity && 00616 AbsVertexReadVarId(result) == localId) { 00617 AbsVertexReadRefs(result)++; 00618 lsFinish(listGen); 00619 return result; 00620 } 00621 } 00622 00623 /* Item has not been found */ 00624 lsFinish(listGen); 00625 result = AbsVertexInitialize(); 00626 lsNewBegin(vertexList, (lsGeneric)result, NIL(lsHandle)); 00627 00628 return result; 00629 } /* End of LookUpVariable */ 00630