ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
mapperTree.c File Reference
#include "mapperInt.h"
Include dependency graph for mapperTree.c:

Go to the source code of this file.

Functions

Map_Super_tMap_LibraryReadGateTree (Map_SuperLib_t *pLib, char *pBuffer, int Number, int nVarsMax)
 FUNCTION DEFINITIONS ///.
 
int Vec_StrGets (char *pBuffer, int nBufferSize, Vec_Str_t *vStr, int *pPos)
 
int Map_LibraryCompareLibNames (char *pName1, char *pName2)
 
int Map_LibraryReadFileTreeStr (Map_SuperLib_t *pLib, Mio_Library_t *pGenlib, Vec_Str_t *vStr, char *pFileName)
 
int Map_LibraryReadTree (Map_SuperLib_t *pLib, Mio_Library_t *pGenlib, char *pFileName, char *pExcludeFile)
 
int Map_LibraryDeriveGateInfo (Map_SuperLib_t *pLib, st__table *tExcludeGate)
 
unsigned Map_CalculatePhase (unsigned uTruths[][2], int nVars, unsigned uTruth, unsigned uPhase)
 
void Map_CalculatePhase6 (unsigned uTruths[][2], int nVars, unsigned uTruth[], unsigned uPhase, unsigned uTruthRes[])
 
void Map_LibraryPrintTree (Map_SuperLib_t *pLib)
 

Function Documentation

◆ Map_CalculatePhase()

unsigned Map_CalculatePhase ( unsigned uTruths[][2],
int nVars,
unsigned uTruth,
unsigned uPhase )

Function*************************************************************

Synopsis [Performs phase transformation for one function.]

Description []

SideEffects []

SeeAlso []

Definition at line 918 of file mapperTree.c.

919{
920 int v, Shift;
921 for ( v = 0, Shift = 1; v < nVars; v++, Shift <<= 1 )
922 if ( uPhase & Shift )
923 uTruth = (((uTruth & ~uTruths[v][0]) << Shift) | ((uTruth & uTruths[v][0]) >> Shift));
924 return uTruth;
925}

◆ Map_CalculatePhase6()

void Map_CalculatePhase6 ( unsigned uTruths[][2],
int nVars,
unsigned uTruth[],
unsigned uPhase,
unsigned uTruthRes[] )

Function*************************************************************

Synopsis [Performs phase transformation for one function.]

Description []

SideEffects []

SeeAlso []

Definition at line 938 of file mapperTree.c.

939{
940 unsigned uTemp;
941 int v, Shift;
942
943 // initialize the result
944 uTruthRes[0] = uTruth[0];
945 uTruthRes[1] = uTruth[1];
946 if ( uPhase == 0 )
947 return;
948 // compute the phase
949 for ( v = 0, Shift = 1; v < nVars; v++, Shift <<= 1 )
950 if ( uPhase & Shift )
951 {
952 if ( Shift < 32 )
953 {
954 uTruthRes[0] = (((uTruthRes[0] & ~uTruths[v][0]) << Shift) | ((uTruthRes[0] & uTruths[v][0]) >> Shift));
955 uTruthRes[1] = (((uTruthRes[1] & ~uTruths[v][1]) << Shift) | ((uTruthRes[1] & uTruths[v][1]) >> Shift));
956 }
957 else
958 {
959 uTemp = uTruthRes[0];
960 uTruthRes[0] = uTruthRes[1];
961 uTruthRes[1] = uTemp;
962 }
963 }
964}

◆ Map_LibraryCompareLibNames()

int Map_LibraryCompareLibNames ( char * pName1,
char * pName2 )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 363 of file mapperTree.c.

