ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ioReadDsd.c File Reference
#include "ioAbc.h"
Include dependency graph for ioReadDsd.c:

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START char * Io_ReadDsdFindEnd (char *pCur)
 DECLARATIONS ///.
 
int Io_ReadDsdStrSplit (char *pCur, char *pParts[], int *pTypeXor)
 
Abc_Obj_tIo_ReadDsd_rec (Abc_Ntk_t *pNtk, char *pCur, char *pSop)
 
Abc_Ntk_tIo_ReadDsd (char *pForm)
 

Function Documentation

◆ Io_ReadDsd()

Abc_Ntk_t * Io_ReadDsd ( char * pForm)

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

Synopsis [Derives the DSD network of the formula.]

Description []

SideEffects []

SeeAlso []

Definition at line 232 of file ioReadDsd.c.

233{
234 Abc_Ntk_t * pNtk;
235 Abc_Obj_t * pObj, * pTop;
236 Vec_Ptr_t * vNames;
237 char * pCur, * pFormCopy;
238 int i, nInputs;
239
240 // count the number of elementary variables
241 nInputs = 0;
242 for ( pCur = pForm; *pCur; pCur++ )
243 if ( *pCur >= 'a' && *pCur <= 'z' )
244 nInputs = Abc_MaxInt( nInputs, *pCur - 'a' );
245 nInputs++;
246
247 // create the network
249 pNtk->pName = Extra_UtilStrsav( "dsd" );
250
251 // create PIs
252 vNames = Abc_NodeGetFakeNames( nInputs );
253 for ( i = 0; i < nInputs; i++ )
254 Abc_ObjAssignName( Abc_NtkCreatePi(pNtk), (char *)Vec_PtrEntry(vNames, i), NULL );
255 Abc_NodeFreeNames( vNames );
256
257 // transform the formula by inserting parentheses
258 // this transforms strings like PRIME(a,b,cd) into (PRIME((a),(b),(cd)))
259 pCur = pFormCopy = ABC_ALLOC( char, 3 * strlen(pForm) + 10 );
260 *pCur++ = '(';
261 for ( ; *pForm; pForm++ )
262 if ( *pForm == '(' )
263 {
264 *pCur++ = '(';
265 *pCur++ = '(';
266 }
267 else if ( *pForm == ')' )
268 {
269 *pCur++ = ')';
270 *pCur++ = ')';
271 }
272 else if ( *pForm == ',' )
273 {
274 *pCur++ = ')';
275 *pCur++ = ',';
276 *pCur++ = '(';
277 }
278 else
279 *pCur++ = *pForm;
280 *pCur++ = ')';
281 *pCur = 0;
282
283 // parse the formula
284 pObj = Io_ReadDsd_rec( pNtk, pFormCopy, NULL );
285 ABC_FREE( pFormCopy );
286 if ( pObj == NULL )
287 return NULL;
288
289 // create output
290 pTop = Abc_NtkCreatePo(pNtk);
291 Abc_ObjAssignName( pTop, "F", NULL );
292 Abc_ObjAddFanin( pTop, pObj );
293
294 // create the only PO
295 if ( !Abc_NtkCheck( pNtk ) )
296 {
297 fprintf( stdout, "Io_ReadDsd(): Network check has failed.\n" );
298 Abc_NtkDelete( pNtk );
299 return NULL;
300 }
301 return pNtk;
302}
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
Definition abcNtk.c:53
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition abcCheck.c:64
ABC_DLL void Abc_NodeFreeNames(Vec_Ptr_t *vNames)
Definition abcNames.c:264
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL char * Abc_ObjAssignName(Abc_Obj_t *pObj, char *pName, char *pSuffix)
Definition abcNames.c:69
@ ABC_NTK_LOGIC
Definition abc.h:57
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
@ ABC_FUNC_SOP
Definition abc.h:65
ABC_DLL Vec_Ptr_t * Abc_NodeGetFakeNames(int nNames)
Definition abcNames.c:228
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
char * Extra_UtilStrsav(const char *s)
Abc_Obj_t * Io_ReadDsd_rec(Abc_Ntk_t *pNtk, char *pCur, char *pSop)
Definition ioReadDsd.c:144
char * pName
Definition abc.h:158
int strlen()
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
Here is the call graph for this function:

