ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ioReadBlif.c File Reference
#include "ioAbc.h"
#include "base/main/main.h"
#include "map/mio/mio.h"
Include dependency graph for ioReadBlif.c:

Go to the source code of this file.

Classes

struct  Io_ReadBlif_t_
 

Typedefs

typedef typedefABC_NAMESPACE_IMPL_START struct Io_ReadBlif_t_ Io_ReadBlif_t
 DECLARATIONS ///.
 

Functions

Abc_Ntk_tIo_ReadBlif (char *pFileName, int fCheck)
 FUNCTION DEFINITIONS ///.
 
int Io_ReadBlifReorderFormalNames (Vec_Ptr_t *vTokens, Mio_Gate_t *pGate, Mio_Gate_t *pTwin)
 
int Io_ReadFindCiId (Abc_Ntk_t *pNtk, Abc_Obj_t *pObj)
 
int Io_ReadFindCoId (Abc_Ntk_t *pNtk, Abc_Obj_t *pObj)
 
int Io_ReadBlifNetworkConnectBoxesOneBox (Io_ReadBlif_t *p, Abc_Obj_t *pBox, stmm_table *tName2Model)
 
int Io_ReadBlifNetworkConnectBoxesOne (Io_ReadBlif_t *p, Abc_Ntk_t *pNtk, stmm_table *tName2Model)
 

Typedef Documentation

◆ Io_ReadBlif_t

typedef typedefABC_NAMESPACE_IMPL_START struct Io_ReadBlif_t_ Io_ReadBlif_t

DECLARATIONS ///.

CFile****************************************************************

FileName [ioReadBlif.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Command processing package.]

