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

Go to the source code of this file.

Macros

#define MIO_SYMB_AND   '*'
 DECLARATIONS ///.
 
#define MIO_SYMB_AND2   '&'
 
#define MIO_SYMB_OR   '+'
 
#define MIO_SYMB_OR2   '|'
 
#define MIO_SYMB_XOR   '^'
 
#define MIO_SYMB_NOT   '!'
 
#define MIO_SYMB_AFTNOT   '\''
 
#define MIO_SYMB_OPEN   '('
 
#define MIO_SYMB_CLOSE   ')'
 

Functions

char * Mio_SopRegister (Mem_Flex_t *pMan, char *pName)
 FUNCTION DEFINITIONS ///.
 
int Mio_GateCollectNames (char *pFormula, char *pPinNames[])
 
int Mio_GateParseFormula (Mio_Gate_t *pGate)
 
int Mio_LibraryParseFormulas (Mio_Library_t *pLib)
 FUNCTION DEFINITIONS ///.
 

Macro Definition Documentation

◆ MIO_SYMB_AFTNOT

#define MIO_SYMB_AFTNOT   '\''

Definition at line 37 of file mioFunc.c.

◆ MIO_SYMB_AND

#define MIO_SYMB_AND   '*'

DECLARATIONS ///.

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

FileName [mioFunc.c]

PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]

Synopsis [File reading/writing for technology mapping.]

Author [MVSIS Group]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - September 8, 2003.]

Revision [

Id
mioFunc.c,v 1.4 2004/06/28 14:20:25 alanmi Exp

]

Definition at line 31 of file mioFunc.c.

◆ MIO_SYMB_AND2

#define MIO_SYMB_AND2   '&'

Definition at line 32 of file mioFunc.c.

◆ MIO_SYMB_CLOSE

#define MIO_SYMB_CLOSE   ')'

Definition at line 39 of file mioFunc.c.

◆ MIO_SYMB_NOT

#define MIO_SYMB_NOT   '!'

Definition at line 36 of file mioFunc.c.

◆ MIO_SYMB_OPEN

#define MIO_SYMB_OPEN   '('

Definition at line 38 of file mioFunc.c.

◆ MIO_SYMB_OR

#define MIO_SYMB_OR   '+'

Definition at line 33 of file mioFunc.c.

◆ MIO_SYMB_OR2

#define MIO_SYMB_OR2   '|'

Definition at line 34 of file mioFunc.c.

◆ MIO_SYMB_XOR

#define MIO_SYMB_XOR   '^'

Definition at line 35 of file mioFunc.c.

Function Documentation

◆ Mio_GateCollectNames()

int Mio_GateCollectNames ( char * pFormula,
char * pPinNames[] )

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

Synopsis [Collect the pin names in the formula.]

Description []

SideEffects []

SeeAlso []

Definition at line 76 of file mioFunc.c.

