abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bblif.h File Reference

Go to the source code of this file.

Macros

#define Bbl_ManForEachObj(p, pObj)   for ( pObj = Bbl_ManObjFirst(p); pObj; pObj = Bbl_ManObjNext(p, pObj) )
 
#define Bbl_ObjForEachFanin(pObj, pFanin)   for ( pFanin = Bbl_ObjFaninFirst(pObj); pFanin; pFanin = Bbl_ObjFaninNext(pObj, pFanin) )
 

Typedefs

typedef struct Bbl_Man_t_ Bbl_Man_t
 
typedef struct Bbl_Obj_t_ Bbl_Obj_t
 

Enumerations

enum  Bbl_Type_t {
  BBL_OBJ_NONE, BBL_OBJ_CI, BBL_OBJ_CO, BBL_OBJ_NODE,
  BBL_OBJ_VOID
}
 INCLUDES ///. More...
 

Functions

Bbl_Man_tBbl_ManStart (char *pName)
 MACRO DEFINITIONS ///. More...
 
void Bbl_ManCreateObject (Bbl_Man_t *p, Bbl_Type_t Type, int ObjId, int nFanins, char *pSop)
 
void Bbl_ManAddFanin (Bbl_Man_t *p, int ObjId, int FaninId)
 
int Bbl_ManCheck (Bbl_Man_t *p)
 
void Bbl_ManPrintStats (Bbl_Man_t *p)
 
void Bbl_ManStop (Bbl_Man_t *p)
 
void Bbl_ManDumpBinaryBlif (Bbl_Man_t *p, char *pFileName)
 
Bbl_Man_tBbl_ManReadBinaryBlif (char *pFileName)
 
char * Bbl_ManName (Bbl_Man_t *p)
 
int Bbl_ObjIsInput (Bbl_Obj_t *p)
 
int Bbl_ObjIsOutput (Bbl_Obj_t *p)
 
int Bbl_ObjIsLut (Bbl_Obj_t *p)
 
int Bbl_ObjId (Bbl_Obj_t *p)
 
int Bbl_ObjIdOriginal (Bbl_Man_t *pMan, Bbl_Obj_t *p)
 
int Bbl_ObjFaninNumber (Bbl_Obj_t *p)
 
char * Bbl_ObjSop (Bbl_Man_t *pMan, Bbl_Obj_t *p)
 
Bbl_Obj_tBbl_ManObjFirst (Bbl_Man_t *p)
 
Bbl_Obj_tBbl_ManObjNext (Bbl_Man_t *p, Bbl_Obj_t *pObj)
 
Bbl_Obj_tBbl_ObjFaninFirst (Bbl_Obj_t *p)
 
Bbl_Obj_tBbl_ObjFaninNext (Bbl_Obj_t *p, Bbl_Obj_t *pPrev)
 
char * Bbl_ManTruthToSop (unsigned *pTruth, int nVars)
 
unsigned * Bbl_ManSopToTruth (char *pSop, int nVars)
 
void Bbl_ManDumpBlif (Bbl_Man_t *p, char *pFileName)
 
void Bbl_ManSimpleDemo ()
 

Macro Definition Documentation

#define Bbl_ManForEachObj (   p,
  pObj 
)    for ( pObj = Bbl_ManObjFirst(p); pObj; pObj = Bbl_ManObjNext(p, pObj) )

Definition at line 257 of file bblif.h.

#define Bbl_ObjForEachFanin (   pObj,
  pFanin 
)    for ( pFanin = Bbl_ObjFaninFirst(pObj); pFanin; pFanin = Bbl_ObjFaninNext(pObj, pFanin) )

Definition at line 260 of file bblif.h.

Typedef Documentation

typedef struct Bbl_Man_t_ Bbl_Man_t

Definition at line 213 of file bblif.h.

typedef struct Bbl_Obj_t_ Bbl_Obj_t

Definition at line 216 of file bblif.h.

Enumeration Type Documentation

enum Bbl_Type_t

INCLUDES ///.

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

FileName [bblif.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Binary BLIF representation for logic networks.]

Synopsis [External declarations.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - February 28, 2009.]

Revision [

Id:
bblif.h,v 1.00 2009/02/28 00:00:00 alanmi Exp

]PARAMETERS ///BASIC TYPES ///

Enumerator
BBL_OBJ_NONE 
BBL_OBJ_CI 
BBL_OBJ_CO 
BBL_OBJ_NODE 
BBL_OBJ_VOID 

Definition at line 204 of file bblif.h.

204  {
205  BBL_OBJ_NONE, // 0: non-existent object
206  BBL_OBJ_CI, // 1: primary input
207  BBL_OBJ_CO, // 2: primary output
208  BBL_OBJ_NODE, // 3: buffer node
209  BBL_OBJ_VOID // 4: unused object
210 } Bbl_Type_t;
Bbl_Type_t
INCLUDES ///.
Definition: bblif.h:204

