abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mioFunc.c File Reference
#include "mioInt.h"
#include "exp.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

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

Macro Definition Documentation

#define MIO_SYMB_AFTNOT   '\''

Definition at line 37 of file mioFunc.c.

#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.

#define MIO_SYMB_AND2   '&'

Definition at line 32 of file mioFunc.c.

#define MIO_SYMB_CLOSE   ')'

Definition at line 39 of file mioFunc.c.

#define MIO_SYMB_NOT   '!'

Definition at line 36 of file mioFunc.c.

#define MIO_SYMB_OPEN   '('

Definition at line 38 of file mioFunc.c.

#define MIO_SYMB_OR   '+'

Definition at line 33 of file mioFunc.c.

#define MIO_SYMB_OR2   '|'

Definition at line 34 of file mioFunc.c.

#define MIO_SYMB_XOR   '^'

Definition at line 35 of file mioFunc.c.

Function Documentation

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[1000];
79  char * pTemp;
80  int nPins, i;
81 
82  // save the formula as it was
83  strcpy( Buffer, pFormula );
84 
85  // remove the non-name symbols
86  for ( pTemp = Buffer; *pTemp; pTemp++ )
87  if ( *pTemp == MIO_SYMB_AND || *pTemp == MIO_SYMB_AND2 ||
88  *pTemp == MIO_SYMB_OR || *pTemp == MIO_SYMB_OR2 ||
89  *pTemp == MIO_SYMB_XOR ||
90  *pTemp == MIO_SYMB_NOT || *pTemp == MIO_SYMB_AFTNOT ||
91  *pTemp == MIO_SYMB_OPEN || *pTemp == MIO_SYMB_CLOSE )
92  *pTemp = ' ';
93 
94  // save the names
95  nPins = 0;
96  pTemp = strtok( Buffer, " " );
97  while ( pTemp )
98  {
99  for ( i = 0; i < nPins; i++ )
100  if ( strcmp( pTemp, pPinNames[i] ) == 0 )
101  break;
102  if ( i == nPins )
103  { // cannot find this name; save it
104  pPinNames[nPins++] = Abc_UtilStrsav(pTemp);
105  }
106  // get the next name
107  pTemp = strtok( NULL, " " );
108  }
109  return nPins;
110 }
#define MIO_SYMB_OR2
Definition: mioFunc.c:34
#define MIO_SYMB_CLOSE
Definition: mioFunc.c:39
char * strtok()
#define MIO_SYMB_XOR
Definition: mioFunc.c:35
#define MIO_SYMB_OR
Definition: mioFunc.c:33
int strcmp()
#define MIO_SYMB_OPEN
Definition: mioFunc.c:38
#define MIO_SYMB_AND2
Definition: mioFunc.c:32
#define MIO_SYMB_AFTNOT
Definition: mioFunc.c:37
#define MIO_SYMB_NOT
Definition: mioFunc.c:36
char * strcpy()
#define MIO_SYMB_AND
DECLARATIONS ///.
Definition: mioFunc.c:31
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
int Mio_GateParseFormula ( Mio_Gate_t pGate)

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

Synopsis [Deriving the functionality of the gates.]

Description []

SideEffects []

SeeAlso []

Definition at line 123 of file mioFunc.c.

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

FUNCTION DEFINITIONS ///.

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

Synopsis [Deriving the functionality of the gates.]

Description []

SideEffects []

SeeAlso []

Definition at line 298 of file mioFunc.c.

299 {
300  Mio_Gate_t * pGate;
301 
302  // count the gates
303  pLib->nGates = 0;
304  Mio_LibraryForEachGate( pLib, pGate )
305  pLib->nGates++;
306 
307  // for each gate, derive its function
308  Mio_LibraryForEachGate( pLib, pGate )
309  if ( Mio_GateParseFormula( pGate ) )
310  return 1;
311  return 0;
312 }
int Mio_GateParseFormula(Mio_Gate_t *pGate)
Definition: mioFunc.c:123
if(last==0)
Definition: sparse_int.h:34
#define Mio_LibraryForEachGate(Lib, Gate)
GLOBAL VARIABLES ///.
Definition: mio.h:65
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:372
char * strcpy()
int strlen()