77{
78 char * Buffer;
79 char * pTemp;
80 int nPins, i;
81
82 // save the formula as it was
83 //strcpy( Buffer, pFormula );
84 Buffer = Abc_UtilStrsav( pFormula );
85
86 // remove the non-name symbols
87 for ( pTemp = Buffer; *pTemp; pTemp++ )
88 if ( *pTemp == MIO_SYMB_AND || *pTemp == MIO_SYMB_AND2 ||
89 *pTemp == MIO_SYMB_OR || *pTemp == MIO_SYMB_OR2 ||
90 *pTemp == MIO_SYMB_XOR ||
91 *pTemp == MIO_SYMB_NOT || *pTemp == MIO_SYMB_AFTNOT ||
92 *pTemp == MIO_SYMB_OPEN || *pTemp == MIO_SYMB_CLOSE )
93 *pTemp = ' ';
94
95 // save the names
96 nPins = 0;
97 pTemp = strtok( Buffer, " " );
98 while ( pTemp )
99 {
100 for ( i = 0; i < nPins; i++ )
101 if ( strcmp( pTemp, pPinNames[i] ) == 0 )
102 break;
103 if ( i == nPins )
104 { // cannot find this name; save it
105 pPinNames[nPins++] = Abc_UtilStrsav(pTemp);
106 }
107 // get the next name
108 pTemp = strtok( NULL, " " );
109 }
110 ABC_FREE( Buffer );
111 return nPins;
112}
#define ABC_FREE(obj)
Definition abc_global.h:267
#define MIO_SYMB_OR2
Definition mioForm.c:33
#define MIO_SYMB_XOR
Definition mioForm.c:34
#define MIO_SYMB_OPEN
Definition mioForm.c:37
#define MIO_SYMB_OR
Definition mioForm.c:32
#define MIO_SYMB_AND
DECLARATIONS ///.
Definition mioForm.c:30
#define MIO_SYMB_NOT
Definition mioForm.c:35
#define MIO_SYMB_CLOSE
Definition mioForm.c:38
#define MIO_SYMB_AFTNOT
Definition mioForm.c:36
#define MIO_SYMB_AND2
Definition mioForm.c:31
int strcmp()
char * strtok()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Mio_GateParseFormula()

int Mio_GateParseFormula ( Mio_Gate_t * pGate)

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

Synopsis [Deriving the functionality of the gates.]

Description []

SideEffects []

SeeAlso []

Definition at line 125 of file mioFunc.c.