364{
365 char * p1 = Abc_UtilStrsav( pName1 );
366 char * p2 = Abc_UtilStrsav( pName2 );
367 int i, RetValue;
368 for ( i = 0; p1[i]; i++ )
369 if ( p1[i] == '>' || p1[i] == '\\' || p1[i] == '/' )
370 p1[i] = '/';
371 for ( i = 0; p2[i]; i++ )
372 if ( p2[i] == '>' || p2[i] == '\\' || p2[i] == '/' )
373 p2[i] = '/';
374 RetValue = strcmp( p1, p2 );
375 ABC_FREE( p1 );
376 ABC_FREE( p2 );
377 return RetValue;
378}
#define ABC_FREE(obj)
Definition abc_global.h:267
int strcmp()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Map_LibraryDeriveGateInfo()

int Map_LibraryDeriveGateInfo ( Map_SuperLib_t * pLib,
st__table * tExcludeGate )

Function*************************************************************

Synopsis [Derives information about the library.]

Description []

SideEffects []

SeeAlso []

Definition at line 586 of file mapperTree.c.

587{
588 Map_Super_t * pGate, * pFanin;
589 Mio_Pin_t * pPin;
590 unsigned uCanon[2];
591 unsigned uTruths[6][2];
592 int i, k, nRealVars;
593
594 // set all the derivable info related to the supergates
595 for ( i = pLib->nVarsMax; i < (int)pLib->nLines; i++ )
596 {
597 pGate = pLib->ppSupers[i];
598
599 if ( tExcludeGate )
600 {
601 if ( st__is_member( tExcludeGate, Mio_GateReadName( pGate->pRoot ) ) )
602 pGate->fExclude = 1;
603 for ( k = 0; k < (int)pGate->nFanins; k++ )
604 {
605 pFanin = pGate->pFanins[k];
606 if ( pFanin->fExclude )
607 {
608 pGate->fExclude = 1;
609 continue;
610 }
611 }
612 }
613
614 // collect the truth tables of the fanins
615 for ( k = 0; k < (int)pGate->nFanins; k++ )
616 {
617 pFanin = pGate->pFanins[k];
618 uTruths[k][0] = pFanin->uTruth[0];
619 uTruths[k][1] = pFanin->uTruth[1];
620 }
621 // derive the new truth table
622 Mio_DeriveTruthTable( pGate->pRoot, uTruths, pGate->nFanins, 6, pGate->uTruth );
623
624 // set the initial delays of the supergate
625 for ( k = 0; k < pLib->nVarsMax; k++ )
626 {
627 pGate->tDelaysR[k].Rise = pGate->tDelaysR[k].Fall = MAP_NO_VAR;
628 pGate->tDelaysF[k].Rise = pGate->tDelaysF[k].Fall = MAP_NO_VAR;
629 }
630 // get the linked list of pins for the given root gate
631 pPin = Mio_GateReadPins( pGate->pRoot );
632 // update the initial delay of the supergate using info from the corresponding pin
633 for ( k = 0; k < (int)pGate->nFanins; k++, pPin = Mio_PinReadNext(pPin) )
634 {
635 // if there is no corresponding pin, this is a bug, return fail
636 if ( pPin == NULL )
637 {
638 printf( "There are less pins than gate inputs.\n" );
639 return 0;
640 }
641 // update the delay information of k-th fanins info from the corresponding pin
642 Map_LibraryAddFaninDelays( pLib, pGate, pGate->pFanins[k], pPin );
643 }
644 // if there are some pins left, this is a bug, return fail
645 if ( pPin != NULL )
646 {
647 printf( "There are more pins than gate inputs.\n" );
648 return 0;
649 }
650 // find the max delay
651 pGate->tDelayMax.Rise = pGate->tDelayMax.Fall = MAP_NO_VAR;
652 for ( k = 0; k < pLib->nVarsMax; k++ )
653 {
654 // the rise of the output depends on the rise and fall of the output
655 if ( pGate->tDelayMax.Rise < pGate->tDelaysR[k].Rise )
656 pGate->tDelayMax.Rise = pGate->tDelaysR[k].Rise;
657 if ( pGate->tDelayMax.Rise < pGate->tDelaysR[k].Fall )
658 pGate->tDelayMax.Rise = pGate->tDelaysR[k].Fall;
659 // the fall of the output depends on the rise and fall of the output
660 if ( pGate->tDelayMax.Fall < pGate->tDelaysF[k].Rise )
661 pGate->tDelayMax.Fall = pGate->tDelaysF[k].Rise;
662 if ( pGate->tDelayMax.Fall < pGate->tDelaysF[k].Fall )
663 pGate->tDelayMax.Fall = pGate->tDelaysF[k].Fall;
664
665 pGate->tDelaysF[k].Worst = MAP_MAX( pGate->tDelaysF[k].Fall, pGate->tDelaysF[k].Rise );
666 pGate->tDelaysR[k].Worst = MAP_MAX( pGate->tDelaysR[k].Fall, pGate->tDelaysR[k].Rise );
667 }
668
669 // count gates and area of the supergate
670 pGate->nGates = 1;
671 pGate->Area = (float)Mio_GateReadArea(pGate->pRoot);
672 for ( k = 0; k < (int)pGate->nFanins; k++ )
673 {
674 pGate->nGates += pGate->pFanins[k]->nGates;
675 pGate->Area += pGate->pFanins[k]->Area;
676 }
677 // do not add the gate to the table, if this gate is an internal gate
678 // of some supegate and does not correspond to a supergate output
679 if ( ( !pGate->fSuper ) || pGate->fExclude )
680 continue;
681
682 // find the maximum index of a variable in the support of the supergates
683 // this is important for two reasons:
684 // (1) to limit the number of permutations considered for canonicization
685 // (2) to get rid of equivalence phases to speed-up matching
686 nRealVars = Map_LibraryGetMaxSuperPi_rec( pGate ) + 1;
687 assert( nRealVars > 0 && nRealVars <= pLib->nVarsMax );
688 // if there are some problems with this code, try this instead
689// nRealVars = pLib->nVarsMax;
690
691 // find the N-canonical form of this supergate
692 pGate->nPhases = Map_CanonComputeSlow( pLib->uTruths, pLib->nVarsMax, nRealVars, pGate->uTruth, pGate->uPhases, uCanon );
693 // add the supergate into the table by its N-canonical table
694 Map_SuperTableInsertC( pLib->tTableC, uCanon, pGate );
695/*
696 {
697 int uCanon1, uCanon2;
698 uCanon1 = uCanon[0];
699 pGate->uTruth[0] = ~pGate->uTruth[0];
700 pGate->uTruth[1] = ~pGate->uTruth[1];
701 Map_CanonComputeSlow( pLib->uTruths, pLib->nVarsMax, nRealVars, pGate->uTruth, pGate->uPhases, uCanon );
702 uCanon2 = uCanon[0];
703Rwt_Man5ExploreCount( uCanon1 < uCanon2 ? uCanon1 : uCanon2 );
704 }
705*/
706 }
707 // sort the gates in each line
709
710 // let the glory be manifest
711// Map_LibraryPrintTree( pLib );
712 return 1;
713}
#define MAP_MAX(a, b)
Definition mapperInt.h:58
#define MAP_NO_VAR
Definition mapperInt.h:54
int Map_SuperTableInsertC(Map_HashTable_t *pLib, unsigned uTruthC[], Map_Super_t *pGate)
Definition mapperTable.c:92
void Map_SuperTableSortSupergatesByDelay(Map_HashTable_t *p, int nSupersMax)
int Map_CanonComputeSlow(unsigned uTruths[][2], int nVarsMax, int nVarsReal, unsigned uTruth[], unsigned char *puPhases, unsigned uTruthRes[])
FUNCTION DEFINITIONS ///.
Definition mapperCanon.c:48
struct Map_SuperStruct_t_ Map_Super_t
Definition mapper.h:45
Mio_Pin_t * Mio_GateReadPins(Mio_Gate_t *pGate)
Definition mioApi.c:173
void Mio_DeriveTruthTable(Mio_Gate_t *pGate, unsigned uTruthsIn[][2], int nSigns, int nInputs, unsigned uTruthRes[])
Definition mioUtils.c:1036
double Mio_GateReadArea(Mio_Gate_t *pGate)
Definition mioApi.c:171
char * Mio_GateReadName(Mio_Gate_t *pGate)
Definition mioApi.c:169
Mio_Pin_t * Mio_PinReadNext(Mio_Pin_t *pPin)
Definition mioApi.c:217
struct Mio_PinStruct_t_ Mio_Pin_t
Definition mio.h:44
#define st__is_member(table, key)
Definition st.h:70
unsigned uTruths[6][2]
Definition mapperInt.h:188
Map_HashTable_t * tTableC
Definition mapperInt.h:184
Map_Super_t ** ppSupers
Definition mapperInt.h:183
Mio_Gate_t * pRoot
Definition mapperInt.h:292
unsigned uTruth[2]
Definition mapperInt.h:293
Map_Time_t tDelayMax
Definition mapperInt.h:296
Map_Time_t tDelaysF[6]
Definition mapperInt.h:295
Map_Time_t tDelaysR[6]
Definition mapperInt.h:294
unsigned char uPhases[4]
Definition mapperInt.h:289
Map_Super_t * pFanins[6]
Definition mapperInt.h:291
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Map_LibraryPrintTree()

