abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
parseStack.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [parseStack.c]
4 
5  PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]
6 
7  Synopsis [Stacks used by the formula parser.]
8 
9  Author [MVSIS Group]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 1.0. Started - August 18, 2003.]
14 
15  Revision [$Id: parseStack.c,v 1.0 2003/02/01 00:00:00 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "parseInt.h"
20 
22 
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// DECLARATIONS ///
26 ////////////////////////////////////////////////////////////////////////
27 
29 {
30  void ** pData; // the array of elements
31  int Top; // the index
32  int Size; // the stack size
33 };
34 
36 {
37  int * pData; // the array of elements
38  int Top; // the index
39  int Size; // the stack size
40 };
41 
42 ////////////////////////////////////////////////////////////////////////
43 /// FUNCTION DEFINITIONS ///
44 ////////////////////////////////////////////////////////////////////////
45 
46 /**Function*************************************************************
47 
48  Synopsis [Starts the stack.]
49 
50  Description []
51 
52  SideEffects []
53 
54  SeeAlso []
55 
56 ***********************************************************************/
58 {
60  p = ABC_ALLOC( Parse_StackFn_t, 1 );
61  memset( p, 0, sizeof(Parse_StackFn_t) );
62  p->pData = ABC_ALLOC( void *, nDepth );
63  p->Size = nDepth;
64  return p;
65 }
66 
67 /**Function*************************************************************
68 
69  Synopsis [Checks whether the stack is empty.]
70 
71  Description []
72 
73  SideEffects []
74 
75  SeeAlso []
76 
77 ***********************************************************************/
79 {
80  return (int)(p->Top == 0);
81 }
82 
83 /**Function*************************************************************
84 
85  Synopsis [Pushes an entry into the stack.]
86 
87  Description []
88 
89  SideEffects []
90 
91  SeeAlso []
92 
93 ***********************************************************************/
94 void Parse_StackFnPush( Parse_StackFn_t * p, void * bFunc )
95 {
96  if ( p->Top >= p->Size )
97  {
98  printf( "Parse_StackFnPush(): Stack size is too small!\n" );
99  return;
100  }
101  p->pData[ p->Top++ ] = bFunc;
102 }
103 
104 /**Function*************************************************************
105 
106  Synopsis [Pops an entry out of the stack.]
107 
108  Description []
109 
110  SideEffects []
111 
112  SeeAlso []
113 
114 ***********************************************************************/
116 {
117  if ( p->Top == 0 )
118  {
119  printf( "Parse_StackFnPush(): Trying to extract data from the empty stack!\n" );
120  return NULL;
121  }
122  return p->pData[ --p->Top ];
123 }
124 
125 /**Function*************************************************************
126 
127  Synopsis [Deletes the stack.]
128 
129  Description []
130 
131  SideEffects []
132 
133  SeeAlso []
134 
135 ***********************************************************************/
137 {
138  ABC_FREE( p->pData );
139  ABC_FREE( p );
140 }
141 
142 
143 
144 
145 /**Function*************************************************************
146 
147  Synopsis [Starts the stack.]
148 
149  Description []
150 
151  SideEffects []
152 
153  SeeAlso []
154 
155 ***********************************************************************/
157 {
158  Parse_StackOp_t * p;
159  p = ABC_ALLOC( Parse_StackOp_t, 1 );
160  memset( p, 0, sizeof(Parse_StackOp_t) );
161  p->pData = ABC_ALLOC( int, nDepth );
162  p->Size = nDepth;
163  return p;
164 }
165 
166 /**Function*************************************************************
167 
168  Synopsis [Checks whether the stack is empty.]
169 
170  Description []
171 
172  SideEffects []
173 
174  SeeAlso []
175 
176 ***********************************************************************/
178 {
179  return (int)(p->Top == 0);
180 }
181 
182 /**Function*************************************************************
183 
184  Synopsis [Pushes an entry into the stack.]
185 
186  Description []
187 
188  SideEffects []
189 
190  SeeAlso []
191 
192 ***********************************************************************/
194 {
195  if ( p->Top >= p->Size )
196  {
197  printf( "Parse_StackOpPush(): Stack size is too small!\n" );
198  return;
199  }
200  p->pData[ p->Top++ ] = Oper;
201 }
202 
203 /**Function*************************************************************
204 
205  Synopsis [Pops an entry out of the stack.]
206 
207  Description []
208 
209  SideEffects []
210 
211  SeeAlso []
212 
213 ***********************************************************************/
215 {
216  if ( p->Top == 0 )
217  {
218  printf( "Parse_StackOpPush(): Trying to extract data from the empty stack!\n" );
219  return -1;
220  }
221  return p->pData[ --p->Top ];
222 }
223 
224 /**Function*************************************************************
225 
226  Synopsis [Deletes the stack.]
227 
228  Description []
229 
230  SideEffects []
231 
232  SeeAlso []
233 
234 ***********************************************************************/
236 {
237  ABC_FREE( p->pData );
238  ABC_FREE( p );
239 }
240 
241 
242 ////////////////////////////////////////////////////////////////////////
243 /// END OF FILE ///
244 ////////////////////////////////////////////////////////////////////////
245 
246 
248 
char * memset()
Parse_StackOp_t * Parse_StackOpStart(int nDepth)
Definition: parseStack.c:156
int Parse_StackOpIsEmpty(Parse_StackOp_t *p)
Definition: parseStack.c:177
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Parse_StackOpPop(Parse_StackOp_t *p)
Definition: parseStack.c:214
void * Parse_StackFnPop(Parse_StackFn_t *p)
Definition: parseStack.c:115
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Parse_StackFnPush(Parse_StackFn_t *p, void *bFunc)
Definition: parseStack.c:94
void Parse_StackOpFree(Parse_StackOp_t *p)
Definition: parseStack.c:235
void Parse_StackFnFree(Parse_StackFn_t *p)
Definition: parseStack.c:136
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
int Parse_StackFnIsEmpty(Parse_StackFn_t *p)
Definition: parseStack.c:78
typedefABC_NAMESPACE_HEADER_START struct ParseStackFnStruct Parse_StackFn_t
INCLUDES ///.
Definition: parseInt.h:43
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define ABC_FREE(obj)
Definition: abc_global.h:232
Parse_StackFn_t * Parse_StackFnStart(int nDepth)
FUNCTION DEFINITIONS ///.
Definition: parseStack.c:57
void Parse_StackOpPush(Parse_StackOp_t *p, int Oper)
Definition: parseStack.c:193
DECLARATIONS ///.
Definition: parseStack.c:28