Function Documentation

void Bbl_ManAddFanin ( Bbl_Man_t p,
int  ObjId,
int  FaninId 
)

Fnction*************************************************************

Synopsis [Creates fanin/fanout relationship between two objects.]

Description []

SideEffects []

SeeAlso []

Definition at line 1023 of file bblif.c.

1024 {
1025  Bbl_Obj_t * pObj, * pFanin;
1026  int iFanin;
1027  pObj = Bbl_ManObj( p, ObjId );
1028  if ( Bbl_ObjIsCi(pObj) )
1029  {
1030  printf( "Bbl_ManAddFanin(): Cannot add fanin of the combinational input (Id = %d).\n", ObjId );
1031  return;
1032  }
1033  pFanin = Bbl_ManObj( p, FaninId );
1034  if ( Bbl_ObjIsCo(pFanin) )
1035  {
1036  printf( "Bbl_ManAddFanin(): Cannot add fanout of the combinational output (Id = %d).\n", FaninId );
1037  return;
1038  }
1039  iFanin = Vec_IntEntry( p->vFaninNums, ObjId );
1040  if ( iFanin >= (int)pObj->nFanins )
1041  {
1042  printf( "Bbl_ManAddFanin(): Trying to add more fanins to object (Id = %d) than declared (%d).\n", ObjId, pObj->nFanins );
1043  return;
1044  }
1045  assert( iFanin < (int)pObj->nFanins );
1046  Vec_IntWriteEntry( p->vFaninNums, ObjId, iFanin+1 );
1047  pObj->pFanins[iFanin] = (char *)pObj - (char *)pFanin;
1048 }
static Bbl_Obj_t * Bbl_ManObj(Bbl_Man_t *p, int Id)
Definition: bblif.c:117
int pFanins[0]
Definition: bblif.c:64
unsigned nFanins
Definition: bblif.c:63
Vec_Int_t * vFaninNums
Definition: bblif.c:93
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static int Bbl_ObjIsCo(Bbl_Obj_t *pObj)
Definition: bblif.c:103
#define assert(ex)
Definition: util_old.h:213
static int Bbl_ObjIsCi(Bbl_Obj_t *pObj)
Definition: bblif.c:102
int Bbl_ManCheck ( Bbl_Man_t p)

Fnction*************************************************************

Synopsis [Returns 1 if the manager was created correctly.]

Description []

SideEffects []

SeeAlso []

Definition at line 1062 of file bblif.c.

1063 {
1064  Bbl_Obj_t * pObj;
1065  int h, RetValue = 1;
1066  Bbl_ManForEachObj_int( p->pObjs, pObj, h )
1067  {
1068  if ( Bbl_ObjIsNode(pObj) && pObj->Fnc == -1 )
1069  RetValue = 0, printf( "Bbl_ManCheck(): Node %d does not have function specified.\n", pObj->Id );
1070  if ( Bbl_ObjIsCi(pObj) && pObj->Fnc != -1 )
1071  RetValue = 0, printf( "Bbl_ManCheck(): CI with %d has function specified.\n", pObj->Id );
1072  if ( Bbl_ObjIsCo(pObj) && pObj->Fnc != -1 )
1073  RetValue = 0, printf( "Bbl_ManCheck(): CO with %d has function specified.\n", pObj->Id );
1074  if ( Vec_IntEntry(p->vFaninNums, pObj->Id) != (int)pObj->nFanins )
1075  RetValue = 0, printf( "Bbl_ManCheck(): Object %d has less fanins (%d) than declared (%d).\n",
1076  pObj->Id, Vec_IntEntry(p->vFaninNums, pObj->Id), pObj->nFanins );
1077  }
1078  return RetValue;
1079 }
unsigned nFanins
Definition: bblif.c:63
Vec_Int_t * vFaninNums
Definition: bblif.c:93
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
#define Bbl_ManForEachObj_int(p, pObj, h)
Definition: bblif.c:119
static int Bbl_ObjIsNode(Bbl_Obj_t *pObj)
Definition: bblif.c:104
static int Bbl_ObjIsCo(Bbl_Obj_t *pObj)
Definition: bblif.c:103
Vec_Str_t * pObjs
Definition: bblif.c:88
int Fnc
Definition: bblif.c:58
static int Bbl_ObjIsCi(Bbl_Obj_t *pObj)
Definition: bblif.c:102
int Id
Definition: bblif.c:57
void Bbl_ManCreateObject ( Bbl_Man_t p,
Bbl_Type_t  Type,
int  ObjId,
int  nFanins,
char *  pSop 
)

Fnction*************************************************************

Synopsis [Adds one object.]

Description []

SideEffects []

SeeAlso []

Definition at line 988 of file bblif.c.

