Commit ffd77ffe by Alan Mishchenko

Improvements to word-level Verilog parser.

parent 43ee0cff
...@@ -42,8 +42,8 @@ ABC_NAMESPACE_HEADER_START ...@@ -42,8 +42,8 @@ ABC_NAMESPACE_HEADER_START
// object types // object types
typedef enum { typedef enum {
WLC_OBJ_NONE = 0, // 00: unknown WLC_OBJ_NONE = 0, // 00: unknown
WLC_OBJ_PI, // 01: primary input terminal WLC_OBJ_PI, // 01: primary input
WLC_OBJ_PO, // 02: primary output terminal WLC_OBJ_PO, // 02: primary output
WLC_OBJ_BO, // 03: box output WLC_OBJ_BO, // 03: box output
WLC_OBJ_BI, // 04: box input WLC_OBJ_BI, // 04: box input
WLC_OBJ_FF, // 05: flop WLC_OBJ_FF, // 05: flop
...@@ -54,34 +54,37 @@ typedef enum { ...@@ -54,34 +54,37 @@ typedef enum {
WLC_OBJ_SHIFT_RA, // 10: shift right (arithmetic) WLC_OBJ_SHIFT_RA, // 10: shift right (arithmetic)
WLC_OBJ_SHIFT_L, // 11: shift left WLC_OBJ_SHIFT_L, // 11: shift left
WLC_OBJ_SHIFT_LA, // 12: shift left (arithmetic) WLC_OBJ_SHIFT_LA, // 12: shift left (arithmetic)
WLC_OBJ_BIT_NOT, // 13: bitwise NOT WLC_OBJ_ROTATE_R, // 13: rotate right
WLC_OBJ_BIT_AND, // 14: bitwise AND WLC_OBJ_ROTATE_L, // 14: rotate left
WLC_OBJ_BIT_OR, // 15: bitwise OR WLC_OBJ_BIT_NOT, // 15: bitwise NOT
WLC_OBJ_BIT_XOR, // 16: bitwise XOR WLC_OBJ_BIT_AND, // 16: bitwise AND
WLC_OBJ_BIT_SELECT, // 17: bit selection WLC_OBJ_BIT_OR, // 17: bitwise OR
WLC_OBJ_BIT_CONCAT, // 18: bit concatenation WLC_OBJ_BIT_XOR, // 18: bitwise XOR
WLC_OBJ_BIT_ZEROPAD, // 19: zero padding WLC_OBJ_BIT_SELECT, // 19: bit selection
WLC_OBJ_BIT_SIGNEXT, // 20: sign extension WLC_OBJ_BIT_CONCAT, // 20: bit concatenation
WLC_OBJ_LOGIC_NOT, // 21: logic NOT WLC_OBJ_BIT_ZEROPAD, // 21: zero padding
WLC_OBJ_LOGIC_AND, // 22: logic AND WLC_OBJ_BIT_SIGNEXT, // 22: sign extension
WLC_OBJ_LOGIC_OR, // 23: logic OR WLC_OBJ_LOGIC_NOT, // 23: logic NOT
WLC_OBJ_COMP_EQU, // 24: compare equal WLC_OBJ_LOGIC_AND, // 24: logic AND
WLC_OBJ_COMP_NOT, // 25: compare not equal WLC_OBJ_LOGIC_OR, // 25: logic OR
WLC_OBJ_COMP_LESS, // 26: compare less WLC_OBJ_COMP_EQU, // 26: compare equal
WLC_OBJ_COMP_MORE, // 27: compare more WLC_OBJ_COMP_NOTEQU, // 27: compare not equal
WLC_OBJ_COMP_LESSEQU, // 28: compare less or equal WLC_OBJ_COMP_LESS, // 28: compare less
WLC_OBJ_COMP_MOREEQU, // 29: compare more or equal WLC_OBJ_COMP_MORE, // 29: compare more
WLC_OBJ_REDUCT_AND, // 30: reduction AND WLC_OBJ_COMP_LESSEQU, // 30: compare less or equal
WLC_OBJ_REDUCT_OR, // 31: reduction OR WLC_OBJ_COMP_MOREEQU, // 31: compare more or equal
WLC_OBJ_REDUCT_XOR, // 32: reduction XOR WLC_OBJ_REDUCT_AND, // 32: reduction AND
WLC_OBJ_ARI_ADD, // 33: arithmetic addition WLC_OBJ_REDUCT_OR, // 33: reduction OR
WLC_OBJ_ARI_SUB, // 34: arithmetic subtraction WLC_OBJ_REDUCT_XOR, // 34: reduction XOR
WLC_OBJ_ARI_MULTI, // 35: arithmetic multiplier WLC_OBJ_ARI_ADD, // 35: arithmetic addition
WLC_OBJ_ARI_DIVIDE, // 36: arithmetic division WLC_OBJ_ARI_SUB, // 36: arithmetic subtraction
WLC_OBJ_ARI_MODULUS, // 37: arithmetic modulus WLC_OBJ_ARI_MULTI, // 37: arithmetic multiplier
WLC_OBJ_ARI_POWER, // 38: arithmetic power WLC_OBJ_ARI_DIVIDE, // 38: arithmetic division
WLC_OBJ_TABLE, // 39: arithmetic power WLC_OBJ_ARI_MODULUS, // 39: arithmetic modulus
WLC_OBJ_NUMBER // 40: unused WLC_OBJ_ARI_POWER, // 40: arithmetic power
WLC_OBJ_ARI_MINUS, // 41: arithmetic minus
WLC_OBJ_TABLE, // 42: bit table
WLC_OBJ_NUMBER // 43: unused
} Wlc_ObjType_t; } Wlc_ObjType_t;
...@@ -89,9 +92,7 @@ typedef enum { ...@@ -89,9 +92,7 @@ typedef enum {
/// BASIC TYPES /// /// BASIC TYPES ///
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
typedef struct Wlc_Ntk_t_ Wlc_Ntk_t;
typedef struct Wlc_Obj_t_ Wlc_Obj_t; typedef struct Wlc_Obj_t_ Wlc_Obj_t;
struct Wlc_Obj_t_ // 16 bytes struct Wlc_Obj_t_ // 16 bytes
{ {
unsigned Type : 6; // node type unsigned Type : 6; // node type
...@@ -104,6 +105,7 @@ struct Wlc_Obj_t_ // 16 bytes ...@@ -104,6 +105,7 @@ struct Wlc_Obj_t_ // 16 bytes
int * pFanins[1]; }; int * pFanins[1]; };
}; };
typedef struct Wlc_Ntk_t_ Wlc_Ntk_t;
struct Wlc_Ntk_t_ struct Wlc_Ntk_t_
{ {
char * pName; // model name char * pName; // model name
...@@ -163,6 +165,7 @@ static inline int Wlc_ObjRangeEnd( Wlc_Obj_t * p ) ...@@ -163,6 +165,7 @@ static inline int Wlc_ObjRangeEnd( Wlc_Obj_t * p )
static inline int Wlc_ObjRangeBeg( Wlc_Obj_t * p ) { assert(p->Type == WLC_OBJ_BIT_SELECT); return p->Fanins[1] & 0xFFFF; } static inline int Wlc_ObjRangeBeg( Wlc_Obj_t * p ) { assert(p->Type == WLC_OBJ_BIT_SELECT); return p->Fanins[1] & 0xFFFF; }
static inline int * Wlc_ObjConstValue( Wlc_Obj_t * p ) { assert(p->Type == WLC_OBJ_CONST); return Wlc_ObjFanins(p); } static inline int * Wlc_ObjConstValue( Wlc_Obj_t * p ) { assert(p->Type == WLC_OBJ_CONST); return Wlc_ObjFanins(p); }
static inline int Wlc_ObjTableId( Wlc_Obj_t * p ) { assert(p->Type == WLC_OBJ_TABLE); return p->Fanins[1]; } static inline int Wlc_ObjTableId( Wlc_Obj_t * p ) { assert(p->Type == WLC_OBJ_TABLE); return p->Fanins[1]; }
static inline word * Wlc_ObjTable( Wlc_Ntk_t * p, Wlc_Obj_t * pObj ) { return (word *)Vec_PtrEntry( p->vTables, Wlc_ObjTableId(pObj) ); }
static inline void Wlc_NtkCleanCopy( Wlc_Ntk_t * p ) { Vec_IntFill( &p->vCopies, p->nObjsAlloc, 0 ); } static inline void Wlc_NtkCleanCopy( Wlc_Ntk_t * p ) { Vec_IntFill( &p->vCopies, p->nObjsAlloc, 0 ); }
static inline int Wlc_NtkHasCopy( Wlc_Ntk_t * p ) { return Vec_IntSize( &p->vCopies ) > 0; } static inline int Wlc_NtkHasCopy( Wlc_Ntk_t * p ) { return Vec_IntSize( &p->vCopies ) > 0; }
......
...@@ -42,34 +42,37 @@ static char * Wlc_Names[WLC_OBJ_NUMBER+1] = { ...@@ -42,34 +42,37 @@ static char * Wlc_Names[WLC_OBJ_NUMBER+1] = {
">>>", // 10: shift right (arithmetic) ">>>", // 10: shift right (arithmetic)
"<<", // 11: shift left "<<", // 11: shift left
"<<<", // 12: shift left (arithmetic) "<<<", // 12: shift left (arithmetic)
"~", // 13: bitwise NOT "rotateR", // 13: shift left (arithmetic)
"&", // 14: bitwise AND "rotateL", // 14: shift left (arithmetic)
"|", // 15: bitwise OR "~", // 15: bitwise NOT
"^", // 16: bitwise XOR "&", // 16: bitwise AND
"[:]", // 17: bit selection "|", // 17: bitwise OR
"{,}", // 18: bit concatenation "^", // 18: bitwise XOR
"BitPad", // 19: zero padding "[:]", // 19: bit selection
"SgnExt", // 20: sign extension "{,}", // 20: bit concatenation
"!", // 21: logic NOT "bitPad", // 21: zero padding
"&&", // 22: logic AND "signExtend", // 22: sign extension
"||", // 23: logic OR "!", // 23: logic NOT
"==", // 24: compare equal "&&", // 24: logic AND
"!=", // 25: compare not equal "||", // 25: logic OR
"<", // 26: compare less "==", // 26: compare equal
">", // 27: compare more "!=", // 27: compare not equal
"<=", // 28: compare less or equal "<", // 28: compare less
">=", // 29: compare more or equal ">", // 29: compare more
"&", // 30: reduction AND "<=", // 30: compare less or equal
"|", // 31: reduction OR ">=", // 31: compare more or equal
"^", // 32: reduction XOR "&", // 32: reduction AND
"+", // 33: arithmetic addition "|", // 33: reduction OR
"-", // 34: arithmetic subtraction "^", // 34: reduction XOR
"*", // 35: arithmetic multiplier "+", // 35: arithmetic addition
"//", // 36: arithmetic division "-", // 36: arithmetic subtraction
"%%", // 37: arithmetic modulus "*", // 37: arithmetic multiplier
"**", // 38: arithmetic power "//", // 38: arithmetic division
"table", // 39: lookup table "%%", // 39: arithmetic modulus
NULL // 40: unused "**", // 40: arithmetic power
"-", // 41: arithmetic minus
"table", // 42: bit table
NULL // 43: unused
}; };
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
......
...@@ -409,6 +409,7 @@ static inline char * Wlc_PrsReadConstant( Wlc_Prs_t * p, char * pStr, Vec_Int_t ...@@ -409,6 +409,7 @@ static inline char * Wlc_PrsReadConstant( Wlc_Prs_t * p, char * pStr, Vec_Int_t
*pRange = Abc_Base2Log( Number ); *pRange = Abc_Base2Log( Number );
while ( Wlc_PrsIsDigit(pStr) ) while ( Wlc_PrsIsDigit(pStr) )
pStr++; pStr++;
Vec_IntFill( vFanins, 1, Number );
return pStr; return pStr;
} }
pStr = Wlc_PrsFindSymbol( pStr, '\'' ); pStr = Wlc_PrsFindSymbol( pStr, '\'' );
...@@ -424,7 +425,7 @@ static inline char * Wlc_PrsReadConstant( Wlc_Prs_t * p, char * pStr, Vec_Int_t ...@@ -424,7 +425,7 @@ static inline char * Wlc_PrsReadConstant( Wlc_Prs_t * p, char * pStr, Vec_Int_t
if ( nDigits != (nBits + 3)/4 ) if ( nDigits != (nBits + 3)/4 )
{ {
// return (char *)(ABC_PTRINT_T)Wlc_PrsWriteErrorMessage( p, pStr, "The length of a constant does not match." ); // return (char *)(ABC_PTRINT_T)Wlc_PrsWriteErrorMessage( p, pStr, "The length of a constant does not match." );
printf( "Warning: The length of a constant (%d hex digits) does not match the number of bits (%d).\n", nDigits, nBits ); // printf( "Warning: The length of a constant (%d hex digits) does not match the number of bits (%d).\n", nDigits, nBits );
} }
*pRange = nBits; *pRange = nBits;
pStr += 2; pStr += 2;
...@@ -452,7 +453,7 @@ static inline char * Wlc_PrsReadName( Wlc_Prs_t * p, char * pStr, Vec_Int_t * vF ...@@ -452,7 +453,7 @@ static inline char * Wlc_PrsReadName( Wlc_Prs_t * p, char * pStr, Vec_Int_t * vF
Wlc_ObjAddFanins( p->pNtk, Wlc_NtkObj(p->pNtk, iObj), vFanins ); Wlc_ObjAddFanins( p->pNtk, Wlc_NtkObj(p->pNtk, iObj), vFanins );
Vec_IntFree( vFanins ); Vec_IntFree( vFanins );
// add node's name // add node's name
sprintf( Buffer, "const%d", p->nConsts++ ); sprintf( Buffer, "_c%d_", p->nConsts++ );
NameId = Abc_NamStrFindOrAdd( p->pNtk->pManName, Buffer, &fFound ); NameId = Abc_NamStrFindOrAdd( p->pNtk->pManName, Buffer, &fFound );
if ( fFound ) if ( fFound )
return (char *)(ABC_PTRINT_T)Wlc_PrsWriteErrorMessage( p, pStr, "Name %s is already used.", Buffer ); return (char *)(ABC_PTRINT_T)Wlc_PrsWriteErrorMessage( p, pStr, "Name %s is already used.", Buffer );
...@@ -530,7 +531,7 @@ static inline int Wlc_PrsFindDefinition( Wlc_Prs_t * p, char * pStr, Vec_Int_t * ...@@ -530,7 +531,7 @@ static inline int Wlc_PrsFindDefinition( Wlc_Prs_t * p, char * pStr, Vec_Int_t *
if ( !(pStr = Wlc_PrsReadName(p, pStr, vFanins)) ) if ( !(pStr = Wlc_PrsReadName(p, pStr, vFanins)) )
return Wlc_PrsWriteErrorMessage( p, pStr, "Cannot read name after !." ); return Wlc_PrsWriteErrorMessage( p, pStr, "Cannot read name after !." );
} }
else if ( pStr[0] == '&' || pStr[0] == '|' || pStr[0] == '^' ) else if ( pStr[0] == '&' || pStr[0] == '|' || pStr[0] == '^' || pStr[0] == '-' )
{ {
if ( pStr[0] == '&' ) if ( pStr[0] == '&' )
Type = WLC_OBJ_REDUCT_AND; Type = WLC_OBJ_REDUCT_AND;
...@@ -538,9 +539,11 @@ static inline int Wlc_PrsFindDefinition( Wlc_Prs_t * p, char * pStr, Vec_Int_t * ...@@ -538,9 +539,11 @@ static inline int Wlc_PrsFindDefinition( Wlc_Prs_t * p, char * pStr, Vec_Int_t *
Type = WLC_OBJ_REDUCT_OR; Type = WLC_OBJ_REDUCT_OR;
else if ( pStr[0] == '^' ) else if ( pStr[0] == '^' )
Type = WLC_OBJ_REDUCT_XOR; Type = WLC_OBJ_REDUCT_XOR;
else if ( pStr[0] == '-' )
Type = WLC_OBJ_ARI_MINUS;
else assert( 0 ); else assert( 0 );
if ( !(pStr = Wlc_PrsReadName(p, pStr+1, vFanins)) ) if ( !(pStr = Wlc_PrsReadName(p, pStr+1, vFanins)) )
return Wlc_PrsWriteErrorMessage( p, pStr, "Cannot read name after reduction operator." ); return Wlc_PrsWriteErrorMessage( p, pStr, "Cannot read name after a unary operator." );
} }
else if ( pStr[0] == '{' ) else if ( pStr[0] == '{' )
{ {
...@@ -603,9 +606,9 @@ static inline int Wlc_PrsFindDefinition( Wlc_Prs_t * p, char * pStr, Vec_Int_t * ...@@ -603,9 +606,9 @@ static inline int Wlc_PrsFindDefinition( Wlc_Prs_t * p, char * pStr, Vec_Int_t *
} }
else else
{ {
if ( pStr[0] == '>' && pStr[1] == '>' && pStr[2] != '>' ) pStr += 2, Type = WLC_OBJ_SHIFT_R; if ( pStr[0] == '>' && pStr[1] == '>' && pStr[2] != '>' ) pStr += 2, Type = fRotating ? WLC_OBJ_ROTATE_R : WLC_OBJ_SHIFT_R;
else if ( pStr[0] == '>' && pStr[1] == '>' && pStr[2] == '>' ) pStr += 3, Type = WLC_OBJ_SHIFT_RA; else if ( pStr[0] == '>' && pStr[1] == '>' && pStr[2] == '>' ) pStr += 3, Type = WLC_OBJ_SHIFT_RA;
else if ( pStr[0] == '<' && pStr[1] == '<' && pStr[2] != '<' ) pStr += 2, Type = WLC_OBJ_SHIFT_L; else if ( pStr[0] == '<' && pStr[1] == '<' && pStr[2] != '<' ) pStr += 2, Type = fRotating ? WLC_OBJ_ROTATE_L : WLC_OBJ_SHIFT_L;
else if ( pStr[0] == '<' && pStr[1] == '<' && pStr[2] == '<' ) pStr += 3, Type = WLC_OBJ_SHIFT_LA; else if ( pStr[0] == '<' && pStr[1] == '<' && pStr[2] == '<' ) pStr += 3, Type = WLC_OBJ_SHIFT_LA;
else if ( pStr[0] == '&' && pStr[1] != '&' ) pStr += 1, Type = WLC_OBJ_BIT_AND; else if ( pStr[0] == '&' && pStr[1] != '&' ) pStr += 1, Type = WLC_OBJ_BIT_AND;
else if ( pStr[0] == '|' && pStr[1] != '|' ) pStr += 1, Type = WLC_OBJ_BIT_OR; else if ( pStr[0] == '|' && pStr[1] != '|' ) pStr += 1, Type = WLC_OBJ_BIT_OR;
...@@ -613,7 +616,7 @@ static inline int Wlc_PrsFindDefinition( Wlc_Prs_t * p, char * pStr, Vec_Int_t * ...@@ -613,7 +616,7 @@ static inline int Wlc_PrsFindDefinition( Wlc_Prs_t * p, char * pStr, Vec_Int_t *
else if ( pStr[0] == '&' && pStr[1] == '&' ) pStr += 2, Type = WLC_OBJ_LOGIC_AND; else if ( pStr[0] == '&' && pStr[1] == '&' ) pStr += 2, Type = WLC_OBJ_LOGIC_AND;
else if ( pStr[0] == '|' && pStr[1] == '|' ) pStr += 2, Type = WLC_OBJ_LOGIC_OR; else if ( pStr[0] == '|' && pStr[1] == '|' ) pStr += 2, Type = WLC_OBJ_LOGIC_OR;
else if ( pStr[0] == '=' && pStr[1] == '=' ) pStr += 2, Type = WLC_OBJ_COMP_EQU; else if ( pStr[0] == '=' && pStr[1] == '=' ) pStr += 2, Type = WLC_OBJ_COMP_EQU;
else if ( pStr[0] == '!' && pStr[1] == '=' ) pStr += 2, Type = WLC_OBJ_COMP_NOT; else if ( pStr[0] == '!' && pStr[1] == '=' ) pStr += 2, Type = WLC_OBJ_COMP_NOTEQU;
else if ( pStr[0] == '<' && pStr[1] != '=' ) pStr += 1, Type = WLC_OBJ_COMP_LESS; else if ( pStr[0] == '<' && pStr[1] != '=' ) pStr += 1, Type = WLC_OBJ_COMP_LESS;
else if ( pStr[0] == '>' && pStr[1] != '=' ) pStr += 1, Type = WLC_OBJ_COMP_MORE; else if ( pStr[0] == '>' && pStr[1] != '=' ) pStr += 1, Type = WLC_OBJ_COMP_MORE;
else if ( pStr[0] == '<' && pStr[1] == '=' ) pStr += 2, Type = WLC_OBJ_COMP_LESSEQU; else if ( pStr[0] == '<' && pStr[1] == '=' ) pStr += 2, Type = WLC_OBJ_COMP_LESSEQU;
...@@ -702,6 +705,7 @@ int Wlc_PrsDerive( Wlc_Prs_t * p ) ...@@ -702,6 +705,7 @@ int Wlc_PrsDerive( Wlc_Prs_t * p )
if ( Wlc_PrsStrCmp( pName, "table" ) ) if ( Wlc_PrsStrCmp( pName, "table" ) )
{ {
// THIS IS A HACK TO DETECT tables // THIS IS A HACK TO DETECT tables
int Width1, Width2;
int v, b, Value, nBits, nInts, * pTable; int v, b, Value, nBits, nInts, * pTable;
Vec_Int_t * vValues = Vec_IntAlloc( 256 ); Vec_Int_t * vValues = Vec_IntAlloc( 256 );
Wlc_PrsForEachLineStart( p, pStart, i, i+1 ) Wlc_PrsForEachLineStart( p, pStart, i, i+1 )
...@@ -711,9 +715,11 @@ int Wlc_PrsDerive( Wlc_Prs_t * p ) ...@@ -711,9 +715,11 @@ int Wlc_PrsDerive( Wlc_Prs_t * p )
pStart = Wlc_PrsFindSymbol( pStart, '\'' ); pStart = Wlc_PrsFindSymbol( pStart, '\'' );
if ( pStart == NULL ) if ( pStart == NULL )
continue; continue;
Width1 = atoi(pStart-1);
pStart = Wlc_PrsFindSymbol( pStart+2, '\'' ); pStart = Wlc_PrsFindSymbol( pStart+2, '\'' );
if ( pStart == NULL ) if ( pStart == NULL )
continue; continue;
Width2 = atoi(pStart-1);
Value = 0; Value = 0;
Abc_TtReadHexNumber( (word *)&Value, pStart+2 ); Abc_TtReadHexNumber( (word *)&Value, pStart+2 );
Vec_IntPush( vValues, Value ); Vec_IntPush( vValues, Value );
...@@ -725,14 +731,15 @@ int Wlc_PrsDerive( Wlc_Prs_t * p ) ...@@ -725,14 +731,15 @@ int Wlc_PrsDerive( Wlc_Prs_t * p )
Vec_IntFree( vValues ); Vec_IntFree( vValues );
return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read module \"%s\".", pName ); return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read module \"%s\".", pName );
} }
assert( Width1 == nBits );
// create bitmap // create bitmap
nInts = Abc_BitWordNum( nBits * Vec_IntSize(vValues) ); nInts = Abc_BitWordNum( Width2 * Vec_IntSize(vValues) );
pTable = (unsigned *)Mem_FlexEntryFetch( p->pMemTable, nInts * sizeof(unsigned) ); pTable = (unsigned *)Mem_FlexEntryFetch( p->pMemTable, nInts * sizeof(unsigned) );
memset( pTable, 0, nInts * sizeof(unsigned) ); memset( pTable, 0, nInts * sizeof(unsigned) );
Vec_IntForEachEntry( vValues, Value, v ) Vec_IntForEachEntry( vValues, Value, v )
for ( b = 0; b < nBits; b++ ) for ( b = 0; b < Width2; b++ )
if ( (Value >> b) & 1 ) if ( (Value >> b) & 1 )
Abc_InfoSetBit( pTable, v * nBits + b ); Abc_InfoSetBit( pTable, v * Width2 + b );
Vec_PtrPush( p->vTables, pTable ); Vec_PtrPush( p->vTables, pTable );
Vec_IntFree( vValues ); Vec_IntFree( vValues );
continue; continue;
......
...@@ -42,6 +42,60 @@ ABC_NAMESPACE_IMPL_START ...@@ -42,6 +42,60 @@ ABC_NAMESPACE_IMPL_START
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Wlc_WriteTableOne( FILE * pFile, int nFans, int nOuts, word * pTable, int Id )
{
int m, nMints = (1<<nFans);
// Abc_TtPrintHexArrayRev( stdout, pTable, nMints ); printf( "\n" );
assert( nOuts > 0 && nOuts <= 64 && (64 % nOuts) == 0 );
fprintf( pFile, "module table%d(ind, val);\n", Id );
fprintf( pFile, " input [%d:0] ind;\n", nFans-1 );
fprintf( pFile, " output [%d:0] val;\n", nOuts-1 );
fprintf( pFile, " reg [%d:0] val;\n", nOuts-1 );
fprintf( pFile, " always @(ind)\n" );
fprintf( pFile, " begin\n" );
fprintf( pFile, " case (ind)\n" );
for ( m = 0; m < nMints; m++ )
fprintf( pFile, " %d\'h%x: val = %d\'h%x;\n", nFans, m, nOuts, (pTable[(nOuts * m) >> 6] >> ((nOuts * m) & 63)) & Abc_Tt6Mask(nOuts) );
fprintf( pFile, " endcase\n" );
fprintf( pFile, " end\n" );
fprintf( pFile, "endmodule\n" );
fprintf( pFile, "\n" );
}
void Wlc_WriteTables( FILE * pFile, Wlc_Ntk_t * p )
{
Vec_Int_t * vNodes;
Wlc_Obj_t * pObj, * pFanin;
word * pTable;
int i;
if ( p->vTables == NULL || Vec_PtrSize(p->vTables) == 0 )
return;
// map tables into their nodes
vNodes = Vec_IntStart( Vec_PtrSize(p->vTables) );
Wlc_NtkForEachObj( p, pObj, i )
if ( pObj->Type == WLC_OBJ_TABLE )
Vec_IntWriteEntry( vNodes, Wlc_ObjTableId(pObj), i );
// write tables
Vec_PtrForEachEntry( word *, p->vTables, pTable, i )
{
pObj = Wlc_NtkObj( p, Vec_IntEntry(vNodes, i) );
assert( pObj->Type == WLC_OBJ_TABLE );
pFanin = Wlc_ObjFanin0( p, pObj );
Wlc_WriteTableOne( pFile, Wlc_ObjRange(pFanin), Wlc_ObjRange(pObj), pTable, i );
}
Vec_IntFree( vNodes );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Wlc_WriteVerIntVec( FILE * pFile, Wlc_Ntk_t * p, Vec_Int_t * vVec, int Start ) void Wlc_WriteVerIntVec( FILE * pFile, Wlc_Ntk_t * p, Vec_Int_t * vVec, int Start )
{ {
char * pName; char * pName;
...@@ -80,23 +134,50 @@ void Wlc_WriteVerInt( FILE * pFile, Wlc_Ntk_t * p ) ...@@ -80,23 +134,50 @@ void Wlc_WriteVerInt( FILE * pFile, Wlc_Ntk_t * p )
if ( Wlc_NtkPoNum(p) > 0 ) if ( Wlc_NtkPoNum(p) > 0 )
Wlc_WriteVerIntVec( pFile, p, &p->vPos, 3 ); Wlc_WriteVerIntVec( pFile, p, &p->vPos, 3 );
fprintf( pFile, " );\n" ); fprintf( pFile, " );\n" );
// mark fanins of rotation shifts
Wlc_NtkForEachObj( p, pObj, i )
if ( pObj->Type == WLC_OBJ_ROTATE_R || pObj->Type == WLC_OBJ_ROTATE_L )
Wlc_ObjFanin1(p, pObj)->Mark = 1;
Wlc_NtkForEachObj( p, pObj, i ) Wlc_NtkForEachObj( p, pObj, i )
{ {
char * pName = Wlc_ObjName(p, i); char * pName = Wlc_ObjName(p, i);
char * pName0 = Wlc_ObjFaninNum(pObj) ? Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) : NULL; char * pName0 = Wlc_ObjFaninNum(pObj) ? Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) : NULL;
int nDigits = Abc_Base10Log(pObj->End+1) + Abc_Base10Log(pObj->Beg+1); int nDigits = Abc_Base10Log(pObj->End+1) + Abc_Base10Log(pObj->Beg+1);
if ( pObj->Mark )
{
pObj->Mark = 0;
continue;
}
sprintf( Range, "%s[%d:%d]%*s", pObj->Signed ? "signed ":" ", pObj->End, pObj->Beg, 8-nDigits, "" ); sprintf( Range, "%s[%d:%d]%*s", pObj->Signed ? "signed ":" ", pObj->End, pObj->Beg, 8-nDigits, "" );
fprintf( pFile, " " ); fprintf( pFile, " " );
assert( pObj->Type != WLC_OBJ_TABLE );
if ( pObj->Type == WLC_OBJ_PI ) if ( pObj->Type == WLC_OBJ_PI )
fprintf( pFile, "input wire %s %-16s", Range, pName ); fprintf( pFile, "input wire %s %s", Range, pName );
else if ( pObj->Type == WLC_OBJ_PO ) else if ( pObj->Type == WLC_OBJ_PO )
fprintf( pFile, "output wire %s %-16s = %s", Range, pName, pName0 ); fprintf( pFile, "output wire %s %-16s = %s", Range, pName, pName0 );
else if ( pObj->Type == WLC_OBJ_TABLE )
{
// wire [3:0] s4972; table0 s4972_Index(s4971, s4972);
fprintf( pFile, " wire %s %s ; table%d s%d_Index(%s, %s)", Range, pName, Wlc_ObjTableId(pObj), i, pName0, pName );
}
else if ( pObj->Type == WLC_OBJ_CONST ) else if ( pObj->Type == WLC_OBJ_CONST )
{ {
fprintf( pFile, " wire %s %-16s = %d\'%sh", Range, pName, Wlc_ObjRange(pObj), pObj->Signed ? "s":"" ); fprintf( pFile, " wire %s %-16s = %d\'%sh", Range, pName, Wlc_ObjRange(pObj), pObj->Signed ? "s":"" );
Abc_TtPrintHexArrayRev( pFile, (word *)Wlc_ObjConstValue(pObj), (Wlc_ObjRange(pObj) + 3) / 4 ); Abc_TtPrintHexArrayRev( pFile, (word *)Wlc_ObjConstValue(pObj), (Wlc_ObjRange(pObj) + 3) / 4 );
} }
else if ( pObj->Type == WLC_OBJ_ROTATE_R || pObj->Type == WLC_OBJ_ROTATE_L )
{
// wire [27:0] s4960 = (s57 >> 17) | (s57 << 11);
Wlc_Obj_t * pShift = Wlc_ObjFanin1(p, pObj);
int Num0 = *Wlc_ObjConstValue(pShift);
int Num1 = Wlc_ObjRange(pObj) - Num0;
assert( pShift->Type == WLC_OBJ_CONST );
assert( Num0 > 0 && Num0 < Wlc_ObjRange(pObj) );
fprintf( pFile, " wire %s %-16s = ", Range, Wlc_ObjName(p, i) );
if ( pObj->Type == WLC_OBJ_ROTATE_R )
fprintf( pFile, "(%s >> %d) | (%s << %d)", pName0, Num0, pName0, Num1 );
else
fprintf( pFile, "(%s << %d) | (%s >> %d)", pName0, Num0, pName0, Num1 );
}
else else
{ {
fprintf( pFile, " wire %s %-16s = ", Range, Wlc_ObjName(p, i) ); fprintf( pFile, " wire %s %-16s = ", Range, Wlc_ObjName(p, i) );
...@@ -150,7 +231,7 @@ void Wlc_WriteVerInt( FILE * pFile, Wlc_Ntk_t * p ) ...@@ -150,7 +231,7 @@ void Wlc_WriteVerInt( FILE * pFile, Wlc_Ntk_t * p )
fprintf( pFile, "||" ); fprintf( pFile, "||" );
else if ( pObj->Type == WLC_OBJ_COMP_EQU ) else if ( pObj->Type == WLC_OBJ_COMP_EQU )
fprintf( pFile, "==" ); fprintf( pFile, "==" );
else if ( pObj->Type == WLC_OBJ_COMP_NOT ) else if ( pObj->Type == WLC_OBJ_COMP_NOTEQU )
fprintf( pFile, "!=" ); fprintf( pFile, "!=" );
else if ( pObj->Type == WLC_OBJ_COMP_LESS ) else if ( pObj->Type == WLC_OBJ_COMP_LESS )
fprintf( pFile, "<" ); fprintf( pFile, "<" );
...@@ -191,6 +272,7 @@ void Wlc_WriteVer( Wlc_Ntk_t * p, char * pFileName ) ...@@ -191,6 +272,7 @@ void Wlc_WriteVer( Wlc_Ntk_t * p, char * pFileName )
} }
fprintf( pFile, "// Benchmark \"%s\" written by ABC on %s\n", p->pName, Extra_TimeStamp() ); fprintf( pFile, "// Benchmark \"%s\" written by ABC on %s\n", p->pName, Extra_TimeStamp() );
fprintf( pFile, "\n" ); fprintf( pFile, "\n" );
Wlc_WriteTables( pFile, p );
Wlc_WriteVerInt( pFile, p ); Wlc_WriteVerInt( pFile, p );
fprintf( pFile, "\n" ); fprintf( pFile, "\n" );
fclose( pFile ); fclose( pFile );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment