summaryrefslogtreecommitdiffstats
path: root/src/base/abci/abcOrder.c
blob: fb8378480d30eb36e8f2b255539fc7b79c6e72e3 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/**CFile****************************************************************

  FileName    [abcOrder.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Network and node package.]

  Synopsis    [Exploring static BDD variable orders.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 20, 2005.]

  Revision    [$Id: abcOrder.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]

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

#include "base/abc/abc.h"

ABC_NAMESPACE_IMPL_START


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

static void Abc_NtkChangeCiOrder( Abc_Ntk_t * pNtk, Vec_Ptr_t * vSupp, int fReverse );

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////
 
/**Function*************************************************************

  Synopsis    [Changes the order of primary inputs.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_NtkFindCiOrder( Abc_Ntk_t * pNtk, int fReverse, int fVerbose )
{
    Vec_Ptr_t * vSupp;
    vSupp = Abc_NtkSupport( pNtk );
    Abc_NtkChangeCiOrder( pNtk, vSupp, fReverse );
    Vec_PtrFree( vSupp );
}

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

  Synopsis    [Implements the given variable order.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_NtkImplementCiOrder( Abc_Ntk_t * pNtk, char * pFileName, int fReverse, int fVerbose )
{
    char Buffer[1000];
    FILE * pFile;
    Vec_Ptr_t * vSupp;
    Abc_Obj_t * pObj;
    pFile = fopen( pFileName, "r" );
    vSupp = Vec_PtrAlloc( Abc_NtkCiNum(pNtk) );
    while ( fscanf( pFile, "%s", Buffer ) == 1 )
    {
        pObj = Abc_NtkFindCi( pNtk, Buffer );
        if ( pObj == NULL || !Abc_ObjIsCi(pObj) )
        {
            printf( "Name \"%s\" is not a PI name. Cannot use this order.\n", Buffer );
            Vec_PtrFree( vSupp );
            fclose( pFile );
            return;
        }
        Vec_PtrPush( vSupp, pObj );
    }
    fclose( pFile );
    if ( Vec_PtrSize(vSupp) != Abc_NtkCiNum(pNtk) )
    {
        printf( "The number of names in the order (%d) is not the same as the number of PIs (%d).\n", Vec_PtrSize(vSupp), Abc_NtkCiNum(pNtk) );
        Vec_PtrFree( vSupp );
        return;
    }
    Abc_NtkChangeCiOrder( pNtk, vSupp, fReverse );
    Vec_PtrFree( vSupp );
}
 
/**Function*************************************************************

  Synopsis    [Changes the order of primary inputs.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_NtkChangeCiOrder( Abc_Ntk_t * pNtk, Vec_Ptr_t * vSupp, int fReverse )
{
    Abc_Obj_t * pObj;
    int i;
    assert( Vec_PtrSize(vSupp) == Abc_NtkCiNum(pNtk) );
    // order CIs using the array
    if ( fReverse )
        Vec_PtrForEachEntry( Abc_Obj_t *, vSupp, pObj, i )
            Vec_PtrWriteEntry( pNtk->vCis, Vec_PtrSize(vSupp)-1-i, pObj );
    else
        Vec_PtrForEachEntry( Abc_Obj_t *, vSupp, pObj, i )
            Vec_PtrWriteEntry( pNtk->vCis, i, pObj );
    // order PIs accordingly
    Vec_PtrClear( pNtk->vPis );
    Abc_NtkForEachCi( pNtk, pObj, i )
        if ( Abc_ObjIsPi(pObj) )
            Vec_PtrPush( pNtk->vPis, pObj );
//    Abc_NtkForEachCi( pNtk, pObj, i )
//        printf( "%s ", Abc_ObjName(pObj) );
//    printf( "\n" );
}

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


ABC_NAMESPACE_IMPL_END