1 /**CFile****************************************************************
2 
3   FileName    [plaWrite.c]
4 
5   SystemName  [ABC: Logic synthesis and verification system.]
6 
7   PackageName [SOP manager.]
8 
9   Synopsis    [Scalable SOP transformations.]
10 
11   Author      [Alan Mishchenko]
12 
13   Affiliation [UC Berkeley]
14 
15   Date        [Ver. 1.0. Started - March 18, 2015.]
16 
17   Revision    [$Id: plaWrite.c,v 1.00 2014/09/12 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "pla.h"
22 
23 ABC_NAMESPACE_IMPL_START
24 
25 ////////////////////////////////////////////////////////////////////////
26 ///                        DECLARATIONS                              ///
27 ////////////////////////////////////////////////////////////////////////
28 
29 ////////////////////////////////////////////////////////////////////////
30 ///                     FUNCTION DEFINITIONS                         ///
31 ////////////////////////////////////////////////////////////////////////
32 
33 /**Function*************************************************************
34 
35   Synopsis    []
36 
37   Description []
38 
39   SideEffects []
40 
41   SeeAlso     []
42 
43 ***********************************************************************/
Pla_WritePlaInt(Pla_Man_t * p)44 Vec_Str_t * Pla_WritePlaInt( Pla_Man_t * p )
45 {
46     Vec_Str_t * vOut = Vec_StrAlloc( 10000 );
47     char * pLits = "-01?";
48     word * pCubeIn, * pCubeOut;
49     int i, k, Lit;
50     // write comments
51     Vec_StrPrintStr( vOut, "# SOP \"" );
52     Vec_StrPrintStr( vOut, Pla_ManName(p) );
53     Vec_StrPrintStr( vOut, "\" written via PLA package in ABC on " );
54     Vec_StrPrintStr( vOut, Extra_TimeStamp() );
55     Vec_StrPrintStr( vOut, "\n\n" );
56     // write header
57     if ( p->Type != PLA_FILE_FD )
58     {
59         if ( p->Type == PLA_FILE_F )
60             Vec_StrPrintStr( vOut, ".type f\n" );
61         else if ( p->Type == PLA_FILE_FR )
62             Vec_StrPrintStr( vOut, ".type fr\n" );
63         else if ( p->Type == PLA_FILE_FDR )
64             Vec_StrPrintStr( vOut, ".type fdr\n" );
65         else if ( p->Type == PLA_FILE_NONE )
66             Vec_StrPrintStr( vOut, ".type ???\n" );
67     }
68     Vec_StrPrintStr( vOut, ".i " );
69     Vec_StrPrintNum( vOut, p->nIns );
70     Vec_StrPrintStr( vOut, "\n.o " );
71     Vec_StrPrintNum( vOut, p->nOuts );
72     Vec_StrPrintStr( vOut, "\n.p " );
73     Vec_StrPrintNum( vOut, Pla_ManCubeNum(p) );
74     Vec_StrPrintStr( vOut, "\n" );
75     // write cube
76     Pla_ForEachCubeInOut( p, pCubeIn, pCubeOut, i )
77     {
78         Pla_CubeForEachLit( p->nIns, pCubeIn, Lit, k )
79             Vec_StrPush( vOut, pLits[Lit] );
80         Vec_StrPush( vOut, ' ' );
81         Pla_CubeForEachLit( p->nOuts, pCubeOut, Lit, k )
82             Vec_StrPush( vOut, pLits[Lit] );
83         Vec_StrPush( vOut, '\n' );
84     }
85     Vec_StrPrintStr( vOut, ".e\n\n\0" );
86     return vOut;
87 }
Pla_WritePla(Pla_Man_t * p,char * pFileName)88 void Pla_WritePla( Pla_Man_t * p, char * pFileName )
89 {
90     Vec_Str_t * vOut = Pla_WritePlaInt( p );
91     if ( Vec_StrSize(vOut) > 0 )
92     {
93         FILE * pFile = fopen( pFileName, "wb" );
94         if ( pFile == NULL )
95             printf( "Cannot open file \"%s\" for writing.\n", pFileName );
96         else
97         {
98             fwrite( Vec_StrArray(vOut), 1, Vec_StrSize(vOut), pFile );
99             fclose( pFile );
100         }
101     }
102     Vec_StrFreeP( &vOut );
103 }
104 
105 
106 ////////////////////////////////////////////////////////////////////////
107 ///                       END OF FILE                                ///
108 ////////////////////////////////////////////////////////////////////////
109 
110 
111 ABC_NAMESPACE_IMPL_END
112 
113