Synopsis [Procedures to read BLIF files.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
ioReadBlif.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 35 of file ioReadBlif.c.

Function Documentation

◆ Io_ReadBlif()

Abc_Ntk_t * Io_ReadBlif ( char * pFileName,
int fCheck )

FUNCTION DEFINITIONS ///.

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

Synopsis [Reads the (hierarchical) network from the BLIF file.]

Description []

SideEffects []

SeeAlso []

Definition at line 113 of file ioReadBlif.c.

114{
116 Abc_Ntk_t * pNtk;
117
118 // start the file
119 p = Io_ReadBlifFile( pFileName );
120 if ( p == NULL )
121 return NULL;
122
123 // read the hierarchical network
124 pNtk = Io_ReadBlifNetwork( p );
125 if ( pNtk == NULL )
126 {
127 Io_ReadBlifFree( p );
128 return NULL;
129 }
130 pNtk->pSpec = Extra_UtilStrsav( pFileName );
131 Io_ReadBlifCreateTiming( p, pNtk );
132 Io_ReadBlifFree( p );
133
134 // make sure that everything is okay with the network structure
135 if ( fCheck && !Abc_NtkCheckRead( pNtk ) )
136 {
137 printf( "Io_ReadBlif: The network check has failed.\n" );
138 Abc_NtkDelete( pNtk );
139 return NULL;
140 }
141 return pNtk;
142}
ABC_DLL int Abc_NtkCheckRead(Abc_Ntk_t *pNtk)
Definition abcCheck.c:80
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
Cube * p
Definition exorList.c:222
char * Extra_UtilStrsav(const char *s)
typedefABC_NAMESPACE_IMPL_START struct Io_ReadBlif_t_ Io_ReadBlif_t
DECLARATIONS ///.
Definition ioReadBlif.c:35
char * pSpec
Definition abc.h:159
Here is the call graph for this function:

◆ Io_ReadBlifNetworkConnectBoxesOne()

int Io_ReadBlifNetworkConnectBoxesOne ( Io_ReadBlif_t * p,
Abc_Ntk_t * pNtk,
stmm_table * tName2Model )

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

Synopsis [Connect the boxes in the hierarchy of networks.]

Description []

SideEffects []

SeeAlso []

Definition at line 1597 of file ioReadBlif.c.

1598{
1599 Abc_Obj_t * pBox;
1600 int i;
1601 // go through the boxes
1602 Abc_NtkForEachBlackbox( pNtk, pBox, i )
1603 if ( Io_ReadBlifNetworkConnectBoxesOneBox( p, pBox, tName2Model ) )
1604 return 1;
1605 Abc_NtkFinalizeRead( pNtk );
1606 return 0;
1607}
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachBlackbox(pNtk, pObj, i)
Definition abc.h:512
ABC_DLL void Abc_NtkFinalizeRead(Abc_Ntk_t *pNtk)
Definition abcNtk.c:413
int Io_ReadBlifNetworkConnectBoxesOneBox(Io_ReadBlif_t *p, Abc_Obj_t *pBox, stmm_table *tName2Model)
Here is the call graph for this function:

◆ Io_ReadBlifNetworkConnectBoxesOneBox()

int Io_ReadBlifNetworkConnectBoxesOneBox ( Io_ReadBlif_t * p,
Abc_Obj_t * pBox,
stmm_table * tName2Model )

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

Synopsis [Connect one box.]

Description []

SideEffects []

SeeAlso []

Definition at line 1437 of file ioReadBlif.c.

1438{
1439 Vec_Ptr_t * pNames;
1440 Abc_Ntk_t * pNtkModel;
1441 Abc_Obj_t * pObj, * pNet;
1442 char * pName = NULL, * pActual;
1443 int i, Length, Start = -1;
1444
1445 // get the model for this box
1446 pNames = (Vec_Ptr_t *)pBox->pData;
1447 if ( !stmm_lookup( tName2Model, (char *)Vec_PtrEntry(pNames, 0), (char **)&pNtkModel ) )
1448 {
1449 p->LineCur = (int)(ABC_PTRINT_T)pBox->pCopy;
1450 sprintf( p->sError, "Cannot find the model for subcircuit %s.", (char*)Vec_PtrEntry(pNames, 0) );
1451 Io_ReadBlifPrintErrorMessage( p );
1452 return 1;
1453 }
1454
1455 // create the fanins of the box
1456 Abc_NtkForEachPi( pNtkModel, pObj, i )
1457 pObj->pCopy = NULL;
1458 if ( Abc_NtkPiNum(pNtkModel) == 0 )
1459 Start = 1;
1460 else
1461 {
1462 Vec_PtrForEachEntryStart( char *, pNames, pName, i, 1 )
1463 {
1464 pActual = Io_ReadBlifCleanName(pName);
1465 if ( pActual == NULL )
1466 {
1467 p->LineCur = (int)(ABC_PTRINT_T)pBox->pCopy;
1468 sprintf( p->sError, "Cannot parse formal/actual name pair \"%s\".", pName );
1469 Io_ReadBlifPrintErrorMessage( p );
1470 return 1;
1471 }
1472 Length = pActual - pName - 1;
1473 pName[Length] = 0;
1474 // find the PI net with this name
1475 pObj = Abc_NtkFindNet( pNtkModel, pName );
1476 if ( pObj == NULL )
1477 {
1478 p->LineCur = (int)(ABC_PTRINT_T)pBox->pCopy;
1479 sprintf( p->sError, "Cannot find formal input \"%s\" as an PI of model \"%s\".", pName, (char*)Vec_PtrEntry(pNames, 0) );
1480 Io_ReadBlifPrintErrorMessage( p );
1481 return 1;
1482 }
1483 // get the PI
1484 pObj = Abc_ObjFanin0(pObj);
1485 // quit if this is not a PI net
1486 if ( !Abc_ObjIsPi(pObj) )
1487 {
1488 pName[Length] = '=';
1489 Start = i;
1490 break;
1491 }
1492 // remember the actual name in the net
1493 if ( pObj->pCopy != NULL )
1494 {
1495 p->LineCur = (int)(ABC_PTRINT_T)pBox->pCopy;
1496 sprintf( p->sError, "Formal input \"%s\" is used more than once.", pName );
1497 Io_ReadBlifPrintErrorMessage( p );
1498 return 1;
1499 }
1500 pObj->pCopy = (Abc_Obj_t *)pActual;
1501 // quit if we processed all PIs
1502 if ( i == Abc_NtkPiNum(pNtkModel) )
1503 {
1504 Start = i+1;
1505 break;
1506 }
1507 }
1508 }
1509 // create the fanins of the box
1510 Abc_NtkForEachPi( pNtkModel, pObj, i )
1511 {
1512 pActual = (char *)pObj->pCopy;
1513 if ( pActual == NULL )
1514 {
1515 p->LineCur = (int)(ABC_PTRINT_T)pBox->pCopy;
1516 sprintf( p->sError, "Formal input \"%s\" of model %s is not driven.", pName, (char*)Vec_PtrEntry(pNames, 0) );
1517 Io_ReadBlifPrintErrorMessage( p );
1518 return 1;
1519 }
1520 pNet = Abc_NtkFindOrCreateNet( pBox->pNtk, pActual );
1521 Abc_ObjAddFanin( pBox, pNet );
1522 }
1523 Abc_NtkForEachPi( pNtkModel, pObj, i )
1524 pObj->pCopy = NULL;
1525
1526 // create the fanouts of the box
1527 Abc_NtkForEachPo( pNtkModel, pObj, i )
1528 pObj->pCopy = NULL;
1529 Vec_PtrForEachEntryStart( char *, pNames, pName, i, Start )
1530 {
1531 pActual = Io_ReadBlifCleanName(pName);
1532 if ( pActual == NULL )
1533 {
1534 p->LineCur = (int)(ABC_PTRINT_T)pBox->pCopy;
1535 sprintf( p->sError, "Cannot parse formal/actual name pair \"%s\".", pName );
1536 Io_ReadBlifPrintErrorMessage( p );
1537 return 1;
1538 }
1539 Length = pActual - pName - 1;
1540 pName[Length] = 0;
1541 // find the PO net with this name
1542 pObj = Abc_NtkFindNet( pNtkModel, pName );
1543 if ( pObj == NULL )
1544 {
1545 p->LineCur = (int)(ABC_PTRINT_T)pBox->pCopy;
1546 sprintf( p->sError, "Cannot find formal output \"%s\" as an PO of model \"%s\".", pName, (char*)Vec_PtrEntry(pNames, 0) );
1547 Io_ReadBlifPrintErrorMessage( p );
1548 return 1;
1549 }
1550 // get the PO
1551 pObj = Abc_ObjFanout0(pObj);
1552 if ( pObj->pCopy != NULL )
1553 {
1554 p->LineCur = (int)(ABC_PTRINT_T)pBox->pCopy;
1555 sprintf( p->sError, "Formal output \"%s\" is used more than once.", pName );
1556 Io_ReadBlifPrintErrorMessage( p );
1557 return 1;
1558 }
1559 pObj->pCopy = (Abc_Obj_t *)pActual;
1560 }
1561 // create the fanouts of the box
1562 Abc_NtkForEachPo( pNtkModel, pObj, i )
1563 {
1564 pActual = (char *)pObj->pCopy;
1565 if ( pActual == NULL )
1566 {
1567 p->LineCur = (int)(ABC_PTRINT_T)pBox->pCopy;
1568 sprintf( p->sError, "Formal output \"%s\" of model %s is not driven.", pName, (char*)Vec_PtrEntry(pNames, 0) );
1569 Io_ReadBlifPrintErrorMessage( p );
1570 return 1;
1571 }
1572 pNet = Abc_NtkFindOrCreateNet( pBox->pNtk, pActual );
1573 Abc_ObjAddFanin( pNet, pBox );
1574 }
1575 Abc_NtkForEachPo( pNtkModel, pObj, i )
1576 pObj->pCopy = NULL;
1577
1578 // remove the array of names, assign the pointer to the model
1579 Vec_PtrForEachEntry( char *, (Vec_Ptr_t *)pBox->pData, pName, i )
1580 ABC_FREE( pName );
1581 Vec_PtrFree( (Vec_Ptr_t *)pBox->pData );
1582 pBox->pData = pNtkModel;
1583 return 0;
1584}
ABC_DLL Abc_Obj_t * Abc_NtkFindOrCreateNet(Abc_Ntk_t *pNtk, char *pName)
Definition abcObj.c:587
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition abc.h:520
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition abc.h:516
ABC_DLL Abc_Obj_t * Abc_NtkFindNet(Abc_Ntk_t *pNtk, char *pName)
Definition abcObj.c:515
#define ABC_FREE(obj)
Definition abc_global.h:267
int stmm_lookup(stmm_table *table, char *key, char **value)
Definition stmm.c:134
void * pData
Definition abc.h:145
Abc_Ntk_t * pNtk
Definition abc.h:130
Abc_Obj_t * pCopy
Definition abc.h:148
char * sprintf()
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
Definition vecPtr.h:57
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Io_ReadBlifReorderFormalNames()

int Io_ReadBlifReorderFormalNames ( Vec_Ptr_t * vTokens,
Mio_Gate_t * pGate,
Mio_Gate_t * pTwin )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 561 of file ioReadBlif.c.

562{
563 Mio_Pin_t * pGatePin;
564 char * pName, * pNamePin;
565 int i, k, nSize, Length;
566 nSize = Vec_PtrSize(vTokens);
567 if ( pTwin == NULL )
568 {
569 if ( nSize - 3 != Mio_GateReadPinNum(pGate) )
570 return 0;
571 }
572 else
573 {
574 if ( nSize - 3 != Mio_GateReadPinNum(pGate) && nSize - 4 != Mio_GateReadPinNum(pGate) )
575 return 0;
576 }
577 // check if the names are in order
578 for ( pGatePin = Mio_GateReadPins(pGate), i = 0; pGatePin; pGatePin = Mio_PinReadNext(pGatePin), i++ )
579 {
580 pNamePin = Mio_PinReadName(pGatePin);
581 Length = strlen(pNamePin);
582 pName = (char *)Vec_PtrEntry(vTokens, i+2);
583 if ( !strncmp( pNamePin, pName, Length ) && pName[Length] == '=' )
584 continue;
585 break;
586 }
587 if ( pTwin == NULL )
588 {
589 if ( i == Mio_GateReadPinNum(pGate) )
590 return 1;
591 // reorder the pins
592 for ( pGatePin = Mio_GateReadPins(pGate), i = 0; pGatePin; pGatePin = Mio_PinReadNext(pGatePin), i++ )
593 {
594 pNamePin = Mio_PinReadName(pGatePin);
595 Length = strlen(pNamePin);
596 for ( k = 2; k < nSize; k++ )
597 {
598 pName = (char *)Vec_PtrEntry(vTokens, k);
599 if ( !strncmp( pNamePin, pName, Length ) && pName[Length] == '=' )
600 {
601 Vec_PtrPush( vTokens, pName );
602 break;
603 }
604 }
605 }
606 pNamePin = Mio_GateReadOutName(pGate);
607 Length = strlen(pNamePin);
608 for ( k = 2; k < nSize; k++ )
609 {
610 pName = (char *)Vec_PtrEntry(vTokens, k);
611 if ( !strncmp( pNamePin, pName, Length ) && pName[Length] == '=' )
612 {
613 Vec_PtrPush( vTokens, pName );
614 break;
615 }
616 }
617 if ( Vec_PtrSize(vTokens) - nSize != nSize - 2 )
618 return 0;
619 Vec_PtrForEachEntryStart( char *, vTokens, pName, k, nSize )
620 Vec_PtrWriteEntry( vTokens, k - nSize + 2, pName );
621 Vec_PtrShrink( vTokens, nSize );
622 }
623 else
624 {
625 if ( i != Mio_GateReadPinNum(pGate) ) // expect the correct order of input pins in the network with twin gates
626 return 0;
627 // check the last two entries
628 if ( nSize - 3 == Mio_GateReadPinNum(pGate) ) // only one output is available
629 {
630 pNamePin = Mio_GateReadOutName(pGate);
631 Length = strlen(pNamePin);
632 pName = (char *)Vec_PtrEntry(vTokens, nSize - 1);
633 if ( !strncmp( pNamePin, pName, Length ) && pName[Length] == '=' ) // the last entry is pGate
634 {
635 Vec_PtrPush( vTokens, NULL );
636 return 1;
637 }
638 pNamePin = Mio_GateReadOutName(pTwin);
639 Length = strlen(pNamePin);
640 pName = (char *)Vec_PtrEntry(vTokens, nSize - 1);
641 if ( !strncmp( pNamePin, pName, Length ) && pName[Length] == '=' ) // the last entry is pTwin
642 {
643 pName = (char *)Vec_PtrPop( vTokens );
644 Vec_PtrPush( vTokens, NULL );
645 Vec_PtrPush( vTokens, pName );
646 return 1;
647 }
648 return 0;
649 }
650 if ( nSize - 4 == Mio_GateReadPinNum(pGate) ) // two outputs are available
651 {
652 pNamePin = Mio_GateReadOutName(pGate);
653 Length = strlen(pNamePin);
654 pName = (char *)Vec_PtrEntry(vTokens, nSize - 2);
655 if ( !(!strncmp( pNamePin, pName, Length ) && pName[Length] == '=') )
656 return 0;
657 pNamePin = Mio_GateReadOutName(pTwin);
658 Length = strlen(pNamePin);
659 pName = (char *)Vec_PtrEntry(vTokens, nSize - 1);
660 if ( !(!strncmp( pNamePin, pName, Length ) && pName[Length] == '=') )
661 return 0;
662 return 1;
663 }
664 assert( 0 );
665 }
666 return 1;
667}
Mio_Pin_t * Mio_GateReadPins(Mio_Gate_t *pGate)
Definition mioApi.c:173
int Mio_GateReadPinNum(Mio_Gate_t *pGate)
Definition mioApi.c:177
char * Mio_PinReadName(Mio_Pin_t *pPin)
Definition mioApi.c:208
Mio_Pin_t * Mio_PinReadNext(Mio_Pin_t *pPin)
Definition mioApi.c:217
struct Mio_PinStruct_t_ Mio_Pin_t
Definition mio.h:44
char * Mio_GateReadOutName(Mio_Gate_t *pGate)
Definition mioApi.c:170
#define assert(ex)
Definition util_old.h:213
int strncmp()
int strlen()
Here is the call graph for this function:

◆ Io_ReadFindCiId()

int Io_ReadFindCiId ( Abc_Ntk_t * pNtk,
Abc_Obj_t * pObj )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 1043 of file ioReadBlif.c.

1044{
1045 Abc_Obj_t * pTemp;
1046 int i;
1047 Abc_NtkForEachCi( pNtk, pTemp, i )
1048 if ( pTemp == pObj )
1049 return i;
1050 return -1;
1051}
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition abc.h:518

◆ Io_ReadFindCoId()

int Io_ReadFindCoId ( Abc_Ntk_t * pNtk,
Abc_Obj_t * pObj )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 1103 of file ioReadBlif.c.

1104{
1105 Abc_Obj_t * pTemp;
1106 int i;
1107 Abc_NtkForEachPo( pNtk, pTemp, i )
1108 if ( pTemp == pObj )
1109 return i;
1110 return -1;
1111}