126{
127 char * pPinNames[100];
128 char * pPinNamesCopy[100];
129 Mio_Pin_t * pPin, ** ppPin;
130 int nPins, iPin, i;
131
132 // set the maximum delay of the gate; count pins
133 pGate->dDelayMax = 0.0;
134 nPins = 0;
135 Mio_GateForEachPin( pGate, pPin )
136 {
137 // set the maximum delay of the gate
138 if ( pGate->dDelayMax < pPin->dDelayBlockMax )
139 pGate->dDelayMax = pPin->dDelayBlockMax;
140 // count the pin
141 nPins++;
142 }
143
144 // check for the gate with const function
145 if ( nPins == 0 )
146 {
147 if ( strcmp( pGate->pForm, MIO_STRING_CONST0 ) == 0 )
148 {
149// pGate->bFunc = b0;
150 pGate->vExpr = Exp_Const0();
151 pGate->pSop = Mio_SopRegister( (Mem_Flex_t *)pGate->pLib->pMmFlex, " 0\n" );
152 pGate->uTruth = 0;
153 pGate->pLib->pGate0 = pGate;
154 }
155 else if ( strcmp( pGate->pForm, MIO_STRING_CONST1 ) == 0 )
156 {
157// pGate->bFunc = b1;
158 pGate->vExpr = Exp_Const1();
159 pGate->pSop = Mio_SopRegister( (Mem_Flex_t *)pGate->pLib->pMmFlex, " 1\n" );
160 pGate->uTruth = ~(word)0;
161 pGate->pLib->pGate1 = pGate;
162 }
163 else
164 {
165 printf( "Cannot parse formula \"%s\" of gate \"%s\".\n", pGate->pForm, pGate->pName );
166 return 1;
167 }
168// Cudd_Ref( pGate->bFunc );
169 return 0;
170 }
171
172 // collect the names as they appear in the formula
173 nPins = Mio_GateCollectNames( pGate->pForm, pPinNames );
174 if ( nPins == 0 )
175 {
176 printf( "Cannot read formula \"%s\" of gate \"%s\".\n", pGate->pForm, pGate->pName );
177 return 1;
178 }
179
180 // set the number of inputs
181 pGate->nInputs = nPins;
182
183 // consider the case when all the pins have identical pin info
184 if ( strcmp( pGate->pPins->pName, "*" ) == 0 )
185 {
186 // get the topmost (generic) pin
187 pPin = pGate->pPins;
188 ABC_FREE( pPin->pName );
189
190 // create individual pins from the generic pin
191 ppPin = &pPin->pNext;
192 for ( i = 1; i < nPins; i++ )
193 {
194 // get the new pin
195 *ppPin = Mio_PinDup( pPin );
196 // set its name
197 (*ppPin)->pName = pPinNames[i];
198 // prepare the next place in the list
199 ppPin = &((*ppPin)->pNext);
200 }
201 *ppPin = NULL;
202
203 // set the name of the topmost pin
204 pPin->pName = pPinNames[0];
205 }
206 else
207 {
208 // reorder the variable names to appear the save way as the pins
209 iPin = 0;
210 Mio_GateForEachPin( pGate, pPin )
211 {
212 // find the pin with the name pPin->pName
213 for ( i = 0; i < nPins; i++ )
214 {
215 if ( pPinNames[i] && strcmp( pPinNames[i], pPin->pName ) == 0 )
216 {
217 // free pPinNames[i] because it is already available as pPin->pName
218 // setting pPinNames[i] to NULL is useful to make sure that
219 // this name is not assigned to two pins in the list
220 ABC_FREE( pPinNames[i] );
221 pPinNamesCopy[iPin++] = pPin->pName;
222 break;
223 }
224 if ( i == nPins )
225 {
226 printf( "Cannot find pin name \"%s\" in the formula \"%s\" of gate \"%s\".\n",
227 pPin->pName, pGate->pForm, pGate->pName );
228 return 1;
229 }
230 }
231 }
232
233 // check for the remaining names
234 for ( i = 0; i < nPins; i++ )
235 if ( pPinNames[i] )
236 {
237 printf( "Name \"%s\" appears in the formula \"%s\" of gate \"%s\" but there is no such pin.\n",
238 pPinNames[i], pGate->pForm, pGate->pName );
239 return 1;
240 }
241
242 // copy the names back
243 memcpy( pPinNames, pPinNamesCopy, nPins * sizeof(char *) );
244 }
245/*
246 // expand the manager if necessary
247 if ( dd->size < nPins )
248 {
249 Cudd_Quit( dd );
250 dd = Cudd_Init( nPins + 10, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 );
251 Cudd_zddVarsFromBddVars( dd, 2 );
252 }
253 // derive formula as the BDD
254 pGate->bFunc = Parse_FormulaParser( stdout, pGate->pForm, nPins, 0, pPinNames, dd, dd->vars );
255 if ( pGate->bFunc == NULL )
256 return 1;
257 Cudd_Ref( pGate->bFunc );
258 // derive cover
259 pGate->pSop = Abc_ConvertBddToSop( pGate->pLib->pMmFlex, dd, pGate->bFunc, pGate->bFunc, nPins, 0, pGate->pLib->vCube, -1 );
260*/
261
262 // derive expression
263 pGate->vExpr = Mio_ParseFormula( pGate->pForm, (char **)pPinNames, nPins );
264// Mio_ParseFormulaTruthTest( pGate->pForm, (char **)pPinNames, nPins );
265 // derive cover
266 pGate->pSop = Mio_LibDeriveSop( nPins, pGate->vExpr, pGate->pLib->vCube );
267 pGate->pSop = Mio_SopRegister( (Mem_Flex_t *)pGate->pLib->pMmFlex, pGate->pSop );
268 // derive truth table
269 if ( nPins <= 6 )
270 pGate->uTruth = Exp_Truth6( nPins, pGate->vExpr, NULL );
271 else if ( nPins <= 8 )
272 {
273 pGate->pTruth = ABC_CALLOC( word, 4 );
274 Exp_Truth8( nPins, pGate->vExpr, NULL, pGate->pTruth );
275 }
276
277/*
278 // verify
279 if ( pGate->nInputs <= 6 )
280 {
281 extern word Abc_SopToTruth( char * pSop, int nInputs );
282 word t2 = Abc_SopToTruth( pGate->pSop, nPins );
283 if ( pGate->uTruth != t2 )
284 {
285 printf( "%s\n", pGate->pForm );
286 Exp_Print( nPins, pGate->vExpr );
287 printf( "Verification failed!\n" );
288 }
289 }
290*/
291 return 0;
292}
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
int Mio_GateCollectNames(char *pFormula, char *pPinNames[])
Definition mioFunc.c:76
char * Mio_SopRegister(Mem_Flex_t *pMan, char *pName)
FUNCTION DEFINITIONS ///.
Definition mioFunc.c:56
#define MIO_STRING_CONST1
Definition mioInt.h:51
#define MIO_STRING_CONST0
Definition mioInt.h:50
Mio_Pin_t * Mio_PinDup(Mio_Pin_t *pPin)
Definition mioUtils.c:131
char * Mio_LibDeriveSop(int nVars, Vec_Int_t *vExpr, Vec_Str_t *vStr)
Definition mioSop.c:257
struct Mio_PinStruct_t_ Mio_Pin_t
Definition mio.h:44
#define Mio_GateForEachPin(Gate, Pin)
Definition mio.h:92
Vec_Int_t * Mio_ParseFormula(char *pFormInit, char **ppVarNames, int nVars)
Definition mioParse.c:105
struct Mem_Flex_t_ Mem_Flex_t
Definition mem.h:34
Vec_Int_t * vExpr
Definition mioInt.h:117
Mio_Library_t * pLib
Definition mioInt.h:105
Mio_Pin_t * pPins
Definition mioInt.h:102
double dDelayMax
Definition mioInt.h:115
Mio_Gate_t * pGate1
Definition mioInt.h:70
Mio_Gate_t * pGate0
Definition mioInt.h:69
Vec_Str_t * vCube
Definition mioInt.h:79
Mem_Flex_t * pMmFlex
Definition mioInt.h:78
double dDelayBlockMax
Definition mioInt.h:133
Mio_Pin_t * pNext
Definition mioInt.h:134
char * memcpy()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Mio_LibraryParseFormulas()