void Map_LibraryPrintTree ( Map_SuperLib_t * pLib)

Function*************************************************************

Synopsis [Prints the supergate library after deriving parameters.]

Description [This procedure is very useful to see the library after it has been read into the mapper by "read_super" and all the information about the supergates derived.]

SideEffects []

SeeAlso []

Definition at line 979 of file mapperTree.c.

980{
981 Map_Super_t * pGate;
982 int i, k;
983
984 // print all the info related to the supergates
985// for ( i = pLib->nVarsMax; i < (int)pLib->nLines; i++ )
986 for ( i = pLib->nVarsMax; i < 20; i++ )
987 {
988 pGate = pLib->ppSupers[i];
989
990 // write the gate's fanin info and formula
991 printf( "%6d ", pGate->Num );
992 printf( "%c ", pGate->fSuper? '*' : ' ' );
993 printf( "%6s", Mio_GateReadName(pGate->pRoot) );
994 for ( k = 0; k < (int)pGate->nFanins; k++ )
995 printf( " %6d", pGate->pFanins[k]->Num );
996 printf( " %s", pGate->pFormula );
997 printf( "\n" );
998
999 // write the gate's derived info
1000 Extra_PrintBinary( stdout, pGate->uTruth, 64 );
1001 printf( " %3d", pGate->nGates );
1002 printf( " %6.2f", pGate->Area );
1003 printf( " (%4.2f, %4.2f)", pGate->tDelayMax.Rise, pGate->tDelayMax.Fall );
1004 printf( "\n" );
1005 for ( k = 0; k < pLib->nVarsMax; k++ )
1006 {
1007 // print the constraint on the rise of the gate in the form (D1, D2),
1008 // where D1 is the constraint related to the rise of the k-th PI
1009 // where D2 is the constraint related to the fall of the k-th PI
1010 if ( pGate->tDelaysR[k].Rise < 0 && pGate->tDelaysR[k].Fall < 0 )
1011 printf( " (----, ----)" );
1012 else if ( pGate->tDelaysR[k].Fall < 0 )
1013 printf( " (%4.2f, ----)", pGate->tDelaysR[k].Rise );
1014 else if ( pGate->tDelaysR[k].Rise < 0 )
1015 printf( " (----, %4.2f)", pGate->tDelaysR[k].Fall );
1016 else
1017 printf( " (%4.2f, %4.2f)", pGate->tDelaysR[k].Rise, pGate->tDelaysR[k].Fall );
1018
1019 // print the constraint on the fall of the gate in the form (D1, D2),
1020 // where D1 is the constraint related to the rise of the k-th PI
1021 // where D2 is the constraint related to the fall of the k-th PI
1022 if ( pGate->tDelaysF[k].Rise < 0 && pGate->tDelaysF[k].Fall < 0 )
1023 printf( " (----, ----)" );
1024 else if ( pGate->tDelaysF[k].Fall < 0 )
1025 printf( " (%4.2f, ----)", pGate->tDelaysF[k].Rise );
1026 else if ( pGate->tDelaysF[k].Rise < 0 )
1027 printf( " (----, %4.2f)", pGate->tDelaysF[k].Fall );
1028 else
1029 printf( " (%4.2f, %4.2f)", pGate->tDelaysF[k].Rise, pGate->tDelaysF[k].Fall );
1030 printf( "\n" );
1031 }
1032 printf( "\n" );
1033 }
1034}
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
Here is the call graph for this function:

