1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
|
/**CFile****************************************************************
FileName [cba.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Verilog parser.]
Synopsis [External declarations.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - November 29, 2014.]
Revision [$Id: cba.h,v 1.00 2014/11/29 00:00:00 alanmi Exp $]
***********************************************************************/
#ifndef ABC__base__cba__cba_h
#define ABC__base__cba__cba_h
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include "aig/gia/gia.h"
#include "misc/extra/extra.h"
#include "misc/util/utilNam.h"
#include "misc/extra/extra.h"
#include "misc/util/utilTruth.h"
#include "misc/vec/vecSet.h"
////////////////////////////////////////////////////////////////////////
/// PARAMETERS ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_HEADER_START
////////////////////////////////////////////////////////////////////////
/// BASIC TYPES ///
////////////////////////////////////////////////////////////////////////
// network objects
typedef enum {
CBA_OBJ_NONE = 0, // 0: unused
CBA_OBJ_BI, // 1: box input
CBA_OBJ_BO, // 2: box output
CBA_OBJ_PI, // 3: input
CBA_OBJ_PO, // 4: output
CBA_OBJ_NODE, // 5: node
CBA_OBJ_BOX, // 6: box
CBA_OBJ_LATCH, // 7: latch
CBA_OBJ_CONCAT, // 8: concatenation
CBA_OBJ_UNKNOWN // 9: unknown
} Cba_ObjType_t;
// Verilog predefined models
typedef enum {
CBA_NODE_NONE = 0, // 0: unused
CBA_NODE_C0, // 1: constant 0
CBA_NODE_C1, // 2: constant 1
CBA_NODE_CX, // 2: constant X
CBA_NODE_CZ, // 2: constant Z
CBA_NODE_BUF, // 3: buffer
CBA_NODE_INV, // 4: inverter
CBA_NODE_AND, // 5: AND
CBA_NODE_NAND, // 6: NAND
CBA_NODE_OR, // 7: OR
CBA_NODE_NOR, // 8: NOR
CBA_NODE_XOR, // 9: XOR
CBA_NODE_XNOR, // 10 XNOR
CBA_NODE_SHARP, // 11: SHARP
CBA_NODE_MUX, // 12: MUX
CBA_NODE_MAJ, // 13: MAJ
CBA_NODE_LUT, // 14: LUT
CBA_NODE_RAND,
CBA_NODE_RNAND,
CBA_NODE_ROR,
CBA_NODE_RNOR,
CBA_NODE_RXOR,
CBA_NODE_RXNOR,
CBA_NODE_SEL,
CBA_NODE_PSEL,
CBA_NODE_ENC,
CBA_NODE_PENC,
CBA_NODE_DEC,
CBA_NODE_ADD,
CBA_NODE_SUB,
CBA_NODE_MUL,
CBA_NODE_DIV,
CBA_NODE_MOD,
CBA_NODE_REM,
CBA_NODE_POW,
CBA_NODE_ABS,
CBA_NODE_LTHEN,
CBA_NODE_MTHEN,
CBA_NODE_EQU,
CBA_NODE_NEQU,
CBA_NODE_SHIL,
CBA_NODE_SHIR,
CBA_NODE_ROTL,
CBA_NODE_ROTR,
CBA_NODE_TRI,
CBA_NODE_RAM,
CBA_NODE_RAMR,
CBA_NODE_RAMW,
CBA_NODE_RAMWC,
CBA_NODE_LATCH,
CBA_NODE_LATCHRS,
CBA_NODE_DFF,
CBA_NODE_DFFRS,
CBA_NODE_UNKNOWN // 50
} Cba_NodeType_t;
// design
typedef struct Cba_Man_t_ Cba_Man_t;
struct Cba_Man_t_
{
// design names
char * pName; // design name
char * pSpec; // spec file name
Abc_Nam_t * pNames; // name manager
Abc_Nam_t * pModels; // model name manager
Abc_Nam_t * pFuncs; // functionality manager
Cba_Man_t * pLib; // library
// internal data
Vec_Set_t Mem; // memory
Vec_Ptr_t vNtks; // networks
int iRoot; // root network
Vec_Int_t vCopies; // copies
Vec_Int_t * vBuf2RootNtk;
Vec_Int_t * vBuf2RootObj;
Vec_Int_t * vBuf2LeafNtk;
Vec_Int_t * vBuf2LeafObj;
void * pMioLib;
void ** ppGraphs;
};
// network
typedef struct Cba_Ntk_t_ Cba_Ntk_t;
struct Cba_Ntk_t_
{
Cba_Man_t * pDesign; // design
int Id; // network ID
int iBoxNtk; // instance network ID
int iBoxObj; // instance object ID
int nObjs; // object counter
int iObjStart;// first object in global order
// interface
Vec_Int_t vInouts; // inouts (used by parser to store signals as NameId)
Vec_Int_t vInputs; // inputs (used by parser to store signals as NameId)
Vec_Int_t vOutputs; // outputs (used by parser to store signals as NameId)
Vec_Int_t vWires; // wires (used by parser to store signals as NameId)
// objects
Vec_Int_t vTypes; // types (used by parser to store Cba_PrsType_t)
Vec_Int_t vFuncs; // functions (used by parser to store function) (node: function; box: model; CI/CO: index)
Vec_Int_t vFanins; // fanins (used by parser to store fanin/fanout/range as NameId) (node: handle; CO/BI fanin0)
// attributes
Vec_Int_t vInstIds; // instance names (used by parser to store instance name as NameId)
Vec_Int_t vNameIds; // original names as NameId
};
static inline char * Cba_ManName( Cba_Man_t * p ) { return p->pName; }
static inline char * Cba_ManSpec( Cba_Man_t * p ) { return p->pSpec; }
static inline int Cba_ManNtkNum( Cba_Man_t * p ) { return Vec_PtrSize(&p->vNtks) - 1; }
static inline int Cba_ManNtkId( Cba_Man_t * p, char * pName ) { return Abc_NamStrFind(p->pModels, pName); }
static inline Cba_Ntk_t * Cba_ManNtk( Cba_Man_t * p, int i ) { assert( i > 0 ); return (Cba_Ntk_t *)Vec_PtrEntry(&p->vNtks, i); }
static inline Cba_Ntk_t * Cba_ManNtkFind( Cba_Man_t * p, char * pName ) { return Cba_ManNtk( p, Cba_ManNtkId(p, pName) ); }
static inline Cba_Ntk_t * Cba_ManRoot( Cba_Man_t * p ) { return Cba_ManNtk(p, p->iRoot); }
static inline Vec_Set_t * Cba_ManMem( Cba_Man_t * p ) { return &p->Mem; }
static inline int Cba_ManMemSave( Cba_Man_t * p, int * d, int s ) { return Vec_SetAppend(Cba_ManMem(p), d, s); }
static inline int * Cba_ManMemRead( Cba_Man_t * p, int h ) { return h ? (int *)Vec_SetEntry(Cba_ManMem(p), h) : NULL; }
static inline Cba_Man_t * Cba_NtkMan( Cba_Ntk_t * p ) { return p->pDesign; }
static inline int Cba_NtkId( Cba_Ntk_t * p ) { return p->Id; }
static inline char * Cba_NtkName( Cba_Ntk_t * p ) { return Abc_NamStr(Cba_NtkMan(p)->pModels, Cba_NtkId(p)); }
static inline int Cba_NtkObjNum( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vFanins); }
static inline int Cba_NtkPioNum( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vInouts); }
static inline int Cba_NtkPiNum( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vInputs); }
static inline int Cba_NtkPoNum( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vOutputs); }
static inline int Cba_NtkNodeNum( Cba_Ntk_t * p ) { return Vec_IntCountEntry(&p->vTypes, CBA_OBJ_NODE); }
static inline int Cba_NtkBoxNum( Cba_Ntk_t * p ) { return Vec_IntCountEntry(&p->vTypes, CBA_OBJ_BOX); }
static inline int Cba_NtkPio( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vInouts, i); }
static inline int Cba_NtkPi( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vInputs, i); }
static inline int Cba_NtkPo( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vOutputs, i); }
static inline char * Cba_NtkStr( Cba_Ntk_t * p, int i ) { return Abc_NamStr(p->pDesign->pNames, i); }
static inline char * Cba_NtkModelStr( Cba_Ntk_t * p, int i ) { return Abc_NamStr(p->pDesign->pModels, i); }
static inline char * Cba_NtkFuncStr( Cba_Ntk_t * p, int i ) { return Abc_NamStr(p->pDesign->pFuncs, i); }
static inline Vec_Set_t * Cba_NtkMem( Cba_Ntk_t * p ) { return Cba_ManMem(p->pDesign); }
static inline int Cba_NtkMemSave( Cba_Ntk_t * p, int * d, int s ) { return Cba_ManMemSave(p->pDesign, d, s); }
static inline int * Cba_NtkMemRead( Cba_Ntk_t * p, int h ) { return Cba_ManMemRead(p->pDesign, h); }
static inline Cba_Ntk_t * Cba_NtkHostNtk( Cba_Ntk_t * p ) { return Cba_ManNtk(p->pDesign, p->iBoxNtk); }
static inline int Cba_NtkHostObj( Cba_Ntk_t * p ) { return p->iBoxObj; }
static inline void Cba_NtkSetHost( Cba_Ntk_t * p, int n, int i ) { p->iBoxNtk = n; p->iBoxObj = i; }
static inline Vec_Int_t * Cba_NtkCopies( Cba_Ntk_t * p ) { return &p->pDesign->vCopies; }
static inline int Cba_NtkCopy( Cba_Ntk_t * p, int i ) { return Vec_IntEntry( Cba_NtkCopies(p), p->iObjStart + i ); }
static inline void Cba_NtkSetCopy( Cba_Ntk_t * p, int i, int x ) { Vec_IntWriteEntry( Cba_NtkCopies(p), p->iObjStart + i, x ); }
static inline Cba_ObjType_t Cba_ObjType( Cba_Ntk_t * p, int i ) { return (Cba_ObjType_t)Vec_IntEntry(&p->vTypes, i); }
static inline int Cba_ObjFuncId( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vFuncs, i); }
static inline int Cba_ObjFaninId( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vFanins, i); }
static inline int Cba_ObjInstId( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vInstIds, i); }
static inline int Cba_ObjNameId( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vNameIds, i); }
static inline int Cba_ObjIsPi( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_OBJ_PI; }
static inline int Cba_ObjIsPo( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_OBJ_PO; }
static inline int Cba_ObjIsBi( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_OBJ_BI; }
static inline int Cba_ObjIsBo( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_OBJ_BO; }
static inline int Cba_ObjIsNode( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_OBJ_NODE; }
static inline int Cba_ObjIsBox( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_OBJ_BOX; }
static inline int Cba_ObjIsConcat( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_OBJ_CONCAT; }
static inline int Cba_ObjIsCi( Cba_Ntk_t * p, int i ) { return Cba_ObjIsPi(p, i) || Cba_ObjIsBo(p, i); }
static inline int Cba_ObjIsCo( Cba_Ntk_t * p, int i ) { return Cba_ObjIsPo(p, i) || Cba_ObjIsBi(p, i); }
static inline int Cba_ObjIsCio( Cba_Ntk_t * p, int i ) { return Cba_ObjIsCi(p, i) || Cba_ObjIsCo(p, i); }
static inline int Cba_ObjIsBio( Cba_Ntk_t * p, int i ) { return Cba_ObjIsBi(p, i) || Cba_ObjIsBo(p, i); }
static inline int Cba_ObjFanin0( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsPo(p, i) || Cba_ObjIsBio(p, i)); return Cba_ObjFaninId(p, i); }
static inline int * Cba_ObjFaninArray( Cba_Ntk_t * p, int i ) { assert(Cba_ObjType(p, i) >= CBA_OBJ_NODE); return Cba_NtkMemRead(p, Cba_ObjFaninId(p, i)); }
static inline int Cba_ObjFaninNum( Cba_Ntk_t * p, int i ) { return *Cba_ObjFaninArray(p, i); }
static inline int * Cba_ObjFanins( Cba_Ntk_t * p, int i ) { return Cba_ObjFaninArray(p, i) + 1; }
static inline Vec_Int_t * Cba_ObjFaninVec( Cba_Ntk_t * p, int i ) { static Vec_Int_t V; V.pArray = Cba_ObjFaninArray(p, i); V.nSize = V.nCap = V.pArray ? *V.pArray++ : 0; return &V; }
static inline Vec_Int_t * Cba_ObjFaninVec2( Cba_Ntk_t * p, int i ) { static Vec_Int_t W; W.pArray = Cba_ObjFaninArray(p, i); W.nSize = W.nCap = W.pArray ? *W.pArray++ : 0; return &W; }
static inline Cba_NodeType_t Cba_ObjNodeType( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsNode(p, i)); return (Cba_NodeType_t)Cba_ObjFuncId(p, i); }
static inline int Cba_ObjBoxModelId( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsBox(p, i)); return Cba_ObjFuncId(p, i); }
static inline Cba_Ntk_t * Cba_ObjBoxModel( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsBox(p, i)); return Cba_ManNtk(p->pDesign, Cba_ObjBoxModelId(p, i)); }
static inline int Cba_ObjBoxSize( Cba_Ntk_t * p, int i ) { return 1 + Cba_NtkPiNum(Cba_ObjBoxModel(p, i)) + Cba_NtkPoNum(Cba_ObjBoxModel(p, i)); }
static inline int Cba_ObjBoxBiNum( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsBox(p, i)); return Cba_NtkPiNum(Cba_ObjBoxModel(p, i)); }
static inline int Cba_ObjBoxBoNum( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsBox(p, i)); return Cba_NtkPoNum(Cba_ObjBoxModel(p, i)); }
static inline int Cba_ObjBoxBi( Cba_Ntk_t * p, int b, int i ) { assert(Cba_ObjIsBox(p, b)); return b - Cba_ObjBoxBiNum(p, b) + i; }
static inline int Cba_ObjBoxBo( Cba_Ntk_t * p, int b, int i ) { assert(Cba_ObjIsBox(p, b)); return b + 1 + i; }
static inline int Cba_ObjBiModelId( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsBi(p, i)); while (!Cba_ObjIsBox(p, i)) i++; return Cba_ObjBoxModelId(p, i); }
static inline int Cba_ObjBoModelId( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsBo(p, i)); return Cba_ObjBoxModelId(p, Cba_ObjFanin0(p, i)); }
static inline Cba_Ntk_t * Cba_ObjBiModel( Cba_Ntk_t * p, int i ) { return Cba_ManNtk( p->pDesign, Cba_ObjBiModelId(p, i) ); }
static inline Cba_Ntk_t * Cba_ObjBoModel( Cba_Ntk_t * p, int i ) { return Cba_ManNtk( p->pDesign, Cba_ObjBoModelId(p, i) ); }
static inline int Cba_ObjCioIndex( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsCio(p, i) || Cba_ObjIsBio(p, i)); return Cba_ObjFuncId(p, i); }
static inline char * Cba_ObjFuncStr( Cba_Ntk_t * p, int i ) { return Cba_NtkStr(p, Cba_ObjFuncId(p, i)); }
static inline char * Cba_ObjInstStr( Cba_Ntk_t * p, int i ) { return Cba_NtkStr(p, Cba_ObjInstId(p, i)); }
static inline char * Cba_ObjNameStr( Cba_Ntk_t * p, int i ) { return Cba_NtkStr(p, Cba_ObjNameId(p, i)); }
////////////////////////////////////////////////////////////////////////
/// MACRO DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// ITERATORS ///
////////////////////////////////////////////////////////////////////////
#define Cba_ManForEachNtk( p, pNtk, i ) \
for ( i = 1; (i <= Cba_ManNtkNum(p)) && (((pNtk) = Cba_ManNtk(p, i)), 1); i++ )
#define Cba_NtkForEachPi( p, iObj, i ) \
for ( i = 0; (i < Cba_NtkPiNum(p)) && (((iObj) = Vec_IntEntry(&p->vInputs, i)), 1); i++ )
#define Cba_NtkForEachPo( p, iObj, i ) \
for ( i = 0; (i < Cba_NtkPoNum(p)) && (((iObj) = Vec_IntEntry(&p->vOutputs, i)), 1); i++ )
#define Cba_NtkForEachObjType( p, Type, i ) \
for ( i = 0; (i < Cba_NtkObjNum(p)) && (((Type) = Cba_ObjType(p, i)), 1); i++ )
#define Cba_NtkForEachBox( p, i ) \
for ( i = 0; (i < Cba_NtkObjNum(p)); i++ ) if ( Cba_ObjType(p, i) != CBA_OBJ_BOX ) {} else
#define Cba_NtkForEachNode( p, i ) \
for ( i = 0; (i < Cba_NtkObjNum(p)); i++ ) if ( Cba_ObjType(p, i) != CBA_OBJ_NODE ) {} else
#define Cba_NtkForEachCi( p, i ) \
for ( i = 0; (i < Cba_NtkObjNum(p)); i++ ) if ( Cba_ObjType(p, i) != CBA_OBJ_PI && Cba_ObjType(p, i) != CBA_OBJ_BO ) {} else
#define Cba_NtkForEachCo( p, i ) \
for ( i = 0; (i < Cba_NtkObjNum(p)); i++ ) if ( Cba_ObjType(p, i) != CBA_OBJ_PO && Cba_ObjType(p, i) != CBA_OBJ_BI ) {} else
#define Cba_BoxForEachBi( p, iBox, iTerm, i ) \
for ( iTerm = iBox - Cba_ObjBoxBiNum(p, iBox), i = 0; iTerm < iBox; iTerm++, i++ )
#define Cba_BoxForEachBo( p, iBox, iTerm, i ) \
for ( iTerm = iBox + 1, i = 0; iTerm < iBox + 1 + Cba_ObjBoxBoNum(p, iBox); iTerm++, i++ )
////////////////////////////////////////////////////////////////////////
/// FUNCTION DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
// copy contents to the vector
static inline int Cba_ManHandleArray( Cba_Man_t * p, Vec_Int_t * vFrom )
{
int h = Vec_SetFetchH( Cba_ManMem(p), sizeof(int) * (Vec_IntSize(vFrom) + 1) );
int * pArray = (int *)Vec_SetEntry( Cba_ManMem(p), h );
pArray[0] = Vec_IntSize(vFrom);
memcpy( pArray+1, Vec_IntArray(vFrom), sizeof(int) * Vec_IntSize(vFrom) );
Vec_IntClear( vFrom );
return h;
}
static inline int Cba_ManHandleBuffer( Cba_Man_t * p, int iFanin )
{
int h = Vec_SetFetchH( Cba_ManMem(p), sizeof(int) * 2 );
int * pArray = (int *)Vec_SetEntry( Cba_ManMem(p), h );
pArray[0] = (iFanin >= 0) ? 1 : 0;
pArray[1] = iFanin;
return h;
}
static inline void Cba_ManAllocArray( Cba_Man_t * p, Vec_Int_t * vTo, int nSize )
{
if ( nSize == 0 )
return;
vTo->nSize = 0;
vTo->nCap = nSize;
vTo->pArray = (int *)Vec_SetFetch( Cba_ManMem(p), sizeof(int) * nSize );
}
static inline void Cba_ManFetchArray( Cba_Man_t * p, Vec_Int_t * vTo, int nSize )
{
if ( nSize == 0 )
return;
vTo->nSize = vTo->nCap = nSize;
vTo->pArray = (int *)Vec_SetFetch( Cba_ManMem(p), sizeof(int) * nSize );
memset( Vec_IntArray(vTo), 0xff, sizeof(int) * nSize );
}
static inline void Cba_ManSetupArray( Cba_Man_t * p, Vec_Int_t * vTo, Vec_Int_t * vFrom )
{
if ( Vec_IntSize(vFrom) == 0 )
return;
vTo->nSize = vTo->nCap = Vec_IntSize(vFrom);
vTo->pArray = (int *)Vec_SetFetch( Cba_ManMem(p), sizeof(int) * Vec_IntSize(vFrom) );
memcpy( Vec_IntArray(vTo), Vec_IntArray(vFrom), sizeof(int) * Vec_IntSize(vFrom) );
Vec_IntClear( vFrom );
}
// constructors desctructors
static inline int Cba_ObjAdd( Cba_Ntk_t * p, int i, Cba_ObjType_t Type, int Func, int Fanin, int NameId )
{
if ( Type == CBA_OBJ_PI )
Vec_IntWriteEntry( &p->vInputs, Func, i );
if ( Type == CBA_OBJ_PO )
Vec_IntWriteEntry( &p->vOutputs, Func, i );
if ( Type >= 0 )
Vec_IntWriteEntry( &p->vTypes, i, Type );
if ( Func >= 0 )
Vec_IntWriteEntry( &p->vFuncs, i, Func );
if ( Fanin >= 0 )
Vec_IntWriteEntry( &p->vFanins, i, Fanin );
if ( NameId >= 0 )
Vec_IntWriteEntry( &p->vNameIds, i, NameId );
return i;
}
static inline int Cba_BoxAdd( Cba_Ntk_t * p, Cba_Ntk_t * pBox, int NameId )
{
int i, ObjId;
for ( i = 0; i < Cba_NtkPiNum(pBox); i++ )
Cba_ObjAdd( p, p->nObjs++, CBA_OBJ_BI, i, -1, -1 );
ObjId = Cba_ObjAdd( p, p->nObjs++, CBA_OBJ_BOX, Cba_NtkId(pBox), -1, NameId );
for ( i = 0; i < Cba_NtkPoNum(pBox); i++ )
Cba_ObjAdd( p, p->nObjs++, CBA_OBJ_BO, i, ObjId, -1 );
Cba_NtkSetHost( pBox, Cba_NtkId(p), ObjId );
return ObjId;
}
static inline Cba_Ntk_t * Cba_NtkAlloc( Cba_Man_t * p, char * pName )
{
int iModelId = Abc_NamStrFindOrAdd( p->pModels, pName, NULL );
Cba_Ntk_t * pNtk = (Cba_Ntk_t *)Vec_SetFetch( Cba_ManMem(p), sizeof(Cba_Ntk_t) );
memset( pNtk, 0, sizeof(Cba_Ntk_t) );
pNtk->pDesign = p;
pNtk->Id = Vec_PtrSize(&p->vNtks);
Vec_PtrPush( &p->vNtks, pNtk );
assert( iModelId <= pNtk->Id );
if ( iModelId < pNtk->Id )
printf( "Model with name %s already exists.\n", pName );
return pNtk;
}
static inline void Cba_NtkResize( Cba_Ntk_t * p, int nObjs )
{
assert( Vec_IntSize(&p->vTypes) == 0 );
Cba_ManFetchArray( p->pDesign, &p->vTypes, nObjs );
Cba_ManFetchArray( p->pDesign, &p->vFuncs, nObjs );
Cba_ManFetchArray( p->pDesign, &p->vFanins, nObjs );
Cba_ManFetchArray( p->pDesign, &p->vNameIds, nObjs );
}
static inline Cba_Man_t * Cba_ManAlloc( Cba_Man_t * pOld, char * pFileName )
{
Cba_Man_t * p = ABC_CALLOC( Cba_Man_t, 1 );
p->pName = pOld ? Abc_UtilStrsav( Cba_ManName(pOld) ) : Extra_FileDesignName( pFileName );
p->pSpec = pOld ? Abc_UtilStrsav( Cba_ManSpec(pOld) ) : Abc_UtilStrsav( pFileName );
p->pNames = pOld ? Abc_NamRef( pOld->pNames ) : Abc_NamStart( 1000, 24 );
p->pModels = pOld ? Abc_NamRef( pOld->pModels ) : Abc_NamStart( 1000, 24 );
p->pFuncs = pOld ? Abc_NamRef( pOld->pFuncs ) : Abc_NamStart( 1000, 24 );
p->iRoot = 1;
Vec_SetAlloc_( &p->Mem, 18 );
Vec_PtrPush( &p->vNtks, NULL );
return p;
}
static inline Cba_Man_t * Cba_ManClone( Cba_Man_t * pOld )
{
Cba_Ntk_t * pNtk, * pNtkNew; int i;
Cba_Man_t * p = Cba_ManAlloc( pOld, NULL );
Cba_ManForEachNtk( pOld, pNtk, i )
{
pNtkNew = Cba_NtkAlloc( p, Cba_NtkName(pNtk) );
Cba_ManFetchArray( p, &pNtkNew->vInputs, Cba_NtkPiNum(pNtk) );
Cba_ManFetchArray( p, &pNtkNew->vOutputs, Cba_NtkPoNum(pNtk) );
}
assert( Cba_ManNtkNum(p) == Cba_ManNtkNum(pOld) );
return p;
}
static inline void Cba_ManFree( Cba_Man_t * p )
{
Vec_IntFreeP( &p->vBuf2LeafNtk );
Vec_IntFreeP( &p->vBuf2LeafObj );
Vec_IntFreeP( &p->vBuf2RootNtk );
Vec_IntFreeP( &p->vBuf2RootObj );
ABC_FREE( p->vCopies.pArray );
ABC_FREE( p->vNtks.pArray );
Vec_SetFree_( &p->Mem );
Abc_NamDeref( p->pNames );
Abc_NamDeref( p->pModels );
Abc_NamDeref( p->pFuncs );
ABC_FREE( p->pName );
ABC_FREE( p->pSpec );
ABC_FREE( p );
}
static inline int Cba_ManMemory( Cba_Man_t * p )
{
int nMem = sizeof(Cba_Man_t);
nMem += Abc_NamMemUsed(p->pNames);
nMem += Abc_NamMemUsed(p->pModels);
nMem += Abc_NamMemUsed(p->pFuncs);
nMem += Vec_SetMemoryAll(&p->Mem);
nMem += (int)Vec_PtrMemory(&p->vNtks);
return nMem;
}
static inline void Cba_NtkPrintStats( Cba_Ntk_t * p )
{
printf( "%-32s ", Cba_NtkName(p) );
printf( "pi =%5d ", Cba_NtkPiNum(p) );
printf( "pi =%5d ", Cba_NtkPoNum(p) );
printf( "box =%6d ", Cba_NtkBoxNum(p) );
printf( "node =%6d ", Cba_NtkNodeNum(p) );
printf( "obj =%6d ", Cba_NtkObjNum(p) );
printf( "\n" );
}
static inline void Cba_ManPrintStats( Cba_Man_t * p, int fVerbose )
{
Cba_Ntk_t * pNtk; int i;
Cba_ManForEachNtk( p, pNtk, i )
{
printf( "Module %4d : ", i );
Cba_NtkPrintStats( pNtk );
}
}
static inline Cba_NodeType_t Ptr_SopToType( char * pSop )
{
if ( !strcmp(pSop, " 1\n") ) return CBA_NODE_C0;
if ( !strcmp(pSop, " 0\n") ) return CBA_NODE_C1;
if ( !strcmp(pSop, "1 1\n") ) return CBA_NODE_BUF;
if ( !strcmp(pSop, "0 1\n") ) return CBA_NODE_INV;
if ( !strcmp(pSop, "11 1\n") ) return CBA_NODE_AND;
if ( !strcmp(pSop, "00 1\n") ) return CBA_NODE_NOR;
if ( !strcmp(pSop, "00 0\n") ) return CBA_NODE_OR;
if ( !strcmp(pSop, "-1 1\n1- 1\n") ) return CBA_NODE_OR;
if ( !strcmp(pSop, "1- 1\n-1 1\n") ) return CBA_NODE_OR;
if ( !strcmp(pSop, "01 1\n10 1\n") ) return CBA_NODE_XOR;
if ( !strcmp(pSop, "10 1\n01 1\n") ) return CBA_NODE_XOR;
if ( !strcmp(pSop, "11 1\n00 1\n") ) return CBA_NODE_XNOR;
if ( !strcmp(pSop, "00 1\n11 1\n") ) return CBA_NODE_XNOR;
if ( !strcmp(pSop, "10 1\n") ) return CBA_NODE_SHARP;
assert( 0 );
return CBA_NODE_NONE;
}
static inline char * Ptr_TypeToName( Cba_NodeType_t Type )
{
if ( Type == CBA_NODE_C0 ) return "const0";
if ( Type == CBA_NODE_C1 ) return "const1";
if ( Type == CBA_NODE_BUF ) return "buf";
if ( Type == CBA_NODE_INV ) return "not";
if ( Type == CBA_NODE_AND ) return "and";
if ( Type == CBA_NODE_NAND ) return "nand";
if ( Type == CBA_NODE_OR ) return "or";
if ( Type == CBA_NODE_NOR ) return "nor";
if ( Type == CBA_NODE_XOR ) return "xor";
if ( Type == CBA_NODE_XNOR ) return "xnor";
if ( Type == CBA_NODE_MUX ) return "mux";
if ( Type == CBA_NODE_MAJ ) return "maj";
if ( Type == CBA_NODE_SHARP ) return "sharp";
assert( 0 );
return "???";
}
static inline char * Ptr_TypeToSop( Cba_NodeType_t Type )
{
if ( Type == CBA_NODE_C0 ) return " 0\n";
if ( Type == CBA_NODE_C1 ) return " 1\n";
if ( Type == CBA_NODE_BUF ) return "1 1\n";
if ( Type == CBA_NODE_INV ) return "0 1\n";
if ( Type == CBA_NODE_AND ) return "11 1\n";
if ( Type == CBA_NODE_NAND ) return "11 0\n";
if ( Type == CBA_NODE_OR ) return "00 0\n";
if ( Type == CBA_NODE_NOR ) return "00 1\n";
if ( Type == CBA_NODE_XOR ) return "01 1\n10 1\n";
if ( Type == CBA_NODE_XNOR ) return "00 1\n11 1\n";
if ( Type == CBA_NODE_SHARP ) return "10 1\n";
if ( Type == CBA_NODE_MUX ) return "11- 1\n0-1 1\n";
if ( Type == CBA_NODE_MAJ ) return "11- 1\n1-1 1\n-11 1\n";
assert( 0 );
return "???";
}
/*=== cbaBlast.c =========================================================*/
extern Gia_Man_t * Cba_ManExtract( Cba_Man_t * p, int fBuffers, int fVerbose );
extern Cba_Man_t * Cba_ManInsertGia( Cba_Man_t * p, Gia_Man_t * pGia );
extern void * Cba_ManInsertAbc( Cba_Man_t * p, void * pAbc );
/*=== cbaBuild.c =========================================================*/
extern Cba_Man_t * Cba_ManBuild( Cba_Man_t * p );
/*=== cbaReadBlif.c =========================================================*/
extern Cba_Man_t * Cba_PrsReadBlif( char * pFileName );
/*=== cbaReadVer.c ==========================================================*/
extern Cba_Man_t * Cba_PrsReadVerilog( char * pFileName, int fBinary );
/*=== cbaWriteBlif.c ========================================================*/
extern void Cba_PrsWriteBlif( char * pFileName, Cba_Man_t * p );
extern void Cba_ManWriteBlif( char * pFileName, Cba_Man_t * p );
/*=== cbaWriteVer.c =========================================================*/
extern void Cba_PrsWriteVerilog( char * pFileName, Cba_Man_t * p );
extern void Cba_ManWriteVerilog( char * pFileName, Cba_Man_t * p );
/*=== cbaNtk.c =========================================================*/
extern void Cba_ManAssignInternNames( Cba_Man_t * p );
extern int Cba_NtkNodeNum( Cba_Ntk_t * p );
extern int Cba_ManObjNum( Cba_Man_t * p );
extern Cba_Man_t * Cba_ManDupStart( Cba_Man_t * p, Vec_Int_t * vNtkSizes );
extern Cba_Man_t * Cba_ManDup( Cba_Man_t * p );
/*=== cbaSimple.c =========================================================*/
extern Cba_Man_t * Cba_PrsReadPtr( Vec_Ptr_t * vDes );
extern void Ptr_ManFreeDes( Vec_Ptr_t * vDes );
ABC_NAMESPACE_HEADER_END
#endif
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
|