abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mioForm.c File Reference
#include "mioInt.h"
#include "bdd/parse/parse.h"

Go to the source code of this file.

Macros

#define MIO_SYMB_AND   '*'
 DECLARATIONS ///. More...
 
#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

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

Macro Definition Documentation

#define MIO_SYMB_AFTNOT   '\''

Definition at line 36 of file mioForm.c.

#define MIO_SYMB_AND   '*'

DECLARATIONS ///.

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

FileName [mioForm.c]

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

Synopsis [Parsing equestion formula.]

Author [MVSIS Group]

Affiliation [UC Berkeley]

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

Revision [

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

]

Definition at line 30 of file mioForm.c.

#define MIO_SYMB_AND2   '&'

Definition at line 31 of file mioForm.c.

#define MIO_SYMB_CLOSE   ')'

Definition at line 38 of file mioForm.c.

#define MIO_SYMB_NOT   '!'

Definition at line 35 of file mioForm.c.

#define MIO_SYMB_OPEN   '('

Definition at line 37 of file mioForm.c.

#define MIO_SYMB_OR   '+'

Definition at line 32 of file mioForm.c.

#define MIO_SYMB_OR2   '|'

Definition at line 33 of file mioForm.c.

#define MIO_SYMB_XOR   '^'

Definition at line 34 of file mioForm.c.

Function Documentation

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

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

Synopsis [Collect the pin names in the formula.]

Description []

SideEffects []

SeeAlso []

Definition at line 265 of file mioForm.c.

266 {
267  char Buffer[1000];
268  char * pTemp;
269  int nPins, i;
270 
271  // save the formula as it was
272  strcpy( Buffer, pFormula );
273 
274  // remove the non-name symbols
275  for ( pTemp = Buffer; *pTemp; pTemp++ )
276  if ( *pTemp == MIO_SYMB_AND || *pTemp == MIO_SYMB_AND2 ||
277  *pTemp == MIO_SYMB_OR || *pTemp == MIO_SYMB_OR2 ||
278  *pTemp == MIO_SYMB_XOR ||
279  *pTemp == MIO_SYMB_NOT || *pTemp == MIO_SYMB_AFTNOT ||
280  *pTemp == MIO_SYMB_OPEN || *pTemp == MIO_SYMB_CLOSE )
281  *pTemp = ' ';
282 
283  // save the names
284  nPins = 0;
285  pTemp = strtok( Buffer, " " );
286  while ( pTemp )
287  {
288  for ( i = 0; i < nPins; i++ )
289  if ( strcmp( pTemp, pPinNames[i] ) == 0 )
290  break;
291  if ( i == nPins )
292  { // cannot find this name; save it
293  pPinNames[nPins++] = Abc_UtilStrsav(pTemp);
294  }
295  // get the next name
296  pTemp = strtok( NULL, " " );
297  }
298  return nPins;
299 }
#define MIO_SYMB_AND2
Definition: mioForm.c:31
#define MIO_SYMB_NOT
Definition: mioForm.c:35
char * strtok()
#define MIO_SYMB_OR
Definition: mioForm.c:32
#define MIO_SYMB_OPEN
Definition: mioForm.c:37
int strcmp()
#define MIO_SYMB_AND
DECLARATIONS ///.
Definition: mioForm.c:30
#define MIO_SYMB_CLOSE
Definition: mioForm.c:38
char * strcpy()
#define MIO_SYMB_XOR
Definition: mioForm.c:34
#define MIO_SYMB_OR2
Definition: mioForm.c:33
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
#define MIO_SYMB_AFTNOT
Definition: mioForm.c:36
int Mio_GateParseFormula ( Mio_Gate_t pGate)
static

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

Synopsis [Deriving the functionality of the gates.]

Description []

SideEffects []

SeeAlso []

Definition at line 111 of file mioForm.c.