989 {
990  Bbl_Obj_t * pObj;
991  if ( Type == BBL_OBJ_CI && nFanins != 0 )
992  {
993  printf( "Attempting to create a combinational input with %d fanins (should be 0).\n", nFanins );
994  return;
995  }
996  if ( Type == BBL_OBJ_CO && nFanins != 1 )
997  {
998  printf( "Attempting to create a combinational output with %d fanins (should be 1).\n", nFanins );
999  return;
1000  }
1001  pObj = (Bbl_Obj_t *)Vec_StrFetch( p->pObjs, sizeof(Bbl_Obj_t) + nFanins * sizeof(int) );
1002  memset( pObj, 0, sizeof(Bbl_Obj_t) );
1003  Vec_IntSetEntry( p->vId2Obj, ObjId, (char *)pObj - p->pObjs->pArray );
1004  Vec_IntSetEntry( p->vFaninNums, ObjId, 0 );
1005  pObj->fCi = (Type == BBL_OBJ_CI);
1006  pObj->fCo = (Type == BBL_OBJ_CO);
1007  pObj->Id = ObjId;
1008  pObj->Fnc = pSop? Bbl_ManSaveSop(p, pSop, nFanins) : -1;
1009  pObj->nFanins = nFanins;
1010 }
char * memset()
static void Vec_IntSetEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:418
Vec_Int_t * vId2Obj
Definition: bblif.c:91
unsigned nFanins
Definition: bblif.c:63
Vec_Int_t * vFaninNums
Definition: bblif.c:93
char * pArray
Definition: bblif.c:51
int Bbl_ManSaveSop(Bbl_Man_t *p, char *pSop, int nVars)
Definition: bblif.c:954
unsigned fCi
Definition: bblif.c:59
unsigned fCo
Definition: bblif.c:60
Vec_Str_t * pObjs
Definition: bblif.c:88
int Fnc
Definition: bblif.c:58
char * Vec_StrFetch(Vec_Str_t *p, int nBytes)
Definition: bblif.c:539
int Id
Definition: bblif.c:57
void Bbl_ManDumpBinaryBlif ( Bbl_Man_t p,
char *  pFileName 
)

Fnction*************************************************************

Synopsis [Writes data into file.]

Description []

SideEffects []

SeeAlso []

Definition at line 691 of file bblif.c.

692 {
693  FILE * pFile;
694  pFile = fopen( pFileName, "wb" );
695  Vec_StrWrite( pFile, p->pName );
696  Vec_StrWrite( pFile, p->pObjs );
697  Vec_StrWrite( pFile, p->pFncs );
698  fclose( pFile );
699 }
Vec_Str_t * pName
Definition: bblif.c:87
void Vec_StrWrite(FILE *pFile, Vec_Str_t *p)
Definition: bblif.c:561
Vec_Str_t * pFncs
Definition: bblif.c:89
Vec_Str_t * pObjs
Definition: bblif.c:88
void Bbl_ManDumpBlif ( Bbl_Man_t p,
char *  pFileName 
)

Fnction*************************************************************

Synopsis [Drives text BLIF file for debugging.]

Description []

SideEffects []

SeeAlso []

Definition at line 1218 of file bblif.c.

1219 {
1220  FILE * pFile;
1221  Bbl_Obj_t * pObj, * pFanin;
1222  pFile = fopen( pFileName, "w" );
1223  fprintf( pFile, "# Test file written by Bbl_ManDumpBlif() in ABC.\n" );
1224  fprintf( pFile, ".model %s\n", Bbl_ManName(p) );
1225  // write objects
1226  Bbl_ManForEachObj( p, pObj )
1227  {
1228  if ( Bbl_ObjIsInput(pObj) )
1229  fprintf( pFile, ".inputs %d\n", Bbl_ObjId(pObj) );
1230  else if ( Bbl_ObjIsOutput(pObj) )
1231  fprintf( pFile, ".outputs %d\n", Bbl_ObjId(pObj) );
1232  else if ( Bbl_ObjIsLut(pObj) )
1233  {
1234  fprintf( pFile, ".names" );
1235  Bbl_ObjForEachFanin( pObj, pFanin )
1236  fprintf( pFile, " %d", Bbl_ObjId(pFanin) );
1237  fprintf( pFile, " %d\n", Bbl_ObjId(pObj) );
1238  fprintf( pFile, "%s", Bbl_ObjSop(p, pObj) );
1239  }
1240  else assert( 0 );
1241  }
1242  // write output drivers
1243  Bbl_ManForEachObj( p, pObj )
1244  {
1245  if ( !Bbl_ObjIsOutput(pObj) )
1246  continue;
1247  fprintf( pFile, ".names" );
1248  Bbl_ObjForEachFanin( pObj, pFanin )
1249  fprintf( pFile, " %d", Bbl_ObjId(pFanin) );
1250  fprintf( pFile, " %d\n", Bbl_ObjId(pObj) );
1251  fprintf( pFile, "1 1\n" );
1252  }
1253  fprintf( pFile, ".end\n" );
1254  fclose( pFile );
1255 }
int Bbl_ObjIsInput(Bbl_Obj_t *p)
Definition: bblif.c:1093
char * Bbl_ManName(Bbl_Man_t *p)
Definition: bblif.c:1115
int Bbl_ObjId(Bbl_Obj_t *p)
Definition: bblif.c:1096
int Bbl_ObjIsLut(Bbl_Obj_t *p)
Definition: bblif.c:1095
#define Bbl_ManForEachObj(p, pObj)
Definition: bblif.h:257
else
Definition: sparse_int.h:55
#define assert(ex)
Definition: util_old.h:213
#define Bbl_ObjForEachFanin(pObj, pFanin)
Definition: bblif.h:260
int Bbl_ObjIsOutput(Bbl_Obj_t *p)
Definition: bblif.c:1094
char * Bbl_ObjSop(Bbl_Man_t *pMan, Bbl_Obj_t *p)
Definition: bblif.c:1099
char* Bbl_ManName ( Bbl_Man_t p)