◆ Map_LibraryReadFileTreeStr()

int Map_LibraryReadFileTreeStr ( Map_SuperLib_t * pLib,
Mio_Library_t * pGenlib,
Vec_Str_t * vStr,
char * pFileName )

Function*************************************************************

Synopsis [Reads the supergate library from file.]

Description []

SideEffects []

SeeAlso []

Definition at line 391 of file mapperTree.c.

392{
393 ProgressBar * pProgress;
394 char pBuffer[5000];
395 Map_Super_t * pGate;
396 char * pTemp = 0, * pLibName;
397 int nCounter, k, i;
398 int RetValue, nPos = 0;
399
400 // skip empty and comment lines
401// while ( fgets( pBuffer, 5000, pFile ) != NULL )
402 while ( 1 )
403 {
404 RetValue = Vec_StrGets( pBuffer, 5000, vStr, &nPos );
405 if ( RetValue == 0 )
406 return 0;
407 // skip leading spaces
408 for ( pTemp = pBuffer; *pTemp == ' ' || *pTemp == '\r' || *pTemp == '\n'; pTemp++ );
409 // skip comment lines and empty lines
410 if ( *pTemp != 0 && *pTemp != '#' )
411 break;
412 }
413
414 pLibName = strtok( pTemp, " \t\r\n" );
415// pLib->pGenlib = (Mio_Library_t *)Abc_FrameReadLibGen();
416 pLib->pGenlib = pGenlib;
417// if ( pLib->pGenlib == NULL || strcmp( , pLibName ) )
418 if ( pLib->pGenlib == NULL || Map_LibraryCompareLibNames(Mio_LibraryReadName(pLib->pGenlib), pLibName) )
419 {
420 printf( "Supergate library \"%s\" requires the use of genlib library \"%s\".\n", pFileName, pLibName );
421 return 0;
422 }
423
424 // read the number of variables
425 RetValue = Vec_StrGets( pBuffer, 5000, vStr, &nPos );
426 if ( RetValue == 0 )
427 return 0;
428 RetValue = sscanf( pBuffer, "%d\n", &pLib->nVarsMax );
429 if ( pLib->nVarsMax < 2 || pLib->nVarsMax > 10 )
430 {
431 printf( "Suspicious number of variables (%d).\n", pLib->nVarsMax );
432 return 0;
433 }
434
435 // read the number of gates
436 RetValue = Vec_StrGets( pBuffer, 5000, vStr, &nPos );
437 if ( RetValue == 0 )
438 return 0;
439 RetValue = sscanf( pBuffer, "%d\n", &pLib->nSupersReal );
440 if ( pLib->nSupersReal < 1 || pLib->nSupersReal > 10000000 )
441 {
442 printf( "Suspicious number of gates (%d).\n", pLib->nSupersReal );
443 return 0;
444 }
445
446 // read the number of lines
447 RetValue = Vec_StrGets( pBuffer, 5000, vStr, &nPos );
448 if ( RetValue == 0 )
449 return 0;
450 RetValue = sscanf( pBuffer, "%d\n", &pLib->nLines );
451 if ( pLib->nLines < 1 || pLib->nLines > 10000000 )
452 {
453 printf( "Suspicious number of lines (%d).\n", pLib->nLines );
454 return 0;
455 }
456
457 // allocate room for supergate pointers
458 pLib->ppSupers = ABC_ALLOC( Map_Super_t *, pLib->nLines + 10000 );
459
460 // create the elementary supergates
461 for ( i = 0; i < pLib->nVarsMax; i++ )
462 {
463 // get a new gate
464 pGate = (Map_Super_t *)Extra_MmFixedEntryFetch( pLib->mmSupers );
465 memset( pGate, 0, sizeof(Map_Super_t) );
466 // assign the elementary variable, the truth table, and the delays
467 pGate->Num = i;
468 // set the truth table
469 pGate->uTruth[0] = pLib->uTruths[i][0];
470 pGate->uTruth[1] = pLib->uTruths[i][1];
471 // set the arrival times of all input to non-existent delay
472 for ( k = 0; k < pLib->nVarsMax; k++ )
473 {
474 pGate->tDelaysR[k].Rise = pGate->tDelaysR[k].Fall = MAP_NO_VAR;
475 pGate->tDelaysF[k].Rise = pGate->tDelaysF[k].Fall = MAP_NO_VAR;
476 }
477 // set an existent arrival time for rise and fall
478 pGate->tDelaysR[i].Rise = 0.0;
479 pGate->tDelaysF[i].Fall = 0.0;
480 // set the gate
481 pLib->ppSupers[i] = pGate;
482 }
483
484 // read the lines
485 nCounter = pLib->nVarsMax;
486 pProgress = Extra_ProgressBarStart( stdout, pLib->nLines );
487// while ( fgets( pBuffer, 5000, pFile ) != NULL )
488 while ( Vec_StrGets( pBuffer, 5000, vStr, &nPos ) )
489 {
490 for ( pTemp = pBuffer; *pTemp == ' ' || *pTemp == '\r' || *pTemp == '\n'; pTemp++ );
491 if ( pTemp[0] == '\0' )
492 continue;
493// if ( pTemp[0] == 'a' || pTemp[2] == 'a' )
494// {
495// pLib->nLines--;
496// continue;
497// }
498
499 // get the gate
500 pGate = Map_LibraryReadGateTree( pLib, pTemp, nCounter, pLib->nVarsMax );
501 if ( pGate == NULL )
502 {
503 Extra_ProgressBarStop( pProgress );
504 return 0;
505 }
506 pLib->ppSupers[nCounter++] = pGate;
507 // later we will derive: truth table, delays, area, number of component gates, etc
508
509 // update the progress bar
510 Extra_ProgressBarUpdate( pProgress, nCounter, NULL );
511 }
512 Extra_ProgressBarStop( pProgress );
513 if ( nCounter != pLib->nLines )
514 printf( "The number of lines read (%d) is different from what the file says (%d).\n", nCounter, pLib->nLines );
515 pLib->nSupersAll = nCounter;
516 // count the number of real supergates
517 nCounter = 0;
518 for ( k = 0; k < pLib->nLines; k++ )
519 nCounter += pLib->ppSupers[k]->fSuper;
520 if ( nCounter != pLib->nSupersReal )
521 printf( "The number of gates read (%d) is different what the file says (%d).\n", nCounter, pLib->nSupersReal );
522 pLib->nSupersReal = nCounter;
523 return 1;
524}
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
Definition bbrNtbdd.c:27
char * Extra_MmFixedEntryFetch(Extra_MmFixed_t *p)
void Extra_ProgressBarStop(ProgressBar *p)
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
Map_Super_t * Map_LibraryReadGateTree(Map_SuperLib_t *pLib, char *pBuffer, int Number, int nVarsMax)
FUNCTION DEFINITIONS ///.
Definition mapperTree.c:54
int Vec_StrGets(char *pBuffer, int nBufferSize, Vec_Str_t *vStr, int *pPos)
Definition mapperTree.c:316
int Map_LibraryCompareLibNames(char *pName1, char *pName2)
Definition mapperTree.c:363
char * Mio_LibraryReadName(Mio_Library_t *pLib)
DECLARATIONS ///.
Definition mioApi.c:43
Mio_Library_t * pGenlib
Definition mapperInt.h:173
Extra_MmFixed_t * mmSupers
Definition mapperInt.h:199
char * memset()
char * strtok()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Map_LibraryReadGateTree()

Map_Super_t * Map_LibraryReadGateTree ( Map_SuperLib_t * pLib,
char * pBuffer,
int Number,
int nVarsMax )

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [Reads one gate.]

Description []

SideEffects []

SeeAlso []

Definition at line 54 of file mapperTree.c.

55{
56 Map_Super_t * pGate;
57 char * pTemp;
58 int i, Num;
59
60 // start and clean the gate
62 memset( pGate, 0, sizeof(Map_Super_t) );
63
64 // set the gate number
65 pGate->Num = Number;
66
67 // read the mark
68 pTemp = strtok( pBuffer, " " );
69 if ( pTemp[0] == '*' )
70 {
71 pGate->fSuper = 1;
72 pTemp = strtok( NULL, " " );
73 }
74
75 // read the root gate
76 pGate->pRoot = Mio_LibraryReadGateByName( pLib->pGenlib, pTemp, NULL );
77 if ( pGate->pRoot == NULL )
78 {
79 printf( "Cannot read the root gate names %s.\n", pTemp );
80 return NULL;
81 }
82 // set the max number of fanouts
83 pGate->nFanLimit = s_MapFanoutLimits[ Mio_GateReadPinNum(pGate->pRoot) ];
84
85 // read the pin-to-pin delay
86 for ( i = 0; ( pTemp = strtok( NULL, " \n\0" ) ); i++ )
87 {
88 if ( pTemp[0] == '#' )
89 break;
90 if ( i == nVarsMax )
91 {
92 printf( "There are too many entries on the line.\n" );
93 return NULL;
94 }
95 Num = atoi(pTemp);
96 if ( Num < 0 )
97 {
98 printf( "The number of a child supergate is negative.\n" );
99 return NULL;
100 }
101 if ( Num > pLib->nLines )
102 {
103 printf( "The number of a child supergate (%d) exceeded the number of lines (%d).\n",
104 Num, pLib->nLines );
105 return NULL;
106 }
107 pGate->pFanins[i] = pLib->ppSupers[Num];
108 }
109 pGate->nFanins = i;
110 if ( pGate->nFanins != (unsigned)Mio_GateReadPinNum(pGate->pRoot) )
111 {
112 printf( "The number of fanins of a root gate is wrong.\n" );
113 return NULL;
114 }
115
116 // save the gate name, just in case
117 if ( pTemp && pTemp[0] == '#' )
118 {
119 if ( pTemp[1] == 0 )
120 pTemp = strtok( NULL, " \n\0" );
121 else // skip spaces
122 for ( pTemp++; *pTemp == ' '; pTemp++ );
123 // save the formula
124 pGate->pFormula = Extra_MmFlexEntryFetch( pLib->mmForms, strlen(pTemp)+1 );
125 strcpy( pGate->pFormula, pTemp );
126 }
127 // check the rest of the string
128 pTemp = strtok( NULL, " \n\0" );
129 if ( pTemp != NULL )
130 printf( "The following trailing symbols found \"%s\".\n", pTemp );
131 return pGate;
132}
char * Extra_MmFlexEntryFetch(Extra_MmFlex_t *p, int nBytes)
int Mio_GateReadPinNum(Mio_Gate_t *pGate)
Definition mioApi.c:177
Mio_Gate_t * Mio_LibraryReadGateByName(Mio_Library_t *pLib, char *pName, char *pOutName)
Definition mioApi.c:105
Extra_MmFlex_t * mmForms
Definition mapperInt.h:201
int strlen()
char * strcpy()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Map_LibraryReadTree()