◆ Io_ReadDsd_rec()

Abc_Obj_t * Io_ReadDsd_rec ( Abc_Ntk_t * pNtk,
char * pCur,
char * pSop )

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

Synopsis [Recursively parses the formula.]

Description []

SideEffects []

SeeAlso []

Definition at line 144 of file ioReadDsd.c.

145{
146 Abc_Obj_t * pObj, * pFanin;
147 char * pEnd, * pParts[32];
148 int i, nParts, TypeExor;
149
150 // consider complemented formula
151 if ( *pCur == '!' )
152 {
153 pObj = Io_ReadDsd_rec( pNtk, pCur + 1, NULL );
154 return Abc_NtkCreateNodeInv( pNtk, pObj );
155 }
156 if ( *pCur == '(' )
157 {
158 assert( pCur[strlen(pCur)-1] == ')' );
159 pCur[strlen(pCur)-1] = 0;
160 nParts = Io_ReadDsdStrSplit( pCur+1, pParts, &TypeExor );
161 if ( nParts == 0 )
162 {
163 Abc_NtkDelete( pNtk );
164 return NULL;
165 }
166 pObj = Abc_NtkCreateNode( pNtk );
167 if ( pSop )
168 {
169// for ( i = nParts - 1; i >= 0; i-- )
170 for ( i = 0; i < nParts; i++ )
171 {
172 pFanin = Io_ReadDsd_rec( pNtk, pParts[i], NULL );
173 if ( pFanin == NULL )
174 return NULL;
175 Abc_ObjAddFanin( pObj, pFanin );
176 }
177 }
178 else
179 {
180 for ( i = 0; i < nParts; i++ )
181 {
182 pFanin = Io_ReadDsd_rec( pNtk, pParts[i], NULL );
183 if ( pFanin == NULL )
184 return NULL;
185 Abc_ObjAddFanin( pObj, pFanin );
186 }
187 }
188 if ( pSop )
189 pObj->pData = Abc_SopRegister( (Mem_Flex_t *)pNtk->pManFunc, pSop );
190 else if ( TypeExor )
191 pObj->pData = Abc_SopCreateXorSpecial( (Mem_Flex_t *)pNtk->pManFunc, nParts );
192 else
193 pObj->pData = Abc_SopCreateAnd( (Mem_Flex_t *)pNtk->pManFunc, nParts, NULL );
194 return pObj;
195 }
196 if ( *pCur >= 'a' && *pCur <= 'z' )
197 {
198 assert( *(pCur+1) == 0 );
199 return Abc_NtkPi( pNtk, *pCur - 'a' );
200 }
201
202 // skip hex truth table
203 pEnd = pCur;
204 while ( (*pEnd >= '0' && *pEnd <= '9') || (*pEnd >= 'A' && *pEnd <= 'F') )
205 pEnd++;
206 if ( *pEnd != '(' )
207 {
208 printf( "Cannot find the end of hexadecimal truth table.\n" );
209 return NULL;
210 }
211
212 // parse the truth table
213 *pEnd = 0;
214 pSop = Abc_SopFromTruthHex( pCur );
215 *pEnd = '(';
216 pObj = Io_ReadDsd_rec( pNtk, pEnd, pSop );
217 ABC_FREE( pSop );
218 return pObj;
219}
ABC_DLL char * Abc_SopFromTruthHex(char *pTruth)
Definition abcSop.c:1060
ABC_DLL char * Abc_SopCreateXorSpecial(Mem_Flex_t *pMan, int nVars)
Definition abcSop.c:297
ABC_DLL char * Abc_SopCreateAnd(Mem_Flex_t *pMan, int nVars, int *pfCompl)
Definition abcSop.c:168
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeInv(Abc_Ntk_t *pNtk, Abc_Obj_t *pFanin)
Definition abcObj.c:674
ABC_DLL char * Abc_SopRegister(Mem_Flex_t *pMan, const char *pName)
DECLARATIONS ///.
Definition abcSop.c:62
int Io_ReadDsdStrSplit(char *pCur, char *pParts[], int *pTypeXor)
Definition ioReadDsd.c:73
struct Mem_Flex_t_ Mem_Flex_t
Definition mem.h:34
void * pManFunc
Definition abc.h:191
void * pData
Definition abc.h:145
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Io_ReadDsdFindEnd()