Fnction*************************************************************

Synopsis [Returns the name of the design.]

Description []

SideEffects []

SeeAlso []

Definition at line 1115 of file bblif.c.

1116 {
1117  return p->pName->pArray;
1118 }
Vec_Str_t * pName
Definition: bblif.c:87
char * pArray
Definition: bblif.c:51
Bbl_Obj_t* Bbl_ManObjFirst ( Bbl_Man_t p)

Fnction*************************************************************

Synopsis [Returns the first object.]

Description []

SideEffects []

SeeAlso []

Definition at line 1147 of file bblif.c.

1148 {
1149  return Bbl_VecObj( p->pObjs, 0 );
1150 }
static Bbl_Obj_t * Bbl_VecObj(Vec_Str_t *p, int h)
Definition: bblif.c:112
Vec_Str_t * pObjs
Definition: bblif.c:88
Bbl_Obj_t* Bbl_ManObjNext ( Bbl_Man_t p,
Bbl_Obj_t pObj 
)

Fnction*************************************************************

Synopsis [Returns the next object.]

Description []

SideEffects []

SeeAlso []

Definition at line 1163 of file bblif.c.

1164 {
1165  char * pNext = (char *)pObj + Bbl_ObjSize(pObj);
1166  char * pEdge = p->pObjs->pArray + p->pObjs->nSize;
1167  return (Bbl_Obj_t *)(pNext < pEdge ? pNext : NULL);
1168 }
char * pArray
Definition: bblif.c:51
static int Bbl_ObjSize(Bbl_Obj_t *pObj)
Definition: bblif.c:109
int nSize
Definition: bblif.c:50
Vec_Str_t * pObjs
Definition: bblif.c:88
void Bbl_ManPrintStats ( Bbl_Man_t p)

Fnction*************************************************************

