31#define AMAP_STRING_GATE "GATE"
32#define AMAP_STRING_PIN "PIN"
33#define AMAP_STRING_NONINV "NONINV"
34#define AMAP_STRING_INV "INV"
35#define AMAP_STRING_UNKNOWN "UNKNOWN"
38#define AMAP_SYMB_AND '*'
39#define AMAP_SYMB_AND2 '&'
40#define AMAP_SYMB_OR1 '+'
41#define AMAP_SYMB_OR2 '|'
42#define AMAP_SYMB_XOR '^'
43#define AMAP_SYMB_NOT '!'
44#define AMAP_SYMB_AFTNOT '\''
45#define AMAP_SYMB_OPEN '('
46#define AMAP_SYMB_CLOSE ')'
56static inline char * Amap_ParseStrsav(
Aig_MmFlex_t *
p,
char * pStr )
82 pFile =
Io_FileOpen( pFileName,
"open_path",
"rb", 1 );
88 printf(
"Cannot open file \"%s\".\n", pFileName );
94 nFileSize = ftell( pFile );
98 pBuffer =
ABC_ALLOC(
char, nFileSize + 10 );
99 RetValue = fread( pBuffer, nFileSize, 1, pFile );
101 pBuffer[ nFileSize ] =
'\0';
102 strcat( pBuffer,
"\n.end\n" );
128 for ( pCur = pBuffer; *pCur; pCur++ )
132 if ( *pCur ==
'#' ) {
133 while ( *pCur !=
'\n' ) {
138 if ( *pCur ==
'\n' ) {
139 if (pCur > pBuffer) {
140 if (*(pCur - 1) ==
'\r') {
142 if (pCur > (pBuffer + 1)) {
143 if (*(pCur - 2)!=
'\\') {
155 if (*(pCur - 1) !=
'\\') {
166 else if ( *pCur ==
'.' ) {
192 vTokens = Vec_PtrAlloc( 1000 );
193 pToken =
strtok( pBuffer,
" =\t\r\n" );
196 Vec_PtrPush( vTokens, pToken );
197 pToken =
strtok( NULL,
" =\t\r\n" );
199 if ( pToken &&
strcmp( pToken,
"LATCH" ) == 0 )
200 while ( pToken &&
strcmp( pToken,
"GATE" ) != 0 )
201 pToken =
strtok( NULL,
" =\t\r\n" );
248 for ( pTemp = Buffer; *pTemp; pTemp++ )
255 pTemp =
strtok( Buffer,
" " );
258 for ( i = 0; i < nPins; i++ )
259 if (
strcmp( pTemp, pPinNames[i] ) == 0 )
263 pPinNames[nPins++] = Amap_ParseStrsav( pMem, pTemp );
266 pTemp =
strtok( NULL,
" " );
286 char * pPinNames[128];
290 pGate = Amap_ParseGateAlloc(
p->pLib->pMemGates, nPinNames );
292 pGate->
nPins = nPinNames;
296 pPin->
pName = pPinNames[pPin - pGate->
Pins];
314 char * pNext, * pPrev;
315 pPrev = pToken +
strlen(pToken);
316 while ( *(pPrev-1) !=
';' )
319 pNext = (
char *)Vec_PtrEntry(vTokens, iPos++);
343 char * pToken, * pMoGate = NULL;
344 int i, nPins, iPos = 0, Count = 0;
346 pToken = (
char *)Vec_PtrEntry(vTokens, iPos++);
357 pGate = Amap_ParseGateAlloc(
p->pMemGates, nPins );
359 pGate->
Id = Vec_PtrSize(
p->vGates );
360 Vec_PtrPush(
p->vGates, pGate );
362 pGate->
nPins = nPins;
364 pToken = (
char *)Vec_PtrEntry(vTokens, iPos++);
365 pGate->
pName = Amap_ParseStrsav(
p->pMemGates, pToken );
366 pToken = (
char *)Vec_PtrEntry(vTokens, iPos++);
368 pToken = (
char *)Vec_PtrEntry(vTokens, iPos++);
369 pGate->
pOutName = Amap_ParseStrsav(
p->pMemGates, pToken );
370 pToken = (
char *)Vec_PtrEntry(vTokens, iPos++);
372 pGate->
pForm = Amap_ParseStrsav(
p->pMemGates, pToken );
376 pToken = (
char *)Vec_PtrEntry(vTokens, iPos++);
380 printf(
"Cannot parse cell %s.\n", pGate->
pName );
384 pToken = (
char *)Vec_PtrEntry(vTokens, iPos++);
385 pPin->
pName = Amap_ParseStrsav(
p->pMemGates, pToken );
386 pToken = (
char *)Vec_PtrEntry(vTokens, iPos++);
396 printf(
"Cannot read phase of pin %s of cell %s\n", pPin->
pName, pGate->
pName );
399 pToken = (
char *)Vec_PtrEntry(vTokens, iPos++);
401 pToken = (
char *)Vec_PtrEntry(vTokens, iPos++);
403 pToken = (
char *)Vec_PtrEntry(vTokens, iPos++);
405 pToken = (
char *)Vec_PtrEntry(vTokens, iPos++);
407 pToken = (
char *)Vec_PtrEntry(vTokens, iPos++);
409 pToken = (
char *)Vec_PtrEntry(vTokens, iPos++);
420 Vec_PtrPop(
p->vGates );
421 Vec_PtrPush(
p->vGates, pGate );
423 pToken = (
char *)Vec_PtrEntry(vTokens, iPos++);
426 while (
strcmp( pToken,
".end" ) );
436 if ( pMoGate == NULL )
437 pMoGate = pGate->
pName;
443 printf(
"Warning: Detected %d multi-output cells (for example, \"%s\").\n", Count, pMoGate );
467 Vec_PtrFree( vTokens );
470 Vec_PtrFree( vTokens );
490 if ( pBuffer == NULL )
494 pLib->pName = Abc_UtilStrsav( pFileName );
#define ABC_ALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
char * Aig_MmFlexEntryFetch(Aig_MmFlex_t *p, int nBytes)
struct Aig_MmFlex_t_ Aig_MmFlex_t
#define Amap_GateForEachPin(pGate, pPin)
Amap_Lib_t * Amap_LibAlloc()
DECLARATIONS ///.
struct Amap_Gat_t_ Amap_Gat_t
#define Amap_LibForEachGate(pLib, pGate, i)
struct Amap_Pin_t_ Amap_Pin_t
BASIC TYPES ///.
int Amap_GateCollectNames(Aig_MmFlex_t *pMem, char *pForm, char *pPinNames[])
#define AMAP_STRING_UNKNOWN
Amap_Lib_t * Amap_LibReadFile(char *pFileName, int fVerbose)
int Amap_CollectFormulaTokens(Vec_Ptr_t *vTokens, char *pToken, int iPos)
void Amap_RemoveComments(char *pBuffer, int *pnDots, int *pnLines)
#define AMAP_STRING_NONINV
int Amap_ParseCountPins(Vec_Ptr_t *vTokens, int iPos)
#define AMAP_STRING_GATE
DECLARATIONS ///.
Amap_Lib_t * Amap_LibReadBuffer(char *pBuffer, int fVerbose)
Vec_Ptr_t * Amap_DeriveTokens(char *pBuffer)
char * Amap_LoadFile(char *pFileName)
FUNCTION DEFINITIONS ///.
Amap_Gat_t * Amap_ParseGateWithSamePins(Amap_Gat_t *p)
Amap_Lib_t * Amap_ParseTokens(Vec_Ptr_t *vTokens, int fVerbose)
typedefABC_NAMESPACE_HEADER_START struct Amap_Lib_t_ Amap_Lib_t
INCLUDES ///.
void Amap_LibFree(Amap_Lib_t *p)
FILE * Io_FileOpen(const char *FileName, const char *PathVar, const char *Mode, int fVerbose)
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.