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
|
/**CFile****************************************************************
FileName [cbaWriteBlif.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Verilog parser.]
Synopsis [Parses several flavors of word-level Verilog.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - November 29, 2014.]
Revision [$Id: cbaWriteVer.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $]
***********************************************************************/
#include "cba.h"
#include "cbaPrs.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Writing parser state into a file.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Cba_PrsWriteBlifArray( FILE * pFile, Cba_Ntk_t * p, Vec_Int_t * vFanins, int fFirst )
{
int NameId, i;
Vec_IntForEachEntryStart( vFanins, NameId, i, fFirst )
fprintf( pFile, " %s", Cba_NtkStr(p, NameId) );
if ( fFirst )
fprintf( pFile, " %s", Cba_NtkStr(p, Vec_IntEntry(vFanins,0)) );
fprintf( pFile, "\n" );
}
void Cba_PrsWriteBlifArray2( FILE * pFile, Cba_Ntk_t * p, Vec_Int_t * vFanins )
{
int FormId, NameId, i;
assert( Vec_IntSize(vFanins) % 2 == 0 );
Vec_IntForEachEntryDouble( vFanins, FormId, NameId, i )
fprintf( pFile, " %s=%s", Cba_NtkStr(p, FormId), Cba_NtkStr(p, NameId) );
fprintf( pFile, "\n" );
}
void Cba_PrsWriteBlifLines( FILE * pFile, Cba_Ntk_t * p )
{
int i, Type;
Cba_NtkForEachObjType( p, Type, i )
if ( Type == CBA_OBJ_NODE ) // .names/assign/box2 (no formal/actual binding)
{
fprintf( pFile, ".names" );
Cba_PrsWriteBlifArray( pFile, p, Cba_ObjFaninVec(p, i), 1 );
//fprintf( pFile, "%s", Cba_NtkFuncStr(p, Cba_ObjFuncId(p, i)) );
fprintf( pFile, "%s", Ptr_TypeToSop( Cba_ObjFuncId(p, i) ) );
}
else if ( Type == CBA_OBJ_BOX ) // .names/assign/box2 (no formal/actual binding)
{
fprintf( pFile, ".subckt" );
fprintf( pFile, " %s", Cba_NtkName(Cba_ObjBoxModel(p, i)) );
Cba_PrsWriteBlifArray2( pFile, p, Cba_ObjFaninVec(p, i) );
}
else if ( Type == CBA_OBJ_LATCH ) // .names/assign/box2 (no formal/actual binding)
{
Vec_Int_t * vFanins = Cba_ObjFaninVec(p, i);
fprintf( pFile, ".latch" );
fprintf( pFile, " %s", Cba_NtkStr(p, Vec_IntEntry(vFanins, 1)) );
fprintf( pFile, " %s", Cba_NtkStr(p, Vec_IntEntry(vFanins, 0)) );
fprintf( pFile, " %c\n", '0' + Cba_ObjFuncId(p, i) );
}
}
void Cba_PrsWriteBlifNtk( FILE * pFile, Cba_Ntk_t * p )
{
assert( Vec_IntSize(&p->vTypes) == Cba_NtkObjNum(p) );
assert( Vec_IntSize(&p->vFuncs) == Cba_NtkObjNum(p) );
// write header
fprintf( pFile, ".model %s\n", Cba_NtkName(p) );
if ( Vec_IntSize(&p->vInouts) )
fprintf( pFile, ".inouts" );
if ( Vec_IntSize(&p->vInouts) )
Cba_PrsWriteBlifArray( pFile, p, &p->vInouts, 0 );
fprintf( pFile, ".inputs" );
Cba_PrsWriteBlifArray( pFile, p, &p->vInputs, 0 );
fprintf( pFile, ".outputs" );
Cba_PrsWriteBlifArray( pFile, p, &p->vOutputs, 0 );
// write objects
Cba_PrsWriteBlifLines( pFile, p );
fprintf( pFile, ".end\n\n" );
}
void Cba_PrsWriteBlif( char * pFileName, Cba_Man_t * p )
{
FILE * pFile;
Cba_Ntk_t * pNtk;
int i;
pFile = fopen( pFileName, "wb" );
if ( pFile == NULL )
{
printf( "Cannot open output file \"%s\".\n", pFileName );
return;
}
fprintf( pFile, "// Design \"%s\" written by ABC on %s\n\n", Cba_ManName(p), Extra_TimeStamp() );
Cba_ManForEachNtk( p, pNtk, i )
Cba_PrsWriteBlifNtk( pFile, pNtk );
fclose( pFile );
}
/**Function*************************************************************
Synopsis [Write elaborated design.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Cba_ManWriteBlifArray( FILE * pFile, Cba_Ntk_t * p, Vec_Int_t * vFanins, int iObj )
{
int iFanin, i;
Vec_IntForEachEntry( vFanins, iFanin, i )
fprintf( pFile, " %s", Cba_ObjNameStr(p, iFanin) );
if ( iObj >= 0 )
fprintf( pFile, " %s", Cba_ObjNameStr(p, iObj) );
fprintf( pFile, "\n" );
}
void Cba_ManWriteBlifArray2( FILE * pFile, Cba_Ntk_t * p, int iObj )
{
int iTerm, i;
Cba_Ntk_t * pModel = Cba_ObjBoxModel( p, iObj );
Cba_NtkForEachPi( pModel, iTerm, i )
fprintf( pFile, " %s=%s", Cba_ObjNameStr(pModel, iTerm), Cba_ObjNameStr(p, Cba_ObjBoxBi(p, iObj, i)) );
Cba_NtkForEachPo( pModel, iTerm, i )
fprintf( pFile, " %s=%s", Cba_ObjNameStr(pModel, iTerm), Cba_ObjNameStr(p, Cba_ObjBoxBo(p, iObj, i)) );
fprintf( pFile, "\n" );
}
void Cba_ManWriteBlifLines( FILE * pFile, Cba_Ntk_t * p )
{
int Type, i;
Cba_NtkForEachObjType( p, Type, i )
{
if ( Type == CBA_OBJ_NODE ) // .names/assign/box2 (no formal/actual binding)
{
fprintf( pFile, ".names" );
Cba_ManWriteBlifArray( pFile, p, Cba_ObjFaninVec(p, i), i );
//fprintf( pFile, "%s", Cba_NtkFuncStr(p, Cba_ObjFuncId(p, i)) );
fprintf( pFile, "%s", Ptr_TypeToSop( Cba_ObjFuncId(p, i) ) );
}
else if ( Type == CBA_OBJ_BOX ) // .names/assign/box2 (no formal/actual binding)
{
fprintf( pFile, ".subckt" );
fprintf( pFile, " %s", Cba_NtkName(Cba_ObjBoxModel(p, i)) );
Cba_ManWriteBlifArray2( pFile, p, i );
}
else if ( Type == CBA_OBJ_LATCH ) // .names/assign/box2 (no formal/actual binding)
{
Vec_Int_t * vFanins = Cba_ObjFaninVec(p, i);
fprintf( pFile, ".latch" );
fprintf( pFile, " %s", Cba_ObjNameStr(p, Vec_IntEntry(vFanins, 1)) );
fprintf( pFile, " %s", Cba_ObjNameStr(p, Vec_IntEntry(vFanins, 0)) );
fprintf( pFile, " %c\n", '0' + Cba_ObjFuncId(p, i) );
}
}
}
void Cba_ManWriteBlifNtk( FILE * pFile, Cba_Ntk_t * p )
{
assert( Vec_IntSize(&p->vTypes) == Cba_NtkObjNum(p) );
assert( Vec_IntSize(&p->vFuncs) == Cba_NtkObjNum(p) );
// write header
fprintf( pFile, ".model %s\n", Cba_NtkName(p) );
if ( Vec_IntSize(&p->vInouts) )
fprintf( pFile, ".inouts" );
if ( Vec_IntSize(&p->vInouts) )
Cba_ManWriteBlifArray( pFile, p, &p->vInouts, -1 );
fprintf( pFile, ".inputs" );
Cba_ManWriteBlifArray( pFile, p, &p->vInputs, -1 );
fprintf( pFile, ".outputs" );
Cba_ManWriteBlifArray( pFile, p, &p->vOutputs, -1 );
// write objects
Cba_ManWriteBlifLines( pFile, p );
fprintf( pFile, ".end\n\n" );
}
void Cba_ManWriteBlif( char * pFileName, Cba_Man_t * p )
{
FILE * pFile;
Cba_Ntk_t * pNtk;
int i;
pFile = fopen( pFileName, "wb" );
if ( pFile == NULL )
{
printf( "Cannot open output file \"%s\".\n", pFileName );
return;
}
fprintf( pFile, "// Design \"%s\" written by ABC on %s\n\n", Cba_ManName(p), Extra_TimeStamp() );
Cba_ManForEachNtk( p, pNtk, i )
Cba_ManWriteBlifNtk( pFile, pNtk );
fclose( pFile );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
|