Synopsis [Prints stats of the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 749 of file bblif.c.

750 {
751  Bbl_Obj_t * pObj;
752  Bbl_Fnc_t * pFnc;
753  int h, nFuncs = 0, nNodes = 0, nObjs = 0;
754  Bbl_ManForEachObj_int( p->pObjs, pObj, h )
755  nObjs++, nNodes += Bbl_ObjIsNode(pObj);
756  Bbl_ManForEachFnc_int( p->pFncs, pFnc, h )
757  nFuncs++;
758  printf( "Total objects = %7d. Total nodes = %7d. Unique functions = %7d.\n", nObjs, nNodes, nFuncs );
759  printf( "Name manager = %5.2f MB\n", 1.0*Vec_StrSize(p->pName)/(1 << 20) );
760  printf( "Objs manager = %5.2f MB\n", 1.0*Vec_StrSize(p->pObjs)/(1 << 20) );
761  printf( "Fncs manager = %5.2f MB\n", 1.0*Vec_StrSize(p->pFncs)/(1 << 20) );
762 }
#define Bbl_ManForEachFnc_int(p, pObj, h)
Definition: bblif.c:121
int nodes
Definition: abcSaucy.c:61
#define Bbl_ManForEachObj_int(p, pObj, h)
Definition: bblif.c:119
static int Bbl_ObjIsNode(Bbl_Obj_t *pObj)
Definition: bblif.c:104
static int Vec_StrSize(Vec_Str_t *p)
Definition: bblif.c:600
Vec_Str_t * pObjs
Definition: bblif.c:88
Bbl_Man_t* Bbl_ManReadBinaryBlif ( char *  pFileName)

Fnction*************************************************************

Synopsis [Creates manager after reading.]

Description []

SideEffects []

SeeAlso []

Definition at line 712 of file bblif.c.

713 {
714  Bbl_Man_t * p;
715  Bbl_Obj_t * pObj;
716  char * pBuffer;
717  int h;
718  p = BBLIF_ALLOC( Bbl_Man_t, 1 );
719  memset( p, 0, sizeof(Bbl_Man_t) );
720  p->nFileSize = Bbl_ManFileSize( pFileName );
721  p->pFileData = Bbl_ManFileRead( pFileName );
722  // extract three managers
723  pBuffer = p->pFileData;
724  p->pName = Vec_StrRead( &pBuffer );
725  p->pObjs = Vec_StrRead( &pBuffer );
726  p->pFncs = Vec_StrRead( &pBuffer );
727  assert( pBuffer - p->pFileData == p->nFileSize );
728  // remember original IDs in the objects
729  p->vObj2Id = Vec_IntAlloc( 1000 );
730  Bbl_ManForEachObj_int( p->pObjs, pObj, h )
731  {
732  Vec_IntPush( p->vObj2Id, pObj->Id );
733  pObj->Id = Vec_IntSize(p->vObj2Id) - 1;
734  }
735  return p;
736 }
char * memset()
Vec_Str_t * pName
Definition: bblif.c:87
int nFileSize
Definition: bblif.c:95
#define BBLIF_ALLOC(type, num)
Definition: bblif.c:126
static Llb_Mgr_t * p
Definition: llb3Image.c:950
char * pFileData
Definition: bblif.c:96
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
int Bbl_ManFileSize(char *pFileName)
Definition: bblif.c:637
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
#define Bbl_ManForEachObj_int(p, pObj, h)
Definition: bblif.c:119
Vec_Str_t * Vec_StrRead(char **ppStr)
Definition: bblif.c:578
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
Vec_Int_t * vObj2Id
Definition: bblif.c:92
#define assert(ex)
Definition: util_old.h:213
char * Bbl_ManFileRead(char *pFileName)
Definition: bblif.c:664
Vec_Str_t * pFncs
Definition: bblif.c:89
Vec_Str_t * pObjs
Definition: bblif.c:88
int Id
Definition: bblif.c:57
void Bbl_ManSimpleDemo ( )

Fnction*************************************************************

Synopsis [This demo shows using the internal to construct a half-adder.]

Description [We construct the logic network for the half-adder represnted using the BLIF file below]

SideEffects []

SeeAlso []

Definition at line 1446 of file bblif.c.

1447 {
1448 /*
1449  # There are contents of a BLIF file representing a half-adder:
1450  .model hadder
1451  .inputs a // ID = 1
1452  .inputs b // ID = 2
1453  .inputs cin // ID = 3
1454  .outputs s // ID = 4
1455  .outputs cout // ID = 5
1456  .names a b cin s_driver // ID = 6
1457  100 1
1458  010 1
1459  001 1
1460  111 1
1461  .names a b cin cout_driver // ID = 7
1462  -11 1
1463  1-1 1
1464  11- 1
1465  .names s_driver s
1466  1 1
1467  .names cout_driver cout
1468  1 1
1469  .end
1470 */
1471  Bbl_Man_t * p;
1472  // start the data manager
1473  p = Bbl_ManStart( "hadder" );
1474  // create CIs
1475  Bbl_ManCreateObject( p, BBL_OBJ_CI, 1, 0, NULL ); // a
1476  Bbl_ManCreateObject( p, BBL_OBJ_CI, 2, 0, NULL ); // b
1477  Bbl_ManCreateObject( p, BBL_OBJ_CI, 3, 0, NULL ); // cin
1478  // create COs
1479  Bbl_ManCreateObject( p, BBL_OBJ_CO, 4, 1, NULL ); // s
1480  Bbl_ManCreateObject( p, BBL_OBJ_CO, 5, 1, NULL ); // cout
1481  // create internal nodes
1482  Bbl_ManCreateObject( p, BBL_OBJ_NODE, 6, 3, "100 1\n010 1\n001 1\n111 1\n" ); // s_driver
1483  Bbl_ManCreateObject( p, BBL_OBJ_NODE, 7, 3, "-11 1\n1-1 1\n11- 1\n" ); // cout_driver
1484  // add fanins of node 6
1485  Bbl_ManAddFanin( p, 6, 1 ); // s_driver <- a
1486  Bbl_ManAddFanin( p, 6, 2 ); // s_driver <- b
1487  Bbl_ManAddFanin( p, 6, 3 ); // s_driver <- cin
1488  // add fanins of node 7
1489  Bbl_ManAddFanin( p, 7, 1 ); // cout_driver <- a
1490  Bbl_ManAddFanin( p, 7, 2 ); // cout_driver <- b
1491  Bbl_ManAddFanin( p, 7, 3 ); // cout_driver <- cin
1492  // add fanins of COs
1493  Bbl_ManAddFanin( p, 4, 6 ); // s <- s_driver
1494  Bbl_ManAddFanin( p, 5, 7 ); // cout <- cout_driver
1495  // sanity check
1496  Bbl_ManCheck( p );
1497  // write BLIF file as a sanity check
1498  Bbl_ManDumpBlif( p, "hadder.blif" );
1499  // write binary BLIF file
1500  Bbl_ManDumpBinaryBlif( p, "hadder.bblif" );
1501  // remove the manager
1502  Bbl_ManStop( p );
1503 
1504 
1505 // Bbl_ManTestTruth( "100 1\n010 1\n001 1\n111 1\n", 3 );
1506 // Bbl_ManTestTruth( "-11 0\n1-1 0\n11- 0\n", 3 );
1507 // Bbl_ManTestTruth( "--- 1\n", 3 );
1508 }
void Bbl_ManAddFanin(Bbl_Man_t *p, int ObjId, int FaninId)
Definition: bblif.c:1023
Bbl_Man_t * Bbl_ManStart(char *pName)
MACRO DEFINITIONS ///.
Definition: bblif.c:806
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Bbl_ManCheck(Bbl_Man_t *p)
Definition: bblif.c:1062
void Bbl_ManDumpBlif(Bbl_Man_t *p, char *pFileName)
Definition: bblif.c:1218
void Bbl_ManDumpBinaryBlif(Bbl_Man_t *p, char *pFileName)
Definition: bblif.c:691
void Bbl_ManStop(Bbl_Man_t *p)
Definition: bblif.c:775
void Bbl_ManCreateObject(Bbl_Man_t *p, Bbl_Type_t Type, int ObjId, int nFanins, char *pSop)
Definition: bblif.c:988
unsigned* Bbl_ManSopToTruth ( char *  pSop,
int  nVars 
)

Fnction*************************************************************

Synopsis [Converting SOP into a truth table.]

Description [The SOP is represented as a C-string, as documented in file "bblif.h". The truth table is returned as a bit-string composed of 2^nVars bits. For functions of less than 6 variables, the full machine word is returned. (The truth table looks as if the function had 5 variables.) The use of this procedure should be limited to Boolean functions with no more than 16 inputs.]

SideEffects []

SeeAlso []

Definition at line 1362 of file bblif.c.

1363 {
1364  unsigned * pTruth, * pCube, * pVars[16];
1365  int nWords = nVars <= 5 ? 1 : (1 << (nVars - 5));
1366  int v, c, w, nCubes, fCompl = 0;
1367  if ( pSop == NULL )
1368  return NULL;
1369  if ( strlen(pSop) % (nVars + 3) != 0 )
1370  {
1371  printf( "Bbl_ManSopToTruth(): SOP is represented incorrectly.\n" );
1372  return NULL;
1373  }
1374  // create storage for TTs of the result, elementary variables and the temp cube
1375  pTruth = BBLIF_ALLOC( unsigned, nWords );
1376  pVars[0] = BBLIF_ALLOC( unsigned, nWords * (nVars+1) );
1377  for ( v = 1; v < nVars; v++ )
1378  pVars[v] = pVars[v-1] + nWords;
1379  pCube = pVars[v-1] + nWords;
1380  Bbl_ManSopToTruthElem( nVars, pVars );
1381  // iterate through the cubes
1382  memset( pTruth, 0, sizeof(unsigned) * nWords );
1383  nCubes = strlen(pSop) / (nVars + 3);
1384  for ( c = 0; c < nCubes; c++ )
1385  {
1386  fCompl = (pSop[nVars+1] == '0');
1387  memset( pCube, 0xff, sizeof(unsigned) * nWords );
1388  // iterate through the literals of the cube
1389  for ( v = 0; v < nVars; v++ )
1390  if ( pSop[v] == '1' )
1391  for ( w = 0; w < nWords; w++ )
1392  pCube[w] &= pVars[v][w];
1393  else if ( pSop[v] == '0' )
1394  for ( w = 0; w < nWords; w++ )
1395  pCube[w] &= ~pVars[v][w];
1396  // add cube to storage
1397  for ( w = 0; w < nWords; w++ )
1398  pTruth[w] |= pCube[w];
1399  // go to the next cube
1400  pSop += (nVars + 3);
1401  }
1402  BBLIF_FREE( pVars[0] );
1403  if ( fCompl )
1404  for ( w = 0; w < nWords; w++ )
1405  pTruth[w] = ~pTruth[w];
1406  return pTruth;
1407 }
char * memset()
#define BBLIF_ALLOC(type, num)
Definition: bblif.c:126
int nWords
Definition: abcNpn.c:127
static void Bbl_ManSopToTruthElem(int nVars, unsigned **pVars)
Definition: bblif.c:1323
#define BBLIF_FREE(obj)
Definition: bblif.c:129
int strlen()
Bbl_Man_t* Bbl_ManStart ( char *  pName)

MACRO DEFINITIONS ///.

FUNCTION DECLARATIONS ///

Fnction*************************************************************

Synopsis [Creates manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 806 of file bblif.c.

807 {
808  Bbl_Man_t * p;
809  int nLength;
810  p = BBLIF_ALLOC( Bbl_Man_t, 1 );
811  memset( p, 0, sizeof(Bbl_Man_t) );
812  nLength = pName? 4 * ((strlen(pName) + 1) / 4 + 1) : 0;
813  p->pName = Vec_StrAlloc( nLength );
814  p->pName->nSize = p->pName->nCap;
815  if ( pName )
816  strcpy( p->pName->pArray, pName );
817  p->pObjs = Vec_StrAlloc( 1 << 16 );
818  p->pFncs = Vec_StrAlloc( 1 << 16 );
819  p->pEnts = Vec_StrAlloc( 1 << 16 ); p->pEnts->nSize = 1;
820  p->vId2Obj = Vec_IntStart( 1 << 10 );
821  p->vFaninNums = Vec_IntStart( 1 << 10 );
822  return p;
823 }
char * memset()
Vec_Str_t * pName
Definition: bblif.c:87
#define BBLIF_ALLOC(type, num)
Definition: bblif.c:126
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Vec_Int_t * vId2Obj
Definition: bblif.c:91
static Vec_Str_t * Vec_StrAlloc(int nCap)
Definition: bblif.c:495
Vec_Int_t * vFaninNums
Definition: bblif.c:93
Vec_Str_t * pEnts
Definition: bblif.c:98
static Vec_Int_t * Vec_IntStart(int nSize)
Definition: bblif.c:172
char * pArray
Definition: bblif.c:51
char * strcpy()
int nSize
Definition: bblif.c:50
int strlen()
Vec_Str_t * pFncs
Definition: bblif.c:89
int nCap
Definition: bblif.c:49
Vec_Str_t * pObjs
Definition: bblif.c:88
void Bbl_ManStop ( Bbl_Man_t p)

Fnction*************************************************************

Synopsis [Deletes the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 775 of file bblif.c.

776 {
777  if ( p->vId2Obj ) Vec_IntFree( p->vId2Obj );
778  if ( p->vObj2Id ) Vec_IntFree( p->vObj2Id );
779  if ( p->vFaninNums ) Vec_IntFree( p->vFaninNums );
780  if ( p->pFileData )
781  {
782  BBLIF_FREE( p->pFileData );
783  p->pName->pArray = NULL;
784  p->pObjs->pArray = NULL;
785  p->pFncs->pArray = NULL;
786  }
787  if ( p->pEnts )
788  Vec_StrFree( p->pEnts );
789  Vec_StrFree( p->pName );
790  Vec_StrFree( p->pObjs );
791  Vec_StrFree( p->pFncs );
792  BBLIF_FREE( p );
793 }
Vec_Str_t * pName
Definition: bblif.c:87
char * pFileData
Definition: bblif.c:96
Vec_Int_t * vId2Obj
Definition: bblif.c:91
Vec_Int_t * vFaninNums
Definition: bblif.c:93
Vec_Str_t * pEnts
Definition: bblif.c:98
char * pArray
Definition: bblif.c:51
static void Vec_StrFree(Vec_Str_t *p)
Definition: bblif.c:616
#define BBLIF_FREE(obj)
Definition: bblif.c:129
Vec_Int_t * vObj2Id
Definition: bblif.c:92
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
Vec_Str_t * pFncs
Definition: bblif.c:89
Vec_Str_t * pObjs
Definition: bblif.c:88
char* Bbl_ManTruthToSop ( unsigned *  pTruth,
int  nVars 
)

Fnction*************************************************************

Synopsis [Converting truth table into an SOP.]

Description [The truth table is given as a bit-string pTruth composed of 2^nVars bits. The result is an SOP derived by collecting minterms appearing in the truth table. The SOP is represented as a C-string, as documented in file "bblif.h". It is recommended to limit the use of this procedure to Boolean functions up to 6 inputs.]

SideEffects []

SeeAlso []

Definition at line 1273 of file bblif.c.

1274 {
1275  char * pResult, * pTemp;
1276  int nMints, nOnes, b, v;
1277  assert( nVars >= 0 && nVars <= 16 );
1278  nMints = (1 << nVars);
1279  // count the number of ones
1280  nOnes = 0;
1281  for ( b = 0; b < nMints; b++ )
1282  nOnes += ((pTruth[b>>5] >> (b&31)) & 1);
1283  // handle constants
1284  if ( nOnes == 0 || nOnes == nMints )
1285  {
1286  pResult = pTemp = BBLIF_ALLOC( char, nVars + 4 );
1287  for ( v = 0; v < nVars; v++ )
1288  *pTemp++ = '-';
1289  *pTemp++ = ' ';
1290  *pTemp++ = nOnes? '1' : '0';
1291  *pTemp++ = '\n';
1292  *pTemp++ = 0;
1293  assert( pTemp - pResult == nVars + 4 );
1294  return pResult;
1295  }
1296  pResult = pTemp = BBLIF_ALLOC( char, nOnes * (nVars + 3) + 1 );
1297  for ( b = 0; b < nMints; b++ )
1298  {
1299  if ( ((pTruth[b>>5] >> (b&31)) & 1) == 0 )
1300  continue;
1301  for ( v = 0; v < nVars; v++ )
1302  *pTemp++ = ((b >> v) & 1)? '1' : '0';
1303  *pTemp++ = ' ';
1304  *pTemp++ = '1';
1305  *pTemp++ = '\n';
1306  }
1307  *pTemp++ = 0;
1308  assert( pTemp - pResult == nOnes * (nVars + 3) + 1 );
1309  return pResult;
1310 }
#define BBLIF_ALLOC(type, num)
Definition: bblif.c:126
#define assert(ex)
Definition: util_old.h:213
Bbl_Obj_t* Bbl_ObjFaninFirst ( Bbl_Obj_t p)

Fnction*************************************************************

Synopsis [Returns the first fanin.]

Description []

SideEffects []

SeeAlso []

Definition at line 1181 of file bblif.c.

1182 {
1183  return Bbl_ObjFaninNum(p) ? Bbl_ObjFanin( p, 0 ) : NULL;
1184 }
static Bbl_Obj_t * Bbl_ObjFanin(Bbl_Obj_t *pObj, int i)
Definition: bblif.c:107
static int Bbl_ObjFaninNum(Bbl_Obj_t *pObj)
Definition: bblif.c:106
Bbl_Obj_t* Bbl_ObjFaninNext ( Bbl_Obj_t p,
Bbl_Obj_t pPrev 
)

Fnction*************************************************************

Synopsis [Returns the next fanin.]

Description []

SideEffects []

SeeAlso []

Definition at line 1197 of file bblif.c.

1198 {
1199  Bbl_Obj_t * pFanin;
1200  int i;
1201  Bbl_ObjForEachFanin_int( p, pFanin, i )
1202  if ( pFanin == pPrev )
1203  break;
1204  return i < Bbl_ObjFaninNum(p) - 1 ? Bbl_ObjFanin( p, i+1 ) : NULL;
1205 }
static Bbl_Obj_t * Bbl_ObjFanin(Bbl_Obj_t *pObj, int i)
Definition: bblif.c:107
#define Bbl_ObjForEachFanin_int(pObj, pFanin, i)
Definition: bblif.c:123
static int Bbl_ObjFaninNum(Bbl_Obj_t *pObj)
Definition: bblif.c:106
if(last==0)
Definition: sparse_int.h:34
int Bbl_ObjFaninNumber ( Bbl_Obj_t p)

Definition at line 1098 of file bblif.c.

1098 { return Bbl_ObjFaninNum(p); }
static int Bbl_ObjFaninNum(Bbl_Obj_t *pObj)
Definition: bblif.c:106
int Bbl_ObjId ( Bbl_Obj_t p)

Definition at line 1096 of file bblif.c.

1096 { return p->Id; }
int Id
Definition: bblif.c:57
int Bbl_ObjIdOriginal ( Bbl_Man_t pMan,
Bbl_Obj_t p 
)

Definition at line 1097 of file bblif.c.

1097 { assert(0); return Vec_IntEntry(pMan->vObj2Id, p->Id); }
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
Vec_Int_t * vObj2Id
Definition: bblif.c:92
#define assert(ex)
Definition: util_old.h:213
int Id
Definition: bblif.c:57
int Bbl_ObjIsInput ( Bbl_Obj_t p)

Fnction*************************************************************

Synopsis [Misc APIs.]

Description []

SideEffects []

SeeAlso []

Definition at line 1093 of file bblif.c.

1093 { return Bbl_ObjIsCi(p); }
static int Bbl_ObjIsCi(Bbl_Obj_t *pObj)
Definition: bblif.c:102
int Bbl_ObjIsLut ( Bbl_Obj_t p)

Definition at line 1095 of file bblif.c.

1095 { return Bbl_ObjIsNode(p); }
static int Bbl_ObjIsNode(Bbl_Obj_t *pObj)
Definition: bblif.c:104
int Bbl_ObjIsOutput ( Bbl_Obj_t p)

Definition at line 1094 of file bblif.c.

1094 { return Bbl_ObjIsCo(p); }
static int Bbl_ObjIsCo(Bbl_Obj_t *pObj)
Definition: bblif.c:103
char* Bbl_ObjSop ( Bbl_Man_t pMan,
Bbl_Obj_t p 
)

Definition at line 1099 of file bblif.c.

1099 { return Bbl_ManSop(pMan, p->Fnc); }
static char * Bbl_ManSop(Bbl_Man_t *p, int h)
Definition: bblif.c:116
int Fnc
Definition: bblif.c:58