OpenCores
URL https://opencores.org/ocsvn/jtag_stapl_player/jtag_stapl_player/trunk

Subversion Repositories jtag_stapl_player

[/] [jtag_stapl_player/] [trunk/] [jamstack.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sukhanov
/****************************************************************************/
2
/*                                                                                                                                                      */
3
/*      Module:                 jamstack.c                                                                                              */
4
/*                                                                                                                                                      */
5
/*                                      Copyright (C) Altera Corporation 1997                                   */
6
/*                                                                                                                                                      */
7
/*      Description:    Functions for maintaining the stack                                             */
8
/*                                                                                                                                                      */
9
/*      Revisions:              1.1 added support for dynamic memory allocation                 */
10
/*                                                                                                                                                      */
11
/****************************************************************************/
12
 
13
/****************************************************************************/
14
/*                                                                                                                                                      */
15
/*      Actel version 1.1             May 2003                                                                  */
16
/*                                                                                                                                                      */
17
/****************************************************************************/
18
 
19
#include "jamexprt.h"
20
#include "jamdefs.h"
21
#include "jamutil.h"
22
#include "jamsym.h"
23
#include "jamstack.h"
24
 
25
JAMS_STACK_RECORD *jam_stack = 0;
26
 
27
/****************************************************************************/
28
/*                                                                                                                                                      */
29
 
30
JAM_RETURN_TYPE jam_init_stack(void)
31
 
32
/*                                                                                                                                                      */
33
/*      Description:    Initialize the stack.  The stack is located after the   */
34
/*                                      symbol table in the workspace buffer.                                   */
35
/*                                                                                                                                                      */
36
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
37
/*                                                                                                                                                      */
38
/****************************************************************************/
39
{
40
        int index = 0;
41
        int size = 0;
42
        JAM_RETURN_TYPE return_code = JAMC_SUCCESS;
43
        void **symbol_table = NULL;
44
 
45
        if (jam_workspace != NULL)
46
        {
47
                symbol_table = (void **) jam_workspace;
48
                jam_stack = (JAMS_STACK_RECORD *) &symbol_table[JAMC_MAX_SYMBOL_COUNT];
49
 
50
                size = (JAMC_MAX_SYMBOL_COUNT * sizeof(void *)) +
51
                        (JAMC_MAX_NESTING_DEPTH * sizeof(JAMS_STACK_RECORD));
52
 
53
                if (jam_workspace_size < size)
54
                {
55
                        return_code = JAMC_OUT_OF_MEMORY;
56
                }
57
        }
58
        else
59
        {
60
                jam_stack = jam_malloc(
61
                        JAMC_MAX_NESTING_DEPTH * sizeof(JAMS_STACK_RECORD));
62
 
63
                if (jam_stack == NULL)
64
                {
65
                        return_code = JAMC_OUT_OF_MEMORY;
66
                }
67
        }
68
 
69
        if (return_code == JAMC_SUCCESS)
70
        {
71
                for (index = 0; index < JAMC_MAX_NESTING_DEPTH; ++index)
72
                {
73
                        jam_stack[index].type = JAM_ILLEGAL_STACK_TYPE;
74
                        jam_stack[index].iterator = (JAMS_SYMBOL_RECORD *) 0;
75
                        jam_stack[index].for_position = 0L;
76
                        jam_stack[index].stop_value = 0L;
77
                        jam_stack[index].step_value = 0L;
78
                        jam_stack[index].push_value = 0L;
79
                        jam_stack[index].return_position = 0L;
80
                }
81
        }
82
 
83
        return (return_code);
84
}
85
 
86
void jam_free_stack(void)
87
{
88
        if ((jam_stack != NULL) && (jam_workspace == NULL))
89
        {
90
                jam_free(jam_stack);
91
        }
92
}
93
 
94
/****************************************************************************/
95
/*                                                                                                                                                      */
96
 
97
JAM_RETURN_TYPE jam_push_stack_record
98
(
99
        JAMS_STACK_RECORD *stack_record
100
)
101
 
102
/*                                                                                                                                                      */
103
/*      Description:    Creates a new stack record with the specified                   */
104
/*                                      attributes.                                                                                             */
105
/*                                                                                                                                                      */
106
/*      Returns:                JAMC_SUCCESS for success, or JAMC_OUT_OF_MEMORY if              */
107
/*                                      the stack was already full                                                              */
108
/*                                                                                                                                                      */
109
/****************************************************************************/
110
{
111
        int index = 0;
112
        JAM_RETURN_TYPE return_code = JAMC_OUT_OF_MEMORY;
113
 
114
        /*
115
        *       Find stack top
116
        */
117
        while ((index < JAMC_MAX_NESTING_DEPTH) &&
118
                (jam_stack[index].type != JAM_ILLEGAL_STACK_TYPE))
119
        {
120
                ++index;
121
        }
122
 
123
        /*
124
        *       Add new stack record
125
        */
126
        if ((index < JAMC_MAX_NESTING_DEPTH) &&
127
                (jam_stack[index].type == JAM_ILLEGAL_STACK_TYPE))
128
        {
129
                jam_stack[index].type            = stack_record->type;
130
                jam_stack[index].iterator        = stack_record->iterator;
131
                jam_stack[index].for_position    = stack_record->for_position;
132
                jam_stack[index].stop_value      = stack_record->stop_value;
133
                jam_stack[index].step_value      = stack_record->step_value;
134
                jam_stack[index].push_value      = stack_record->push_value;
135
                jam_stack[index].return_position = stack_record->return_position;
136
 
137
                return_code = JAMC_SUCCESS;
138
        }
139
 
140
        return (return_code);
141
}
142
 
143
/****************************************************************************/
144
/*                                                                                                                                                      */
145
 
146
JAMS_STACK_RECORD *jam_peek_stack_record(void)
147
 
148
/*                                                                                                                                                      */
149
/*      Description:    Finds the top of the stack                                                              */
150
/*                                                                                                                                                      */
151
/*      Returns:                Pointer to the top-most stack record, or NULL if the    */
152
/*                                      stack is empty                                                                                  */
153
/*                                                                                                                                                      */
154
/****************************************************************************/
155
{
156
        int index = 0;
157
        JAMS_STACK_RECORD *top = NULL;
158
 
159
        /*
160
        *       Find stack top
161
        */
162
        while ((index < JAMC_MAX_NESTING_DEPTH) &&
163
                (jam_stack[index].type != JAM_ILLEGAL_STACK_TYPE))
164
        {
165
                ++index;
166
        }
167
 
168
        if ((index > 0) && (index < JAMC_MAX_NESTING_DEPTH))
169
        {
170
                top = &jam_stack[index - 1];
171
        }
172
 
173
        return (top);
174
}
175
 
176
/****************************************************************************/
177
/*                                                                                                                                                      */
178
 
179
JAM_RETURN_TYPE jam_pop_stack_record(void)
180
 
181
/*                                                                                                                                                      */
182
/*      Description:    Deletes the top-most stack record from the stack                */
183
/*                                                                                                                                                      */
184
/*      Returns:                JAMC_SUCCESS for success, or JAMC_OUT_OF_MEMORY if the  */
185
/*                                      stack was empty                                                                                 */
186
/*                                                                                                                                                      */
187
/****************************************************************************/
188
{
189
        int index = 0;
190
        JAM_RETURN_TYPE return_code = JAMC_OUT_OF_MEMORY;
191
 
192
        /*
193
        *       Find stack top
194
        */
195
        while ((index < JAMC_MAX_NESTING_DEPTH) &&
196
                (jam_stack[index].type != JAM_ILLEGAL_STACK_TYPE))
197
        {
198
                ++index;
199
        }
200
 
201
        /*
202
        *       Delete stack record
203
        */
204
        if ((index > 0) && (index < JAMC_MAX_NESTING_DEPTH))
205
        {
206
                --index;
207
 
208
                jam_stack[index].type = JAM_ILLEGAL_STACK_TYPE;
209
                jam_stack[index].iterator = (JAMS_SYMBOL_RECORD *) 0;
210
                jam_stack[index].for_position = 0L;
211
                jam_stack[index].stop_value = 0L;
212
                jam_stack[index].step_value = 0L;
213
                jam_stack[index].push_value = 0L;
214
                jam_stack[index].return_position = 0L;
215
 
216
                return_code = JAMC_SUCCESS;
217
        }
218
 
219
        return (return_code);
220
}
221
 
222
/****************************************************************************/
223
/*                                                                                                                                                      */
224
 
225
JAM_RETURN_TYPE jam_push_fornext_record
226
(
227
        JAMS_SYMBOL_RECORD *iterator,
228
        long for_position,
229
        long stop_value,
230
        long step_value
231
)
232
 
233
/*                                                                                                                                                      */
234
/*      Description:    Pushes a FOR/NEXT record onto the stack                                 */
235
/*                                                                                                                                                      */
236
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
237
/*                                                                                                                                                      */
238
/****************************************************************************/
239
{
240
        JAMS_STACK_RECORD stack_record;
241
 
242
        stack_record.type            = JAM_STACK_FOR_NEXT;
243
        stack_record.iterator        = iterator;
244
        stack_record.for_position    = for_position;
245
        stack_record.stop_value      = stop_value;
246
        stack_record.step_value      = step_value;
247
        stack_record.push_value      = 0L;
248
        stack_record.return_position = 0L;
249
 
250
        return (jam_push_stack_record(&stack_record));
251
}
252
 
253
/****************************************************************************/
254
/*                                                                                                                                                      */
255
 
256
JAM_RETURN_TYPE jam_push_pushpop_record
257
(
258
        long value
259
)
260
 
261
/*                                                                                                                                                      */
262
/*      Description:    Pushes a PUSH/POP record onto the stack                                 */
263
/*                                                                                                                                                      */
264
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
265
/*                                                                                                                                                      */
266
/****************************************************************************/
267
{
268
        JAMS_STACK_RECORD stack_record;
269
 
270
        stack_record.type            = JAM_STACK_PUSH_POP;
271
        stack_record.iterator        = NULL;
272
        stack_record.for_position    = 0L;
273
        stack_record.stop_value      = 0L;
274
        stack_record.step_value      = 0L;
275
        stack_record.push_value      = value;
276
        stack_record.return_position = 0L;
277
 
278
        return (jam_push_stack_record(&stack_record));
279
}
280
 
281
/****************************************************************************/
282
/*                                                                                                                                                      */
283
 
284
JAM_RETURN_TYPE jam_push_callret_record
285
(
286
        long return_position
287
)
288
 
289
/*                                                                                                                                                      */
290
/*      Description:    Pushes a CALL/RETURN record onto the stack                              */
291
/*                                                                                                                                                      */
292
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
293
/*                                                                                                                                                      */
294
/****************************************************************************/
295
{
296
        JAMS_STACK_RECORD stack_record;
297
 
298
        stack_record.type            = JAM_STACK_CALL_RETURN;
299
        stack_record.iterator        = NULL;
300
        stack_record.for_position    = 0L;
301
        stack_record.stop_value      = 0L;
302
        stack_record.step_value      = 0L;
303
        stack_record.push_value      = 0L;
304
        stack_record.return_position = return_position;
305
 
306
        return (jam_push_stack_record(&stack_record));
307
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.