abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cbaWriteVer.c File Reference
#include "cba.h"
#include "cbaPrs.h"

Go to the source code of this file.

Functions

void Cba_PrsWriteVerilogMux (FILE *pFile, Cba_Ntk_t *p, Vec_Int_t *vFanins)
 FUNCTION DEFINITIONS ///. More...
 
void Cba_PrsWriteVerilogConcat (FILE *pFile, Cba_Ntk_t *p, int Id)
 
void Cba_PrsWriteVerilogArray2 (FILE *pFile, Cba_Ntk_t *p, Vec_Int_t *vFanins)
 
void Cba_PrsWriteVerilogArray3 (FILE *pFile, Cba_Ntk_t *p, Vec_Int_t *vFanins)
 
void Cba_PrsWriteVerilogNodes (FILE *pFile, Cba_Ntk_t *p)
 
void Cba_PrsWriteVerilogBoxes (FILE *pFile, Cba_Ntk_t *p)
 
void Cba_PrsWriteVerilogSignals (FILE *pFile, Cba_Ntk_t *p, int SigType)
 
void Cba_PrsWriteVerilogSignalList (FILE *pFile, Cba_Ntk_t *p, int SigType, int fSkipComma)
 
void Cba_PrsWriteVerilogNtk (FILE *pFile, Cba_Ntk_t *p)
 
void Cba_PrsWriteVerilog (char *pFileName, Cba_Man_t *pDes)
 

Variables

ABC_NAMESPACE_IMPL_START const
char * 
s_NodeTypes [CBA_NODE_UNKNOWN+1]
 DECLARATIONS ///. More...
 

Function Documentation

void Cba_PrsWriteVerilog ( char *  pFileName,
Cba_Man_t pDes 
)

Definition at line 207 of file cbaWriteVer.c.

208 {
209  FILE * pFile;
210  Cba_Ntk_t * pNtk;
211  int i;
212  pFile = fopen( pFileName, "wb" );
213  if ( pFile == NULL )
214  {
215  printf( "Cannot open output file \"%s\".\n", pFileName );
216  return;
217  }
218  fprintf( pFile, "// Design \"%s\" written by ABC on %s\n\n", Cba_ManName(pDes), Extra_TimeStamp() );
219  Cba_ManForEachNtk( pDes, pNtk, i )
220  Cba_PrsWriteVerilogNtk( pFile, pNtk );
221  fclose( pFile );
222 }
Definition: cba.h:99
void Cba_PrsWriteVerilogNtk(FILE *pFile, Cba_Ntk_t *p)
Definition: cbaWriteVer.c:181
static char * Cba_ManName(Cba_Man_t *p)
Definition: cba.h:120
char * Extra_TimeStamp()
#define Cba_ManForEachNtk(p, pNtk, i)
MACRO DEFINITIONS ///.
Definition: cba.h:155
void Cba_PrsWriteVerilogArray2 ( FILE *  pFile,
Cba_Ntk_t p,
Vec_Int_t vFanins 
)

Definition at line 101 of file cbaWriteVer.c.

102 {
103  int NameId, RangeId, i;
104  assert( Vec_IntSize(vFanins) % 2 == 0 );
105  Vec_IntForEachEntryDouble( vFanins, NameId, RangeId, i )
106  {
107  assert( RangeId >= -2 );
108  if ( RangeId == -2 )
109  Cba_PrsWriteVerilogConcat( pFile, p, NameId-1 );
110  else if ( RangeId == -1 )
111  fprintf( pFile, "%s", Cba_NtkStr(p, NameId) );
112  else
113  fprintf( pFile, "%s%s", Cba_NtkStr(p, NameId), RangeId ? Cba_NtkStr(p, RangeId) : "" );
114  fprintf( pFile, "%s", (i == Vec_IntSize(vFanins) - 2) ? "" : ", " );
115  }
116 }
static char * Cba_NtkStr(Cba_Ntk_t *p, int i)
Definition: cba.h:127
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
Definition: vecInt.h:66
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define assert(ex)
Definition: util_old.h:213
void Cba_PrsWriteVerilogConcat(FILE *pFile, Cba_Ntk_t *p, int Id)
Definition: cbaWriteVer.c:94
void Cba_PrsWriteVerilogArray3 ( FILE *  pFile,
Cba_Ntk_t p,
Vec_Int_t vFanins 
)

