ntlObj.c 8.95 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/**CFile****************************************************************

  FileName    [.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Netlist representation.]

  Synopsis    []

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

#include "ntl.h"

23 24 25
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
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
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

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

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

  Synopsis    [Creates the primary input.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Ntl_Obj_t * Ntl_ModelCreatePi( Ntl_Mod_t * pModel )
{
    Ntl_Obj_t * p;
    p = (Ntl_Obj_t *)Aig_MmFlexEntryFetch( pModel->pMan->pMemObjs, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) );
    memset( p, 0, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) );
    p->Id = Vec_PtrSize( pModel->vObjs );
    Vec_PtrPush( pModel->vObjs, p );
    Vec_PtrPush( pModel->vPis, p );
Alan Mishchenko committed
53
//    p->pModel   = pModel;
Alan Mishchenko committed
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
    p->Type     = NTL_OBJ_PI;
    p->nFanins  = 0;
    p->nFanouts = 1;
    pModel->nObjs[NTL_OBJ_PI]++;
    return p;
}

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

  Synopsis    [Creates the primary output.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Ntl_Obj_t * Ntl_ModelCreatePo( Ntl_Mod_t * pModel, Ntl_Net_t * pNet )
{
    Ntl_Obj_t * p;
    p = (Ntl_Obj_t *)Aig_MmFlexEntryFetch( pModel->pMan->pMemObjs, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) );
    memset( p, 0, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) );
    p->Id = Vec_PtrSize( pModel->vObjs );
    Vec_PtrPush( pModel->vObjs, p );
    Vec_PtrPush( pModel->vPos, p );
Alan Mishchenko committed
80
//    p->pModel    = pModel;
Alan Mishchenko committed
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
    p->Type      = NTL_OBJ_PO;
    p->nFanins   = 1;
    p->nFanouts  = 0;
    p->pFanio[0] = pNet;
    pModel->nObjs[NTL_OBJ_PO]++;
    return p;
}

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

  Synopsis    [Creates the primary output.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Ntl_Obj_t * Ntl_ModelCreateLatch( Ntl_Mod_t * pModel )
{
    Ntl_Obj_t * p;
    p = (Ntl_Obj_t *)Aig_MmFlexEntryFetch( pModel->pMan->pMemObjs, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) * 3 );
    memset( p, 0, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) * 3 );
    p->Id = Vec_PtrSize( pModel->vObjs );
    Vec_PtrPush( pModel->vObjs, p );
Alan Mishchenko committed
107
//    p->pModel   = pModel;
Alan Mishchenko committed
108
    p->Type     = NTL_OBJ_LATCH;
Alan Mishchenko committed
109
    p->nFanins  = 1;
Alan Mishchenko committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    p->nFanouts = 1;
    pModel->nObjs[NTL_OBJ_LATCH]++;
    return p;
}

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

  Synopsis    [Creates the node.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Ntl_Obj_t * Ntl_ModelCreateNode( Ntl_Mod_t * pModel, int nFanins )
{
    Ntl_Obj_t * p;
    p = (Ntl_Obj_t *)Aig_MmFlexEntryFetch( pModel->pMan->pMemObjs, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) * (nFanins + 1) );
    memset( p, 0, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) * (nFanins + 1) );
    p->Id = Vec_PtrSize( pModel->vObjs );
    Vec_PtrPush( pModel->vObjs, p );
Alan Mishchenko committed
133
//    p->pModel   = pModel;
Alan Mishchenko committed
134 135 136
    p->Type     = NTL_OBJ_NODE;
    p->nFanins  = nFanins;
    p->nFanouts = 1;
Alan Mishchenko committed
137 138 139 140
    if ( nFanins == 1 )
        pModel->nObjs[NTL_OBJ_LUT1]++;
    else
        pModel->nObjs[NTL_OBJ_NODE]++;
Alan Mishchenko committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
    return p;
}

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

  Synopsis    [Create the latch.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Ntl_Obj_t * Ntl_ModelCreateBox( Ntl_Mod_t * pModel, int nFanins, int nFanouts )
{
    Ntl_Obj_t * p;
    p = (Ntl_Obj_t *)Aig_MmFlexEntryFetch( pModel->pMan->pMemObjs, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) * (nFanins + nFanouts) );
    memset( p, 0, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) * (nFanins + nFanouts) );
    p->Id = Vec_PtrSize( pModel->vObjs );
    Vec_PtrPush( pModel->vObjs, p );
Alan Mishchenko committed
162
//    p->pModel   = pModel;
Alan Mishchenko committed
163 164 165
    p->Type     = NTL_OBJ_BOX;
    p->nFanins  = nFanins;
    p->nFanouts = nFanouts;
166
    p->Reset    = -1;
Alan Mishchenko committed
167 168 169 170 171 172
    pModel->nObjs[NTL_OBJ_BOX]++;
    return p;
}

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

Alan Mishchenko committed
173 174 175 176 177 178 179 180 181 182 183
  Synopsis    [Create the latch.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Ntl_Obj_t * Ntl_ModelDupObj( Ntl_Mod_t * pModel, Ntl_Obj_t * pOld )
{
Alan Mishchenko committed
184
    Ntl_Obj_t * pNew = NULL; // Supprses "might be used uninitialized"
Alan Mishchenko committed
185 186 187 188 189 190 191 192 193 194 195 196 197
    if ( Ntl_ObjIsPi( pOld ) )
        pNew = Ntl_ModelCreatePi( pModel ); 
    else if ( Ntl_ObjIsPo( pOld ) )
        pNew = Ntl_ModelCreatePo( pModel, NULL ); 
    else if ( Ntl_ObjIsLatch( pOld ) )
        pNew = Ntl_ModelCreateLatch( pModel ); 
    else if ( Ntl_ObjIsNode( pOld ) )
        pNew = Ntl_ModelCreateNode( pModel, Ntl_ObjFaninNum(pOld) ); 
    else if ( Ntl_ObjIsBox( pOld ) )
        pNew = Ntl_ModelCreateBox( pModel, Ntl_ObjFaninNum(pOld), Ntl_ObjFanoutNum(pOld) ); 
    return pNew;
}

Alan Mishchenko committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221

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

  Synopsis    [Creates the primary input with the given name.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Ntl_Obj_t * Ntl_ModelCreatePiWithName( Ntl_Mod_t * pModel, char * pName )
{
    Ntl_Obj_t * pObj;
    Ntl_Net_t * pNet;
    pNet = Ntl_ModelFindOrCreateNet( pModel, pName );
    if ( pNet->pDriver )
        return NULL;
    pObj = Ntl_ModelCreatePi( pModel );
    Ntl_ModelSetNetDriver( pObj, pNet );
    return pObj;
}

Alan Mishchenko committed
222 223
/**Function*************************************************************

Alan Mishchenko committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
  Synopsis    [Allocates memory and copies the name into it.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
char * Ntl_ManStoreName( Ntl_Man_t * p, char * pName )
{
    char * pStore;
    pStore = Aig_MmFlexEntryFetch( p->pMemObjs, strlen(pName) + 1 );
    strcpy( pStore, pName );
    return pStore;
}

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

  Synopsis    [Allocates memory and copies the SOP into it.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
252
char * Ntl_ManStoreSop( Aig_MmFlex_t * pMan, const char * pSop )
Alan Mishchenko committed
253 254
{
    char * pStore;
Alan Mishchenko committed
255
    pStore = Aig_MmFlexEntryFetch( pMan, strlen(pSop) + 1 );
Alan Mishchenko committed
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
    strcpy( pStore, pSop );
    return pStore;
}

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

  Synopsis    [Allocates memory and copies the root of file name there.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
char * Ntl_ManStoreFileName( Ntl_Man_t * p, char * pFileName )
{
    char * pBeg, * pEnd, * pStore, * pCur;
    // find the first dot
    for ( pEnd = pFileName; *pEnd; pEnd++ )
        if ( *pEnd == '.' )
            break;
    // find the first char
    for ( pBeg = pEnd - 1; pBeg >= pFileName; pBeg-- )
        if ( !((*pBeg >= 'a' && *pBeg <= 'z') || (*pBeg >= 'A' && *pBeg <= 'Z') || (*pBeg >= '0' && *pBeg <= '9') || *pBeg == '_') )
            break;
    pBeg++;
    // fill up storage
    pStore = Aig_MmFlexEntryFetch( p->pMemSops, pEnd - pBeg + 1 );
    for ( pCur = pStore; pBeg < pEnd; pBeg++, pCur++ )
        *pCur = *pBeg;
    *pCur = 0;
    return pStore;
}


Alan Mishchenko committed
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
/**Function*************************************************************

  Synopsis    [Returns the index of the fanin in the fanin list of the fanout.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Ntl_ManObjWhichFanout( Ntl_Obj_t * pNode, Ntl_Net_t * pFanout )
{
    Ntl_Net_t * pObj;
    int i;
    Ntl_ObjForEachFanout( pNode, pObj, i )
        if ( pObj == pFanout )
            return i;
    return -1;
}

Alan Mishchenko committed
313 314 315 316 317
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


318 319
ABC_NAMESPACE_IMPL_END