summaryrefslogtreecommitdiffstats
path: root/src/map/amap/amapOutput.c
blob: d590b7b953a93f48682cdf6c7f3848bf222e0093 (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/**CFile****************************************************************

  FileName    [amapOutput.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Technology mapper for standard cells.]

  Synopsis    [Core mapping procedures.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

#include "amapInt.h"

ABC_NAMESPACE_IMPL_START


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

static inline char * Amap_OuputStrsav( Aig_MmFlex_t * p, char * pStr ) 
{ return pStr ? strcpy(Aig_MmFlexEntryFetch(p, strlen(pStr)+1), pStr) : NULL; }

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

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

  Synopsis    [Allocates structure for storing one gate.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Amap_Out_t * Amap_OutputStructAlloc( Aig_MmFlex_t * pMem, Amap_Gat_t * pGate )
{
    Amap_Out_t * pRes;
    int nFans = pGate? pGate->nPins : 1;
    pRes = (Amap_Out_t *)Aig_MmFlexEntryFetch( pMem, sizeof(Amap_Out_t)+sizeof(int)*nFans );
    memset( pRes, 0, sizeof(Amap_Out_t) );
    memset( pRes->pFans, 0xff, sizeof(int)*nFans );
    pRes->pName = pGate? Amap_OuputStrsav( pMem, pGate->pName ) : NULL;
    pRes->nFans = nFans;
    return pRes;
}

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

  Synopsis    [Returns mapped network as an array of structures.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Vec_Ptr_t * Amap_ManProduceMapped( Amap_Man_t * p )
{
    Vec_Ptr_t * vNodes;
    Aig_MmFlex_t * pMem;
    Amap_Obj_t * pObj, * pFanin;
    Amap_Gat_t * pGate;
    Amap_Out_t * pRes;
    int i, k, iFanin, fCompl;
    float TotalArea = 0.0;
    pMem = Aig_MmFlexStart();
    // create mapping object for each node used in the mapping
    vNodes = Vec_PtrAlloc( 10 );
    Amap_ManForEachObj( p, pObj, i )
    {
        if ( Amap_ObjIsPi(pObj) )
        {
            assert( pObj->fPolar == 0 );
            pRes = Amap_OutputStructAlloc( pMem, NULL );
            pRes->Type  = -1;
            pRes->nFans = 0;
            // save this structure
            pObj->iData = Vec_PtrSize( vNodes );
            Vec_PtrPush( vNodes, pRes );
            // create invertor if needed
            if ( pObj->nFouts[1] ) // this PI is used in the neg polarity
            {
                pRes = Amap_OutputStructAlloc( pMem, p->pLib->pGateInv );
                pRes->pFans[0] = pObj->iData;
                // save this structure
                Vec_PtrPush( vNodes, pRes );
                TotalArea += p->pLib->pGateInv->dArea;
            }
            continue;
        }
        if ( Amap_ObjIsNode(pObj) )
        {
            // skip the node that is not used in the mapping
            if ( Amap_ObjRefsTotal(pObj) == 0 )
                continue;
            // get the gate
            pGate = Amap_LibGate( p->pLib, pObj->Best.pSet->iGate );
            assert( pGate->nPins == pObj->Best.pCut->nFans );
            // allocate structure
            pRes = Amap_OutputStructAlloc( pMem, pGate );
            Amap_MatchForEachFaninCompl( p, &pObj->Best, pFanin, fCompl, k )
            {
                assert( Amap_ObjRefsTotal(pFanin) );
                if ( (int)pFanin->fPolar == fCompl )
                    pRes->pFans[k] = pFanin->iData;
                else
                    pRes->pFans[k] = pFanin->iData + 1;
            }
            // save this structure
            pObj->iData = Vec_PtrSize( vNodes );
            Vec_PtrPush( vNodes, pRes );
            TotalArea += pGate->dArea;
            // create invertor if needed
            if ( pObj->nFouts[!pObj->fPolar] ) // needed in the opposite polarity
            {
                pRes = Amap_OutputStructAlloc( pMem, p->pLib->pGateInv );
                pRes->pFans[0] = pObj->iData;
                // save this structure
                Vec_PtrPush( vNodes, pRes );
                TotalArea += p->pLib->pGateInv->dArea;
            }
            continue;
        }
        if ( Amap_ObjIsPo(pObj) )
        {
            assert( pObj->fPolar == 0 );
            pFanin = Amap_ObjFanin0(p, pObj);
            assert( Amap_ObjRefsTotal(pFanin) );
            if ( Amap_ObjIsConst1(pFanin)  )
            { // create constant node
                if ( Amap_ObjFaninC0(pObj) )
                {
                    pRes = Amap_OutputStructAlloc( pMem, p->pLib->pGate0 );
                    TotalArea += p->pLib->pGate0->dArea;
                }
                else
                {
                    pRes = Amap_OutputStructAlloc( pMem, p->pLib->pGate1 );
                    TotalArea += p->pLib->pGate1->dArea;
                }
                // save this structure
                iFanin = Vec_PtrSize( vNodes );
                Vec_PtrPush( vNodes, pRes );
            }
            else 
            {
                if ( (int)pFanin->fPolar == Amap_ObjFaninC0(pObj) )
                    iFanin = pFanin->iData;
                else
                    iFanin = pFanin->iData + 1;
            }
            // create PO node
            pRes = Amap_OutputStructAlloc( pMem, NULL );
            pRes->Type     = 1;
            pRes->pFans[0] = iFanin;
            // save this structure
            Vec_PtrPush( vNodes, pRes );
        }
    }
    // return memory manager in the last entry of the array
    Vec_PtrPush( vNodes, pMem );
    return vNodes;
}


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


ABC_NAMESPACE_IMPL_END