VIS

src/tbl/tblEntryUtil.c

Go to the documentation of this file.
00001 
00037 #include "tblInt.h"
00038 
00039 static char rcsid[] UNUSED = "$Id: tblEntryUtil.c,v 1.16 2009/04/11 02:01:29 fabio Exp $";
00040 
00043 /*---------------------------------------------------------------------------*/
00044 /* Static function prototypes                                                */
00045 /*---------------------------------------------------------------------------*/
00046 
00047 static int RangeCompare(lsGeneric entry1, lsGeneric entry2);
00048 static void EntryCanonicalize(Tbl_Entry_t * entry);
00049 static void EntryComplement(Tbl_Entry_t * entry, int min, int max);
00050 
00052 /*---------------------------------------------------------------------------*/
00053 /* Definition of exported functions                                          */
00054 /*---------------------------------------------------------------------------*/
00055 
00068 Tbl_Entry_t*
00069 Tbl_EntryAlloc(
00070   Tbl_EntryType_t  type)
00071 {
00072   Tbl_Entry_t *entry;
00073 
00074   entry = ALLOC(Tbl_Entry_t,1);
00075   entry->type = type;
00076   if (type == Tbl_EntryEqual_c) {
00077     entry->EntryData.var = -1;
00078   }
00079   else if (type == Tbl_EntryNormal_c) {
00080     entry->EntryData.listOfRanges = lsCreate();
00081   }
00082   return entry;
00083 }
00084 
00097 void
00098 Tbl_EntryFree(
00099   Tbl_Entry_t * entry)
00100 {
00101   if (entry->type == Tbl_EntryNormal_c) {
00102     lsDestroy(entry->EntryData.listOfRanges,(void (*)(lsGeneric))TblRangeFree);
00103   }
00104 
00105   FREE(entry);
00106   entry = NIL(Tbl_Entry_t);
00107 }
00123 Tbl_Entry_t *
00124 Tbl_EntryDup(
00125   Tbl_Entry_t *entry)
00126 {
00127   Tbl_Entry_t *newEntry;
00128   lsGen gen;
00129   Tbl_Range_t *range;
00130 
00131   assert(entry != NIL(Tbl_Entry_t));
00132   assert(entry->type != Tbl_EntryUnassigned_c);
00133 
00134   newEntry = Tbl_EntryAlloc(entry->type);
00135   newEntry->ioType = entry->ioType;
00136   newEntry->varColNum = entry->varColNum;
00137   
00138   if (entry->type == Tbl_EntryNormal_c) {
00139     lsForEachItem(entry->EntryData.listOfRanges, gen, range) {
00140       Tbl_Range_t *newRange = ALLOC(Tbl_Range_t,1);
00141       newRange->begin = range->begin;
00142       newRange->end = range->end;
00143       lsNewEnd(newEntry->EntryData.listOfRanges,(lsGeneric)newRange,LS_NH);     
00144  
00145     }
00146   }
00147   else if (entry->type == Tbl_EntryEqual_c) {
00148     newEntry->EntryData.var = entry->EntryData.var;
00149   }
00150   return newEntry;
00151 }
00152         
00153 
00167 void
00168 Tbl_EntrySetValue(
00169   Tbl_Entry_t *  entry,
00170   int  val1,
00171   int  val2)
00172 {
00173   Tbl_Range_t *range;
00174 
00175   assert(val2 >= val1);
00176   assert(val1 >= 0);
00177 
00178   entry->type = Tbl_EntryNormal_c;
00179   range  = ALLOC(Tbl_Range_t,1);
00180   range->begin = val1;
00181   range->end = val2;
00182   lsNewEnd(entry->EntryData.listOfRanges,(lsGeneric)range,LS_NH);
00183   EntryCanonicalize(entry);
00184 }
00185 
00198 Tbl_Entry_t*
00199 Tbl_EntryMerge(
00200     Tbl_Entry_t* entry1,
00201     Tbl_Entry_t* entry2)
00202 {
00203   lsGen gen, gen2,newGen;
00204   Tbl_Range_t *range, *newRange;
00205   Tbl_Entry_t *newEntry;
00206     
00207   if ((entry1->type == Tbl_EntryEqual_c)||(entry2->type ==
00208                                             Tbl_EntryEqual_c)) {
00209     return NIL(Tbl_Entry_t);
00210   }
00211 
00212   if ((entry1->type == Tbl_EntryUnassigned_c)||(entry2->type ==
00213                                                  Tbl_EntryUnassigned_c)) {
00214     return NIL(Tbl_Entry_t);
00215   }
00216 
00217   newEntry = Tbl_EntryAlloc(Tbl_EntryNormal_c);
00218   newGen = lsStart(newEntry->EntryData.listOfRanges);
00219   lsForEachItem(entry1->EntryData.listOfRanges, gen, range) {
00220     newRange = ALLOC(Tbl_Range_t,1);
00221     newRange->begin = range->begin;
00222     newRange->end = range->end;
00223     lsInAfter(newGen,(lsGeneric)newRange,LS_NH);
00224   }
00225   lsForEachItem(entry2->EntryData.listOfRanges, gen2, range) {
00226     newRange = ALLOC(Tbl_Range_t,1);
00227     newRange->begin = range->begin;
00228     newRange->end = range->end;
00229     lsInAfter(newGen,(lsGeneric)newRange,LS_NH);
00230   }
00231   EntryCanonicalize(newEntry);
00232   lsFinish(newGen);
00233   return newEntry;
00234 }
00235 
00236 
00249 void
00250 Tbl_EntryComplement(
00251   Tbl_Entry_t *  entry,
00252   int min,
00253   int max)
00254 {
00255   EntryComplement(entry, min, max);
00256   EntryCanonicalize(entry);
00257 }
00258 
00259 
00272 void
00273 Tbl_EntrySetEqual(
00274   Tbl_Entry_t *  entry,
00275 /*  Var_Variable_t *  var*/
00276   int varCol)
00277 {
00278   entry->type=Tbl_EntryEqual_c;
00279   entry->EntryData.var = varCol;   
00280 }
00281 
00296 boolean
00297 Tbl_EntryCheckRange(
00298   Tbl_Entry_t *  entry,
00299   int  val1,
00300   int  val2)
00301 {
00302   lsGen gen;
00303   lsGeneric data;
00304   Tbl_Range_t *range;
00305   
00306   gen = lsStart(entry->EntryData.listOfRanges);
00307   while (lsNext(gen, &data, LS_NH) == LS_OK) {
00308     range = (Tbl_Range_t*)data;
00309     if (range->begin < val1) {
00310       lsFinish(gen);
00311       return FALSE;
00312     }
00313     if (range->end > val2) {
00314       lsFinish(gen);      
00315       return FALSE;
00316     }
00317   }
00318   lsFinish(gen);  
00319   return TRUE;
00320 }
00321 
00333 boolean Tbl_EntryIsEqual(
00334   Tbl_Entry_t *entry)
00335 {
00336   return (entry->type==Tbl_EntryEqual_c);
00337 }
00338 
00339 
00340 
00353 Var_Variable_t*
00354 Tbl_EntryReadActualVar(
00355     Tbl_Table_t *table,
00356     Tbl_Entry_t *entry)
00357 {
00358   array_t *carray;
00359 
00360   if (entry->ioType==0) {
00361     carray = table->inputNames;
00362   }
00363   else if (entry->ioType==1) {
00364     carray = table->outputNames;
00365   }
00366   else return NIL(Var_Variable_t);         
00367     
00368   return (array_fetch(Var_Variable_t*,carray,entry->varColNum));
00369 }
00370 
00371 
00384 Var_Variable_t*
00385 Tbl_EntryReadVar(
00386     Tbl_Table_t *table,
00387     Tbl_Entry_t *entry)
00388 {
00389   array_t *carray;
00390   
00391   carray = table->inputNames;
00392   if (array_n(carray) < Tbl_EntryReadVarIndex(entry)) {
00393     fail(" FAIL: equal to output not supported\n");
00394   }
00395   return (array_fetch(Var_Variable_t*,carray,Tbl_EntryReadVarIndex(entry)));
00396 }
00397 
00410 int
00411 Tbl_EntryReadVarIndex(
00412   Tbl_Entry_t * entry)
00413 {
00414   assert(entry->type == Tbl_EntryEqual_c);
00415   return (entry->EntryData.var);
00416 }
00417 
00431 int
00432 Tbl_EntryReadNumValues(
00433   Tbl_Entry_t * entry)
00434 {
00435   lsGen gen;
00436   int numOfValues;
00437   Tbl_Range_t *range;
00438 
00439   numOfValues = 0;
00440   assert(entry->type == Tbl_EntryNormal_c);    
00441   lsForEachItem(entry->EntryData.listOfRanges, gen, range) {
00442     numOfValues = numOfValues + (range->end - range->begin + 1);
00443   }
00444   return (numOfValues);
00445 }
00446 
00460 boolean
00461 Tbl_EntryTestEqualEntry(
00462   Tbl_Entry_t * entrya,
00463   Tbl_Entry_t * entryb)
00464 {
00465   lsGen gena;
00466   lsGen genb;  
00467   Tbl_Range_t *rangea;
00468   Tbl_Range_t *rangeb;
00469   lsGeneric data;
00470 
00471   assert(entrya->type == Tbl_EntryNormal_c);
00472   assert(entryb->type == Tbl_EntryNormal_c);
00473 
00474   if (lsLength(entrya->EntryData.listOfRanges) != \
00475       lsLength(entryb->EntryData.listOfRanges))   {
00476     return FALSE;
00477   }
00478 
00479   genb = lsStart(entryb->EntryData.listOfRanges);  
00480   lsForEachItem(entrya->EntryData.listOfRanges, gena, rangea) {
00481     if (lsNext(genb, &data,LS_NH) == LS_OK) {
00482       rangeb = (Tbl_Range_t*)data;                        
00483       if (rangea->begin != rangeb->begin) {
00484         lsFinish(gena);
00485         lsFinish(genb);
00486         return FALSE;
00487       }
00488       if (rangea->end != rangeb->end){
00489         lsFinish(gena);
00490         lsFinish(genb);
00491         return FALSE;
00492       }
00493     }
00494     else {
00495       return FALSE;
00496     }
00497   }
00498   return TRUE;
00499 }
00500 
00515 boolean
00516 Tbl_EntryTestIntersectEntry(
00517   Tbl_Entry_t * entrya,
00518   Tbl_Entry_t * entryb)
00519 {
00520   lsGen gena;
00521   lsGen genb;  
00522   lsGeneric dataa;
00523   lsGeneric datab;  
00524   boolean checka, checkb;
00525   Tbl_Range_t *rangea = NIL(Tbl_Range_t);
00526   Tbl_Range_t *rangeb = NIL(Tbl_Range_t);
00527 
00528   assert(entrya->type == Tbl_EntryNormal_c);
00529   assert(entryb->type == Tbl_EntryNormal_c);
00530 
00531   gena = lsStart(entrya->EntryData.listOfRanges);
00532   genb = lsStart(entryb->EntryData.listOfRanges);
00533 
00534   checka = TRUE;
00535   checkb = TRUE;  
00536   while((checka)||(checkb)) {
00537     if (checka) {
00538       if (lsNext(gena, &dataa,LS_NH) == LS_OK) {
00539         rangea = (Tbl_Range_t*)dataa;
00540       }
00541       else {
00542         lsFinish(gena);
00543         lsFinish(genb);        
00544         return FALSE;
00545       }
00546     }
00547 
00548     if (checkb) {
00549       if (lsNext(genb, &datab,LS_NH) == LS_OK) {
00550         rangeb = (Tbl_Range_t*)datab;
00551       }
00552       else {
00553         lsFinish(gena);
00554         lsFinish(genb);        
00555         return FALSE;
00556       }  
00557     }
00558 
00559     if ((rangea->begin <= rangeb->end) &&(rangeb->begin <= rangea->end)) {      
00560       lsFinish(gena);
00561       lsFinish(genb);
00562       return TRUE;
00563     }
00564     else if (rangea->end < rangeb->begin){
00565       checka = TRUE;
00566       checkb = FALSE;
00567     }
00568     else {
00569       checka = FALSE;
00570       checkb = TRUE;
00571     }    
00572   }
00573   lsFinish(gena);
00574   lsFinish(genb);  
00575   return FALSE;    
00576 }
00577 
00592 lsList
00593 Tbl_EntryReadList(
00594   Tbl_Entry_t * entry)
00595 {
00596   return (entry->EntryData.listOfRanges);
00597 }
00598 
00599 
00612 Tbl_EntryType_t
00613 Tbl_EntryReadType(
00614   Tbl_Entry_t *entry)
00615 {
00616   return (entry->type);
00617 }
00618 
00619 
00620 /*---------------------------------------------------------------------------*/
00621 /* Definition of internal functions                                          */
00622 /*---------------------------------------------------------------------------*/
00623 
00637 mdd_t *
00638 TblEntryNormalConstructMdd(
00639     mdd_manager *manager,
00640     Tbl_Entry_t * entry,
00641     array_t * mddArray)
00642 {
00643   lsGen gen;
00644   Tbl_Range_t *range;
00645   int i;
00646   mdd_t *result, *temp, *x;
00647     
00648   result = mdd_zero(manager);
00649   lsForEachItem(entry->EntryData.listOfRanges, gen, range) {
00650     for (i=range->begin; i< (range->end +1); i++) {
00651       temp = result;
00652       x = Mvf_FunctionObtainComponent(mddArray,i);
00653       result = mdd_or(temp, x,1,1);
00654       mdd_free(temp);
00655       mdd_free(x);
00656     }
00657   }
00658   return result;
00659 }
00660 
00661 
00675 mdd_t *
00676 TblEntryEqualConstructMdd(
00677     mdd_manager *manager,
00678     Tbl_Entry_t * entry,
00679     Mvf_Function_t * mddArray,
00680     Mvf_Function_t * mddEArray)
00681 {
00682   lsGen gen;
00683   Tbl_Range_t *range;
00684   int i;
00685   mdd_t *result, *temp, *x;
00686 
00687   assert(entry->type == Tbl_EntryNormal_c);
00688   result = mdd_zero(manager);
00689   lsForEachItem(entry->EntryData.listOfRanges, gen, range) {
00690     for (i=range->begin; i< (range->end +1); i++) {
00691       temp = result;
00692       x = Mvf_FunctionObtainComponent(mddArray,i);
00693       result = mdd_or(temp, x,1,1);
00694       mdd_free(temp);
00695       temp = result;
00696       x = Mvf_FunctionObtainComponent(mddEArray,i);
00697       result = mdd_or(temp, x,1,1);
00698       mdd_free(temp);
00699     }
00700   }
00701   return result;
00702 }
00703 
00716 void
00717 TblEntryWriteBlifMv(
00718     Tbl_Table_t *table,
00719     Tbl_Entry_t *entry,
00720     FILE *fp)
00721 {
00722   lsGen gen;
00723   Tbl_Range_t *range;
00724   Var_Variable_t *var;
00725   boolean test, testParen;
00726   int i, itemNum, length;
00727     
00728   var = Tbl_EntryReadActualVar(table,entry);
00729   test = Var_VariableTestIsSymbolic(var);
00730   testParen = TRUE;
00731   
00732   if (entry != NIL(Tbl_Entry_t)) {
00733     if (entry->type == Tbl_EntryNormal_c) {
00734       length = lsLength(entry->EntryData.listOfRanges);
00735       
00736       if (length == 1){
00737         var = Tbl_EntryReadActualVar(table,entry);
00738         lsForEachItem(entry->EntryData.listOfRanges, gen, range) {
00739           if ((range->begin ==0)&&(range->end == Var_VariableReadNumValues(var)-1)){
00740             fprintf(fp,"-");
00741           lsFinish(gen);            
00742             return;
00743           }
00744         }
00745       }
00746       
00747       itemNum = 1;
00748       if (length ==1) {
00749         testParen = FALSE;
00750       }
00751       
00752       lsForEachItem(entry->EntryData.listOfRanges, gen, range) {
00753         if (itemNum ==1) {
00754           if (testParen) {
00755               fprintf(fp,"(");
00756           }
00757         }
00758           
00759         if (itemNum < length) {
00760           if (test == FALSE) {
00761             if (range->end != range->begin) {
00762               fprintf(fp,"{%d-%d},", range->begin, range->end);
00763             }
00764             else {
00765               fprintf(fp,"%d,", range->end);
00766             }
00767           }
00768           else {
00769             if (range->end != range->begin) {
00770                 fprintf(fp,"(%s,",Var_VariableReadSymbolicValueFromIndex(var,range->begin));
00771                 for (i= range->begin+1; i < range->end ; i++) {
00772                 fprintf(fp,"%s,",Var_VariableReadSymbolicValueFromIndex(var,i));
00773               }
00774                         
00775               fprintf(fp,"%s),",Var_VariableReadSymbolicValueFromIndex(var,range->end));
00776             }
00777             else {
00778               fprintf(fp,"%s,",Var_VariableReadSymbolicValueFromIndex(var,range->end));
00779             }
00780           }
00781         }
00782         else {
00783           if (test == FALSE) {
00784             if (range->end != range->begin)
00785               fprintf(fp,"{%d-%d}", range->begin, range->end);
00786             else fprintf(fp,"%d", range->end);
00787           }
00788           else {
00789             if (range->end != range->begin) {
00790                 fprintf(fp,"(%s,",Var_VariableReadSymbolicValueFromIndex(var,range->begin));
00791                 for (i= range->begin+1; i < range->end ; i++) {
00792                 fprintf(fp,"%s,",Var_VariableReadSymbolicValueFromIndex(var,i));
00793               }
00794                         
00795               fprintf(fp,"%s)",Var_VariableReadSymbolicValueFromIndex(var,range->end));
00796             }
00797             else {
00798               fprintf(fp,"%s",Var_VariableReadSymbolicValueFromIndex(var,range->end));
00799             }
00800           }   
00801         }
00802       itemNum++;        
00803       }
00804       if (testParen) {      
00805         fprintf(fp,")");
00806       }
00807     }
00808     else if (entry->type == Tbl_EntryEqual_c) {
00809       fprintf(fp,"=%s", Var_VariableReadName(Tbl_EntryReadVar(table,entry)));
00810     }
00811   }
00812   else printf("NIL Entry ");
00813 }
00814 
00827 void
00828 TblEntryWriteSmv(
00829     Tbl_Table_t *table,
00830     Tbl_Entry_t *entry,
00831     boolean varnameflag,
00832     FILE *fp)
00833 {
00834   lsGen gen;
00835   Tbl_Range_t *range;
00836   Var_Variable_t *var;
00837   boolean symbolic, testParen;
00838   int i, itemNum, length;
00839     
00840   var = Tbl_EntryReadActualVar(table,entry);
00841   symbolic = Var_VariableTestIsSymbolic(var);
00842   testParen = TRUE;
00843   
00844   if (entry != NIL(Tbl_Entry_t)) {
00845     if (entry->type == Tbl_EntryNormal_c) {
00846       length = lsLength(entry->EntryData.listOfRanges);
00847       
00848       if (length == 1){
00849         var = Tbl_EntryReadActualVar(table,entry);
00850         lsForEachItem(entry->EntryData.listOfRanges, gen, range) {
00851           if ((range->begin ==0)&&(range->end == Var_VariableReadNumValues(var)-1)){
00852             fprintf(fp,"1"); /* A don't-care is always true */
00853           lsFinish(gen);            
00854             return;
00855           }
00856         }
00857       }
00858       
00859       if (!varnameflag) {
00860         fprintf(fp,"(");
00861         Io_SmvPrintVar(fp,var);
00862       }
00863       itemNum = 1;
00864       if (length ==1) {
00865         testParen = FALSE;
00866       }
00867       
00868       lsForEachItem(entry->EntryData.listOfRanges, gen, range) {
00869         if (!varnameflag) {
00870           if (itemNum ==1) {
00871             if (testParen) {
00872               fprintf(fp," IN {");
00873             } else {
00874               fprintf(fp, "=");
00875             }
00876           }
00877         }
00878         
00879         if (itemNum < length) {
00880           if (symbolic == FALSE) {
00881             if (range->end != range->begin) {
00882               for (i= range->begin; i < range->end ; i++)
00883                 fprintf(fp,"%d,",i);
00884             }
00885             fprintf(fp,"%d,", range->end);
00886           }
00887           else {
00888             if (range->end != range->begin) {
00889                 fprintf(fp,"%s,",Var_VariableReadSymbolicValueFromIndex(var,range->begin));
00890                 for (i= range->begin+1; i < range->end ; i++) {
00891                   fprintf(fp,"%s,",Var_VariableReadSymbolicValueFromIndex(var,i));
00892                 }
00893                         
00894                 fprintf(fp,"%s,",Var_VariableReadSymbolicValueFromIndex(var,range->end));
00895             }
00896             else {
00897               fprintf(fp,"%s,",Var_VariableReadSymbolicValueFromIndex(var,range->end));
00898             }
00899           }
00900         }
00901         else {
00902           if (symbolic == FALSE) {
00903             if (range->end != range->begin) {
00904               for (i= range->begin; i < range->end ; i++)
00905                 fprintf(fp,"%d,",i);
00906             }
00907             fprintf(fp,"%d", range->end);
00908           }
00909           else {
00910             if (range->end != range->begin) {
00911                 fprintf(fp,"%s,",Var_VariableReadSymbolicValueFromIndex(var,range->begin));
00912                 for (i= range->begin+1; i < range->end ; i++) {
00913                 fprintf(fp,"%s,",Var_VariableReadSymbolicValueFromIndex(var,i));
00914               }
00915                         
00916               fprintf(fp,"%s",Var_VariableReadSymbolicValueFromIndex(var,range->end));
00917             }
00918             else {
00919               fprintf(fp,"%s",Var_VariableReadSymbolicValueFromIndex(var,range->end));
00920             }
00921           }   
00922         }
00923       itemNum++;        
00924       }
00925       if (testParen) {      
00926         fprintf(fp,"} ");
00927       }
00928       if (!varnameflag) {
00929         fprintf(fp, ") ");
00930       }
00931     }
00932     else if (entry->type == Tbl_EntryEqual_c) {
00933       if (!varnameflag) {
00934         Io_SmvPrintVar(fp, var);
00935         fprintf(fp,"=");
00936       }
00937       Io_SmvPrintVar(fp, Tbl_EntryReadVar(table,entry));
00938     }
00939   }
00940   else printf("NIL Entry ");
00941 }
00942 
00943 
00956 void
00957 TblEntryWriteBlif(
00958     Tbl_Table_t *table,
00959     Tbl_Entry_t *entry,
00960     FILE *fp)
00961 {
00962   lsGen gen;
00963   Tbl_Range_t *range;
00964   Var_Variable_t *var;
00965   boolean test;
00966   int i, itemNum, length;
00967     
00968   var = Tbl_EntryReadActualVar(table,entry);
00969   test = Var_VariableTestIsSymbolic(var);
00970   if (entry != NIL(Tbl_Entry_t)) {
00971     if (entry->type == Tbl_EntryNormal_c) {
00972       length = lsLength(entry->EntryData.listOfRanges);      
00973       if (length == 1){
00974         var = Tbl_EntryReadActualVar(table,entry);
00975         lsForEachItem(entry->EntryData.listOfRanges, gen, range) {
00976           if ((range->begin ==0)&&(range->end == Var_VariableReadNumValues(var)-1)){
00977             fprintf(fp,"-");
00978           lsFinish(gen);            
00979             return;
00980           }
00981         }
00982       }
00983 
00984       length = lsLength(entry->EntryData.listOfRanges);
00985       itemNum = 1;
00986       lsForEachItem(entry->EntryData.listOfRanges, gen, range) {
00987         if (itemNum < length) {
00988           if (test == FALSE) {
00989             if (range->end != range->begin) {
00990               fprintf(fp,"{%d-%d},", range->begin, range->end);
00991             }
00992             else {
00993               fprintf(fp,"%d,", range->end);
00994             }
00995           }
00996           else {
00997             if (range->end != range->begin) {
00998               for (i= range->begin; i < range->end ; i++) {
00999                 fprintf(fp,"%s,",Var_VariableReadSymbolicValueFromIndex(var,i));
01000               }
01001                         
01002               fprintf(fp,"%s",Var_VariableReadSymbolicValueFromIndex(var,range->end));
01003             }
01004             else {
01005               fprintf(fp,"%s,",Var_VariableReadSymbolicValueFromIndex(var,range->end));
01006             }
01007           }
01008         }
01009         else {
01010           if (test == FALSE) {
01011             if (range->end != range->begin)
01012               fprintf(fp,"{%d-%d}", range->begin, range->end);
01013             else fprintf(fp,"%d", range->end);
01014           }
01015           else {
01016             if (range->end != range->begin) {
01017               for (i= range->begin; i < range->end ; i++) {
01018                 fprintf(fp,"%s,",Var_VariableReadSymbolicValueFromIndex(var,i));
01019               }
01020                         
01021               fprintf(fp,"%s",Var_VariableReadSymbolicValueFromIndex(var,range->end));
01022             }
01023             else {
01024               fprintf(fp,"%s",Var_VariableReadSymbolicValueFromIndex(var,range->end));
01025             }   
01026           }
01027         }
01028         itemNum++;        
01029       }
01030     }
01031     else if (entry->type == Tbl_EntryEqual_c) {
01032       fprintf(fp," =%s ",Var_VariableReadName(Tbl_EntryReadVar(table,entry)));
01033     }
01034   }
01035   else printf("NIL Entry ");
01036 }
01037 
01050 void
01051 TblRangeFree(
01052   Tbl_Range_t * range)
01053 {
01054   FREE(range);
01055 }
01056 
01071 int
01072 Tbl_RangeBegin(
01073   Tbl_Range_t *range)
01074 {
01075   return(range->begin);
01076 }
01077 
01092 int
01093 Tbl_RangeEnd(
01094   Tbl_Range_t *range)
01095 {
01096   return(range->end);
01097 }
01098 
01099 /*---------------------------------------------------------------------------*/
01100 /* Definition of static functions                                            */
01101 /*---------------------------------------------------------------------------*/
01102 
01116 static int
01117 RangeCompare(
01118   lsGeneric entry1,
01119   lsGeneric entry2)
01120 {
01121   Tbl_Range_t * range1 = (Tbl_Range_t *) entry1;
01122   Tbl_Range_t * range2 = (Tbl_Range_t *) entry2;
01123   int value = 0;
01124 
01125   if (range1->begin > range2->begin) {
01126     value = 1;
01127   }
01128   else if (range1->begin < range2->begin) {
01129     value = -1;
01130   }
01131   else if (range1->begin == range2->begin) {
01132     if (range1->end > range2->end) {
01133       value = 1;
01134     }
01135     else if (range1->end <  range2->end) {
01136       value = -1;
01137     }
01138   }
01139   return value;
01140 }
01141 
01164 static void
01165 EntryCanonicalize(
01166   Tbl_Entry_t *  entry)
01167 {
01168   lsGen gen;
01169   Tbl_Range_t *range, *newRange, *nextRange;
01170   lsGeneric data;
01171 
01172   if (entry->type == Tbl_EntryEqual_c) {
01173     return;
01174   }
01175 
01176   if (entry->type == Tbl_EntryUnassigned_c) {
01177     return;
01178   }
01179 
01180   if (lsLength(entry->EntryData.listOfRanges)  > 1) {
01181     lsSort(entry->EntryData.listOfRanges,RangeCompare);
01182     lsForEachItem(entry->EntryData.listOfRanges, gen, range) {
01183       if (lsNext(gen, &data,LS_NH) == LS_OK) {
01184         nextRange = (Tbl_Range_t*)data;
01185         if (nextRange->begin < (range->end + 2)) {
01186           if (nextRange->end > range->end) {
01187             newRange = ALLOC(Tbl_Range_t,1);
01188             newRange->begin = range->begin;
01189             newRange->end = nextRange->end;
01190             lsInAfter(gen,(lsGeneric)newRange,LS_NH);
01191             lsDelBefore(gen,(lsGeneric*)nextRange);
01192             TblRangeFree(nextRange);
01193             lsDelBefore(gen,(lsGeneric*)range);
01194             TblRangeFree(range);
01195           }
01196           else {
01197             lsDelBefore(gen,(lsGeneric*)nextRange);
01198             TblRangeFree(nextRange);
01199             if (lsPrev(gen,&data,LS_NH)!= LS_OK) {
01200               (void) lsFinish(gen);
01201             }
01202           }
01203         }
01204         else {
01205           lsPrev(gen,&data,LS_NH);
01206         }
01207       }
01208     }
01209   }
01210 }
01211 
01212 
01229 static void
01230 EntryComplement(
01231   Tbl_Entry_t *  entry,
01232   int min,
01233   int max)
01234 {
01235   lsGen gen, newGen;
01236   Tbl_Range_t *range, *newRange, *nextRange;
01237   lsList newRangeList;
01238   int listMin, listMax;
01239   lsGeneric data;
01240     
01241   if (entry->type == Tbl_EntryEqual_c) {
01242     return;
01243   }
01244 
01245   if (entry->type == Tbl_EntryUnassigned_c) {
01246     return;
01247   }
01248 
01249   listMin = max;
01250   listMax = min;
01251   newRangeList = lsCreate();
01252   newGen = lsStart(newRangeList);
01253   lsForEachItem(entry->EntryData.listOfRanges, gen, range) {
01254     if (lsNext(gen, &data, LS_NH) == LS_OK) {
01255       nextRange = (Tbl_Range_t*)data;
01256       newRange = ALLOC(Tbl_Range_t,1);
01257       newRange->begin = range->end +1;
01258       newRange->end = nextRange->begin -1;
01259       lsInAfter(newGen,(lsGeneric)newRange,LS_NH);
01260       lsPrev(gen, &data, LS_NH);
01261     }      
01262     if (listMin > range->begin) listMin = range->begin;
01263     if (listMax < range->end) listMax = range->end;
01264   }
01265   lsFinish(newGen);
01266   if (min < listMin) {
01267     newRange = ALLOC(Tbl_Range_t,1);
01268     newRange->begin = min;
01269     newRange->end = listMin -1;
01270     lsNewBegin(newRangeList,(lsGeneric)newRange,LS_NH);
01271   }
01272   if (listMax < max) {
01273     newRange = ALLOC(Tbl_Range_t,1);
01274     newRange->begin = listMax +1;
01275     newRange->end = max;
01276     lsNewEnd(newRangeList,(lsGeneric)newRange,LS_NH);
01277   }
01278   lsDestroy(entry->EntryData.listOfRanges,(void (*)(lsGeneric))TblRangeFree);
01279   entry->EntryData.listOfRanges = newRangeList;
01280 }