Definition at line 117 of file cbaWriteVer.c.

118 {
119  int FormId, NameId, RangeId, i;
120  assert( Vec_IntSize(vFanins) % 3 == 0 );
121  Vec_IntForEachEntryTriple( vFanins, FormId, NameId, RangeId, i )
122  {
123  fprintf( pFile, ".%s(", Cba_NtkStr(p, FormId) );
124  if ( RangeId == -2 )
125  Cba_PrsWriteVerilogConcat( pFile, p, NameId-1 );
126  else if ( RangeId == -1 )
127  fprintf( pFile, "%s", Cba_NtkStr(p, NameId) );
128  else
129  fprintf( pFile, "%s%s", Cba_NtkStr(p, NameId), RangeId ? Cba_NtkStr(p, RangeId) : "" );
130  fprintf( pFile, ")%s", (i == Vec_IntSize(vFanins) - 3) ? "" : ", " );
131  }
132 }
static char * Cba_NtkStr(Cba_Ntk_t *p, int i)
Definition: cba.h:127
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define assert(ex)
Definition: util_old.h:213
#define Vec_IntForEachEntryTriple(vVec, Entry1, Entry2, Entry3, i)
Definition: vecInt.h:68
void Cba_PrsWriteVerilogConcat(FILE *pFile, Cba_Ntk_t *p, int Id)
Definition: cbaWriteVer.c:94
void Cba_PrsWriteVerilogBoxes ( FILE *  pFile,
Cba_Ntk_t p 
)

Definition at line 155 of file cbaWriteVer.c.

156 {
157  int Type, i;
158  Cba_NtkForEachObjType( p, Type, i )
159  if ( Type == CBA_PRS_BOX ) // .subckt/.gate/box (formal/actual binding)
160  {
161  fprintf( pFile, " %s %s (", Cba_ObjFuncStr(p, i), Cba_ObjInstStr(p, i) );
162  Cba_PrsWriteVerilogArray3( pFile, p, Cba_ObjFanins(p, i) );
163  fprintf( pFile, ");\n" );
164  }
165 }
#define Cba_NtkForEachObjType(p, Type, i)
Definition: cba.h:158
static Vec_Int_t * Cba_ObjFanins(Cba_Ntk_t *p, int i)
Definition: cba.h:134
static char * Cba_ObjFuncStr(Cba_Ntk_t *p, int i)
Definition: cba.h:140
if(last==0)
Definition: sparse_int.h:34
static char * Cba_ObjInstStr(Cba_Ntk_t *p, int i)
Definition: cba.h:141
void Cba_PrsWriteVerilogArray3(FILE *pFile, Cba_Ntk_t *p, Vec_Int_t *vFanins)
Definition: cbaWriteVer.c:117
void Cba_PrsWriteVerilogConcat ( FILE *  pFile,
Cba_Ntk_t p,
int  Id 
)

Definition at line 94 of file cbaWriteVer.c.

95 {
96  extern void Cba_PrsWriteVerilogArray2( FILE * pFile, Cba_Ntk_t * p, Vec_Int_t * vFanins );
97  fprintf( pFile, "{" );
98  Cba_PrsWriteVerilogArray2( pFile, p, Cba_ObjFanins(p, Id) );
99  fprintf( pFile, "}" );
100 }
Definition: cba.h:99
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static Vec_Int_t * Cba_ObjFanins(Cba_Ntk_t *p, int i)
Definition: cba.h:134
void Cba_PrsWriteVerilogArray2(FILE *pFile, Cba_Ntk_t *p, Vec_Int_t *vFanins)
Definition: cbaWriteVer.c:101
void Cba_PrsWriteVerilogMux ( FILE *  pFile,
Cba_Ntk_t p,
Vec_Int_t vFanins 
)

