mapper.c 5.24 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/**CFile****************************************************************

  FileName    [mapper.c]

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

  Synopsis    [Command file for the mapper package.]

  Author      [MVSIS Group]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 2.0. Started - June 1, 2004.]

  Revision    [$Id: mapper.c,v 1.7 2005/01/23 06:59:42 alanmi Exp $]

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

19 20 21
#include "base/abc/abc.h"
#include "base/main/mainInt.h"
#include "map/mio/mio.h"
Alan Mishchenko committed
22 23
#include "mapperInt.h"

24 25 26
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
27 28 29 30 31 32 33
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

static int Map_CommandReadLibrary ( Abc_Frame_t * pAbc, int argc, char **argv );

////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
34
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
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
////////////////////////////////////////////////////////////////////////

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Map_Init( Abc_Frame_t * pAbc )
{
    Cmd_CommandAdd( pAbc, "SC mapping", "read_super",  Map_CommandReadLibrary, 0 ); 
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
64
void Map_End( Abc_Frame_t * pAbc )
Alan Mishchenko committed
65 66
{
//    Map_SuperLibFree( s_pSuperLib );
67
     Map_SuperLibFree( (Map_SuperLib_t *)Abc_FrameReadLibSuper() );
Alan Mishchenko committed
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
}


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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Map_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv )
{
    FILE * pFile;
    FILE * pOut, * pErr;
    Map_SuperLib_t * pLib;
    Abc_Ntk_t * pNet;
    char * FileName, * ExcludeFile;
    int fVerbose;
    int fAlgorithm;
    int c;

Alan Mishchenko committed
93
    pNet = Abc_FrameReadNtk(pAbc);
Alan Mishchenko committed
94 95 96 97 98 99 100
    pOut = Abc_FrameReadOut(pAbc);
    pErr = Abc_FrameReadErr(pAbc);

    // set the defaults
    fVerbose = 1;
    fAlgorithm = 1;
    ExcludeFile = 0;
Alan Mishchenko committed
101 102
    Extra_UtilGetoptReset();
    while ( (c = Extra_UtilGetopt(argc, argv, "eovh")) != EOF ) 
Alan Mishchenko committed
103 104 105 106
    {
        switch (c) 
        {
            case 'e':
Alan Mishchenko committed
107
                ExcludeFile = argv[globalUtilOptind];
Alan Mishchenko committed
108 109
                if ( ExcludeFile == 0 )
                    goto usage;
Alan Mishchenko committed
110
                globalUtilOptind++;
Alan Mishchenko committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
                break;
            case 'o':
                fAlgorithm ^= 1;
                break;
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
                break;
            default:
                goto usage;
        }
    }


Alan Mishchenko committed
127
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
128 129 130 131 132
    {
        goto usage;
    }

    // get the input file name
Alan Mishchenko committed
133 134 135
    FileName = argv[globalUtilOptind];
    if ( (pFile = Io_FileOpen( FileName, "open_path", "r", 0 )) == NULL )
//    if ( (pFile = fopen( FileName, "r" )) == NULL )
Alan Mishchenko committed
136 137
    {
        fprintf( pErr, "Cannot open input file \"%s\". ", FileName );
Alan Mishchenko committed
138
        if (( FileName = Extra_FileGetSimilarName( FileName, ".genlib", ".lib", ".gen", ".g", NULL )) )
Alan Mishchenko committed
139 140 141 142 143 144
            fprintf( pErr, "Did you mean \"%s\"?", FileName );
        fprintf( pErr, "\n" );
        return 1;
    }
    fclose( pFile );

145 146 147 148 149 150
    if ( Abc_FrameReadLibGen() == NULL )
    {
        fprintf( pErr, "Genlib library should be read in first..\n" );
        return 1;
    }

Alan Mishchenko committed
151
    // set the new network
152
    pLib = Map_SuperLibCreate( (Mio_Library_t *)Abc_FrameReadLibGen(), NULL, FileName, ExcludeFile, fAlgorithm, fVerbose );
Alan Mishchenko committed
153 154 155
    if ( pLib == NULL )
    {
        fprintf( pErr, "Reading supergate library has failed.\n" );
156
        return 1;
Alan Mishchenko committed
157 158 159 160
    }
    // replace the current library
//    Map_SuperLibFree( s_pSuperLib );
//    s_pSuperLib = pLib;
161
    Map_SuperLibFree( (Map_SuperLib_t *)Abc_FrameReadLibSuper() );
Alan Mishchenko committed
162
    Abc_FrameSetLibSuper( pLib );
Alan Mishchenko committed
163
    // replace the current genlib library
164 165
//    Mio_LibraryDelete( (Mio_Library_t *)Abc_FrameReadLibGen() );
//    Abc_FrameSetLibGen( (Mio_Library_t *)pLib->pGenlib );
Alan Mishchenko committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
    return 0;

usage:
    fprintf( pErr, "\nusage: read_super [-ovh]\n");
    fprintf( pErr, "\t         read the supergate library from the file\n" );  
    fprintf( pErr, "\t-e file : file contains list of genlib gates to exclude\n" );
    fprintf( pErr, "\t-o      : toggles the use of old file format [default = %s]\n", (fAlgorithm? "new" : "old") );
    fprintf( pErr, "\t-v      : toggles enabling of verbose output [default = %s]\n", (fVerbose? "yes" : "no") );
    fprintf( pErr, "\t-h      : print the command usage\n");
    return 1;       /* error exit */
}


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


184 185
ABC_NAMESPACE_IMPL_END