112 {
113  extern char * Abc_ConvertBddToSop( Mem_Flex_t * pMan, DdManager * dd, DdNode * bFuncOn, DdNode * bFuncOnDc, int nFanins, int fAllPrimes, Vec_Str_t * vCube, int fMode );
114  DdManager * dd = pGate->pLib->dd;
115  char * pPinNames[100];
116  char * pPinNamesCopy[100];
117  Mio_Pin_t * pPin, ** ppPin;
118  int nPins, iPin, i;
119 
120  // set the maximum delay of the gate; count pins
121  pGate->dDelayMax = 0.0;
122  nPins = 0;
123  Mio_GateForEachPin( pGate, pPin )
124  {
125  // set the maximum delay of the gate
126  if ( pGate->dDelayMax < pPin->dDelayBlockMax )
127  pGate->dDelayMax = pPin->dDelayBlockMax;
128  // count the pin
129  nPins++;
130  }
131 
132  // check for the gate with const function
133  if ( nPins == 0 )
134  {
135  if ( strcmp( pGate->pForm, MIO_STRING_CONST0 ) == 0 )
136  {
137  pGate->bFunc = b0;
138  pGate->pSop = Mio_SopRegister( (Mem_Flex_t *)pGate->pLib->pMmFlex, " 0\n" );
139  pGate->pLib->pGate0 = pGate;
140  }
141  else if ( strcmp( pGate->pForm, MIO_STRING_CONST1 ) == 0 )
142  {
143  pGate->bFunc = b1;
144  pGate->pSop = Mio_SopRegister( (Mem_Flex_t *)pGate->pLib->pMmFlex, " 1\n" );
145  pGate->pLib->pGate1 = pGate;
146  }
147  else
148  {
149  printf( "Cannot parse formula \"%s\" of gate \"%s\".\n", pGate->pForm, pGate->pName );
150  return 1;
151  }
152  Cudd_Ref( pGate->bFunc );
153  return 0;
154  }
155 
156  // collect the names as they appear in the formula
157  nPins = Mio_GateCollectNames( pGate->pForm, pPinNames );
158  if ( nPins == 0 )
159  {
160  printf( "Cannot read formula \"%s\" of gate \"%s\".\n", pGate->pForm, pGate->pName );
161  return 1;
162  }
163 
164  // set the number of inputs
165  pGate->nInputs = nPins;
166 
167  // consider the case when all the pins have identical pin info
168  if ( strcmp( pGate->pPins->pName, "*" ) == 0 )
169  {
170  // get the topmost (generic) pin
171  pPin = pGate->pPins;
172  ABC_FREE( pPin->pName );
173 
174  // create individual pins from the generic pin
175  ppPin = &pPin->pNext;
176  for ( i = 1; i < nPins; i++ )
177  {
178  // get the new pin
179  *ppPin = Mio_PinDup( pPin );
180  // set its name
181  (*ppPin)->pName = pPinNames[i];
182  // prepare the next place in the list
183  ppPin = &((*ppPin)->pNext);
184  }
185  *ppPin = NULL;
186 
187  // set the name of the topmost pin
188  pPin->pName = pPinNames[0];
189  }
190  else
191  {
192  // reorder the variable names to appear the save way as the pins
193  iPin = 0;
194  Mio_GateForEachPin( pGate, pPin )
195  {
196  // find the pin with the name pPin->pName
197  for ( i = 0; i < nPins; i++ )
198  {
199  if ( pPinNames[i] && strcmp( pPinNames[i], pPin->pName ) == 0 )
200  {
201  // free pPinNames[i] because it is already available as pPin->pName
202  // setting pPinNames[i] to NULL is useful to make sure that
203  // this name is not assigned to two pins in the list
204  ABC_FREE( pPinNames[i] );
205  pPinNamesCopy[iPin++] = pPin->pName;
206  break;
207  }
208  if ( i == nPins )
209  {
210  printf( "Cannot find pin name \"%s\" in the formula \"%s\" of gate \"%s\".\n",
211  pPin->pName, pGate->pForm, pGate->pName );
212  return 1;
213  }
214  }
215  }
216 
217  // check for the remaining names
218  for ( i = 0; i < nPins; i++ )
219  if ( pPinNames[i] )
220  {
221  printf( "Name \"%s\" appears in the formula \"%s\" of gate \"%s\" but there is no such pin.\n",
222  pPinNames[i], pGate->pForm, pGate->pName );
223  return 1;
224  }
225 
226  // copy the names back
227  memcpy( pPinNames, pPinNamesCopy, nPins * sizeof(char *) );
228  }
229 
230  // expand the manager if necessary
231  if ( dd->size < nPins )
232  {
233  Cudd_Quit( dd );
234  dd = Cudd_Init( nPins + 10, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 );
235  Cudd_zddVarsFromBddVars( dd, 2 );
236  }
237 
238  // derive the formula as the BDD
239  pGate->bFunc = Parse_FormulaParser( stdout, pGate->pForm, nPins, 0, pPinNames, dd, dd->vars );
240  if ( pGate->bFunc == NULL )
241  return 1;
242  Cudd_Ref( pGate->bFunc );
243 
244  // derive the cover (SOP)
245  pGate->pSop = Abc_ConvertBddToSop( pGate->pLib->pMmFlex, dd, pGate->bFunc, pGate->bFunc, nPins, 0, pGate->pLib->vCube, -1 );
246 
247  // derive the truth table
248  if ( pGate->nInputs <= 6 )
249  pGate->uTruth = Mio_DeriveTruthTable6( pGate );
250 
251  return 0;
252 }
char * pName
Definition: mioInt.h:82
Mio_Pin_t * pNext
Definition: mioInt.h:114
#define CUDD_UNIQUE_SLOTS
Definition: cudd.h:97
Definition: cudd.h:278
double dDelayBlockMax
Definition: mioInt.h:113
#define Mio_GateForEachPin(Gate, Pin)
Definition: mio.h:76
int size
Definition: cuddInt.h:361
#define b1
Definition: extraBdd.h:76
char * pSop
Definition: mioInt.h:96
Mem_Flex_t * pMmFlex
Definition: mioInt.h:75
Mio_Library_t * pLib
Definition: mioInt.h:88
#define CUDD_CACHE_SLOTS
Definition: cudd.h:98
char * memcpy()
word Mio_DeriveTruthTable6(Mio_Gate_t *pGate)
Definition: mioUtils.c:514
Mio_Gate_t * pGate0
Definition: mioInt.h:68
char * pName
Definition: mioInt.h:105
Mio_Pin_t * pPins
Definition: mioInt.h:85
int strcmp()
ABC_NAMESPACE_HEADER_START DdNode * Parse_FormulaParser(FILE *pOutput, char *pFormula, int nVars, int nRanks, char *ppVarNames[], DdManager *dd, DdNode *pbVars[])
INCLUDES ///.
Definition: parseCore.c:116
static int Mio_GateCollectNames(char *pFormula, char *pPinNames[])
Definition: mioForm.c:265
char * pForm
Definition: mioInt.h:84
char * Abc_ConvertBddToSop(Mem_Flex_t *pMan, DdManager *dd, DdNode *bFuncOn, DdNode *bFuncOnDc, int nFanins, int fAllPrimes, Vec_Str_t *vCube, int fMode)
Definition: abcFunc.c:209
DdManager * Cudd_Init(unsigned int numVars, unsigned int numVarsZ, unsigned int numSlots, unsigned int cacheSize, unsigned long maxMemory)
Definition: cuddInit.c:125
Vec_Str_t * vCube
Definition: mioInt.h:76
Mio_Pin_t * Mio_PinDup(Mio_Pin_t *pPin)
Definition: mioUtils.c:125
double dDelayMax
Definition: mioInt.h:95
#define b0
Definition: extraBdd.h:75
#define ABC_FREE(obj)
Definition: abc_global.h:232
DdNode ** vars
Definition: cuddInt.h:390
char * Mio_SopRegister(Mem_Flex_t *pMan, char *pName)
Definition: mioForm.c:91
int Cudd_zddVarsFromBddVars(DdManager *dd, int multiplicity)
Definition: cuddAPI.c:519
void Cudd_Quit(DdManager *unique)
Definition: cuddInit.c:225
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
#define MIO_STRING_CONST1
Definition: mioInt.h:51
#define MIO_STRING_CONST0
Definition: mioInt.h:50
Mio_Gate_t * pGate1
Definition: mioInt.h:69
int Mio_LibraryParseFormulas ( Mio_Library_t pLib)

FUNCTION DEFINITIONS ///.

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

Synopsis [Deriving the functionality of the gates.]

Description []

SideEffects []

SeeAlso []

Definition at line 58 of file mioForm.c.

59 {
60  Mio_Gate_t * pGate;
61 
62  // count the gates
63  pLib->nGates = 0;
64  Mio_LibraryForEachGate( pLib, pGate )
65  pLib->nGates++;
66 
67  // start a temporary BDD manager
68  pLib->dd = Cudd_Init( 20, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 );
69  // introduce ZDD variables
70  Cudd_zddVarsFromBddVars( pLib->dd, 2 );
71 
72  // for each gate, derive its function
73  Mio_LibraryForEachGate( pLib, pGate )
74  if ( Mio_GateParseFormula( pGate ) )
75  return 1;
76  return 0;
77 }
#define CUDD_UNIQUE_SLOTS
Definition: cudd.h:97
#define CUDD_CACHE_SLOTS
Definition: cudd.h:98
static int Mio_GateParseFormula(Mio_Gate_t *pGate)
Definition: mioForm.c:111
DdManager * Cudd_Init(unsigned int numVars, unsigned int numVarsZ, unsigned int numSlots, unsigned int cacheSize, unsigned long maxMemory)
Definition: cuddInit.c:125
if(last==0)
Definition: sparse_int.h:34
int Cudd_zddVarsFromBddVars(DdManager *dd, int multiplicity)
Definition: cuddAPI.c:519
#define Mio_LibraryForEachGate(Lib, Gate)
GLOBAL VARIABLES ///.
Definition: mio.h:65
char* Mio_SopRegister ( Mem_Flex_t pMan,
char *  pName 
)

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

Synopsis [Registers the cube string with the network.]

Description []

SideEffects []

SeeAlso []

Definition at line 91 of file mioForm.c.

92 {
93  char * pRegName;
94  if ( pName == NULL ) return NULL;
95  pRegName = Mem_FlexEntryFetch( pMan, strlen(pName) + 1 );
96  strcpy( pRegName, pName );
97  return pRegName;
98 }
char * Mem_FlexEntryFetch(Mem_Flex_t *p, int nBytes)
Definition: mem.c:372
char * strcpy()
int strlen()