int Map_LibraryReadTree ( Map_SuperLib_t * pLib,
Mio_Library_t * pGenlib,
char * pFileName,
char * pExcludeFile )

Definition at line 525 of file mapperTree.c.

526{
527 char * pBuffer;
528 Vec_Str_t * vStr;
529 int Status, num;
530 Abc_Frame_t * pAbc;
531 st__table * tExcludeGate = 0;
532
533 // read the beginning of the file
534 assert( pLib->pGenlib == NULL );
535// pFile = Io_FileOpen( pFileName, "open_path", "r", 1 );
536 pBuffer = Mio_ReadFile( pFileName, 0 );
537 if ( pBuffer == NULL )
538 {
539 printf( "Cannot open input file \"%s\".\n", pFileName );
540 return 0;
541 }
542 vStr = Vec_StrAllocArray( pBuffer, strlen(pBuffer) );
543
544 if ( pExcludeFile )
545 {
547
548 tExcludeGate = st__init_table(strcmp, st__strhash);
549 if ( (num = Mio_LibraryReadExclude( pExcludeFile, tExcludeGate )) == -1 )
550 {
551 st__free_table( tExcludeGate );
552 tExcludeGate = 0;
553 Vec_StrFree( vStr );
554 return 0;
555 }
556
557 fprintf ( Abc_FrameReadOut( pAbc ), "Read %d gates from exclude file\n", num );
558 }
559
560 Status = Map_LibraryReadFileTreeStr( pLib, pGenlib, vStr, pFileName );
561 Vec_StrFree( vStr );
562 if ( Status == 0 )
563 return 0;
564 // prepare the info about the library
565 return Map_LibraryDeriveGateInfo( pLib, tExcludeGate );
566}
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
Definition abcapis.h:38
ABC_DLL Abc_Frame_t * Abc_FrameGetGlobalFrame()
Definition mainFrame.c:643
ABC_DLL FILE * Abc_FrameReadOut(Abc_Frame_t *p)
Definition mainFrame.c:359
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
int Map_LibraryDeriveGateInfo(Map_SuperLib_t *pLib, st__table *tExcludeGate)
Definition mapperTree.c:586
int Map_LibraryReadFileTreeStr(Map_SuperLib_t *pLib, Mio_Library_t *pGenlib, Vec_Str_t *vStr, char *pFileName)
Definition mapperTree.c:391
char * Mio_ReadFile(char *FileName, int fAddEnd)
Definition mioRead.c:115
int Mio_LibraryReadExclude(char *ExcludeFile, st__table *tExcludeGate)
Definition mioRead.c:699
int st__strhash(const char *string, int modulus)
Definition st.c:449
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition st.c:72
void st__free_table(st__table *table)
Definition st.c:81
Definition st.h:52
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Vec_StrGets()

