summaryrefslogtreecommitdiffstats
path: root/src/base/wln/wlnGuide.c
blob: b7e656ebaa5fc46d8e523629f01d31e4c9c3478e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**CFile****************************************************************

  FileName    [wln.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Word-level network.]

  Synopsis    []

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - September 23, 2018.]

  Revision    [$Id: wln.c,v 1.00 2018/09/23 00:00:00 alanmi Exp $]

***********************************************************************/

#include "wln.h"

ABC_NAMESPACE_IMPL_START

////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Wln_ReadFindToken( char * pToken, Abc_Nam_t * p )
{
    char * pBuffer = Abc_UtilStrsavTwo( "\\", pToken );
    int RetValue = Abc_NamStrFindOrAdd( p, pBuffer, NULL );
    ABC_FREE( pBuffer );
    return RetValue;
}
void Wln_PrintGuidance( Vec_Wec_t * vGuide, Abc_Nam_t * p )
{
    Vec_Int_t * vLevel; int i, k, Obj; 
    Vec_WecForEachLevel( vGuide, vLevel, i )
    {
        Vec_IntForEachEntry( vLevel, Obj, k )
            printf( "%s ", Obj >= 0 ? Abc_NamStr(p, Obj) : "[unknown]" );
        printf( "\n" );
    }
}
Vec_Wec_t * Wln_ReadGuidance( char * pFileName, Abc_Nam_t * p )
{
    char * pBuffer = ABC_CALLOC( char, 10000 ), * pToken;
    Vec_Wec_t * vTokens = Vec_WecAlloc( 100 ); Vec_Int_t * vLevel;
    FILE * pFile = fopen( pFileName, "rb" );
    while ( fgets( pBuffer, 10000, pFile ) )
    {
        if ( pBuffer[0] == '#' )
            continue;
        vLevel = Vec_WecPushLevel( vTokens );
        pToken = strtok( pBuffer, " \t\r\n" );
        while ( pToken )
        {
            Vec_IntPush( vLevel, Vec_IntSize(vLevel) < 2 ? Abc_NamStrFindOrAdd(p, pToken, NULL) : Wln_ReadFindToken(pToken, p) );
            pToken = strtok( NULL, " \t\r\n" );
        }
        if ( Vec_IntSize(vLevel) % 4 == 3 ) // account for "property"
            Vec_IntPush( vLevel, -1 );
        assert( Vec_IntSize(vLevel) % 4 == 0 );
    }
    fclose( pFile );
    if ( Vec_WecSize(vTokens) == 0 )
        printf( "Guidance is empty.\n" );
    //Wln_PrintGuidance( vTokens, p );
    ABC_FREE( pBuffer );
    return vTokens;
}

////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


ABC_NAMESPACE_IMPL_END