FUNCTION DEFINITIONS ///.

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

Synopsis [Writing parser state into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 83 of file cbaWriteVer.c.

84 {
85  int NameId, RangeId, i;
86  char * pStrs[4] = { " = ", " ? ", " : ", ";\n" };
87  assert( Vec_IntSize(vFanins) == 8 );
88  fprintf( pFile, " assign " );
89  Vec_IntForEachEntryDouble( vFanins, NameId, RangeId, i )
90  {
91  fprintf( pFile, "%s%s%s", Cba_NtkStr(p, NameId), RangeId > 0 ? Cba_NtkStr(p, RangeId) : "", pStrs[i/2] );
92  }
93 }
static char * Cba_NtkStr(Cba_Ntk_t *p, int i)
Definition: cba.h:127
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
Definition: vecInt.h:66
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define assert(ex)
Definition: util_old.h:213
void Cba_PrsWriteVerilogNodes ( FILE *  pFile,
Cba_Ntk_t p 
)

Definition at line 133 of file cbaWriteVer.c.

134 {
135  int Type, Func, i;
136  Cba_NtkForEachObjType( p, Type, i )
137  if ( Type == CBA_PRS_NODE ) // .names/assign/box2 (no formal/actual binding)
138  {
139  Func = Cba_ObjFuncId(p, i);
140  if ( Func >= CBA_NODE_BUF && Func <= CBA_NODE_XNOR )
141  {
142  fprintf( pFile, " %s (", s_NodeTypes[Func] );
143  Cba_PrsWriteVerilogArray2( pFile, p, Cba_ObjFanins(p, i) );
144  fprintf( pFile, ");\n" );
145  }
146  else if ( Func == CBA_NODE_MUX )
147  Cba_PrsWriteVerilogMux( pFile, p, Cba_ObjFanins(p, i) );
148  else
149  {
150  //char * pName = Cba_NtkStr(p, Func);
151  assert( 0 );
152  }
153  }
154 }
void Cba_PrsWriteVerilogMux(FILE *pFile, Cba_Ntk_t *p, Vec_Int_t *vFanins)
FUNCTION DEFINITIONS ///.
Definition: cbaWriteVer.c:83
static int Cba_ObjFuncId(Cba_Ntk_t *p, int i)
Definition: cba.h:132
#define Cba_NtkForEachObjType(p, Type, i)
Definition: cba.h:158
static Vec_Int_t * Cba_ObjFanins(Cba_Ntk_t *p, int i)
Definition: cba.h:134
void Cba_PrsWriteVerilogArray2(FILE *pFile, Cba_Ntk_t *p, Vec_Int_t *vFanins)
Definition: cbaWriteVer.c:101
if(last==0)
Definition: sparse_int.h:34
ABC_NAMESPACE_IMPL_START const char * s_NodeTypes[CBA_NODE_UNKNOWN+1]
DECLARATIONS ///.
Definition: cbaWriteVer.c:51
#define assert(ex)
Definition: util_old.h:213
void Cba_PrsWriteVerilogNtk ( FILE *  pFile,
Cba_Ntk_t p 
)

Definition at line 181 of file cbaWriteVer.c.

182 {
183  int s;
184  assert( Vec_IntSize(&p->vTypes) == Cba_NtkObjNum(p) );
185  assert( Vec_IntSize(&p->vFuncs) == Cba_NtkObjNum(p) );
187  // write header
188  fprintf( pFile, "module %s (\n", Cba_NtkName(p) );
189  for ( s = 0; s < 3; s++ )
190  {
191  if ( s == 0 && Vec_IntSize(&p->vInouts) == 0 )
192  continue;
193  fprintf( pFile, " " );
194  Cba_PrsWriteVerilogSignalList( pFile, p, s, s==2 );
195  fprintf( pFile, "\n" );
196  }
197  fprintf( pFile, " );\n" );
198  // write declarations
199  for ( s = 0; s < 4; s++ )
200  Cba_PrsWriteVerilogSignals( pFile, p, s );
201  fprintf( pFile, "\n" );
202  // write objects
203  Cba_PrsWriteVerilogNodes( pFile, p );
204  Cba_PrsWriteVerilogBoxes( pFile, p );
205  fprintf( pFile, "endmodule\n\n" );
206 }
static char * Cba_NtkName(Cba_Ntk_t *p)
Definition: cba.h:125
Vec_Int_t vFuncs
Definition: cba.h:110
static int Cba_NtkObjNum(Cba_Ntk_t *p)
Definition: cba.h:126
void Cba_PrsWriteVerilogSignalList(FILE *pFile, Cba_Ntk_t *p, int SigType, int fSkipComma)
Definition: cbaWriteVer.c:174
Vec_Int_t vInstIds
Definition: cba.h:111
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
void Cba_PrsWriteVerilogSignals(FILE *pFile, Cba_Ntk_t *p, int SigType)
Definition: cbaWriteVer.c:166
#define assert(ex)
Definition: util_old.h:213
Vec_Int_t vInouts
Definition: cba.h:104
void Cba_PrsWriteVerilogNodes(FILE *pFile, Cba_Ntk_t *p)
Definition: cbaWriteVer.c:133
Vec_Int_t vTypes
Definition: cba.h:109
void Cba_PrsWriteVerilogBoxes(FILE *pFile, Cba_Ntk_t *p)
Definition: cbaWriteVer.c:155
void Cba_PrsWriteVerilogSignalList ( FILE *  pFile,
Cba_Ntk_t p,
int  SigType,
int  fSkipComma 
)

Definition at line 174 of file cbaWriteVer.c.

175 {
176  int NameId, RangeId, i;
177  Vec_Int_t * vSigs[4] = { &p->vInouts, &p->vInputs, &p->vOutputs, &p->vWires };
178  Vec_IntForEachEntryDouble( vSigs[SigType], NameId, RangeId, i )
179  fprintf( pFile, "%s%s", Cba_NtkStr(p, NameId), (fSkipComma && i == Vec_IntSize(vSigs[SigType]) - 2) ? "" : ", " );
180 }
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
Vec_Int_t vWires
Definition: cba.h:107
Vec_Int_t vInputs
Definition: cba.h:105
Vec_Int_t vOutputs
Definition: cba.h:106
static char * Cba_NtkStr(Cba_Ntk_t *p, int i)
Definition: cba.h:127
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
Definition: vecInt.h:66
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
Vec_Int_t vInouts
Definition: cba.h:104
void Cba_PrsWriteVerilogSignals ( FILE *  pFile,
Cba_Ntk_t p,
int  SigType 
)

Definition at line 166 of file cbaWriteVer.c.

167 {
168  int NameId, RangeId, i;
169  char * pSigNames[4] = { "inout", "input", "output", "wire" };
170  Vec_Int_t * vSigs[4] = { &p->vInouts, &p->vInputs, &p->vOutputs, &p->vWires };
171  Vec_IntForEachEntryDouble( vSigs[SigType], NameId, RangeId, i )
172  fprintf( pFile, " %s %s%s;\n", pSigNames[SigType], RangeId ? Cba_NtkStr(p, RangeId) : "", Cba_NtkStr(p, NameId) );
173 }
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
Vec_Int_t vWires
Definition: cba.h:107
Vec_Int_t vInputs
Definition: cba.h:105
Vec_Int_t vOutputs
Definition: cba.h:106
static char * Cba_NtkStr(Cba_Ntk_t *p, int i)
Definition: cba.h:127
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
Definition: vecInt.h:66
Vec_Int_t vInouts
Definition: cba.h:104

Variable Documentation

Initial value:
= {
NULL,
"const",
"buf",
"not",
"and",
"nand",
"or",
"nor",
"xor",
"xnor",
"mux",
"maj",
"???"
"???"
}

DECLARATIONS ///.

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

FileName [cba.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:
cba.c,v 1.00 2014/11/29 00:00:00 alanmi Exp

]

Definition at line 51 of file cbaWriteVer.c.