summaryrefslogtreecommitdiffstats
path: root/src/base/ver/verParse.c
blob: c1ae1781fcdd6f5c6bd2fa1171964c4a8e0bed4c (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
/**CFile****************************************************************

  FileName    [verParse.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Verilog parser.]

  Synopsis    [Performs some Verilog parsing tasks.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - August 19, 2006.]

  Revision    [$Id: verParse.c,v 1.00 2006/08/19 00:00:00 alanmi Exp $]

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

#include "ver.h"

ABC_NAMESPACE_IMPL_START


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

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

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

  Synopsis    [Skips the comments of they are present.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Ver_ParseSkipComments( Ver_Man_t * pMan )
{
    Ver_Stream_t * p = pMan->pReader;
    char Symbol;
    // skip spaces
    Ver_StreamSkipChars( p, " \t\n\r" );
    if ( !Ver_StreamIsOkey(pMan->pReader) )
        return 1;
    // read the first symbol
    Symbol = Ver_StreamScanChar( p );
    if ( Symbol != '/' )
        return 1;
    Ver_StreamPopChar( p );
    // read the second symbol
    Symbol = Ver_StreamScanChar( p );
    if ( Symbol == '/' )
    { // skip till the end of line
        Ver_StreamSkipToChars( p, "\n" );
        return Ver_ParseSkipComments( pMan );
    }
    if ( Symbol == '*' )
    { // skip till the next occurance of */
        Ver_StreamPopChar( p );
        do {
            Ver_StreamSkipToChars( p, "*" );
            Ver_StreamPopChar( p );
        } while ( Ver_StreamScanChar( p ) != '/' );
        Ver_StreamPopChar( p );
        return Ver_ParseSkipComments( pMan );
    }
    sprintf( pMan->sError, "Cannot parse after symbol \"/\"." );
    Ver_ParsePrintErrorMessage( pMan );
    return 0;
}

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

  Synopsis    [Parses a Verilog name that can be being with a slash.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
char * Ver_ParseGetName( Ver_Man_t * pMan )
{
    Ver_Stream_t * p = pMan->pReader;
    char Symbol;
    char * pWord;
    pMan->fNameLast = 0;
    if ( !Ver_StreamIsOkey(p) )
        return NULL;
    if ( !Ver_ParseSkipComments( pMan ) )
        return NULL;
    Symbol = Ver_StreamScanChar( p );
    if ( Symbol == '\\' )
    {
        pMan->fNameLast = 1;
        Ver_StreamPopChar( p );
        pWord = Ver_StreamGetWord( p, " \r\n" );
        Ver_StreamSkipChars( p, " \r\n" );
        if ( Ver_StreamScanChar(p) == '[' )
        {
            char This, * pEnd = pWord + strlen( pWord );
            while ( (This = Ver_StreamPopChar(p)) != ']' )
                *pEnd++ = This;
            *pEnd++ = This;
            *pEnd = 0;
        }
    }
    else
        pWord = Ver_StreamGetWord( p, " \t\n\r(),;" );
    if ( Ver_StreamIsOkey(p) && !Ver_ParseSkipComments( pMan ) )
        return NULL;
    return pWord;
}


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


ABC_NAMESPACE_IMPL_END