int Mio_LibraryParseFormulas ( Mio_Library_t * pLib)

FUNCTION DEFINITIONS ///.

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

Synopsis [Deriving the functionality of the gates.]

Description []

SideEffects []

SeeAlso []

Definition at line 305 of file mioFunc.c.

306{
307 Mio_Gate_t * pGate;
308
309 // count the gates
310 pLib->nGates = 0;
311 Mio_LibraryForEachGate( pLib, pGate )
312 pLib->nGates++;
313
314 // for each gate, derive its function
315 Mio_LibraryForEachGate( pLib, pGate )
316 if ( Mio_GateParseFormula( pGate ) )
317 return 1;
318 return 0;
319}
int Mio_GateParseFormula(Mio_Gate_t *pGate)
Definition mioFunc.c:125
#define Mio_LibraryForEachGate(Lib, Gate)
GLOBAL VARIABLES ///.
Definition mio.h:81
struct Mio_GateStruct_t_ Mio_Gate_t
Definition mio.h:43
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Mio_SopRegister()

char * Mio_SopRegister ( Mem_Flex_t * pMan,
char * pName )

FUNCTION DEFINITIONS ///.

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

Synopsis [Registers the cube string with the network.]

Description []

SideEffects []

SeeAlso []

Definition at line 56 of file mioFunc.c.

57{
58 char * pRegName;
59 if ( pName == NULL ) return NULL;
60 pRegName = Mem_FlexEntryFetch( pMan, strlen(pName) + 1 );
61 strcpy( pRegName, pName );
62 return pRegName;
63}
char * Mem_FlexEntryFetch(Mem_Flex_t *p, int nBytes)
Definition mem.c:388
int strlen()
char * strcpy()
Here is the call graph for this function:
Here is the caller graph for this function: