Commit 64afe6e9 by Alan Mishchenko

Extending Verilog parser to handle 'default' in the case-statement.

parent e9abb0f4
...@@ -1033,7 +1033,7 @@ startword: ...@@ -1033,7 +1033,7 @@ startword:
else if ( Wlc_PrsStrCmp( pStart, "always" ) ) else if ( Wlc_PrsStrCmp( pStart, "always" ) )
{ {
// THIS IS A HACK to detect always statement representing combinational MUX // THIS IS A HACK to detect always statement representing combinational MUX
int NameId, NameIdOut = -1, fFound; int NameId, NameIdOut = -1, fFound, nValues, fDefaultFound = 0;
// find control // find control
pStart = Wlc_PrsFindWord( pStart, "case", &fFound ); pStart = Wlc_PrsFindWord( pStart, "case", &fFound );
if ( pStart == NULL ) if ( pStart == NULL )
...@@ -1054,6 +1054,11 @@ startword: ...@@ -1054,6 +1054,11 @@ startword:
Vec_IntClear( p->vFanins ); Vec_IntClear( p->vFanins );
Vec_IntPush( p->vFanins, NameId ); Vec_IntPush( p->vFanins, NameId );
// read data inputs // read data inputs
pObj = Wlc_NtkObj( p->pNtk, NameId );
if ( pObj == NULL )
return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot find the object in case statement." );
// remember the number of values
nValues = (1 << Wlc_ObjRange(pObj));
while ( 1 ) while ( 1 )
{ {
// find opening // find opening
...@@ -1076,6 +1081,17 @@ startword: ...@@ -1076,6 +1081,17 @@ startword:
pStart = Wlc_PrsReadName( p, pStart, p->vFanins ); pStart = Wlc_PrsReadName( p, pStart, p->vFanins );
if ( pStart == NULL ) if ( pStart == NULL )
return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read name inside case statement." ); return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read name inside case statement." );
// consider default
if ( fDefaultFound )
{
int EntryLast = Vec_IntEntryLast( p->vFanins );
Vec_IntFillExtra( p->vFanins, nValues + 1, EntryLast );
// get next line and check its opening character
pStart = Wlc_PrsStr(p, Vec_IntEntry(p->vStarts, ++i));
pStart = Wlc_PrsSkipSpaces( pStart );
}
else
{
// get next line and check its opening character // get next line and check its opening character
pStart = Wlc_PrsStr(p, Vec_IntEntry(p->vStarts, ++i)); pStart = Wlc_PrsStr(p, Vec_IntEntry(p->vStarts, ++i));
pStart = Wlc_PrsSkipSpaces( pStart ); pStart = Wlc_PrsSkipSpaces( pStart );
...@@ -1083,8 +1099,9 @@ startword: ...@@ -1083,8 +1099,9 @@ startword:
continue; continue;
if ( Wlc_PrsStrCmp( pStart, "default" ) ) if ( Wlc_PrsStrCmp( pStart, "default" ) )
{ {
printf( "Ignoring default in Line %d.\n", i ); fDefaultFound = 1;
pStart = Wlc_PrsStr(p, Vec_IntEntry(p->vStarts, ++i)); continue;
}
} }
// find closing // find closing
pStart = Wlc_PrsFindWord( pStart, "endcase", &fFound ); pStart = Wlc_PrsFindWord( pStart, "endcase", &fFound );
...@@ -1098,8 +1115,7 @@ startword: ...@@ -1098,8 +1115,7 @@ startword:
break; break;
} }
// check range of the control // check range of the control
pObj = Wlc_NtkObj( p->pNtk, Vec_IntEntry(p->vFanins, 0) ); if ( nValues != Vec_IntSize(p->vFanins) - 1 )
if ( (1 << Wlc_ObjRange(pObj)) != Vec_IntSize(p->vFanins) - 1 )
return Wlc_PrsWriteErrorMessage( p, pStart, "The number of values in the case statement is wrong.", pName ); return Wlc_PrsWriteErrorMessage( p, pStart, "The number of values in the case statement is wrong.", pName );
if ( Wlc_ObjRange(pObj) == 1 ) if ( Wlc_ObjRange(pObj) == 1 )
return Wlc_PrsWriteErrorMessage( p, pStart, "Always-statement with 1-bit control is not bit-blasted correctly.", pName ); return Wlc_PrsWriteErrorMessage( p, pStart, "Always-statement with 1-bit control is not bit-blasted correctly.", pName );
......
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