int Vec_StrGets ( char * pBuffer,
int nBufferSize,
Vec_Str_t * vStr,
int * pPos )

Function*************************************************************

Synopsis [Reads the supergate library from file.]

Description []

SideEffects []

SeeAlso [] Function*************************************************************

Synopsis [Similar to fgets.]

Description []

SideEffects []

SeeAlso []

Definition at line 316 of file mapperTree.c.

317{
318 char * pCur;
319 char * pBeg = Vec_StrArray(vStr) + *pPos;
320 char * pEnd = Vec_StrArray(vStr) + Vec_StrSize(vStr);
321 assert( nBufferSize > 1 );
322 if ( pBeg == pEnd )
323 {
324 *pBuffer = 0;
325 return 0;
326 }
327 assert( pBeg < pEnd );
328 for ( pCur = pBeg; pCur < pEnd; pCur++ )
329 {
330 *pBuffer++ = *pCur;
331 if ( *pCur == 0 )
332 {
333 *pPos += pCur - pBeg;
334 return 0;
335 }
336 if ( *pCur == '\n' )
337 {
338 *pPos += pCur - pBeg + 1;
339 *pBuffer = 0;
340 return 1;
341 }
342 if ( pCur - pBeg == nBufferSize-1 )
343 {
344 *pPos += pCur - pBeg + 1;
345 *pBuffer = 0;
346 return 1;
347 }
348 }
349 return 0;
350}
Here is the caller graph for this function: