mioApi.c 11.7 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
/**CFile****************************************************************

  FileName    [mioApi.c]

  PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]

  Synopsis    [File reading/writing for technology mapping.]

  Author      [MVSIS Group]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - September 8, 2003.]

  Revision    [$Id: mioApi.c,v 1.4 2004/06/28 14:20:25 alanmi Exp $]

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

#include "mioInt.h"

21 22 23
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
24 25 26 27 28
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
29
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
30 31 32 33 34 35 36 37 38 39 40 41 42
////////////////////////////////////////////////////////////////////////

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
43 44 45 46
char *            Mio_LibraryReadName          ( Mio_Library_t * pLib )  { return pLib->pName;      }
int               Mio_LibraryReadGateNum       ( Mio_Library_t * pLib )  { return pLib->nGates;     }
Mio_Gate_t *      Mio_LibraryReadGates         ( Mio_Library_t * pLib )  { return pLib->pGates;     }
Mio_Gate_t **     Mio_LibraryReadGateArray     ( Mio_Library_t * pLib )  { return pLib->ppGatesName;}
47
Mio_Gate_t *      Mio_LibraryReadGateById      ( Mio_Library_t * pLib, int Id ) { assert( pLib->ppGates0[Id]->Cell == Id ); return pLib->ppGates0[Id];}
48 49
Mio_Gate_t *      Mio_LibraryReadBuf           ( Mio_Library_t * pLib )  { return pLib->pGateBuf;   }
Mio_Gate_t *      Mio_LibraryReadInv           ( Mio_Library_t * pLib )  { return pLib->pGateInv;   }
Alan Mishchenko committed
50 51
Mio_Gate_t *      Mio_LibraryReadConst0        ( Mio_Library_t * pLib )  { return pLib->pGate0;     }
Mio_Gate_t *      Mio_LibraryReadConst1        ( Mio_Library_t * pLib )  { return pLib->pGate1;     }
Alan Mishchenko committed
52
Mio_Gate_t *      Mio_LibraryReadNand2         ( Mio_Library_t * pLib )  { return pLib->pGateNand2; }
Alan Mishchenko committed
53
Mio_Gate_t *      Mio_LibraryReadAnd2          ( Mio_Library_t * pLib )  { return pLib->pGateAnd2;  }
54 55
Mio_Gate_t *      Mio_LibraryReadNor2          ( Mio_Library_t * pLib )  { return pLib->pGateNor2;  }
Mio_Gate_t *      Mio_LibraryReadOr2           ( Mio_Library_t * pLib )  { return pLib->pGateOr2;   }
Alan Mishchenko committed
56 57 58 59 60 61
float             Mio_LibraryReadDelayInvRise  ( Mio_Library_t * pLib )  { return (float)(pLib->pGateInv?   pLib->pGateInv->pPins->dDelayBlockRise   : 0.0); }
float             Mio_LibraryReadDelayInvFall  ( Mio_Library_t * pLib )  { return (float)(pLib->pGateInv?   pLib->pGateInv->pPins->dDelayBlockFall   : 0.0); }
float             Mio_LibraryReadDelayInvMax   ( Mio_Library_t * pLib )  { return (float)(pLib->pGateInv?   pLib->pGateInv->pPins->dDelayBlockMax    : 0.0); }
float             Mio_LibraryReadDelayNand2Rise( Mio_Library_t * pLib )  { return (float)(pLib->pGateNand2? pLib->pGateNand2->pPins->dDelayBlockRise : 0.0); }
float             Mio_LibraryReadDelayNand2Fall( Mio_Library_t * pLib )  { return (float)(pLib->pGateNand2? pLib->pGateNand2->pPins->dDelayBlockFall : 0.0); }
float             Mio_LibraryReadDelayNand2Max ( Mio_Library_t * pLib )  { return (float)(pLib->pGateNand2? pLib->pGateNand2->pPins->dDelayBlockMax  : 0.0); }
Alan Mishchenko committed
62
float             Mio_LibraryReadDelayAnd2Max  ( Mio_Library_t * pLib )  { return (float)(pLib->pGateAnd2?  pLib->pGateAnd2->pPins->dDelayBlockMax   : 0.0); }
63
float             Mio_LibraryReadDelayAigNode  ( Mio_Library_t * pLib )  { return pLib->pGateAnd2 ? Mio_LibraryReadDelayAnd2Max(pLib) : Mio_LibraryReadDelayNand2Max(pLib); } // approximate delay of the AIG node
Alan Mishchenko committed
64 65 66
float             Mio_LibraryReadAreaInv       ( Mio_Library_t * pLib )  { return (float)(pLib->pGateInv?   pLib->pGateInv->dArea   : 0.0); }
float             Mio_LibraryReadAreaBuf       ( Mio_Library_t * pLib )  { return (float)(pLib->pGateBuf?   pLib->pGateBuf->dArea   : 0.0); }
float             Mio_LibraryReadAreaNand2     ( Mio_Library_t * pLib )  { return (float)(pLib->pGateNand2? pLib->pGateNand2->dArea : 0.0); }
Alan Mishchenko committed
67 68 69

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

Alan Mishchenko committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
  Synopsis    [Returns the longest gate name.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Mio_LibraryReadGateNameMax( Mio_Library_t * pLib )
{
    Mio_Gate_t * pGate;
    int LenMax = 0, LenCur;
    Mio_LibraryForEachGate( pLib, pGate )
    {
        LenCur = strlen( Mio_GateReadName(pGate) );
        if ( LenMax < LenCur )
            LenMax = LenCur;
    }
    return LenMax;
}

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

Alan Mishchenko committed
94 95 96 97 98 99 100 101 102
  Synopsis    [Read Mvc of the gate by name.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
103
Mio_Gate_t * Mio_LibraryReadGateByName( Mio_Library_t * pLib, char * pName, char * pOutName )      
Alan Mishchenko committed
104 105
{ 
    Mio_Gate_t * pGate;
106
    if ( ! st__lookup( pLib->tName2Gate, pName, (char **)&pGate ) )
107 108 109 110
        return NULL;
    if ( pOutName == NULL )
        return pGate;
    if ( !strcmp(pGate->pOutName, pOutName) )
Alan Mishchenko committed
111
        return pGate;
112 113
    if ( pGate->pTwin && !strcmp(pGate->pTwin->pOutName, pOutName) )
        return pGate->pTwin;
Alan Mishchenko committed
114 115 116 117 118
    return NULL;
}

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

119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
  Synopsis    [Returns the first gate in the library with the given TT.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Mio_Gate_t * Mio_LibraryReadGateByTruth( Mio_Library_t * pLib, word t )
{
    Mio_Gate_t * pGate;
    Mio_LibraryForEachGate( pLib, pGate )
        if ( pGate->nInputs <= 6 && pGate->uTruth == t )
            return pGate;
    return NULL;
}

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

Alan Mishchenko committed
139 140 141 142 143 144 145 146 147 148 149 150
  Synopsis    [Read Mvc of the gate by name.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
char * Mio_LibraryReadSopByName( Mio_Library_t * pLib, char * pName )      
{ 
    Mio_Gate_t * pGate;
151
    if ( st__lookup( pLib->tName2Gate, pName, (char **)&pGate ) )
Alan Mishchenko committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
        return pGate->pSop;
    return NULL;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
167 168 169 170 171 172 173 174 175 176 177 178 179
char *            Mio_GateReadName     ( Mio_Gate_t * pGate )            { return pGate->pName;     }
char *            Mio_GateReadOutName  ( Mio_Gate_t * pGate )            { return pGate->pOutName;  }
double            Mio_GateReadArea     ( Mio_Gate_t * pGate )            { return pGate->dArea;     }
char *            Mio_GateReadForm     ( Mio_Gate_t * pGate )            { return pGate->pForm;     }
Mio_Pin_t *       Mio_GateReadPins     ( Mio_Gate_t * pGate )            { return pGate->pPins;     }
Mio_Library_t *   Mio_GateReadLib      ( Mio_Gate_t * pGate )            { return pGate->pLib;      }
Mio_Gate_t *      Mio_GateReadNext     ( Mio_Gate_t * pGate )            { return pGate->pNext;     }
Mio_Gate_t *      Mio_GateReadTwin     ( Mio_Gate_t * pGate )            { return pGate->pTwin;     }
int               Mio_GateReadPinNum   ( Mio_Gate_t * pGate )            { return pGate->nInputs;   }
double            Mio_GateReadDelayMax ( Mio_Gate_t * pGate )            { return pGate->dDelayMax; }
char *            Mio_GateReadSop      ( Mio_Gate_t * pGate )            { return pGate->pSop;      }
Vec_Int_t *       Mio_GateReadExpr     ( Mio_Gate_t * pGate )            { return pGate->vExpr;     }
word              Mio_GateReadTruth    ( Mio_Gate_t * pGate )            { return pGate->nInputs <= 6 ? pGate->uTruth : 0;   }
180
word *            Mio_GateReadTruthP   ( Mio_Gate_t * pGate )            { return pGate->nInputs <= 6 ? &pGate->uTruth: pGate->pTruth; }
181 182 183 184 185 186 187 188 189 190 191 192 193
int               Mio_GateReadValue    ( Mio_Gate_t * pGate )            { return pGate->Value;     }
int               Mio_GateReadCell     ( Mio_Gate_t * pGate )            { return pGate->Cell;      }
int               Mio_GateReadProfile  ( Mio_Gate_t * pGate )            { return pGate->Profile;   }
int               Mio_GateReadProfile2 ( Mio_Gate_t * pGate )            { return pGate->Profile2;  }
void              Mio_GateSetValue     ( Mio_Gate_t * pGate, int Value ) { pGate->Value = Value;    }
void              Mio_GateSetCell      ( Mio_Gate_t * pGate, int Cell )  { pGate->Cell  = Cell;     }
void              Mio_GateSetProfile   ( Mio_Gate_t * pGate, int Prof )  { pGate->Profile = Prof;   }
void              Mio_GateSetProfile2  ( Mio_Gate_t * pGate, int Prof )  { pGate->Profile2 = Prof;  }
void              Mio_GateIncProfile2  ( Mio_Gate_t * pGate )            { pGate->Profile2++;       }
void              Mio_GateDecProfile2  ( Mio_Gate_t * pGate )            { pGate->Profile2--;       }
void              Mio_GateAddToProfile ( Mio_Gate_t * pGate, int Prof )  { pGate->Profile  += Prof; }
void              Mio_GateAddToProfile2( Mio_Gate_t * pGate, int Prof )  { pGate->Profile2 += Prof; }
int               Mio_GateIsInv        ( Mio_Gate_t * pGate )            { return pGate->uTruth == ABC_CONST(0x5555555555555555); }
Alan Mishchenko committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
char *            Mio_PinReadName           ( Mio_Pin_t * pPin )      { return pPin->pName;           }
Mio_PinPhase_t    Mio_PinReadPhase          ( Mio_Pin_t * pPin )      { return pPin->Phase;           }
double            Mio_PinReadInputLoad      ( Mio_Pin_t * pPin )      { return pPin->dLoadInput;      }
double            Mio_PinReadMaxLoad        ( Mio_Pin_t * pPin )      { return pPin->dLoadMax;        }
double            Mio_PinReadDelayBlockRise ( Mio_Pin_t * pPin )      { return pPin->dDelayBlockRise; }
double            Mio_PinReadDelayFanoutRise( Mio_Pin_t * pPin )      { return pPin->dDelayFanoutRise;}
double            Mio_PinReadDelayBlockFall ( Mio_Pin_t * pPin )      { return pPin->dDelayBlockFall; }
double            Mio_PinReadDelayFanoutFall( Mio_Pin_t * pPin )      { return pPin->dDelayFanoutFall;}
214
double            Mio_PinReadDelayBlockMax  ( Mio_Pin_t * pPin )      { return pPin->dDelayBlockMax;  }
Alan Mishchenko committed
215 216
Mio_Pin_t *       Mio_PinReadNext           ( Mio_Pin_t * pPin )      { return pPin->pNext;           }

217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
char * Mio_GateReadPinName( Mio_Gate_t * pGate, int iPin )
{
    Mio_Pin_t * pPin;
    int i = 0;
    Mio_GateForEachPin( pGate, pPin )
        if ( i++ == iPin )
            return Mio_PinReadName(pPin);
    return NULL;
}
Alan Mishchenko committed
237 238 239 240 241 242 243 244 245
float Mio_GateReadPinDelay( Mio_Gate_t * pGate, int iPin )
{
    Mio_Pin_t * pPin;
    int i = 0;
    Mio_GateForEachPin( pGate, pPin )
        if ( i++ == iPin )
            return 0.5 * pPin->dDelayBlockRise + 0.5 * pPin->dDelayBlockFall;
    return ABC_INFINITY;
}
246

Alan Mishchenko committed
247 248 249 250 251
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


252 253
ABC_NAMESPACE_IMPL_END