ABC_NAMESPACE_IMPL_START char * Io_ReadDsdFindEnd ( char * pCur)

DECLARATIONS ///.

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

FileName [ioReadDsd.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Command processing package.]

Synopsis [Procedure to read network from file.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
ioReadDsd.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

] FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Finds the end of the part.]

Description []

SideEffects []

SeeAlso []

Definition at line 45 of file ioReadDsd.c.

46{
47 char * pEnd;
48 int nParts = 0;
49 assert( *pCur == '(' );
50 for ( pEnd = pCur; *pEnd; pEnd++ )
51 {
52 if ( *pEnd == '(' )
53 nParts++;
54 else if ( *pEnd == ')' )
55 nParts--;
56 if ( nParts == 0 )
57 return pEnd;
58 }
59 return NULL;
60}
Here is the caller graph for this function:

◆ Io_ReadDsdStrSplit()

int Io_ReadDsdStrSplit ( char * pCur,
char * pParts[],
int * pTypeXor )

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

Synopsis [Splits the formula into parts.]

Description []

SideEffects []

SeeAlso []

Definition at line 73 of file ioReadDsd.c.

74{
75 int fAnd = 0, fXor = 0, fPri = 0, nParts = 0;
76 assert( *pCur );
77 // process the parts
78 while ( 1 )
79 {
80 // save the current part
81 pParts[nParts++] = pCur;
82 // skip the complement
83 if ( *pCur == '!' )
84 pCur++;
85 // skip var
86 if ( *pCur >= 'a' && *pCur <= 'z' )
87 pCur++;
88 else
89 {
90 // skip hex truth table
91 while ( (*pCur >= '0' && *pCur <= '9') || (*pCur >= 'A' && *pCur <= 'F') )
92 pCur++;
93 // process parentheses
94 if ( *pCur != '(' )
95 {
96 printf( "Cannot find the opening parenthesis.\n" );
97 break;
98 }
99 // find the corresponding closing parenthesis
100 pCur = Io_ReadDsdFindEnd( pCur );
101 if ( pCur == NULL )
102 {
103 printf( "Cannot find the closing parenthesis.\n" );
104 break;
105 }
106 pCur++;
107 }
108 // check the end
109 if ( *pCur == 0 )
110 break;
111 // check symbol
112 if ( *pCur != '*' && *pCur != '+' && *pCur != ',' )
113 {
114 printf( "Wrong separating symbol.\n" );
115 break;
116 }
117 // remember the symbol
118 fAnd |= (*pCur == '*');
119 fXor |= (*pCur == '+');
120 fPri |= (*pCur == ',');
121 *pCur++ = 0;
122 }
123 // check separating symbols
124 if ( fAnd + fXor + fPri > 1 )
125 {
126 printf( "Different types of separating symbol ennPartsed.\n" );
127 return 0;
128 }
129 *pTypeXor = fXor;
130 return nParts;
131}
ABC_NAMESPACE_IMPL_START char * Io_ReadDsdFindEnd(char *pCur)
DECLARATIONS ///.
Definition ioReadDsd.c:45
Here is the call graph for this function:
Here is the caller graph for this function: