2005-07-29 17:01:00 +02:00
|
|
|
/**CFile****************************************************************
|
|
|
|
|
|
2005-09-02 17:01:00 +02:00
|
|
|
FileName [decPrint.c]
|
2005-07-29 17:01:00 +02:00
|
|
|
|
|
|
|
|
PackageName [MVSIS 2.0: Multi-valued logic synthesis system.]
|
|
|
|
|
|
2005-09-02 17:01:00 +02:00
|
|
|
Synopsis [Procedures to print the decomposition graphs (factored forms).]
|
2005-07-29 17:01:00 +02:00
|
|
|
|
|
|
|
|
Author [MVSIS Group]
|
|
|
|
|
|
|
|
|
|
Affiliation [UC Berkeley]
|
|
|
|
|
|
|
|
|
|
Date [Ver. 1.0. Started - February 1, 2003.]
|
|
|
|
|
|
2005-09-02 17:01:00 +02:00
|
|
|
Revision [$Id: decPrint.c,v 1.1 2003/05/22 19:20:05 alanmi Exp $]
|
2005-07-29 17:01:00 +02:00
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
2012-07-08 05:14:12 +02:00
|
|
|
#include "base/abc/abc.h"
|
2005-09-02 17:01:00 +02:00
|
|
|
#include "dec.h"
|
2005-07-29 17:01:00 +02:00
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
ABC_NAMESPACE_IMPL_START
|
|
|
|
|
|
|
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// DECLARATIONS ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2005-09-02 17:01:00 +02:00
|
|
|
static void Dec_GraphPrint_rec( FILE * pFile, Dec_Graph_t * pGraph, Dec_Node_t * pNode, int fCompl, char * pNamesIn[], int * pPos, int LitSizeMax );
|
|
|
|
|
static int Dec_GraphPrintGetLeafName( FILE * pFile, int iLeaf, int fCompl, char * pNamesIn[] );
|
|
|
|
|
static void Dec_GraphPrintUpdatePos( FILE * pFile, int * pPos, int LitSizeMax );
|
2012-07-30 19:29:35 +02:00
|
|
|
static int Dec_GraphPrintOutputName( FILE * pFile, char * pNameOut );
|
2005-07-29 17:01:00 +02:00
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2008-01-31 05:01:00 +01:00
|
|
|
/// FUNCTION DEFINITIONS ///
|
2005-07-29 17:01:00 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
2005-09-02 17:01:00 +02:00
|
|
|
Synopsis [Prints the decomposition graph.]
|
2005-07-29 17:01:00 +02:00
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2005-09-02 17:01:00 +02:00
|
|
|
void Dec_GraphPrint( FILE * pFile, Dec_Graph_t * pGraph, char * pNamesIn[], char * pNameOut )
|
2005-07-29 17:01:00 +02:00
|
|
|
{
|
2005-09-01 17:01:00 +02:00
|
|
|
Vec_Ptr_t * vNamesIn = NULL;
|
2005-09-02 17:01:00 +02:00
|
|
|
int LitSizeMax, LitSizeCur, Pos, i;
|
2005-07-29 17:01:00 +02:00
|
|
|
|
|
|
|
|
// create the names if not given by the user
|
|
|
|
|
if ( pNamesIn == NULL )
|
|
|
|
|
{
|
2005-09-02 17:01:00 +02:00
|
|
|
vNamesIn = Abc_NodeGetFakeNames( Dec_GraphLeaveNum(pGraph) );
|
2005-09-01 17:01:00 +02:00
|
|
|
pNamesIn = (char **)vNamesIn->pArray;
|
2005-07-29 17:01:00 +02:00
|
|
|
}
|
2005-09-01 17:01:00 +02:00
|
|
|
if ( pNameOut == NULL )
|
|
|
|
|
pNameOut = "F";
|
2005-07-29 17:01:00 +02:00
|
|
|
|
|
|
|
|
// get the size of the longest literal
|
|
|
|
|
LitSizeMax = 0;
|
2005-09-02 17:01:00 +02:00
|
|
|
for ( i = 0; i < Dec_GraphLeaveNum(pGraph); i++ )
|
2005-07-29 17:01:00 +02:00
|
|
|
{
|
|
|
|
|
LitSizeCur = strlen(pNamesIn[i]);
|
|
|
|
|
if ( LitSizeMax < LitSizeCur )
|
|
|
|
|
LitSizeMax = LitSizeCur;
|
|
|
|
|
}
|
|
|
|
|
if ( LitSizeMax > 50 )
|
|
|
|
|
LitSizeMax = 20;
|
|
|
|
|
|
2005-09-02 17:01:00 +02:00
|
|
|
// write the decomposition graph (factored form)
|
|
|
|
|
if ( Dec_GraphIsConst(pGraph) ) // constant
|
2005-07-29 17:01:00 +02:00
|
|
|
{
|
2012-07-30 19:29:35 +02:00
|
|
|
Pos = Dec_GraphPrintOutputName( pFile, pNameOut );
|
2005-09-02 17:01:00 +02:00
|
|
|
fprintf( pFile, "Constant %d", !Dec_GraphIsComplement(pGraph) );
|
2005-07-29 17:01:00 +02:00
|
|
|
}
|
2005-09-02 17:01:00 +02:00
|
|
|
else if ( Dec_GraphIsVar(pGraph) ) // literal
|
2005-07-29 17:01:00 +02:00
|
|
|
{
|
2012-07-30 19:29:35 +02:00
|
|
|
Pos = Dec_GraphPrintOutputName( pFile, pNameOut );
|
2005-09-02 17:01:00 +02:00
|
|
|
Dec_GraphPrintGetLeafName( pFile, Dec_GraphVarInt(pGraph), Dec_GraphIsComplement(pGraph), pNamesIn );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-07-30 19:29:35 +02:00
|
|
|
Pos = Dec_GraphPrintOutputName( pFile, pNameOut );
|
|
|
|
|
Dec_GraphPrint_rec( pFile, pGraph, Dec_GraphNodeLast(pGraph), Dec_GraphIsComplement(pGraph), pNamesIn, &Pos, LitSizeMax );
|
2005-07-29 17:01:00 +02:00
|
|
|
}
|
|
|
|
|
fprintf( pFile, "\n" );
|
|
|
|
|
|
2005-09-01 17:01:00 +02:00
|
|
|
if ( vNamesIn )
|
|
|
|
|
Abc_NodeFreeNames( vNamesIn );
|
2005-07-29 17:01:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2008-01-31 05:01:00 +01:00
|
|
|
void Dec_GraphPrint2_rec( FILE * pFile, Dec_Graph_t * pGraph, Dec_Node_t * pNode, int fCompl, char * pNamesIn[], int * pPos, int LitSizeMax )
|
2005-07-29 17:01:00 +02:00
|
|
|
{
|
2005-09-02 17:01:00 +02:00
|
|
|
Dec_Node_t * pNode0, * pNode1;
|
|
|
|
|
pNode0 = Dec_GraphNode(pGraph, pNode->eEdge0.Node);
|
|
|
|
|
pNode1 = Dec_GraphNode(pGraph, pNode->eEdge1.Node);
|
|
|
|
|
if ( Dec_GraphNodeIsVar(pGraph, pNode) ) // FT_NODE_LEAF )
|
2005-07-29 17:01:00 +02:00
|
|
|
{
|
2005-09-02 17:01:00 +02:00
|
|
|
(*pPos) += Dec_GraphPrintGetLeafName( pFile, Dec_GraphNodeInt(pGraph,pNode), fCompl, pNamesIn );
|
2005-07-29 17:01:00 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( !pNode->fNodeOr ) // FT_NODE_AND )
|
|
|
|
|
{
|
|
|
|
|
if ( !pNode0->fNodeOr ) // != FT_NODE_OR )
|
2005-09-02 17:01:00 +02:00
|
|
|
Dec_GraphPrint_rec( pFile, pGraph, pNode0, pNode->fCompl0, pNamesIn, pPos, LitSizeMax );
|
2005-07-29 17:01:00 +02:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fprintf( pFile, "(" );
|
|
|
|
|
(*pPos)++;
|
2005-09-02 17:01:00 +02:00
|
|
|
Dec_GraphPrint_rec( pFile, pGraph, pNode0, pNode->fCompl0, pNamesIn, pPos, LitSizeMax );
|
2005-07-29 17:01:00 +02:00
|
|
|
fprintf( pFile, ")" );
|
|
|
|
|
(*pPos)++;
|
|
|
|
|
}
|
|
|
|
|
fprintf( pFile, " " );
|
|
|
|
|
(*pPos)++;
|
|
|
|
|
|
2005-09-02 17:01:00 +02:00
|
|
|
Dec_GraphPrintUpdatePos( pFile, pPos, LitSizeMax );
|
2005-07-29 17:01:00 +02:00
|
|
|
|
|
|
|
|
if ( !pNode1->fNodeOr ) // != FT_NODE_OR )
|
2005-09-02 17:01:00 +02:00
|
|
|
Dec_GraphPrint_rec( pFile, pGraph, pNode1, pNode->fCompl1, pNamesIn, pPos, LitSizeMax );
|
2005-07-29 17:01:00 +02:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fprintf( pFile, "(" );
|
|
|
|
|
(*pPos)++;
|
2005-09-02 17:01:00 +02:00
|
|
|
Dec_GraphPrint_rec( pFile, pGraph, pNode1, pNode->fCompl1, pNamesIn, pPos, LitSizeMax );
|
2005-07-29 17:01:00 +02:00
|
|
|
fprintf( pFile, ")" );
|
|
|
|
|
(*pPos)++;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( pNode->fNodeOr ) // FT_NODE_OR )
|
|
|
|
|
{
|
2005-09-02 17:01:00 +02:00
|
|
|
Dec_GraphPrint_rec( pFile, pGraph, pNode0, pNode->fCompl0, pNamesIn, pPos, LitSizeMax );
|
2005-07-29 17:01:00 +02:00
|
|
|
fprintf( pFile, " + " );
|
|
|
|
|
(*pPos) += 3;
|
|
|
|
|
|
2005-09-02 17:01:00 +02:00
|
|
|
Dec_GraphPrintUpdatePos( pFile, pPos, LitSizeMax );
|
2005-07-29 17:01:00 +02:00
|
|
|
|
2005-09-02 17:01:00 +02:00
|
|
|
Dec_GraphPrint_rec( pFile, pGraph, pNode1, pNode->fCompl1, pNamesIn, pPos, LitSizeMax );
|
2005-07-29 17:01:00 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
assert( 0 );
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
void Dec_GraphPrint_rec( FILE * pFile, Dec_Graph_t * pGraph, Dec_Node_t * pNode, int fCompl, char * pNamesIn[], int * pPos, int LitSizeMax )
|
|
|
|
|
{
|
|
|
|
|
Dec_Node_t * pNode0, * pNode1;
|
|
|
|
|
Dec_Node_t * pNode00, * pNode01, * pNode10, * pNode11;
|
|
|
|
|
pNode0 = Dec_GraphNode(pGraph, pNode->eEdge0.Node);
|
|
|
|
|
pNode1 = Dec_GraphNode(pGraph, pNode->eEdge1.Node);
|
|
|
|
|
if ( Dec_GraphNodeIsVar(pGraph, pNode) ) // FT_NODE_LEAF )
|
|
|
|
|
{
|
|
|
|
|
(*pPos) += Dec_GraphPrintGetLeafName( pFile, Dec_GraphNodeInt(pGraph,pNode), fCompl, pNamesIn );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( !Dec_GraphNodeIsVar(pGraph, pNode0) && !Dec_GraphNodeIsVar(pGraph, pNode1) )
|
|
|
|
|
{
|
|
|
|
|
pNode00 = Dec_GraphNode(pGraph, pNode0->eEdge0.Node);
|
|
|
|
|
pNode01 = Dec_GraphNode(pGraph, pNode0->eEdge1.Node);
|
|
|
|
|
pNode10 = Dec_GraphNode(pGraph, pNode1->eEdge0.Node);
|
|
|
|
|
pNode11 = Dec_GraphNode(pGraph, pNode1->eEdge1.Node);
|
|
|
|
|
if ( (pNode00 == pNode10 || pNode00 == pNode11) && (pNode01 == pNode10 || pNode01 == pNode11) )
|
|
|
|
|
{
|
|
|
|
|
fprintf( pFile, "(" );
|
|
|
|
|
(*pPos)++;
|
|
|
|
|
Dec_GraphPrint_rec( pFile, pGraph, pNode00, pNode00->fCompl0, pNamesIn, pPos, LitSizeMax );
|
|
|
|
|
fprintf( pFile, " # " );
|
|
|
|
|
(*pPos) += 3;
|
|
|
|
|
Dec_GraphPrint_rec( pFile, pGraph, pNode01, pNode01->fCompl1, pNamesIn, pPos, LitSizeMax );
|
|
|
|
|
fprintf( pFile, ")" );
|
|
|
|
|
(*pPos)++;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( fCompl )
|
|
|
|
|
{
|
|
|
|
|
fprintf( pFile, "(" );
|
|
|
|
|
(*pPos)++;
|
2012-07-30 19:29:35 +02:00
|
|
|
Dec_GraphPrint_rec( pFile, pGraph, pNode0, !pNode->eEdge0.fCompl, pNamesIn, pPos, LitSizeMax );
|
2008-01-31 05:01:00 +01:00
|
|
|
fprintf( pFile, " + " );
|
|
|
|
|
(*pPos) += 3;
|
2012-07-30 19:29:35 +02:00
|
|
|
Dec_GraphPrint_rec( pFile, pGraph, pNode1, !pNode->eEdge1.fCompl, pNamesIn, pPos, LitSizeMax );
|
2008-01-31 05:01:00 +01:00
|
|
|
fprintf( pFile, ")" );
|
|
|
|
|
(*pPos)++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fprintf( pFile, "(" );
|
|
|
|
|
(*pPos)++;
|
2012-07-30 19:29:35 +02:00
|
|
|
Dec_GraphPrint_rec( pFile, pGraph, pNode0, pNode->eEdge0.fCompl, pNamesIn, pPos, LitSizeMax );
|
|
|
|
|
Dec_GraphPrint_rec( pFile, pGraph, pNode1, pNode->eEdge1.fCompl, pNamesIn, pPos, LitSizeMax );
|
2008-01-31 05:01:00 +01:00
|
|
|
fprintf( pFile, ")" );
|
|
|
|
|
(*pPos)++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2005-09-02 17:01:00 +02:00
|
|
|
int Dec_GraphPrintGetLeafName( FILE * pFile, int iLeaf, int fCompl, char * pNamesIn[] )
|
2005-07-29 17:01:00 +02:00
|
|
|
{
|
|
|
|
|
static char Buffer[100];
|
2012-07-30 19:29:35 +02:00
|
|
|
sprintf( Buffer, "%s%s", fCompl? "!" : "", pNamesIn[iLeaf] );
|
2005-07-29 17:01:00 +02:00
|
|
|
fprintf( pFile, "%s", Buffer );
|
|
|
|
|
return strlen( Buffer );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2005-09-02 17:01:00 +02:00
|
|
|
void Dec_GraphPrintUpdatePos( FILE * pFile, int * pPos, int LitSizeMax )
|
2005-07-29 17:01:00 +02:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
if ( *pPos + LitSizeMax < 77 )
|
|
|
|
|
return;
|
|
|
|
|
fprintf( pFile, "\n" );
|
|
|
|
|
for ( i = 0; i < 10; i++ )
|
|
|
|
|
fprintf( pFile, " " );
|
|
|
|
|
*pPos = 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
2005-09-02 17:01:00 +02:00
|
|
|
Synopsis [Starts the printout for a decomposition graph.]
|
2005-07-29 17:01:00 +02:00
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2012-07-30 19:29:35 +02:00
|
|
|
int Dec_GraphPrintOutputName( FILE * pFile, char * pNameOut )
|
2005-07-29 17:01:00 +02:00
|
|
|
{
|
|
|
|
|
if ( pNameOut == NULL )
|
|
|
|
|
return 0;
|
2012-07-30 19:29:35 +02:00
|
|
|
fprintf( pFile, "%6s = ", pNameOut );
|
2005-07-29 17:01:00 +02:00
|
|
|
return 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// END OF FILE ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
ABC_NAMESPACE_IMPL_END
|
|
|
|
|
|