#include "mioInt.h"
#include "parse.h"
Go to the source code of this file.
Defines | |
#define | MIO_SYMB_AND '*' |
#define | MIO_SYMB_OR '+' |
#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) |
#define MIO_SYMB_AND '*' |
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 [
] DECLARATIONS ///
int Mio_GateCollectNames | ( | char * | pFormula, | |
char * | pPinNames[] | |||
) | [static] |
Function*************************************************************
Synopsis [Collect the pin names in the formula.]
Description []
SideEffects []
SeeAlso []
Definition at line 231 of file mioFunc.c.
00232 { 00233 char Buffer[1000]; 00234 char * pTemp; 00235 int nPins, i; 00236 00237 // save the formula as it was 00238 strcpy( Buffer, pFormula ); 00239 00240 // remove the non-name symbols 00241 for ( pTemp = Buffer; *pTemp; pTemp++ ) 00242 if ( *pTemp == MIO_SYMB_AND || *pTemp == MIO_SYMB_OR || *pTemp == MIO_SYMB_NOT 00243 || *pTemp == MIO_SYMB_OPEN || *pTemp == MIO_SYMB_CLOSE || *pTemp == MIO_SYMB_AFTNOT ) 00244 *pTemp = ' '; 00245 00246 // save the names 00247 nPins = 0; 00248 pTemp = strtok( Buffer, " " ); 00249 while ( pTemp ) 00250 { 00251 for ( i = 0; i < nPins; i++ ) 00252 if ( strcmp( pTemp, pPinNames[i] ) == 0 ) 00253 break; 00254 if ( i == nPins ) 00255 { // cannot find this name; save it 00256 pPinNames[nPins++] = Extra_UtilStrsav(pTemp); 00257 } 00258 // get the next name 00259 pTemp = strtok( NULL, " " ); 00260 } 00261 return nPins; 00262 }
int Mio_GateParseFormula | ( | Mio_Gate_t * | pGate | ) | [static] |
Function*************************************************************
Synopsis [Deriving the functionality of the gates.]
Description []
SideEffects []
SeeAlso []
Definition at line 85 of file mioFunc.c.
00086 { 00087 DdManager * dd = pGate->pLib->dd; 00088 char * pPinNames[100]; 00089 char * pPinNamesCopy[100]; 00090 Mio_Pin_t * pPin, ** ppPin; 00091 int nPins, iPin, i; 00092 00093 // set the maximum delay of the gate; count pins 00094 pGate->dDelayMax = 0.0; 00095 nPins = 0; 00096 Mio_GateForEachPin( pGate, pPin ) 00097 { 00098 // set the maximum delay of the gate 00099 if ( pGate->dDelayMax < pPin->dDelayBlockMax ) 00100 pGate->dDelayMax = pPin->dDelayBlockMax; 00101 // count the pin 00102 nPins++; 00103 } 00104 00105 // check for the gate with const function 00106 if ( nPins == 0 ) 00107 { 00108 if ( strcmp( pGate->pForm, MIO_STRING_CONST0 ) == 0 ) 00109 { 00110 pGate->bFunc = b0; 00111 pGate->pSop = Abc_SopRegister( pGate->pLib->pMmFlex, " 0\n" ); 00112 pGate->pLib->pGate0 = pGate; 00113 } 00114 else if ( strcmp( pGate->pForm, MIO_STRING_CONST1 ) == 0 ) 00115 { 00116 pGate->bFunc = b1; 00117 pGate->pSop = Abc_SopRegister( pGate->pLib->pMmFlex, " 1\n" ); 00118 pGate->pLib->pGate1 = pGate; 00119 } 00120 else 00121 { 00122 printf( "Cannot parse formula \"%s\" of gate \"%s\".\n", pGate->pForm, pGate->pName ); 00123 return 1; 00124 } 00125 Cudd_Ref( pGate->bFunc ); 00126 return 0; 00127 } 00128 00129 // collect the names as they appear in the formula 00130 nPins = Mio_GateCollectNames( pGate->pForm, pPinNames ); 00131 if ( nPins == 0 ) 00132 { 00133 printf( "Cannot read formula \"%s\" of gate \"%s\".\n", pGate->pForm, pGate->pName ); 00134 return 1; 00135 } 00136 00137 // set the number of inputs 00138 pGate->nInputs = nPins; 00139 00140 // consider the case when all the pins have identical pin info 00141 if ( strcmp( pGate->pPins->pName, "*" ) == 0 ) 00142 { 00143 // get the topmost (generic) pin 00144 pPin = pGate->pPins; 00145 FREE( pPin->pName ); 00146 00147 // create individual pins from the generic pin 00148 ppPin = &pPin->pNext; 00149 for ( i = 1; i < nPins; i++ ) 00150 { 00151 // get the new pin 00152 *ppPin = Mio_PinDup( pPin ); 00153 // set its name 00154 (*ppPin)->pName = pPinNames[i]; 00155 // prepare the next place in the list 00156 ppPin = &((*ppPin)->pNext); 00157 } 00158 *ppPin = NULL; 00159 00160 // set the name of the topmost pin 00161 pPin->pName = pPinNames[0]; 00162 } 00163 else 00164 { 00165 // reorder the variable names to appear the save way as the pins 00166 iPin = 0; 00167 Mio_GateForEachPin( pGate, pPin ) 00168 { 00169 // find the pin with the name pPin->pName 00170 for ( i = 0; i < nPins; i++ ) 00171 { 00172 if ( pPinNames[i] && strcmp( pPinNames[i], pPin->pName ) == 0 ) 00173 { 00174 // free pPinNames[i] because it is already available as pPin->pName 00175 // setting pPinNames[i] to NULL is useful to make sure that 00176 // this name is not assigned to two pins in the list 00177 FREE( pPinNames[i] ); 00178 pPinNamesCopy[iPin++] = pPin->pName; 00179 break; 00180 } 00181 if ( i == nPins ) 00182 { 00183 printf( "Cannot find pin name \"%s\" in the formula \"%s\" of gate \"%s\".\n", 00184 pPin->pName, pGate->pForm, pGate->pName ); 00185 return 1; 00186 } 00187 } 00188 } 00189 00190 // check for the remaining names 00191 for ( i = 0; i < nPins; i++ ) 00192 if ( pPinNames[i] ) 00193 { 00194 printf( "Name \"%s\" appears in the formula \"%s\" of gate \"%s\" but there is no such pin.\n", 00195 pPinNames[i], pGate->pForm, pGate->pName ); 00196 return 1; 00197 } 00198 00199 // copy the names back 00200 memcpy( pPinNames, pPinNamesCopy, nPins * sizeof(char *) ); 00201 } 00202 00203 // expand the manager if necessary 00204 if ( dd->size < nPins ) 00205 { 00206 Cudd_Quit( dd ); 00207 dd = Cudd_Init( nPins + 10, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 ); 00208 Cudd_zddVarsFromBddVars( dd, 2 ); 00209 } 00210 00211 // derive the formula as the BDD 00212 pGate->bFunc = Parse_FormulaParser( stdout, pGate->pForm, nPins, 0, pPinNames, dd, dd->vars ); 00213 Cudd_Ref( pGate->bFunc ); 00214 00215 // derive the cover (SOP) 00216 pGate->pSop = Abc_ConvertBddToSop( pGate->pLib->pMmFlex, dd, pGate->bFunc, pGate->bFunc, nPins, 0, pGate->pLib->vCube, -1 ); 00217 return 0; 00218 }
int Mio_LibraryParseFormulas | ( | Mio_Library_t * | pLib | ) |
FUNCTION DEFINITIONS ///Function*************************************************************
Synopsis [Deriving the functionality of the gates.]
Description []
SideEffects []
SeeAlso []
Definition at line 52 of file mioFunc.c.
00053 { 00054 Mio_Gate_t * pGate; 00055 00056 // count the gates 00057 pLib->nGates = 0; 00058 Mio_LibraryForEachGate( pLib, pGate ) 00059 pLib->nGates++; 00060 00061 // start a temporary BDD manager 00062 pLib->dd = Cudd_Init( 20, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 ); 00063 // introduce ZDD variables 00064 Cudd_zddVarsFromBddVars( pLib->dd, 2 ); 00065 00066 // for each gate, derive its function 00067 Mio_LibraryForEachGate( pLib, pGate ) 00068 if ( Mio_GateParseFormula( pGate ) ) 00069 return 1; 00070 return 0; 00071 }