1 /**CFile****************************************************************
2 
3   FileName    [bac.h]
4 
5   SystemName  [ABC: Logic synthesis and verification system.]
6 
7   PackageName [Hierarchical word-level netlist.]
8 
9   Synopsis    [External declarations.]
10 
11   Author      [Alan Mishchenko]
12 
13   Affiliation [UC Berkeley]
14 
15   Date        [Ver. 1.0. Started - November 29, 2014.]
16 
17   Revision    [$Id: bac.h,v 1.00 2014/11/29 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #ifndef ABC__base__bac__bac_h
22 #define ABC__base__bac__bac_h
23 
24 ////////////////////////////////////////////////////////////////////////
25 ///                          INCLUDES                                ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 #include "aig/gia/gia.h"
29 #include "misc/extra/extra.h"
30 #include "misc/util/utilNam.h"
31 
32 ////////////////////////////////////////////////////////////////////////
33 ///                         PARAMETERS                               ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 ABC_NAMESPACE_HEADER_START
37 
38 ////////////////////////////////////////////////////////////////////////
39 ///                         BASIC TYPES                              ///
40 ////////////////////////////////////////////////////////////////////////
41 
42 // network objects
43 typedef enum {
44     BAC_OBJ_NONE = 0,  // 0:  unused
45     BAC_OBJ_PI,        // 1:  input
46     BAC_OBJ_PO,        // 2:  output
47     BAC_OBJ_BI,        // 3:  box input
48     BAC_OBJ_BO,        // 4:  box output
49     BAC_OBJ_BOX,       // 5:  box
50 
51     BAC_BOX_CF,
52     BAC_BOX_CT,
53     BAC_BOX_CX,
54     BAC_BOX_CZ,
55     BAC_BOX_BUF,
56     BAC_BOX_INV,
57     BAC_BOX_AND,
58     BAC_BOX_NAND,
59     BAC_BOX_OR,
60     BAC_BOX_NOR,
61     BAC_BOX_XOR,
62     BAC_BOX_XNOR,
63     BAC_BOX_SHARP,
64     BAC_BOX_SHARPL,
65     BAC_BOX_MUX,
66     BAC_BOX_MAJ,
67 
68     BAC_BOX_RAND,
69     BAC_BOX_RNAND,
70     BAC_BOX_ROR,
71     BAC_BOX_RNOR,
72     BAC_BOX_RXOR,
73     BAC_BOX_RXNOR,
74 
75     BAC_BOX_LAND,
76     BAC_BOX_LNAND,
77     BAC_BOX_LOR,
78     BAC_BOX_LNOR,
79     BAC_BOX_LXOR,
80     BAC_BOX_LXNOR,
81 
82     BAC_BOX_NMUX,
83     BAC_BOX_SEL,
84     BAC_BOX_PSEL,
85     BAC_BOX_ENC,
86     BAC_BOX_PENC,
87     BAC_BOX_DEC,
88     BAC_BOX_EDEC,
89 
90     BAC_BOX_ADD,
91     BAC_BOX_SUB,
92     BAC_BOX_MUL,
93     BAC_BOX_DIV,
94     BAC_BOX_MOD,
95     BAC_BOX_REM,
96     BAC_BOX_POW,
97     BAC_BOX_MIN,
98     BAC_BOX_ABS,
99 
100     BAC_BOX_LTHAN,
101     BAC_BOX_LETHAN,
102     BAC_BOX_METHAN,
103     BAC_BOX_MTHAN,
104     BAC_BOX_EQU,
105     BAC_BOX_NEQU,
106 
107     BAC_BOX_SHIL,
108     BAC_BOX_SHIR,
109     BAC_BOX_ROTL,
110     BAC_BOX_ROTR,
111 
112     BAC_BOX_GATE,
113     BAC_BOX_LUT,
114     BAC_BOX_ASSIGN,
115 
116     BAC_BOX_TRI,
117     BAC_BOX_RAM,
118     BAC_BOX_RAMR,
119     BAC_BOX_RAMW,
120     BAC_BOX_RAMWC,
121     BAC_BOX_RAMBOX,
122 
123     BAC_BOX_LATCH,
124     BAC_BOX_LATCHRS,
125     BAC_BOX_DFF,
126     BAC_BOX_DFFRS,
127 
128     BAC_BOX_UNKNOWN   // 67
129 } Bac_ObjType_t;
130 
131 
132 // name types
133 typedef enum {
134     BAC_NAME_BIN = 0,        // 0:  binary variable
135     BAC_NAME_WORD,           // 1:  first bit of word-level variable
136     BAC_NAME_INFO,           // 2:  first bit of special variable
137     BAC_NAME_INDEX,          // 3:  index of word-level variable
138 } Bac_NameType_t;
139 
140 
141 typedef struct Bac_Ntk_t_ Bac_Ntk_t;
142 typedef struct Bac_Man_t_ Bac_Man_t;
143 
144 // network
145 struct Bac_Ntk_t_
146 {
147     Bac_Man_t *  pDesign;  // design
148     int          NameId;   // name ID
149     int          iCopy;    // copy module
150     int          iBoxNtk;  // instance network ID
151     int          iBoxObj;  // instance object ID
152     int          Count;    // object counter
153     int          Mark;     // visit mark
154     // interface
155     Vec_Int_t    vInputs;  // inputs
156     Vec_Int_t    vOutputs; // outputs
157     Vec_Int_t    vInfo;    // input/output/wire info
158     // object attributes
159     Vec_Str_t    vType;    // types
160     Vec_Int_t    vFanin;   // fanin
161     Vec_Int_t    vIndex;   // index
162     Vec_Int_t    vName;    // original NameId or InstId
163     Vec_Int_t    vFanout;  // fanout
164     Vec_Int_t    vCopy;    // copy
165     // other
166     Vec_Int_t    vArray;
167     Vec_Int_t    vArray2;
168 };
169 
170 // design
171 struct Bac_Man_t_
172 {
173     // design names
174     char *       pName;    // design name
175     char *       pSpec;    // spec file name
176     Abc_Nam_t *  pStrs;    // string manager
177     Abc_Nam_t *  pMods;    // module name manager
178     // internal data
179     int          iRoot;    // root network
180     int          nNtks;    // number of current networks
181     Bac_Ntk_t *  pNtks;    // networks
182     // user data
183     Vec_Str_t *  vOut;
184     Vec_Str_t *  vOut2;
185     Vec_Int_t    vBuf2RootNtk;
186     Vec_Int_t    vBuf2RootObj;
187     Vec_Int_t    vBuf2LeafNtk;
188     Vec_Int_t    vBuf2LeafObj;
189     void *       pMioLib;
190     void **      ppGraphs;
191     int          ElemGates[4];
192     char *       pPrimNames[BAC_BOX_UNKNOWN];
193     char *       pPrimSymbs[BAC_BOX_UNKNOWN];
194 };
195 
Bac_ManName(Bac_Man_t * p)196 static inline char *         Bac_ManName( Bac_Man_t * p )                    { return p->pName;                                                                            }
Bac_ManSpec(Bac_Man_t * p)197 static inline char *         Bac_ManSpec( Bac_Man_t * p )                    { return p->pSpec;                                                                            }
Bac_ManNtkNum(Bac_Man_t * p)198 static inline int            Bac_ManNtkNum( Bac_Man_t * p )                  { return p->nNtks;                                                                            }
Bac_ManPrimNum(Bac_Man_t * p)199 static inline int            Bac_ManPrimNum( Bac_Man_t * p )                 { return Abc_NamObjNumMax(p->pMods) - Bac_ManNtkNum(p);                                       }
Bac_ManNtkIsOk(Bac_Man_t * p,int i)200 static inline int            Bac_ManNtkIsOk( Bac_Man_t * p, int i )          { return i > 0 && i <= Bac_ManNtkNum(p);                                                      }
Bac_ManNtk(Bac_Man_t * p,int i)201 static inline Bac_Ntk_t *    Bac_ManNtk( Bac_Man_t * p, int i )              { return Bac_ManNtkIsOk(p, i) ? p->pNtks + i : NULL;                                          }
Bac_ManNtkFindId(Bac_Man_t * p,char * pName)202 static inline int            Bac_ManNtkFindId( Bac_Man_t * p, char * pName ) { return Abc_NamStrFind(p->pMods, pName);                                                     }
Bac_ManNtkFind(Bac_Man_t * p,char * pName)203 static inline Bac_Ntk_t *    Bac_ManNtkFind( Bac_Man_t * p, char * pName )   { return Bac_ManNtk( p, Bac_ManNtkFindId(p, pName) );                                         }
Bac_ManRoot(Bac_Man_t * p)204 static inline Bac_Ntk_t *    Bac_ManRoot( Bac_Man_t * p )                    { return Bac_ManNtk(p, p->iRoot);                                                             }
Bac_ManStr(Bac_Man_t * p,int i)205 static inline char *         Bac_ManStr( Bac_Man_t * p, int i )              { return Abc_NamStr(p->pStrs, i);                                                             }
Bac_ManStrId(Bac_Man_t * p,char * pStr)206 static inline int            Bac_ManStrId( Bac_Man_t * p, char * pStr )      { return Abc_NamStrFind(p->pStrs, pStr);                                                      }
Bac_ManPrimName(Bac_Man_t * p,Bac_ObjType_t Type)207 static inline char *         Bac_ManPrimName( Bac_Man_t * p, Bac_ObjType_t Type ) { return p->pPrimNames[Type];                                                            }
Bac_ManPrimSymb(Bac_Man_t * p,Bac_ObjType_t Type)208 static inline char *         Bac_ManPrimSymb( Bac_Man_t * p, Bac_ObjType_t Type ) { return p->pPrimSymbs[Type];                                                            }
209 
Bac_NtkId(Bac_Ntk_t * p)210 static inline int            Bac_NtkId( Bac_Ntk_t * p )                      { int i = p - p->pDesign->pNtks; assert(Bac_ManNtkIsOk(p->pDesign, i)); return i;             }
Bac_NtkMan(Bac_Ntk_t * p)211 static inline Bac_Man_t *    Bac_NtkMan( Bac_Ntk_t * p )                     { return p->pDesign;                                                                          }
Bac_NtkNameId(Bac_Ntk_t * p)212 static inline int            Bac_NtkNameId( Bac_Ntk_t * p )                  { return p->NameId;                                                                           }
Bac_NtkName(Bac_Ntk_t * p)213 static inline char *         Bac_NtkName( Bac_Ntk_t * p )                    { return Bac_ManStr(p->pDesign, Bac_NtkNameId(p));                                            }
Bac_NtkCopy(Bac_Ntk_t * p)214 static inline int            Bac_NtkCopy( Bac_Ntk_t * p )                    { return p->iCopy;                                                                            }
Bac_NtkCopyNtk(Bac_Man_t * pNew,Bac_Ntk_t * p)215 static inline Bac_Ntk_t *    Bac_NtkCopyNtk(Bac_Man_t * pNew, Bac_Ntk_t * p) { return Bac_ManNtk(pNew, Bac_NtkCopy(p));                                                    }
Bac_NtkSetCopy(Bac_Ntk_t * p,int i)216 static inline void           Bac_NtkSetCopy( Bac_Ntk_t * p, int i )          { assert(p->iCopy == -1); p->iCopy = i;                                                       }
217 
Bac_NtkObjNum(Bac_Ntk_t * p)218 static inline int            Bac_NtkObjNum( Bac_Ntk_t * p )                  { return Vec_StrSize(&p->vType);                                                              }
Bac_NtkObjNumAlloc(Bac_Ntk_t * p)219 static inline int            Bac_NtkObjNumAlloc( Bac_Ntk_t * p )             { return Vec_StrCap(&p->vType);                                                               }
Bac_NtkPiNum(Bac_Ntk_t * p)220 static inline int            Bac_NtkPiNum( Bac_Ntk_t * p )                   { return Vec_IntSize(&p->vInputs);                                                            }
Bac_NtkPoNum(Bac_Ntk_t * p)221 static inline int            Bac_NtkPoNum( Bac_Ntk_t * p )                   { return Vec_IntSize(&p->vOutputs);                                                           }
Bac_NtkPioNum(Bac_Ntk_t * p)222 static inline int            Bac_NtkPioNum( Bac_Ntk_t * p )                  { return Bac_NtkPiNum(p) + Bac_NtkPoNum(p);                                                   }
Bac_NtkPiNumAlloc(Bac_Ntk_t * p)223 static inline int            Bac_NtkPiNumAlloc( Bac_Ntk_t * p )              { return Vec_IntCap(&p->vInputs);                                                             }
Bac_NtkPoNumAlloc(Bac_Ntk_t * p)224 static inline int            Bac_NtkPoNumAlloc( Bac_Ntk_t * p )              { return Vec_IntCap(&p->vOutputs);                                                            }
Bac_NtkBiNum(Bac_Ntk_t * p)225 static inline int            Bac_NtkBiNum( Bac_Ntk_t * p )                   { return Vec_StrCountEntryLit(&p->vType, (char)BAC_OBJ_BI);                                   }
Bac_NtkBoNum(Bac_Ntk_t * p)226 static inline int            Bac_NtkBoNum( Bac_Ntk_t * p )                   { return Vec_StrCountEntryLit(&p->vType, (char)BAC_OBJ_BO);                                   }
Bac_NtkCiNum(Bac_Ntk_t * p)227 static inline int            Bac_NtkCiNum( Bac_Ntk_t * p )                   { return Bac_NtkPiNum(p) + Bac_NtkBoNum(p);                                                   }
Bac_NtkCoNum(Bac_Ntk_t * p)228 static inline int            Bac_NtkCoNum( Bac_Ntk_t * p )                   { return Bac_NtkPoNum(p) + Bac_NtkBiNum(p);                                                   }
Bac_NtkBoxNum(Bac_Ntk_t * p)229 static inline int            Bac_NtkBoxNum( Bac_Ntk_t * p )                  { return Bac_NtkObjNum(p) - Vec_StrCountSmallerLit(&p->vType, (char)BAC_OBJ_BOX);             }
Bac_NtkPrimNum(Bac_Ntk_t * p)230 static inline int            Bac_NtkPrimNum( Bac_Ntk_t * p )                 { return Vec_StrCountLargerLit(&p->vType, (char)BAC_OBJ_BOX);                                 }
Bac_NtkUserNum(Bac_Ntk_t * p)231 static inline int            Bac_NtkUserNum( Bac_Ntk_t * p )                 { return Vec_StrCountEntryLit(&p->vType, (char)BAC_OBJ_BOX);                                  }
232 
Bac_NtkPi(Bac_Ntk_t * p,int i)233 static inline int            Bac_NtkPi( Bac_Ntk_t * p, int i )               { return Vec_IntEntry(&p->vInputs, i);                                                        }
Bac_NtkPo(Bac_Ntk_t * p,int i)234 static inline int            Bac_NtkPo( Bac_Ntk_t * p, int i )               { return Vec_IntEntry(&p->vOutputs, i);                                                       }
Bac_NtkStr(Bac_Ntk_t * p,int i)235 static inline char *         Bac_NtkStr( Bac_Ntk_t * p, int i )              { return Bac_ManStr(p->pDesign, i);                                                           }
Bac_NtkHostNtk(Bac_Ntk_t * p)236 static inline Bac_Ntk_t *    Bac_NtkHostNtk( Bac_Ntk_t * p )                 { return p->iBoxNtk > 0 ? Bac_ManNtk(p->pDesign, p->iBoxNtk) : NULL;                          }
Bac_NtkHostObj(Bac_Ntk_t * p)237 static inline int            Bac_NtkHostObj( Bac_Ntk_t * p )                 { return p->iBoxObj;                                                                          }
Bac_NtkSetHost(Bac_Ntk_t * p,int n,int i)238 static inline void           Bac_NtkSetHost( Bac_Ntk_t * p, int n, int i )   { assert(p->iBoxNtk == -1); p->iBoxNtk = n; p->iBoxObj = i;                                   }
239 
Bac_InfoRange(int Beg,int End)240 static inline int            Bac_InfoRange( int Beg, int End )               { return End > Beg ? End - Beg + 1 : Beg - End + 1;                                           }
Bac_NtkInfoNum(Bac_Ntk_t * p)241 static inline int            Bac_NtkInfoNum( Bac_Ntk_t * p )                 { return Vec_IntSize(&p->vInfo)/3;                                                            }
Bac_NtkInfoNumAlloc(Bac_Ntk_t * p)242 static inline int            Bac_NtkInfoNumAlloc( Bac_Ntk_t * p )            { return Vec_IntCap(&p->vInfo)/3;                                                             }
Bac_NtkInfoType(Bac_Ntk_t * p,int i)243 static inline int            Bac_NtkInfoType( Bac_Ntk_t * p, int i )         { return Abc_Lit2Att2(Vec_IntEntry(&p->vInfo, 3*i));                                          }
Bac_NtkInfoName(Bac_Ntk_t * p,int i)244 static inline int            Bac_NtkInfoName( Bac_Ntk_t * p, int i )         { return Abc_Lit2Var2(Vec_IntEntry(&p->vInfo, 3*i));                                          }
Bac_NtkInfoBeg(Bac_Ntk_t * p,int i)245 static inline int            Bac_NtkInfoBeg( Bac_Ntk_t * p, int i )          { return Vec_IntEntry(&p->vInfo, 3*i+1);                                                      }
Bac_NtkInfoEnd(Bac_Ntk_t * p,int i)246 static inline int            Bac_NtkInfoEnd( Bac_Ntk_t * p, int i )          { return Vec_IntEntry(&p->vInfo, 3*i+2);                                                      }
Bac_NtkInfoRange(Bac_Ntk_t * p,int i)247 static inline int            Bac_NtkInfoRange( Bac_Ntk_t * p, int i )        { int* a = Vec_IntEntryP(&p->vInfo, 3*i); return a[1]>=0 ? Bac_InfoRange( a[1], a[2] ) : 1;   }
Bac_NtkInfoIndex(Bac_Ntk_t * p,int i,int j)248 static inline int            Bac_NtkInfoIndex( Bac_Ntk_t * p, int i, int j ) { int* a = Vec_IntEntryP(&p->vInfo, 3*i); assert(a[1]>=0); return a[1]<a[2] ? a[1]+j : a[1]-j;}
Bac_NtkAddInfo(Bac_Ntk_t * p,int i,int b,int e)249 static inline void           Bac_NtkAddInfo( Bac_Ntk_t * p,int i,int b,int e){ Vec_IntPush(&p->vInfo, i); Vec_IntPushTwo(&p->vInfo, b, e);                                 }
Bac_NtkSetInfoName(Bac_Ntk_t * p,int i,int n)250 static inline void           Bac_NtkSetInfoName( Bac_Ntk_t * p, int i, int n){ Vec_IntWriteEntry( &p->vInfo, 3*i, n );                                                     }
251 
Bac_NtkStartNames(Bac_Ntk_t * p)252 static inline void           Bac_NtkStartNames( Bac_Ntk_t * p )              { assert(Bac_NtkObjNumAlloc(p)); Vec_IntFill(&p->vName,   Bac_NtkObjNumAlloc(p),  0);         }
Bac_NtkStartFanouts(Bac_Ntk_t * p)253 static inline void           Bac_NtkStartFanouts( Bac_Ntk_t * p )            { assert(Bac_NtkObjNumAlloc(p)); Vec_IntFill(&p->vFanout, Bac_NtkObjNumAlloc(p),  0);         }
Bac_NtkStartCopies(Bac_Ntk_t * p)254 static inline void           Bac_NtkStartCopies( Bac_Ntk_t * p )             { assert(Bac_NtkObjNumAlloc(p)); Vec_IntFill(&p->vCopy,   Bac_NtkObjNumAlloc(p), -1);         }
Bac_NtkFreeNames(Bac_Ntk_t * p)255 static inline void           Bac_NtkFreeNames( Bac_Ntk_t * p )               { Vec_IntErase(&p->vName);                                                                    }
Bac_NtkFreeFanouts(Bac_Ntk_t * p)256 static inline void           Bac_NtkFreeFanouts( Bac_Ntk_t * p )             { Vec_IntErase(&p->vFanout);                                                                  }
Bac_NtkFreeCopies(Bac_Ntk_t * p)257 static inline void           Bac_NtkFreeCopies( Bac_Ntk_t * p )              { Vec_IntErase(&p->vCopy);                                                                    }
Bac_NtkHasNames(Bac_Ntk_t * p)258 static inline int            Bac_NtkHasNames( Bac_Ntk_t * p )                { return p->vName.pArray != NULL;                                                             }
Bac_NtkHasFanouts(Bac_Ntk_t * p)259 static inline int            Bac_NtkHasFanouts( Bac_Ntk_t * p )              { return p->vFanout.pArray != NULL;                                                           }
Bac_NtkHasCopies(Bac_Ntk_t * p)260 static inline int            Bac_NtkHasCopies( Bac_Ntk_t * p )               { return p->vCopy.pArray != NULL;                                                             }
261 
Bac_TypeIsBox(Bac_ObjType_t Type)262 static inline int            Bac_TypeIsBox( Bac_ObjType_t Type )             { return Type >= BAC_OBJ_BOX && Type < BAC_BOX_UNKNOWN;                                       }
Bac_NameType(int n)263 static inline Bac_NameType_t Bac_NameType( int n )                           { assert( n ); return (Bac_NameType_t)Abc_Lit2Att2( n );                                      }
Bac_CharIsDigit(char c)264 static inline int            Bac_CharIsDigit( char c )                       { return c >= '0' && c <= '9'; }
265 
Bac_ObjType(Bac_Ntk_t * p,int i)266 static inline Bac_ObjType_t  Bac_ObjType( Bac_Ntk_t * p, int i )             { return (Bac_ObjType_t)Abc_Lit2Var((int)(unsigned char)Vec_StrEntry(&p->vType, i));          }
Bac_ObjIsPi(Bac_Ntk_t * p,int i)267 static inline int            Bac_ObjIsPi( Bac_Ntk_t * p, int i )             { return Bac_ObjType(p, i) == BAC_OBJ_PI;                                                     }
Bac_ObjIsPo(Bac_Ntk_t * p,int i)268 static inline int            Bac_ObjIsPo( Bac_Ntk_t * p, int i )             { return Bac_ObjType(p, i) == BAC_OBJ_PO;                                                     }
Bac_ObjIsPio(Bac_Ntk_t * p,int i)269 static inline int            Bac_ObjIsPio( Bac_Ntk_t * p, int i )            { return Bac_ObjIsPi(p, i) || Bac_ObjIsPo(p, i);                                              }
Bac_ObjIsBi(Bac_Ntk_t * p,int i)270 static inline int            Bac_ObjIsBi( Bac_Ntk_t * p, int i )             { return Bac_ObjType(p, i) == BAC_OBJ_BI;                                                     }
Bac_ObjIsBo(Bac_Ntk_t * p,int i)271 static inline int            Bac_ObjIsBo( Bac_Ntk_t * p, int i )             { return Bac_ObjType(p, i) == BAC_OBJ_BO;                                                     }
Bac_ObjIsBio(Bac_Ntk_t * p,int i)272 static inline int            Bac_ObjIsBio( Bac_Ntk_t * p, int i )            { return Bac_ObjIsBi(p, i) || Bac_ObjIsBo(p, i);                                              }
Bac_ObjIsBox(Bac_Ntk_t * p,int i)273 static inline int            Bac_ObjIsBox( Bac_Ntk_t * p, int i )            { return Bac_TypeIsBox(Bac_ObjType(p, i));                                                    }
Bac_ObjIsBoxUser(Bac_Ntk_t * p,int i)274 static inline int            Bac_ObjIsBoxUser( Bac_Ntk_t * p, int i )        { return Bac_ObjType(p, i) == BAC_OBJ_BOX;                                                    }
Bac_ObjIsBoxPrim(Bac_Ntk_t * p,int i)275 static inline int            Bac_ObjIsBoxPrim( Bac_Ntk_t * p, int i )        { return Bac_ObjIsBox(p, i) && !Bac_ObjIsBoxUser(p, i);                                       }
Bac_ObjIsGate(Bac_Ntk_t * p,int i)276 static inline int            Bac_ObjIsGate( Bac_Ntk_t * p, int i )           { return Bac_ObjType(p, i) == BAC_BOX_GATE;                                                   }
Bac_ObjIsCi(Bac_Ntk_t * p,int i)277 static inline int            Bac_ObjIsCi( Bac_Ntk_t * p, int i )             { return Bac_ObjIsPi(p, i) || Bac_ObjIsBo(p, i);                                              }
Bac_ObjIsCo(Bac_Ntk_t * p,int i)278 static inline int            Bac_ObjIsCo( Bac_Ntk_t * p, int i )             { return Bac_ObjIsPo(p, i) || Bac_ObjIsBi(p, i);                                              }
Bac_ObjIsCio(Bac_Ntk_t * p,int i)279 static inline int            Bac_ObjIsCio( Bac_Ntk_t * p, int i )            { return Bac_ObjType(p, i) < BAC_OBJ_BOX;                                                     }
Bac_ObjIsConst(Bac_Ntk_t * p,int i)280 static inline int            Bac_ObjIsConst( Bac_Ntk_t * p, int i )          { return Bac_ObjType(p, i) >= BAC_BOX_CF && Bac_ObjType(p, i) <= BAC_BOX_CZ;                  }
Bac_ObjIsConstBin(Bac_Ntk_t * p,int i)281 static inline int            Bac_ObjIsConstBin( Bac_Ntk_t * p, int i )       { return Bac_ObjType(p, i) == BAC_BOX_CF || Bac_ObjType(p, i) == BAC_BOX_CT;                  }
282 
Bac_ObjBit(Bac_Ntk_t * p,int i)283 static inline int            Bac_ObjBit( Bac_Ntk_t * p, int i )              { assert(!Bac_ObjIsBox(p, i)); return Abc_LitIsCompl((int)Vec_StrEntry(&p->vType, i));        }
Bac_ObjSetBit(Bac_Ntk_t * p,int i)284 static inline void           Bac_ObjSetBit( Bac_Ntk_t * p, int i )           { char *q = Vec_StrArray(&p->vType); assert(!Bac_ObjIsBox(p, i)); q[i] = (char)Abc_LitNot((int)q[i]); }
Bac_ObjFanin(Bac_Ntk_t * p,int i)285 static inline int            Bac_ObjFanin( Bac_Ntk_t * p, int i )            { assert(Bac_ObjIsCo(p, i)); return Vec_IntEntry(&p->vFanin, i);                              }
Bac_ObjIndex(Bac_Ntk_t * p,int i)286 static inline int            Bac_ObjIndex( Bac_Ntk_t * p, int i )            { assert(Bac_ObjIsCio(p, i)); return Vec_IntEntry(&p->vIndex, i);                             }
Bac_ObjNameInt(Bac_Ntk_t * p,int i)287 static inline int            Bac_ObjNameInt( Bac_Ntk_t * p, int i )          { assert(!Bac_ObjIsCo(p, i)); return Vec_IntEntry(&p->vName, i);                              }
Bac_ObjName(Bac_Ntk_t * p,int i)288 static inline int            Bac_ObjName( Bac_Ntk_t * p, int i )             { return Bac_ObjIsCo(p, i) ? Bac_ObjNameInt(p, Bac_ObjFanin(p,i)) : Bac_ObjNameInt(p, i);     }
Bac_ObjNameType(Bac_Ntk_t * p,int i)289 static inline Bac_NameType_t Bac_ObjNameType( Bac_Ntk_t * p, int i )         { return Bac_NameType( Bac_ObjName(p, i) );                                                   }
Bac_ObjNameId(Bac_Ntk_t * p,int i)290 static inline int            Bac_ObjNameId( Bac_Ntk_t * p, int i )           { return Abc_Lit2Var2( Bac_ObjName(p, i) );                                                   }
Bac_ObjNameStr(Bac_Ntk_t * p,int i)291 static inline char *         Bac_ObjNameStr( Bac_Ntk_t * p, int i )          { assert(Bac_ObjNameType(p, i) <= BAC_NAME_WORD); return Bac_NtkStr(p, Bac_ObjNameId(p, i));  }
Bac_ObjCopy(Bac_Ntk_t * p,int i)292 static inline int            Bac_ObjCopy( Bac_Ntk_t * p, int i )             { return Vec_IntEntry(&p->vCopy, i);                                                          }
Bac_ObjFanout(Bac_Ntk_t * p,int i)293 static inline int            Bac_ObjFanout( Bac_Ntk_t * p, int i )           { assert(Bac_ObjIsCi(p, i)); return Vec_IntEntry(&p->vFanout, i);                             }
Bac_ObjNextFanout(Bac_Ntk_t * p,int i)294 static inline int            Bac_ObjNextFanout( Bac_Ntk_t * p, int i )       { assert(Bac_ObjIsCo(p, i)); return Vec_IntEntry(&p->vFanout, i);                             }
Bac_ObjSetFanout(Bac_Ntk_t * p,int i,int x)295 static inline void           Bac_ObjSetFanout( Bac_Ntk_t * p, int i, int x ) { assert(Bac_ObjIsCi(p, i)); Vec_IntSetEntry(&p->vFanout, i, x);                              }
Bac_ObjSetNextFanout(Bac_Ntk_t * p,int i,int x)296 static inline void           Bac_ObjSetNextFanout( Bac_Ntk_t * p,int i,int x){ assert(Bac_ObjIsCo(p, i)); Vec_IntSetEntry(&p->vFanout, i, x);                              }
Bac_ObjCleanFanin(Bac_Ntk_t * p,int i)297 static inline void           Bac_ObjCleanFanin( Bac_Ntk_t * p, int i )       { assert(Bac_ObjFanin(p, i) >= 0 && Bac_ObjIsCo(p, i)); Vec_IntSetEntry( &p->vFanin, i, -1);  }
Bac_ObjSetFanin(Bac_Ntk_t * p,int i,int x)298 static inline void           Bac_ObjSetFanin( Bac_Ntk_t * p, int i, int x )  { assert(Bac_ObjFanin(p, i) == -1 && Bac_ObjIsCo(p, i)); Vec_IntSetEntry( &p->vFanin, i, x);  }
Bac_ObjSetIndex(Bac_Ntk_t * p,int i,int x)299 static inline void           Bac_ObjSetIndex( Bac_Ntk_t * p, int i, int x )  { assert(Bac_ObjIndex(p, i) == -1); Vec_IntSetEntry( &p->vIndex, i, x );                      }
Bac_ObjSetName(Bac_Ntk_t * p,int i,int x)300 static inline void           Bac_ObjSetName( Bac_Ntk_t * p, int i, int x )   { assert(Bac_ObjName(p, i) == 0 && !Bac_ObjIsCo(p, i)); Vec_IntSetEntry( &p->vName, i, x );   }
Bac_ObjSetCopy(Bac_Ntk_t * p,int i,int x)301 static inline void           Bac_ObjSetCopy( Bac_Ntk_t * p, int i, int x )   { assert(Bac_ObjCopy(p, i) == -1);  Vec_IntSetEntry( &p->vCopy,  i, x );                      }
Bac_ObjGetConst(Bac_Ntk_t * p,int i)302 static inline int            Bac_ObjGetConst( Bac_Ntk_t * p, int i )         { assert(Bac_ObjIsCi(p, i)); return Bac_ObjIsBo(p, i) && Bac_ObjIsConst(p, i-1) ? Bac_ObjType(p, i-1) : 0;              }
303 
Bac_BoxBiNum(Bac_Ntk_t * p,int i)304 static inline int            Bac_BoxBiNum( Bac_Ntk_t * p, int i )            { int s = i-1; assert(Bac_ObjIsBox(p, i)); while (--i >= 0               && Bac_ObjIsBi(p, i)) {} return s - i;  }
Bac_BoxBoNum(Bac_Ntk_t * p,int i)305 static inline int            Bac_BoxBoNum( Bac_Ntk_t * p, int i )            { int s = i+1; assert(Bac_ObjIsBox(p, i)); while (++i < Bac_NtkObjNum(p) && Bac_ObjIsBo(p, i)) {} return i - s;  }
Bac_BoxSize(Bac_Ntk_t * p,int i)306 static inline int            Bac_BoxSize( Bac_Ntk_t * p, int i )             { return 1 + Bac_BoxBiNum(p, i) + Bac_BoxBoNum(p, i);                                         }
Bac_BoxBi(Bac_Ntk_t * p,int b,int i)307 static inline int            Bac_BoxBi( Bac_Ntk_t * p, int b, int i )        { assert(Bac_ObjIsBox(p, b)); return b - 1 - i;                                               }
Bac_BoxBo(Bac_Ntk_t * p,int b,int i)308 static inline int            Bac_BoxBo( Bac_Ntk_t * p, int b, int i )        { assert(Bac_ObjIsBox(p, b)); return b + 1 + i;                                               }
309 //static inline int            Bac_BoxBiBox( Bac_Ntk_t * p, int i )            { assert(Bac_ObjIsBi(p, i)); return i + 1 + Bac_ObjIndex(p, i);                               }
Bac_BoxBoBox(Bac_Ntk_t * p,int i)310 static inline int            Bac_BoxBoBox( Bac_Ntk_t * p, int i )            { assert(Bac_ObjIsBo(p, i)); return i - 1 - Bac_ObjIndex(p, i);                               }
Bac_BoxFanin(Bac_Ntk_t * p,int b,int i)311 static inline int            Bac_BoxFanin( Bac_Ntk_t * p, int b, int i )     { return Bac_ObjFanin(p, Bac_BoxBi(p, b, i));                                                 }
Bac_BoxFaninBox(Bac_Ntk_t * p,int b,int i)312 static inline int            Bac_BoxFaninBox( Bac_Ntk_t * p, int b, int i )  { return Bac_BoxBoBox(p, Bac_BoxFanin(p, b, i));                                              }
Bac_BoxBiRange(Bac_Ntk_t * p,int i)313 static inline int            Bac_BoxBiRange( Bac_Ntk_t * p, int i )          { int s = i; assert(Bac_ObjIsBi(p, i) && !Bac_ObjBit(p, i)); while (--i >= 0               && Bac_ObjIsBi(p, i) && Bac_ObjBit(p, i)) {} return s - i;  }
Bac_BoxBoRange(Bac_Ntk_t * p,int i)314 static inline int            Bac_BoxBoRange( Bac_Ntk_t * p, int i )          { int s = i; assert(Bac_ObjIsBo(p, i) && !Bac_ObjBit(p, i)); while (++i < Bac_NtkObjNum(p) && Bac_ObjIsBo(p, i) && Bac_ObjBit(p, i)) {} return i - s;  }
Bac_ObjPiRange(Bac_Ntk_t * p,int i)315 static inline int            Bac_ObjPiRange( Bac_Ntk_t * p, int i )          { int s = i; assert(Bac_ObjIsPi(p, i) && !Bac_ObjBit(p, i)); while (++i < Bac_NtkObjNum(p) && Bac_ObjIsPi(p, i) && Bac_ObjBit(p, i)) {} return i - s;  }
316 
Bac_BoxNtkId(Bac_Ntk_t * p,int i)317 static inline int            Bac_BoxNtkId( Bac_Ntk_t * p, int i )            { assert(Bac_ObjIsBox(p, i)); return Vec_IntEntry(&p->vFanin, i);                             }
Bac_BoxSetNtkId(Bac_Ntk_t * p,int i,int x)318 static inline void           Bac_BoxSetNtkId( Bac_Ntk_t * p, int i, int x )  { assert(Bac_ObjIsBox(p, i)&&Bac_ManNtkIsOk(p->pDesign, x));Vec_IntSetEntry(&p->vFanin, i, x);}
319 //static inline int            Bac_BoxBiNtkId( Bac_Ntk_t * p, int i )          { assert(Bac_ObjIsBi(p, i)); return Bac_BoxNtkId(p, Bac_BoxBiBox(p, i));                      }
Bac_BoxBoNtkId(Bac_Ntk_t * p,int i)320 static inline int            Bac_BoxBoNtkId( Bac_Ntk_t * p, int i )          { assert(Bac_ObjIsBo(p, i)); return Bac_BoxNtkId(p, Bac_BoxBoBox(p, i));                      }
Bac_BoxNtk(Bac_Ntk_t * p,int i)321 static inline Bac_Ntk_t *    Bac_BoxNtk( Bac_Ntk_t * p, int i )              { return Bac_ManNtk( p->pDesign, Bac_BoxNtkId(p, i) );                                        }
322 //static inline Bac_Ntk_t *    Bac_BoxBiNtk( Bac_Ntk_t * p, int i )            { return Bac_ManNtk( p->pDesign, Bac_BoxBiNtkId(p, i) );                                      }
Bac_BoxBoNtk(Bac_Ntk_t * p,int i)323 static inline Bac_Ntk_t *    Bac_BoxBoNtk( Bac_Ntk_t * p, int i )            { return Bac_ManNtk( p->pDesign, Bac_BoxBoNtkId(p, i) );                                      }
Bac_BoxNtkName(Bac_Ntk_t * p,int i)324 static inline char *         Bac_BoxNtkName( Bac_Ntk_t * p, int i )          { return Abc_NamStr( p->pDesign->pMods, Bac_BoxNtkId(p, i) );                                 }
325 
326 ////////////////////////////////////////////////////////////////////////
327 ///                      MACRO DEFINITIONS                           ///
328 ////////////////////////////////////////////////////////////////////////
329 
330 ////////////////////////////////////////////////////////////////////////
331 ///                             ITERATORS                            ///
332 ////////////////////////////////////////////////////////////////////////
333 
334 #define Bac_ManForEachNtk( p, pNtk, i )                                   \
335     for ( i = 1; (i <= Bac_ManNtkNum(p)) && (((pNtk) = Bac_ManNtk(p, i)), 1); i++ )
336 
337 #define Bac_NtkForEachPi( p, iObj, i )                                    \
338     for ( i = 0; (i < Bac_NtkPiNum(p))  && (((iObj) = Bac_NtkPi(p, i)), 1); i++ )
339 #define Bac_NtkForEachPo( p, iObj, i )                                    \
340     for ( i = 0; (i < Bac_NtkPoNum(p))  && (((iObj) = Bac_NtkPo(p, i)), 1); i++ )
341 #define Bac_NtkForEachPoDriver( p, iObj, i )                              \
342     for ( i = 0; (i < Bac_NtkPoNum(p))  && (((iObj) = Bac_ObjFanin(p, Bac_NtkPo(p, i))), 1); i++ )
343 
344 #define Bac_NtkForEachPiMain( p, iObj, i )                                \
345     for ( i = 0; (i < Bac_NtkPiNum(p))  && (((iObj) = Bac_NtkPi(p, i)), 1); i++ )  if ( Bac_ObjBit(p, iObj) ) {} else
346 #define Bac_NtkForEachPoMain( p, iObj, i )                                \
347     for ( i = 0; (i < Bac_NtkPoNum(p))  && (((iObj) = Bac_NtkPo(p, i)), 1); i++ )  if ( Bac_ObjBit(p, iObj) ) {} else
348 
349 #define Bac_NtkForEachObj( p, i )  if ( !Bac_ObjType(p, i) ) {} else      \
350     for ( i = 0; (i < Bac_NtkObjNum(p)); i++ )
351 #define Bac_NtkForEachObjType( p, Type, i )                               \
352     for ( i = 0; (i < Bac_NtkObjNum(p))  && (((Type) = Bac_ObjType(p, i)), 1); i++ ) if ( !Type ) {} else
353 
354 #define Bac_NtkForEachBox( p, i )                                         \
355     for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsBox(p, i) ) {} else
356 #define Bac_NtkForEachBoxUser( p, i )                                     \
357     for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsBoxUser(p, i) ) {} else
358 #define Bac_NtkForEachBoxPrim( p, i )                                     \
359     for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsBoxPrim(p, i) ) {} else
360 
361 #define Bac_NtkForEachCi( p, i )                                          \
362     for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsCi(p, i) ) {} else
363 #define Bac_NtkForEachCo( p, i )                                          \
364     for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsCo(p, i) ) {} else
365 #define Bac_NtkForEachCio( p, i )                                         \
366     for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsCio(p, i) ){} else
367 
368 #define Bac_NtkForEachBi( p, i )                                          \
369     for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsBi(p, i) ){} else
370 #define Bac_NtkForEachBo( p, i )                                          \
371     for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsBo(p, i) ){} else
372 #define Bac_NtkForEachBio( p, i )                                         \
373     for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsBio(p, i) ){} else
374 
375 #define Bac_BoxForEachBi( p, iBox, iTerm, i )                             \
376     for ( iTerm = iBox - 1, i = 0; iTerm >= 0 && Bac_ObjIsBi(p, iTerm); iTerm--, i++ )
377 #define Bac_BoxForEachBo( p, iBox, iTerm, i )                             \
378     for ( iTerm = iBox + 1, i = 0; iTerm < Bac_NtkObjNum(p) && Bac_ObjIsBo(p, iTerm); iTerm++, i++ )
379 #define Bac_BoxForEachBiReverse( p, iBox, iTerm, i )                      \
380     for ( i = Bac_BoxBiNum(p, iBox), iTerm = iBox - i--; Bac_ObjIsBi(p, iTerm); iTerm++, i-- )
381 
382 #define Bac_BoxForEachBiMain( p, iBox, iTerm, i )                         \
383     for ( iTerm = iBox - 1, i = 0; iTerm >= 0 && Bac_ObjIsBi(p, iTerm); iTerm--, i++ )                if ( Bac_ObjBit(p, iTerm) ) {} else
384 #define Bac_BoxForEachBoMain( p, iBox, iTerm, i )                         \
385     for ( iTerm = iBox + 1, i = 0; iTerm < Bac_NtkObjNum(p) && Bac_ObjIsBo(p, iTerm); iTerm++, i++ )  if ( Bac_ObjBit(p, iTerm) ) {} else
386 
387 #define Bac_BoxForEachFanin( p, iBox, iFanin, i )                         \
388     for ( i = 0; iBox - 1 - i >= 0 && Bac_ObjIsBi(p, iBox - 1 - i) && (((iFanin) = Bac_BoxFanin(p, iBox, i)), 1); i++ )
389 #define Bac_BoxForEachFaninBox( p, iBox, iFanin, i )                      \
390     for ( i = 0; iBox - 1 - i >= 0 && Bac_ObjIsBi(p, iBox - 1 - i) && (((iFanin) = Bac_BoxFaninBox(p, iBox, i)), 1); i++ )
391 
392 #define Bac_ObjForEachFanout( p, iCi, iCo )                               \
393     for ( iCo = Bac_ObjFanout(p, iCi); iCo; iCo = Bac_ObjNextFanout(p, iCo) )
394 #define Bac_BoxForEachFanoutBox( p, iBox, iCo, iFanBox )                  \
395     for ( assert(Bac_BoxBoNum(p, iBox) == 1), iCo = Bac_ObjFanout(p, Bac_BoxBo(p, iBox, 0)); iCo && ((iFanBox = Bac_BoxBiBox(p, iCo)), 1); iCo = Bac_ObjNextFanout(p, iCo) )
396 
397 ////////////////////////////////////////////////////////////////////////
398 ///                    FUNCTION DECLARATIONS                         ///
399 ////////////////////////////////////////////////////////////////////////
400 
401 /**Function*************************************************************
402 
403   Synopsis    [Object APIs.]
404 
405   Description []
406 
407   SideEffects []
408 
409   SeeAlso     []
410 
411 ***********************************************************************/
Bac_ObjAlloc(Bac_Ntk_t * p,Bac_ObjType_t Type,int Fanin)412 static inline int Bac_ObjAlloc( Bac_Ntk_t * p, Bac_ObjType_t Type, int Fanin )
413 {
414     int iObj = Bac_NtkObjNum(p);
415     assert( iObj == Vec_IntSize(&p->vFanin) );
416     if ( Type == BAC_OBJ_PI )
417         Vec_IntPush( &p->vInputs, iObj );
418     else if ( Type == BAC_OBJ_PO )
419         Vec_IntPush( &p->vOutputs, iObj );
420     Vec_StrPush( &p->vType, (char)Abc_Var2Lit(Type, 0) );
421     Vec_IntPush( &p->vFanin, Fanin );
422     return iObj;
423 }
Bac_ObjDup(Bac_Ntk_t * pNew,Bac_Ntk_t * p,int i)424 static inline int Bac_ObjDup( Bac_Ntk_t * pNew, Bac_Ntk_t * p, int i )
425 {
426     int iObj = Bac_ObjAlloc( pNew, Bac_ObjType(p, i), Bac_ObjIsBox(p, i) ? Bac_BoxNtkId(p, i) : -1 );
427     if ( Bac_NtkHasNames(p) && Bac_NtkHasNames(pNew) && !Bac_ObjIsCo(p, i) )
428         Bac_ObjSetName( pNew, iObj, Bac_ObjName(p, i) );
429     Bac_ObjSetCopy( p, i, iObj );
430     return iObj;
431 }
Bac_BoxAlloc(Bac_Ntk_t * p,Bac_ObjType_t Type,int nIns,int nOuts,int iNtk)432 static inline int Bac_BoxAlloc( Bac_Ntk_t * p, Bac_ObjType_t Type, int nIns, int nOuts, int iNtk )
433 {
434     int i, iObj;
435     for ( i = nIns - 1; i >= 0; i-- )
436         Bac_ObjAlloc( p, BAC_OBJ_BI, -1 );
437     iObj = Bac_ObjAlloc( p, Type, iNtk );
438     for ( i = 0; i < nOuts; i++ )
439         Bac_ObjAlloc( p, BAC_OBJ_BO, -1 );
440     return iObj;
441 }
Bac_BoxDup(Bac_Ntk_t * pNew,Bac_Ntk_t * p,int iBox)442 static inline int Bac_BoxDup( Bac_Ntk_t * pNew, Bac_Ntk_t * p, int iBox )
443 {
444     int i, iTerm, iBoxNew;
445     Bac_BoxForEachBiReverse( p, iBox, iTerm, i )
446         Bac_ObjDup( pNew, p, iTerm );
447     iBoxNew = Bac_ObjDup( pNew, p, iBox );
448     if ( Bac_NtkHasNames(p) && Bac_NtkHasNames(pNew) && Bac_ObjName(p, iBox) )
449         Bac_ObjSetName( pNew, iBoxNew, Bac_ObjName(p, iBox) );
450     if ( Bac_BoxNtk(p, iBox) )
451         Bac_BoxSetNtkId( pNew, iBoxNew, Bac_NtkCopy(Bac_BoxNtk(p, iBox)) );
452     Bac_BoxForEachBo( p, iBox, iTerm, i )
453         Bac_ObjDup( pNew, p, iTerm );
454     return iBoxNew;
455 }
Bac_BoxDelete(Bac_Ntk_t * p,int iBox)456 static inline void Bac_BoxDelete( Bac_Ntk_t * p, int iBox )
457 {
458     int iStart = iBox - Bac_BoxBiNum(p, iBox);
459     int i, iStop = iBox + Bac_BoxBoNum(p, iBox);
460     for ( i = iStart; i <= iStop; i++ )
461     {
462         Vec_StrWriteEntry( &p->vType,  i, (char)0 );
463         Vec_IntWriteEntry( &p->vFanin, i, -1 );
464         if ( Bac_NtkHasNames(p) )
465             Vec_IntWriteEntry( &p->vName, i, 0 );
466         if ( Bac_NtkHasFanouts(p) )
467             Vec_IntWriteEntry( &p->vFanout, i, 0 );
468     }
469 }
Bac_BoxReplace(Bac_Ntk_t * p,int iBox,int * pArray,int nSize)470 static inline void Bac_BoxReplace( Bac_Ntk_t * p, int iBox, int * pArray, int nSize )
471 {
472     extern void Bac_NtkUpdateFanout( Bac_Ntk_t * p, int iOld, int iNew );
473     int i, Limit = Bac_BoxBoNum(p, iBox);
474     assert( Limit == nSize );
475     for ( i = 0; i < Limit; i++ )
476         Bac_NtkUpdateFanout( p, Bac_BoxBo(p, iBox, i), pArray[i] );
477 }
478 
479 
Bac_BoxCollectRanges(Bac_Ntk_t * p,int iBox)480 static inline Vec_Int_t * Bac_BoxCollectRanges( Bac_Ntk_t * p, int iBox )
481 {
482     static Vec_Int_t Bits, * vBits = &Bits;
483     static int pArray[10]; int i, iTerm;
484     assert( !Bac_ObjIsBoxUser(p, iBox) );
485     // initialize array
486     vBits->pArray = pArray;
487     vBits->nSize = 0;
488     vBits->nCap = 10;
489     // iterate through inputs
490     Bac_BoxForEachBiMain( p, iBox, iTerm, i )
491         Vec_IntPush( vBits, Bac_BoxBiRange(p, iTerm) );
492     // iterate through outputs
493     Bac_BoxForEachBoMain( p, iBox, iTerm, i )
494         Vec_IntPush( vBits, Bac_BoxBoRange(p, iTerm) );
495     assert( Vec_IntSize(vBits) < 10 );
496     //Vec_IntPrint( vBits );
497     return vBits;
498 }
499 
500 /**Function*************************************************************
501 
502   Synopsis    [Prints vector.]
503 
504   Description []
505 
506   SideEffects []
507 
508   SeeAlso     []
509 
510 ***********************************************************************/
Vec_StrPrint(Vec_Str_t * p,int fInt)511 static inline void Vec_StrPrint( Vec_Str_t * p, int fInt )
512 {
513     int i;
514     for ( i = 0; i < p->nSize; i++ )
515         if ( fInt )
516             printf( "%d ", (int)p->pArray[i] );
517         else
518             printf( "%c ", p->pArray[i] );
519     printf( "\n" );
520 }
521 
522 /**Function*************************************************************
523 
524   Synopsis    [Network APIs.]
525 
526   Description []
527 
528   SideEffects []
529 
530   SeeAlso     []
531 
532 ***********************************************************************/
Bac_NtkAlloc(Bac_Ntk_t * pNew,int NameId,int nIns,int nOuts,int nObjs)533 static inline void Bac_NtkAlloc( Bac_Ntk_t * pNew, int NameId, int nIns, int nOuts, int nObjs )
534 {
535     int NtkId, fFound;
536     assert( pNew->pDesign != NULL );
537     assert( Bac_NtkPiNum(pNew) == 0 );
538     assert( Bac_NtkPoNum(pNew) == 0 );
539     pNew->NameId  = NameId;
540     pNew->iCopy   = -1;
541     pNew->iBoxNtk = -1;
542     pNew->iBoxObj = -1;
543     Vec_IntGrow( &pNew->vInputs,  nIns );
544     Vec_IntGrow( &pNew->vOutputs, nOuts );
545     Vec_StrGrow( &pNew->vType,    nObjs );
546     Vec_IntGrow( &pNew->vFanin,   nObjs );
547     // check if the network is unique
548     NtkId = Abc_NamStrFindOrAdd( pNew->pDesign->pMods, Bac_NtkStr(pNew, NameId), &fFound );
549     if ( fFound )
550         printf( "Network with name %s already exists.\n", Bac_NtkStr(pNew, NameId) );
551     else
552         assert( NtkId == Bac_NtkId(pNew) );
553 }
Bac_NtkDup(Bac_Ntk_t * pNew,Bac_Ntk_t * p)554 static inline void Bac_NtkDup( Bac_Ntk_t * pNew, Bac_Ntk_t * p )
555 {
556     int i, iObj;
557     assert( pNew != p );
558     Bac_NtkAlloc( pNew, Bac_NtkNameId(p), Bac_NtkPiNum(p), Bac_NtkPoNum(p), Bac_NtkObjNum(p) );
559     if ( Vec_IntSize(&p->vInfo) )
560         Vec_IntAppend( &pNew->vInfo, &p->vInfo );
561     Bac_NtkStartCopies( p );
562     if ( Bac_NtkHasNames(p) )
563         Bac_NtkStartNames( pNew );
564     Bac_NtkForEachPi( p, iObj, i )
565         Bac_ObjDup( pNew, p, iObj );
566     Bac_NtkForEachBox( p, iObj )
567         Bac_BoxDup( pNew, p, iObj );
568     Bac_NtkForEachPo( p, iObj, i )
569         Bac_ObjDup( pNew, p, iObj );
570     Bac_NtkForEachCo( p, iObj )
571         Bac_ObjSetFanin( pNew, Bac_ObjCopy(p, iObj), Bac_ObjCopy(p, Bac_ObjFanin(p, iObj)) );
572     //Bac_NtkFreeCopies( p ); // needed for name transfer and host ntk
573     assert( Bac_NtkObjNum(pNew) == Bac_NtkObjNumAlloc(pNew) );
574 }
Bac_NtkDupUserBoxes(Bac_Ntk_t * pNew,Bac_Ntk_t * p)575 static inline void Bac_NtkDupUserBoxes( Bac_Ntk_t * pNew, Bac_Ntk_t * p )
576 {
577     int i, iObj;
578     assert( pNew != p );
579     Bac_NtkAlloc( pNew, Bac_NtkNameId(p), Bac_NtkPiNum(p), Bac_NtkPoNum(p), Bac_NtkObjNum(p) + 3*Bac_NtkCoNum(p) );
580     if ( Vec_IntSize(&p->vInfo) )
581         Vec_IntAppend( &pNew->vInfo, &p->vInfo );
582     Bac_NtkStartCopies( p );
583     Bac_NtkForEachPi( p, iObj, i )
584         Bac_ObjDup( pNew, p, iObj );
585     Bac_NtkForEachPo( p, iObj, i )
586         Bac_ObjDup( pNew, p, iObj );
587     Bac_NtkForEachBoxUser( p, iObj )
588         Bac_BoxDup( pNew, p, iObj );
589     // connect feed-throughs
590     Bac_NtkForEachCo( p, iObj )
591         if ( Bac_ObjCopy(p, iObj) >= 0 && Bac_ObjCopy(p, Bac_ObjFanin(p, iObj)) >= 0 )
592             Bac_ObjSetFanin( pNew, Bac_ObjCopy(p, iObj), Bac_ObjCopy(p, Bac_ObjFanin(p, iObj)) );
593 }
Bac_NtkMoveNames(Bac_Ntk_t * pNew,Bac_Ntk_t * p)594 static inline void Bac_NtkMoveNames( Bac_Ntk_t * pNew, Bac_Ntk_t * p )
595 {
596     int i, iBox, iObj;
597     assert( Bac_NtkHasNames(p) );
598     assert( !Bac_NtkHasNames(pNew) );
599     Bac_NtkStartNames( pNew );
600     Bac_NtkForEachPi( p, iObj, i )
601         Bac_ObjSetName( pNew, Bac_ObjCopy(p, iObj), Bac_ObjName(p, iObj) );
602     Bac_NtkForEachBoxUser( p, iBox )
603     {
604         Bac_ObjSetName( pNew, Bac_ObjCopy(p, iBox), Bac_ObjName(p, iBox) );
605         Bac_BoxForEachBo( p, iBox, iObj, i )
606             Bac_ObjSetName( pNew, Bac_ObjCopy(p, iObj), Bac_ObjName(p, iObj) );
607     }
608     Bac_NtkForEachBoxUser( p, iBox )
609         Bac_BoxForEachBi( p, iBox, iObj, i )
610             if ( !Bac_ObjName(pNew, Bac_ObjFanin(pNew, Bac_ObjCopy(p, iObj))) )
611                 Bac_ObjSetName( pNew, Bac_ObjFanin(pNew, Bac_ObjCopy(p, iObj)), Bac_ObjName(p, iObj) );
612     Bac_NtkForEachPo( p, iObj, i )
613         if ( !Bac_ObjName(pNew, Bac_ObjFanin(pNew, Bac_ObjCopy(p, iObj))) )
614             Bac_ObjSetName( pNew, Bac_ObjFanin(pNew, Bac_ObjCopy(p, iObj)), Bac_ObjName(p, iObj) );
615 }
616 
Bac_NtkFree(Bac_Ntk_t * p)617 static inline void Bac_NtkFree( Bac_Ntk_t * p )
618 {
619     Vec_IntErase( &p->vInputs );
620     Vec_IntErase( &p->vOutputs );
621     Vec_IntErase( &p->vInfo );
622     Vec_StrErase( &p->vType );
623     Vec_IntErase( &p->vFanin );
624     Vec_IntErase( &p->vIndex );
625     Vec_IntErase( &p->vName );
626     Vec_IntErase( &p->vFanout );
627     Vec_IntErase( &p->vCopy );
628     Vec_IntErase( &p->vArray );
629     Vec_IntErase( &p->vArray2 );
630 }
Bac_NtkMemory(Bac_Ntk_t * p)631 static inline int Bac_NtkMemory( Bac_Ntk_t * p )
632 {
633     int nMem = sizeof(Bac_Ntk_t);
634     nMem += (int)Vec_IntMemory(&p->vInputs);
635     nMem += (int)Vec_IntMemory(&p->vOutputs);
636     nMem += (int)Vec_IntMemory(&p->vInfo);
637     nMem += (int)Vec_StrMemory(&p->vType);
638     nMem += (int)Vec_IntMemory(&p->vFanin);
639     nMem += (int)Vec_IntMemory(&p->vIndex);
640     nMem += (int)Vec_IntMemory(&p->vName);
641     nMem += (int)Vec_IntMemory(&p->vFanout);
642     nMem += (int)Vec_IntMemory(&p->vCopy);
643     return nMem;
644 }
Bac_NtkPrintStats(Bac_Ntk_t * p)645 static inline void Bac_NtkPrintStats( Bac_Ntk_t * p )
646 {
647     printf( "pi =%5d  ",   Bac_NtkPiNum(p) );
648     printf( "pi =%5d  ",   Bac_NtkPoNum(p) );
649     printf( "box =%6d  ",  Bac_NtkBoxNum(p) );
650     printf( "clp =%7d  ",  p->Count );
651     printf( "obj =%7d  ",  Bac_NtkObjNum(p) );
652     printf( "%s ",         Bac_NtkName(p) );
653     if ( Bac_NtkHostNtk(p) )
654         printf( "-> %s",   Bac_NtkName(Bac_NtkHostNtk(p)) );
655     printf( "\n" );
656 }
Bac_NtkDeriveIndex(Bac_Ntk_t * p)657 static inline void Bac_NtkDeriveIndex( Bac_Ntk_t * p )
658 {
659     int i, iObj, iTerm;
660     Vec_IntFill( &p->vIndex, Bac_NtkObjNum(p), -1 );
661     Bac_NtkForEachPi( p, iObj, i )
662         Bac_ObjSetIndex( p, iObj, i );
663     Bac_NtkForEachPo( p, iObj, i )
664         Bac_ObjSetIndex( p, iObj, i );
665     Bac_NtkForEachBox( p, iObj )
666     {
667         Bac_BoxForEachBi( p, iObj, iTerm, i )
668             Bac_ObjSetIndex( p, iTerm, i );
669         Bac_BoxForEachBo( p, iObj, iTerm, i )
670             Bac_ObjSetIndex( p, iTerm, i );
671     }
672 }
Bac_NtkPrint(Bac_Ntk_t * p)673 static inline void Bac_NtkPrint( Bac_Ntk_t * p )
674 {
675     int i, Type, Value, Beg, End;
676     printf( "Interface (%d):\n", Bac_NtkInfoNum(p) );
677     Vec_IntForEachEntryTriple( &p->vInfo, Value, Beg, End, i )
678     {
679         printf( "%6d : ", i );
680         printf( "Type =%3d  ", Bac_NtkInfoType(p, i/3) );
681         if ( Beg >= 0 )
682             printf( "[%d:%d]   ", End, Beg );
683         else
684             printf( "        " );
685         printf( "Name =%3d   ", Bac_NtkInfoName(p, i/3) );
686         if ( Bac_NtkInfoName(p, i/3) )
687             printf( "%s", Bac_NtkStr( p, Bac_NtkInfoName(p, i/3) ) );
688         printf( "\n" );
689     }
690     printf( "Objects (%d):\n", Bac_NtkObjNum(p) );
691     Bac_NtkForEachObjType( p, Type, i )
692     {
693         printf( "%6d : ", i );
694         printf( "Type =%3d  ", Type );
695         if ( Bac_ObjIsCo(p, i) )
696             printf( "Fanin =%6d  ", Bac_ObjFanin(p, i) );
697         else if ( Bac_NtkHasNames(p) && Bac_ObjName(p, i) )
698         {
699             printf( "Name  =%6d(%d)  ", Bac_ObjNameId(p, i), Bac_ObjNameType(p, i) );
700             if ( Bac_ObjNameType(p, i) <= BAC_NAME_WORD )
701                 printf( "%s", Bac_ObjNameStr(p, i) );
702         }
703         printf( "\n" );
704     }
705 }
706 
707 
708 /**Function*************************************************************
709 
710   Synopsis    [Manager APIs.]
711 
712   Description []
713 
714   SideEffects []
715 
716   SeeAlso     []
717 
718 ***********************************************************************/
Bac_ManAlloc(char * pFileName,int nNtks)719 static inline Bac_Man_t * Bac_ManAlloc( char * pFileName, int nNtks )
720 {
721     extern void Bac_ManSetupTypes( char ** pNames, char ** pSymbs );
722     Bac_Ntk_t * pNtk; int i;
723     Bac_Man_t * pNew = ABC_CALLOC( Bac_Man_t, 1 );
724     pNew->pName = Extra_FileDesignName( pFileName );
725     pNew->pSpec = Abc_UtilStrsav( pFileName );
726     pNew->pStrs = Abc_NamStart( 1000, 24 );
727     pNew->pMods = Abc_NamStart( 1000, 24 );
728     pNew->iRoot = 1;
729     pNew->nNtks = nNtks;
730     pNew->pNtks = ABC_CALLOC( Bac_Ntk_t, pNew->nNtks + 1 );
731     Bac_ManForEachNtk( pNew, pNtk, i )
732         pNtk->pDesign = pNew;
733     Bac_ManSetupTypes( pNew->pPrimNames, pNew->pPrimSymbs );
734     return pNew;
735 }
Bac_ManStart(Bac_Man_t * p,int nNtks)736 static inline Bac_Man_t * Bac_ManStart( Bac_Man_t * p, int nNtks )
737 {
738     Bac_Ntk_t * pNtk; int i;
739     Bac_Man_t * pNew = ABC_CALLOC( Bac_Man_t, 1 );
740     pNew->pName = Abc_UtilStrsav( Bac_ManName(p) );
741     pNew->pSpec = Abc_UtilStrsav( Bac_ManSpec(p) );
742     pNew->pStrs = Abc_NamRef( p->pStrs );
743     pNew->pMods = Abc_NamStart( 1000, 24 );
744     pNew->iRoot = 1;
745     pNew->nNtks = nNtks;
746     pNew->pNtks = ABC_CALLOC( Bac_Ntk_t, nNtks + 1 );
747     Bac_ManForEachNtk( pNew, pNtk, i )
748         pNtk->pDesign = pNew;
749     return pNew;
750 }
Bac_ManDup(Bac_Man_t * p)751 static inline Bac_Man_t * Bac_ManDup( Bac_Man_t * p )
752 {
753     Bac_Ntk_t * pNtk, * pHost; int i;
754     Bac_Man_t * pNew = Bac_ManStart( p, Bac_ManNtkNum(p) );
755     Bac_ManForEachNtk( p, pNtk, i )
756         Bac_NtkSetCopy( pNtk, i );
757     Bac_ManForEachNtk( p, pNtk, i )
758         Bac_NtkDup( Bac_NtkCopyNtk(pNew, pNtk), pNtk );
759     Bac_ManForEachNtk( p, pNtk, i )
760         if ( (pHost = Bac_NtkHostNtk(pNtk)) )
761             Bac_NtkSetHost( Bac_NtkCopyNtk(pNew, pNtk), Bac_NtkCopy(pHost), Bac_ObjCopy(pHost, Bac_NtkHostObj(pNtk)) );
762     return pNew;
763 }
Bac_ManDupUserBoxes(Bac_Man_t * p)764 static inline Bac_Man_t * Bac_ManDupUserBoxes( Bac_Man_t * p )
765 {
766     Bac_Ntk_t * pNtk, * pHost; int i;
767     Bac_Man_t * pNew = Bac_ManStart( p, Bac_ManNtkNum(p) );
768     Bac_ManForEachNtk( p, pNtk, i )
769         Bac_NtkSetCopy( pNtk, i );
770     Bac_ManForEachNtk( p, pNtk, i )
771         Bac_NtkDupUserBoxes( Bac_NtkCopyNtk(pNew, pNtk), pNtk );
772     Bac_ManForEachNtk( p, pNtk, i )
773         if ( (pHost = Bac_NtkHostNtk(pNtk)) )
774             Bac_NtkSetHost( Bac_NtkCopyNtk(pNew, pNtk), Bac_NtkCopy(pHost), Bac_ObjCopy(pHost, Bac_NtkHostObj(pNtk)) );
775     return pNew;
776 }
Bac_ManMoveNames(Bac_Man_t * pNew,Bac_Man_t * p)777 static inline void Bac_ManMoveNames( Bac_Man_t * pNew, Bac_Man_t * p )
778 {
779     Bac_Ntk_t * pNtk; int i;
780     Bac_ManForEachNtk( p, pNtk, i )
781         Bac_NtkMoveNames( Bac_NtkCopyNtk(pNew, pNtk), pNtk );
782 }
783 
784 
Bac_ManFree(Bac_Man_t * p)785 static inline void Bac_ManFree( Bac_Man_t * p )
786 {
787     Bac_Ntk_t * pNtk; int i;
788     Bac_ManForEachNtk( p, pNtk, i )
789         Bac_NtkFree( pNtk );
790     Vec_IntErase( &p->vBuf2LeafNtk );
791     Vec_IntErase( &p->vBuf2LeafObj );
792     Vec_IntErase( &p->vBuf2RootNtk );
793     Vec_IntErase( &p->vBuf2RootObj );
794     Abc_NamDeref( p->pStrs );
795     Abc_NamDeref( p->pMods );
796     ABC_FREE( p->pName );
797     ABC_FREE( p->pSpec );
798     ABC_FREE( p->pNtks );
799     ABC_FREE( p );
800 }
Bac_ManMemory(Bac_Man_t * p)801 static inline int Bac_ManMemory( Bac_Man_t * p )
802 {
803     Bac_Ntk_t * pNtk; int i;
804     int nMem = sizeof(Bac_Man_t);
805     if ( p->pName )
806     nMem += (int)strlen(p->pName);
807     if ( p->pSpec )
808     nMem += (int)strlen(p->pSpec);
809     nMem += Abc_NamMemUsed(p->pStrs);
810     nMem += Abc_NamMemUsed(p->pMods);
811     Bac_ManForEachNtk( p, pNtk, i )
812         nMem += Bac_NtkMemory( pNtk );
813     return nMem;
814 }
Bac_ManObjNum(Bac_Man_t * p)815 static inline int Bac_ManObjNum( Bac_Man_t * p )
816 {
817     Bac_Ntk_t * pNtk; int i, Count = 0;
818     Bac_ManForEachNtk( p, pNtk, i )
819         Count += Bac_NtkObjNum(pNtk);
820     return Count;
821 }
Bac_ManNodeNum(Bac_Man_t * p)822 static inline int Bac_ManNodeNum( Bac_Man_t * p )
823 {
824     Bac_Ntk_t * pNtk; int i, Count = 0;
825     Bac_ManForEachNtk( p, pNtk, i )
826         Count += Bac_NtkBoxNum( pNtk );
827     return Count;
828 }
Bac_ManBoxNum_rec(Bac_Ntk_t * p)829 static inline int Bac_ManBoxNum_rec( Bac_Ntk_t * p )
830 {
831     int iObj, Counter = 0;
832     if ( p->Count >= 0 )
833         return p->Count;
834     Bac_NtkForEachBox( p, iObj )
835         Counter += Bac_ObjIsBoxUser(p, iObj) ? Bac_ManBoxNum_rec( Bac_BoxNtk(p, iObj) ) : 1;
836     return (p->Count = Counter);
837 }
Bac_ManBoxNum(Bac_Man_t * p)838 static inline int Bac_ManBoxNum( Bac_Man_t * p )
839 {
840     Bac_Ntk_t * pNtk; int i;
841     Bac_ManForEachNtk( p, pNtk, i )
842         pNtk->Count = -1;
843     return Bac_ManBoxNum_rec( Bac_ManRoot(p) );
844 }
Bac_ManPrintStats(Bac_Man_t * p,int nModules,int fVerbose)845 static inline void Bac_ManPrintStats( Bac_Man_t * p, int nModules, int fVerbose )
846 {
847     Bac_Ntk_t * pNtk; int i;
848     Bac_Ntk_t * pRoot = Bac_ManRoot( p );
849     printf( "%-12s : ",   Bac_ManName(p) );
850     printf( "pi =%5d  ",  Bac_NtkPiNum(pRoot) );
851     printf( "po =%5d  ",  Bac_NtkPoNum(pRoot) );
852     printf( "pri =%4d  ", Bac_ManPrimNum(p) );
853     printf( "mod =%6d  ", Bac_ManNtkNum(p) );
854     printf( "box =%7d  ", Bac_ManNodeNum(p) );
855     printf( "obj =%7d  ", Bac_ManObjNum(p) );
856     printf( "mem =%6.3f MB", 1.0*Bac_ManMemory(p)/(1<<20) );
857     printf( "\n" );
858     Bac_ManBoxNum( p );
859     Bac_ManForEachNtk( p, pNtk, i )
860     {
861         if ( i == nModules+1 )
862             break;
863         printf( "Module %5d : ", i );
864         Bac_NtkPrintStats( pNtk );
865     }
866 }
867 
868 
869 
870 /**Function*************************************************************
871 
872   Synopsis    [Other APIs.]
873 
874   Description []
875 
876   SideEffects []
877 
878   SeeAlso     []
879 
880 ***********************************************************************/
Ptr_SopToType(char * pSop)881 static inline Bac_ObjType_t Ptr_SopToType( char * pSop )
882 {
883     if ( !strcmp(pSop, " 0\n") )         return BAC_BOX_CF;
884     if ( !strcmp(pSop, " 1\n") )         return BAC_BOX_CT;
885     if ( !strcmp(pSop, "1 1\n") )        return BAC_BOX_BUF;
886     if ( !strcmp(pSop, "0 1\n") )        return BAC_BOX_INV;
887     if ( !strcmp(pSop, "11 1\n") )       return BAC_BOX_AND;
888     if ( !strcmp(pSop, "00 1\n") )       return BAC_BOX_NOR;
889     if ( !strcmp(pSop, "00 0\n") )       return BAC_BOX_OR;
890     if ( !strcmp(pSop, "-1 1\n1- 1\n") ) return BAC_BOX_OR;
891     if ( !strcmp(pSop, "1- 1\n-1 1\n") ) return BAC_BOX_OR;
892     if ( !strcmp(pSop, "01 1\n10 1\n") ) return BAC_BOX_XOR;
893     if ( !strcmp(pSop, "10 1\n01 1\n") ) return BAC_BOX_XOR;
894     if ( !strcmp(pSop, "11 1\n00 1\n") ) return BAC_BOX_XNOR;
895     if ( !strcmp(pSop, "00 1\n11 1\n") ) return BAC_BOX_XNOR;
896     if ( !strcmp(pSop, "10 1\n") )       return BAC_BOX_SHARP;
897     if ( !strcmp(pSop, "01 1\n") )       return BAC_BOX_SHARPL;
898     assert( 0 );
899     return BAC_OBJ_NONE;
900 }
Ptr_SopToTypeName(char * pSop)901 static inline char * Ptr_SopToTypeName( char * pSop )
902 {
903     if ( !strcmp(pSop, " 0\n") )         return "BAC_BOX_C0";
904     if ( !strcmp(pSop, " 1\n") )         return "BAC_BOX_C1";
905     if ( !strcmp(pSop, "1 1\n") )        return "BAC_BOX_BUF";
906     if ( !strcmp(pSop, "0 1\n") )        return "BAC_BOX_INV";
907     if ( !strcmp(pSop, "11 1\n") )       return "BAC_BOX_AND";
908     if ( !strcmp(pSop, "00 1\n") )       return "BAC_BOX_NOR";
909     if ( !strcmp(pSop, "00 0\n") )       return "BAC_BOX_OR";
910     if ( !strcmp(pSop, "-1 1\n1- 1\n") ) return "BAC_BOX_OR";
911     if ( !strcmp(pSop, "1- 1\n-1 1\n") ) return "BAC_BOX_OR";
912     if ( !strcmp(pSop, "01 1\n10 1\n") ) return "BAC_BOX_XOR";
913     if ( !strcmp(pSop, "10 1\n01 1\n") ) return "BAC_BOX_XOR";
914     if ( !strcmp(pSop, "11 1\n00 1\n") ) return "BAC_BOX_XNOR";
915     if ( !strcmp(pSop, "00 1\n11 1\n") ) return "BAC_BOX_XNOR";
916     if ( !strcmp(pSop, "10 1\n") )       return "BAC_BOX_SHARP";
917     if ( !strcmp(pSop, "01 1\n") )       return "BAC_BOX_SHARPL";
918     assert( 0 );
919     return NULL;
920 }
Ptr_TypeToName(Bac_ObjType_t Type)921 static inline char * Ptr_TypeToName( Bac_ObjType_t Type )
922 {
923     if ( Type == BAC_BOX_CF )    return "const0";
924     if ( Type == BAC_BOX_CT )    return "const1";
925     if ( Type == BAC_BOX_CX )    return "constX";
926     if ( Type == BAC_BOX_CZ )    return "constZ";
927     if ( Type == BAC_BOX_BUF )   return "buf";
928     if ( Type == BAC_BOX_INV )   return "not";
929     if ( Type == BAC_BOX_AND )   return "and";
930     if ( Type == BAC_BOX_NAND )  return "nand";
931     if ( Type == BAC_BOX_OR )    return "or";
932     if ( Type == BAC_BOX_NOR )   return "nor";
933     if ( Type == BAC_BOX_XOR )   return "xor";
934     if ( Type == BAC_BOX_XNOR )  return "xnor";
935     if ( Type == BAC_BOX_MUX )   return "mux";
936     if ( Type == BAC_BOX_MAJ )   return "maj";
937     if ( Type == BAC_BOX_SHARP ) return "sharp";
938     if ( Type == BAC_BOX_SHARPL) return "sharpl";
939     assert( 0 );
940     return "???";
941 }
Ptr_TypeToSop(Bac_ObjType_t Type)942 static inline char * Ptr_TypeToSop( Bac_ObjType_t Type )
943 {
944     if ( Type == BAC_BOX_CF )    return " 0\n";
945     if ( Type == BAC_BOX_CT )    return " 1\n";
946     if ( Type == BAC_BOX_CX )    return " 0\n";
947     if ( Type == BAC_BOX_CZ )    return " 0\n";
948     if ( Type == BAC_BOX_BUF )   return "1 1\n";
949     if ( Type == BAC_BOX_INV )   return "0 1\n";
950     if ( Type == BAC_BOX_AND )   return "11 1\n";
951     if ( Type == BAC_BOX_NAND )  return "11 0\n";
952     if ( Type == BAC_BOX_OR )    return "00 0\n";
953     if ( Type == BAC_BOX_NOR )   return "00 1\n";
954     if ( Type == BAC_BOX_XOR )   return "01 1\n10 1\n";
955     if ( Type == BAC_BOX_XNOR )  return "00 1\n11 1\n";
956     if ( Type == BAC_BOX_SHARP ) return "10 1\n";
957     if ( Type == BAC_BOX_SHARPL) return "01 1\n";
958     if ( Type == BAC_BOX_MUX )   return "11- 1\n0-1 1\n";
959     if ( Type == BAC_BOX_MAJ )   return "11- 1\n1-1 1\n-11 1\n";
960     assert( 0 );
961     return "???";
962 }
963 
964 /*=== bacCom.c ===============================================================*/
965 extern void          Abc_FrameImportPtr( Vec_Ptr_t * vPtr );
966 extern Vec_Ptr_t *   Abc_FrameExportPtr();
967 
968 /*=== bacBlast.c =============================================================*/
969 extern int           Bac_NtkBuildLibrary( Bac_Man_t * p );
970 extern Gia_Man_t *   Bac_ManExtract( Bac_Man_t * p, int fBuffers, int fVerbose );
971 extern Bac_Man_t *   Bac_ManInsertGia( Bac_Man_t * p, Gia_Man_t * pGia );
972 extern void *        Bac_ManInsertAbc( Bac_Man_t * p, void * pAbc );
973 /*=== bacCba.c ===============================================================*/
974 extern Bac_Man_t *   Bac_ManReadBac( char * pFileName );
975 extern void          Bac_ManWriteBac( char * pFileName, Bac_Man_t * p );
976 /*=== bacNtk.c ===============================================================*/
977 extern char *        Bac_NtkGenerateName( Bac_Ntk_t * p, Bac_ObjType_t Type, Vec_Int_t * vBits );
978 extern Bac_ObjType_t Bac_NameToType( char * pName );
979 extern Vec_Int_t *   Bac_NameToRanges( char * pName );
980 extern void          Bac_NtkUpdateFanout( Bac_Ntk_t * p, int iOld, int iNew );
981 extern void          Bac_ManDeriveFanout( Bac_Man_t * p );
982 //extern void          Bac_ManAssignInternNames( Bac_Man_t * p );
983 extern void          Bac_ManAssignInternWordNames( Bac_Man_t * p );
984 extern Bac_Man_t *   Bac_ManCollapse( Bac_Man_t * p );
985 extern void          Bac_ManSetupTypes( char ** pNames, char ** pSymbs );
986 /*=== bacPtr.c ===============================================================*/
987 extern void          Bac_PtrFree( Vec_Ptr_t * vDes );
988 extern int           Bac_PtrMemory( Vec_Ptr_t * vDes );
989 extern void          Bac_PtrDumpBlif( char * pFileName, Vec_Ptr_t * vDes );
990 extern void          Bac_PtrDumpVerilog( char * pFileName, Vec_Ptr_t * vDes );
991 extern Vec_Ptr_t *   Bac_PtrTransformTest( Vec_Ptr_t * vDes );
992 /*=== bacPtrAbc.c ============================================================*/
993 extern Bac_Man_t *   Bac_PtrTransformToCba( Vec_Ptr_t * vDes );
994 extern Vec_Ptr_t *   Bac_PtrDeriveFromCba( Bac_Man_t * p );
995 /*=== bacPrsBuild.c ==========================================================*/
996 extern Bac_Man_t *   Psr_ManBuildCba( char * pFileName, Vec_Ptr_t * vDes );
997 /*=== bacReadBlif.c ==========================================================*/
998 extern Vec_Ptr_t *   Psr_ManReadBlif( char * pFileName );
999 /*=== bacReadSmt.c ===========================================================*/
1000 extern Vec_Ptr_t *   Psr_ManReadSmt( char * pFileName );
1001 /*=== bacReadVer.c ===========================================================*/
1002 extern Vec_Ptr_t *   Psr_ManReadVerilog( char * pFileName );
1003 /*=== bacWriteBlif.c =========================================================*/
1004 extern void          Psr_ManWriteBlif( char * pFileName, Vec_Ptr_t * p );
1005 extern void          Bac_ManWriteBlif( char * pFileName, Bac_Man_t * p );
1006 /*=== bacWriteVer.c ==========================================================*/
1007 extern void          Psr_ManWriteVerilog( char * pFileName, Vec_Ptr_t * p );
1008 extern void          Bac_ManWriteVerilog( char * pFileName, Bac_Man_t * p, int fUseAssign );
1009 
1010 ABC_NAMESPACE_HEADER_END
1011 
1012 #endif
1013 
1014 ////////////////////////////////////////////////////////////////////////
1015 ///                       END OF FILE                                ///
1016 ////////////////////////////////////////////////////////////////////////
1017 
1018