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

Subversion Repositories jtag_stapl_player

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sukhanov
/****************************************************************************/
2
/*                                                                                                                                                      */
3
/*      Module:                 jamexec.c                                                                                               */
4
/*                                                                                                                                                      */
5
/*                                      Copyright (C) Altera Corporation 1997                                   */
6
/*                                                                                                                                                      */
7
/*      Description:    Contains the main entry point jam_execute(), and                */
8
/*                                      other functions to implement the main execution loop.   */
9
/*                                      This loop repeatedly calls jam_get_statement() and              */
10
/*                                      jam_execute_statement() to process statements in                */
11
/*                                      the JAM source file.                                                                    */
12
/*                                                                                                                                                      */
13
/*      Revisions:              1.1     added support for VECTOR CAPTURE and VECTOR COMPARE     */
14
/*                                      statements                                                                                              */
15
/*                                      added support for dynamic memory allocation                             */
16
/*                                      1.2 fixed STATE statement to accept a space-separated   */
17
/*                                      list of states as well as a comma-separated list                */
18
/*                                                                                                                                                      */
19
/****************************************************************************/
20
 
21
/****************************************************************************/
22
/*                                                                                                                                                      */
23
/*      Actel version 1.1             May 2003                                                                  */
24
/*                                                                                                                                                      */
25
/****************************************************************************/
26
 
27
#include "jamport.h"
28
#include "jamexprt.h"
29
#include "jamdefs.h"
30
#include "jamexec.h"
31
#include "jamutil.h"
32
#include "jamexp.h"
33
#include "jamsym.h"
34
#include "jamstack.h"
35
#include "jamheap.h"
36
#include "jamarray.h"
37
#include "jamjtag.h"
38
#include "jamcomp.h"
39
 
40
/****************************************************************************/
41
/*                                                                                                                                                      */
42
/*      Global variables                                                                                                                */
43
/*                                                                                                                                                      */
44
/****************************************************************************/
45
 
46
/* pointer to memory buffer for variable, symbol and stack storage */
47
char *jam_workspace = NULL;
48
 
49
/* size of available memory buffer */
50
long jam_workspace_size = 0L;
51
 
52
/* pointer to Jam program text */
53
char *jam_program = NULL;
54
 
55
/* size of program buffer */
56
long jam_program_size = 0L;
57
 
58
/* current position in input stream */
59
long jam_current_file_position = 0L;
60
 
61
/* position in input stream of the beginning of the current statement */
62
long jam_current_statement_position = 0L;
63
 
64
/* position of the beginning of the next statement (the one after the */
65
/* current statement, but not necessarily the next one to be executed) */
66
long jam_next_statement_position = 0L;
67
 
68
/* name of desired action (Jam 2.0 only) */
69
char *jam_action = NULL;
70
 
71
/* pointer to initialization list */
72
char **jam_init_list = NULL;
73
 
74
/* buffer for constant literal boolean array data */
75
#define JAMC_MAX_LITERAL_ARRAYS 4
76
long jam_literal_array_buffer[JAMC_MAX_LITERAL_ARRAYS];
77
 
78
/* buffer for constant literal ACA array data */
79
long *jam_literal_aca_buffer[JAMC_MAX_LITERAL_ARRAYS];
80
 
81
/* number of vector signals */
82
int jam_vector_signal_count = 0;
83
 
84
/* version of Jam language used:  0 = unknown */
85
int jam_version = 0;
86
 
87
/* phase of Jam execution */
88
JAME_PHASE_TYPE jam_phase = JAM_UNKNOWN_PHASE;
89
 
90
/* current procedure or data block */
91
JAMS_SYMBOL_RECORD *jam_current_block = NULL;
92
 
93
/* this global flag indicates that we are processing the items in */
94
/* the "uses" list for a procedure, executing the data blocks if */
95
/* they have not yet been initialized, but not calling any procedures */
96
BOOL jam_checking_uses_list = FALSE;
97
 
98
/* function prototypes for forward reference */
99
JAM_RETURN_TYPE jam_process_data(char *statement_buffer);
100
JAM_RETURN_TYPE jam_process_procedure(char *statement_buffer);
101
JAM_RETURN_TYPE jam_process_wait(char *statement_buffer);
102
JAM_RETURN_TYPE jam_execute_statement(char *statement_buffer, BOOL *done,
103
        BOOL *reuse_statement_buffer, int *exit_code);
104
 
105
/* prototype for external function in jamarray.c */
106
extern int jam_6bit_char(int ch);
107
 
108
/* prototype for external function in jamsym.c */
109
extern BOOL jam_check_init_list(char *name, long *value);
110
 
111
/****************************************************************************/
112
/*                                                                                                                                                      */
113
 
114
JAM_RETURN_TYPE jam_get_statement
115
(
116
        char *statement_buffer,
117
        char *label_buffer
118
)
119
 
120
/*                                                                                                                                                      */
121
/*      Description:    This function reads a full statement from the input             */
122
/*                                      stream, preprocesses it to remove comments, and stores  */
123
/*                                      it in a buffer.  If the statement is an array                   */
124
/*                                      declaration the initialization data is not stored in    */
125
/*                                      the buffer but must be read from the input stream when  */
126
/*                                      the array is used.                                                                              */
127
/*                                                                                                                                                      */
128
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
129
/*                                                                                                                                                      */
130
/****************************************************************************/
131
{
132
        int index = 0;
133
        int label_index = 0;
134
        int ch = 0;
135
        int last_ch = 0;
136
        BOOL comment = FALSE;
137
        BOOL quoted_string = FALSE;
138
        BOOL boolean_array_data = FALSE;
139
        BOOL literal_aca_array = FALSE;
140
        BOOL label_found = FALSE;
141
        BOOL done = FALSE;
142
        long position = jam_current_file_position;
143
        long first_char_position = -1L;
144
        long semicolon_position = -1L;
145
        long left_quote_position = -1L;
146
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
147
 
148
        label_buffer[0] = JAMC_NULL_CHAR;
149
        statement_buffer[0] = JAMC_NULL_CHAR;
150
 
151
        while (!done)
152
        {
153
                last_ch = ch;
154
                ch = jam_getc();
155
 
156
                if ((!comment) && (!quoted_string))
157
                {
158
                        if (ch == JAMC_COMMENT_CHAR)
159
                        {
160
                                /* beginning of comment */
161
                                comment = TRUE;
162
                        }
163
                        else if (ch == JAMC_QUOTE_CHAR)
164
                        {
165
                                /* beginning of quoted string */
166
                                quoted_string = TRUE;
167
                                left_quote_position = position;
168
                        }
169
                        else if (ch == JAMC_COLON_CHAR)
170
                        {
171
                                /* statement contains a label */
172
                                if (label_found)
173
                                {
174
                                        /* multiple labels found */
175
                                        status = JAMC_SYNTAX_ERROR;
176
                                        done = TRUE;
177
                                }
178
                                else if (index <= JAMC_MAX_NAME_LENGTH)
179
                                {
180
                                        /* copy label into label_buffer */
181
                                        for (label_index = 0; label_index < index; label_index++)
182
                                        {
183
                                                label_buffer[label_index] =
184
                                                        statement_buffer[label_index];
185
                                        }
186
                                        label_buffer[index] = JAMC_NULL_CHAR;
187
                                        label_found = TRUE;
188
 
189
                                        /* delete label from statement_buffer */
190
                                        index = 0;
191
                                        statement_buffer[0] = JAMC_NULL_CHAR;
192
                                        first_char_position = -1L;
193
                                        ch = JAMC_SPACE_CHAR;
194
                                }
195
                                else
196
                                {
197
                                        /* label name was too long */
198
                                        status = JAMC_ILLEGAL_SYMBOL;
199
                                        done = TRUE;
200
                                }
201
                        }
202
                        else if ((ch == JAMC_TAB_CHAR) ||
203
                                (ch == JAMC_NEWLINE_CHAR) ||
204
                                (ch == JAMC_RETURN_CHAR))
205
                        {
206
                                /* convert tab, CR, LF to space character */
207
                                ch = JAMC_SPACE_CHAR;
208
                        }
209
                }
210
 
211
                /* save character in statement_buffer */
212
                if ((!comment) && (index < JAMC_MAX_STATEMENT_LENGTH) &&
213
                        ((first_char_position != -1L) || (ch != JAMC_SPACE_CHAR)) &&
214
                        (quoted_string ||
215
                                (ch != JAMC_SPACE_CHAR) || (last_ch != JAMC_SPACE_CHAR)))
216
                {
217
                        /* save the character */
218
                        /* convert to upper case except quotes and boolean arrays */
219
                        if (quoted_string || boolean_array_data || literal_aca_array)
220
                        {
221
                                statement_buffer[index] = (char) ch;
222
                        }
223
                        else
224
                        {
225
                                statement_buffer[index] = (char)
226
                                        (((ch >= 'a') && (ch <= 'z')) ? (ch - ('a' - 'A')) : ch);
227
                        }
228
                        ++index;
229
                        if (first_char_position == -1L) first_char_position = position;
230
 
231
                        /*
232
                        *       Whenever we see a right bracket character, check if the
233
                        *       statement is a Boolean array declaration statement.
234
                        */
235
                        if ((!boolean_array_data) && (ch == JAMC_RBRACKET_CHAR)
236
                                && (statement_buffer[0] == 'B'))
237
                        {
238
                                if (jam_strncmp(statement_buffer, "BOOLEAN", 7) == 0)
239
                                {
240
                                        boolean_array_data = TRUE;
241
                                }
242
                        }
243
 
244
                        /*
245
                        *       Check for literal ACA array assignment
246
                        */
247
                        if ((!quoted_string) && (!boolean_array_data) &&
248
                                (!literal_aca_array) && (ch == JAMC_AT_CHAR))
249
                        {
250
                                /* this is the beginning of a literal ACA array */
251
                                literal_aca_array = TRUE;
252
                        }
253
 
254
                        if (literal_aca_array &&
255
                                (!jam_isalnum((char) ch)) &&
256
                                (ch != JAMC_AT_CHAR) &&
257
                                (ch != JAMC_UNDERSCORE_CHAR) &&
258
                                (ch != JAMC_SPACE_CHAR))
259
                        {
260
                                /* this is the end of the literal ACA array */
261
                                literal_aca_array = FALSE;
262
                        }
263
                }
264
 
265
                if ((!comment) && (!quoted_string) && (ch == JAMC_SEMICOLON_CHAR))
266
                {
267
                        /* end of statement */
268
                        done = TRUE;
269
                        semicolon_position = position;
270
                }
271
 
272
                if (ch == EOF)
273
                {
274
                        /* end of file */
275
                        done = TRUE;
276
                        status = JAMC_UNEXPECTED_END;
277
                }
278
 
279
                if (comment &&
280
                        ((ch == JAMC_NEWLINE_CHAR) || (ch == JAMC_RETURN_CHAR)))
281
                {
282
                        /* end of comment */
283
                        comment = FALSE;
284
                }
285
                else if (quoted_string && (ch == JAMC_QUOTE_CHAR) &&
286
                        (position > left_quote_position))
287
                {
288
                        /* end of quoted string */
289
                        quoted_string = FALSE;
290
                }
291
 
292
                ++position;     /* position of next character to be read */
293
        }
294
 
295
        if (index < JAMC_MAX_STATEMENT_LENGTH)
296
        {
297
                statement_buffer[index] = JAMC_NULL_CHAR;
298
        }
299
        else
300
        {
301
                statement_buffer[JAMC_MAX_STATEMENT_LENGTH] = JAMC_NULL_CHAR;
302
        }
303
 
304
        jam_current_file_position = position;
305
 
306
        if (first_char_position != -1L)
307
        {
308
                jam_current_statement_position = first_char_position;
309
        }
310
 
311
        if (semicolon_position != -1L)
312
        {
313
                jam_next_statement_position = semicolon_position + 1;
314
        }
315
 
316
        return (status);
317
}
318
 
319
struct JAMS_INSTR_MAP
320
{
321
        JAME_INSTRUCTION instruction;
322
        char string[JAMC_MAX_INSTR_LENGTH + 1];
323
} jam_instruction_table[] =
324
{
325
        { JAM_ACTION_INSTR,  "ACTION"  },
326
        { JAM_BOOLEAN_INSTR, "BOOLEAN" },
327
        { JAM_CALL_INSTR,    "CALL"    },
328
        { JAM_CRC_INSTR,     "CRC"     },
329
        { JAM_DATA_INSTR,    "DATA"    },
330
        { JAM_DRSCAN_INSTR,  "DRSCAN"  },
331
        { JAM_DRSTOP_INSTR,  "DRSTOP"  },
332
        { JAM_ENDDATA_INSTR, "ENDDATA" },
333
        { JAM_ENDPROC_INSTR, "ENDPROC" },
334
        { JAM_EXIT_INSTR,    "EXIT"    },
335
        { JAM_EXPORT_INSTR,  "EXPORT"  },
336
        { JAM_FOR_INSTR,     "FOR"     },
337
        { JAM_FREQUENCY_INSTR, "FREQUENCY" },
338
        { JAM_GOTO_INSTR,    "GOTO"    },
339
        { JAM_IF_INSTR,      "IF"      },
340
        { JAM_INTEGER_INSTR, "INTEGER" },
341
        { JAM_IRSCAN_INSTR,  "IRSCAN"  },
342
        { JAM_IRSTOP_INSTR,  "IRSTOP"  },
343
        { JAM_LET_INSTR,     "LET"     },
344
        { JAM_NEXT_INSTR,    "NEXT"    },
345
        { JAM_NOTE_INSTR,    "NOTE"    },
346
        { JAM_PADDING_INSTR, "PADDING" },
347
        { JAM_POP_INSTR,     "POP"     },
348
        { JAM_POSTDR_INSTR,  "POSTDR"  },
349
        { JAM_POSTIR_INSTR,  "POSTIR"  },
350
        { JAM_PREDR_INSTR,   "PREDR"   },
351
        { JAM_PREIR_INSTR,   "PREIR"   },
352
        { JAM_PRINT_INSTR,   "PRINT"   },
353
        { JAM_PROCEDURE_INSTR, "PROCEDURE" },
354
        { JAM_PUSH_INSTR,    "PUSH"    },
355
        { JAM_REM_INSTR,     "REM"     },
356
        { JAM_RETURN_INSTR,  "RETURN"  },
357
        { JAM_STATE_INSTR,   "STATE"   },
358
        { JAM_TRST_INSTR,    "TRST"    },
359
        { JAM_VECTOR_INSTR,  "VECTOR"  },
360
        { JAM_VMAP_INSTR,    "VMAP"    },
361
        { JAM_WAIT_INSTR,    "WAIT"    }
362
};
363
 
364
#define JAMC_INSTR_COUNT \
365
  ((int) (sizeof(jam_instruction_table) / sizeof(jam_instruction_table[0])))
366
 
367
/****************************************************************************/
368
/*                                                                                                                                                      */
369
 
370
JAME_INSTRUCTION jam_get_instruction
371
(
372
        char *statement
373
)
374
 
375
/*                                                                                                                                                      */
376
/*      Description:    This function extracts the instruction name from the    */
377
/*                                      statement buffer and looks up the instruction code.             */
378
/*                                                                                                                                                      */
379
/*      Returns:                instruction code                                                                                */
380
/*                                                                                                                                                      */
381
/****************************************************************************/
382
{
383
        int index = 0;
384
        int instr_index = 0;
385
        int length = 0;
386
        BOOL done = FALSE;
387
        JAME_INSTRUCTION instruction = JAM_ILLEGAL_INSTR;
388
        char instr_name[JAMC_MAX_INSTR_LENGTH + 1];
389
 
390
        /*
391
        *       Extract instruction name and convert to upper case
392
        */
393
        for (index = 0; (!done) && (index < JAMC_MAX_INSTR_LENGTH); index++)
394
        {
395
                /* copy characters until non-alphabetic character */
396
                if ((statement[index] >= 'A') && (statement[index] <= 'Z'))
397
                {
398
                        instr_name[index] = statement[index];
399
                }
400
                else if ((statement[index] >= 'a') && (statement[index] <= 'z'))
401
                {
402
                        /* convert to upper case */
403
                        instr_name[index] = (char) ((statement[index] - 'a') + 'A');
404
                }
405
                else
406
                {
407
                        /* end of instruction name */
408
                        instr_name[index] = JAMC_NULL_CHAR;
409
                        length = index;
410
                        done = TRUE;
411
                }
412
        }
413
 
414
        /*
415
        *       Search for instruction name in instruction table
416
        */
417
        if (done && (length > 0))
418
        {
419
                done = FALSE;
420
 
421
                for (index = 0; (!done) && (index < JAMC_INSTR_COUNT); index++)
422
                {
423
                        done = TRUE;
424
 
425
                        for (instr_index = 0; done && (instr_index < length); instr_index++)
426
                        {
427
                                if (instr_name[instr_index] !=
428
                                        jam_instruction_table[index].string[instr_index])
429
                                {
430
                                        done = FALSE;
431
                                }
432
                        }
433
 
434
                        if (done &&
435
                                (jam_instruction_table[index].string[length] != '\0'))
436
                        {
437
                                done = FALSE;
438
                        }
439
 
440
                        if (done)
441
                        {
442
                                instruction = jam_instruction_table[index].instruction;
443
                        }
444
                }
445
        }
446
 
447
        return (instruction);
448
}
449
 
450
/****************************************************************************/
451
/*                                                                                                                                                      */
452
 
453
int jam_skip_instruction_name
454
(
455
        char *statement_buffer
456
)
457
 
458
/*                                                                                                                                                      */
459
/*      Description:    This function skips over the first "word" in the                */
460
/*                                      statement buffer, which is assumed to be the name of    */
461
/*                                      the instruction, and returns the index of the next              */
462
/*                                      non-white-space character in the buffer.                                */
463
/*                                                                                                                                                      */
464
/*      Returns:                index of statement text after instruction name                  */
465
/*                                                                                                                                                      */
466
/****************************************************************************/
467
{
468
        int index = 0;
469
 
470
        while ((jam_isspace(statement_buffer[index])) &&
471
                (index < JAMC_MAX_STATEMENT_LENGTH))
472
        {
473
                ++index;        /* skip over white space */
474
        }
475
 
476
        while ((jam_is_name_char(statement_buffer[index])) &&
477
                (index < JAMC_MAX_STATEMENT_LENGTH))
478
        {
479
                ++index;        /* skip over instruction name */
480
        }
481
 
482
        while ((jam_isspace(statement_buffer[index])) &&
483
                (index < JAMC_MAX_STATEMENT_LENGTH))
484
        {
485
                ++index;        /* skip over white space */
486
        }
487
 
488
        return (index);
489
}
490
 
491
/****************************************************************************/
492
/*                                                                                                                                                      */
493
 
494
int jam_find_keyword
495
(
496
        char *buffer,
497
        char *keyword
498
)
499
 
500
/*                                                                                                                                                      */
501
/*      Description:    This function searches in the statement buffer for the  */
502
/*                                      specified keyword.                                                                              */
503
/*                                                                                                                                                      */
504
/*      Returns:                index of keyword in buffer, or -1 if keyword not found  */
505
/*                                                                                                                                                      */
506
/****************************************************************************/
507
{
508
        BOOL found = FALSE;
509
        int index = 0;
510
        int buffer_length = jam_strlen(buffer);
511
        int keyword_length = jam_strlen(keyword);
512
 
513
        /* look at beginning of string */
514
        if ((buffer[0] == keyword[0]) &&
515
                (jam_strncmp(buffer, keyword, keyword_length) == 0) &&
516
                (!jam_is_name_char(buffer[keyword_length])))
517
        {
518
                found = TRUE;
519
        }
520
 
521
        /* look inside string */
522
        while ((!found) && (index + keyword_length <= buffer_length))
523
        {
524
                if ((buffer[index + 1] == keyword[0]) &&
525
                        (!jam_is_name_char(buffer[index])) &&
526
                        (jam_strncmp(&buffer[index + 1], keyword, keyword_length) == 0) &&
527
                        (!jam_is_name_char(buffer[index + keyword_length + 1])))
528
                {
529
                        found = TRUE;
530
                }
531
 
532
                ++index;
533
        }
534
 
535
        return (found ? index : -1);
536
}
537
 
538
/****************************************************************************/
539
/*                                                                                                                                                      */
540
 
541
JAM_RETURN_TYPE jam_get_array_subrange
542
(
543
        JAMS_SYMBOL_RECORD *symbol_record,
544
        char *statement_buffer,
545
        long *start_index,
546
        long *stop_index
547
)
548
 
549
/*                                                                                                                                                      */
550
/*      Description:    Gets start_index and stop_index of an array subrange    */
551
/*                                      specification of the form <start_index>..<stop_index>   */
552
/*                                                                                                                                                      */
553
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
554
/*                                                                                                                                                      */
555
/****************************************************************************/
556
{
557
        int index = 0;
558
        int expr_begin = 0;
559
        int expr_end = 0;
560
        char save_ch = 0;
561
        BOOL found_elipsis = FALSE;
562
        BOOL found = FALSE;
563
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
564
        JAME_EXPRESSION_TYPE expr_type = JAM_ILLEGAL_EXPR_TYPE;
565
 
566
        while ((statement_buffer[index] != JAMC_NULL_CHAR) && !found_elipsis)
567
        {
568
                if ((statement_buffer[index] == JAMC_PERIOD_CHAR) &&
569
                        (statement_buffer[index + 1] == JAMC_PERIOD_CHAR))
570
                {
571
                        expr_end = index;
572
                        found_elipsis = TRUE;
573
                }
574
                ++index;
575
        }
576
 
577
        if (found_elipsis && (expr_end > expr_begin))
578
        {
579
                save_ch = statement_buffer[expr_end];
580
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
581
                status = jam_evaluate_expression(
582
                        &statement_buffer[expr_begin], start_index, &expr_type);
583
                statement_buffer[expr_end] = save_ch;
584
 
585
                /*
586
                *       Check for integer expression
587
                */
588
                if ((status == JAMC_SUCCESS) &&
589
                        (expr_type != JAM_INTEGER_EXPR) &&
590
                        (expr_type != JAM_INT_OR_BOOL_EXPR))
591
                {
592
                        status = JAMC_TYPE_MISMATCH;
593
                }
594
        }
595
        else
596
        {
597
                status = JAMC_SYNTAX_ERROR;
598
        }
599
 
600
        if (status == JAMC_SUCCESS)
601
        {
602
                expr_begin = expr_end + 2;
603
 
604
                status = jam_evaluate_expression(
605
                        &statement_buffer[expr_begin], stop_index, &expr_type);
606
 
607
                if ((status == JAMC_SUCCESS) &&
608
                        (expr_type != JAM_INTEGER_EXPR) &&
609
                        (expr_type != JAM_INT_OR_BOOL_EXPR))
610
                {
611
                        status = JAMC_TYPE_MISMATCH;
612
                }
613
                else
614
                {
615
                        found = TRUE;
616
                }
617
        }
618
 
619
        if ((status == JAMC_SUCCESS) && (!found))
620
        {
621
                status = JAMC_SYNTAX_ERROR;
622
        }
623
 
624
        if ((jam_version == 2) && (!found_elipsis) && (symbol_record != NULL))
625
        {
626
                /* if there is nothing between the brackets, select the entire array */
627
                index = 0;
628
 
629
                while (jam_isspace(statement_buffer[index])) ++index;
630
 
631
                if (statement_buffer[index] == JAMC_NULL_CHAR)
632
                {
633
                        JAMS_HEAP_RECORD *heap_record =
634
                                (JAMS_HEAP_RECORD *) symbol_record->value;
635
 
636
                        if (heap_record == NULL)
637
                        {
638
                                status = JAMC_INTERNAL_ERROR;
639
                        }
640
                        else
641
                        {
642
                                *start_index = heap_record->dimension - 1;
643
                                *stop_index = 0;
644
                                status = JAMC_SUCCESS;
645
                        }
646
                }
647
        }
648
 
649
        if ((status == JAMC_SUCCESS) && (jam_version == 2))
650
        {
651
                /* for Jam 2.0, swap the start and stop indices */
652
                long temp = *start_index;
653
                *start_index = *stop_index;
654
                *stop_index = temp;
655
        }
656
 
657
        return (status);
658
}
659
 
660
/****************************************************************************/
661
/*                                                                                                                                                      */
662
 
663
JAM_RETURN_TYPE jam_convert_literal_binary
664
(
665
        char *statement_buffer,
666
        long **output_buffer,
667
        long *length,
668
        int arg
669
)
670
 
671
/*                                                                                                                                                      */
672
/*      Description:    converts BINARY string in statement buffer into binary  */
673
/*                                      values.  Stores binary result back into the buffer,             */
674
/*                                      overwriting the input text.                                                             */
675
/*                                                                                                                                                      */
676
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
677
/*                                                                                                                                                      */
678
/****************************************************************************/
679
{
680
        int in_index = 0;
681
        int out_index = 0;
682
        int rev_index = 0;
683
        int i = 0;
684
        int j = 0;
685
        char ch = 0;
686
        int data = 0;
687
        long *long_ptr = NULL;
688
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
689
 
690
        while ((status == JAMC_SUCCESS) &&
691
                ((ch = statement_buffer[in_index]) != '\0'))
692
        {
693
                if ((ch == '0') || (ch == '1'))
694
                {
695
                        data = (int) (ch - '0');
696
                }
697
                else
698
                {
699
                        status = JAMC_SYNTAX_ERROR;
700
                }
701
 
702
                if (status == JAMC_SUCCESS)
703
                {
704
                        if ((in_index & 7) == 0)
705
                        {
706
                                statement_buffer[out_index] = 0;
707
                        }
708
 
709
                        if (data)
710
                        {
711
                                statement_buffer[out_index] |= (1 << (in_index & 7));
712
                        }
713
 
714
                        if ((in_index & 7) == 7)
715
                        {
716
                                ++out_index;
717
                        }
718
                }
719
 
720
                ++in_index;
721
        }
722
 
723
        if (status == JAMC_SUCCESS)
724
        {
725
                *length = (long) in_index;
726
 
727
                /* reverse the order of binary data */
728
                rev_index = in_index / 2;
729
                while (rev_index > 0)
730
                {
731
                        data = (statement_buffer[(rev_index - 1) >> 3] &
732
                                (1 << ((rev_index - 1) & 7)));
733
 
734
                        if (statement_buffer[(in_index - rev_index) >> 3] &
735
                                (1 << ((in_index - rev_index) & 7)))
736
                        {
737
                                statement_buffer[(rev_index - 1) >> 3] |=
738
                                        (1 << ((rev_index - 1) & 7));
739
                        }
740
                        else
741
                        {
742
                                statement_buffer[(rev_index - 1) >> 3] &=
743
                                        ~(1 << ((rev_index - 1) & 7));
744
                        }
745
 
746
                        if (data)
747
                        {
748
                                statement_buffer[(in_index - rev_index) >> 3] |=
749
                                        (1 << ((in_index - rev_index) & 7));
750
                        }
751
                        else
752
                        {
753
                                statement_buffer[(in_index - rev_index) >> 3] &=
754
                                        ~(1 << ((in_index - rev_index) & 7));
755
                        }
756
 
757
                        --rev_index;
758
                }
759
 
760
                out_index = (in_index + 7) / 8;         /* number of bytes */
761
                rev_index = (out_index + 3) / 4;        /* number of longs */
762
 
763
                if (rev_index > 1)
764
                {
765
                        long_ptr = (long *) (((long) statement_buffer) & 0xfffffffcL);
766
                }
767
                else if (arg < JAMC_MAX_LITERAL_ARRAYS)
768
                {
769
                        long_ptr = &jam_literal_array_buffer[arg];
770
                }
771
                else
772
                {
773
                        status = JAMC_INTERNAL_ERROR;
774
                }
775
        }
776
 
777
        if (status == JAMC_SUCCESS)
778
        {
779
                for (i = 0; i < rev_index; ++i)
780
                {
781
                        j = i * 4;
782
                        long_ptr[i] = (
783
                                (((long)statement_buffer[j + 3] << 24L) & 0xff000000L) |
784
                                (((long)statement_buffer[j + 2] << 16L) & 0x00ff0000L) |
785
                                (((long)statement_buffer[j + 1] <<  8L) & 0x0000ff00L) |
786
                                (((long)statement_buffer[j    ]       ) & 0x000000ffL));
787
                }
788
 
789
                if (output_buffer != NULL) *output_buffer = long_ptr;
790
        }
791
 
792
        return (status);
793
}
794
 
795
/****************************************************************************/
796
/*                                                                                                                                                      */
797
 
798
JAM_RETURN_TYPE jam_convert_literal_array
799
(
800
        char *statement_buffer,
801
        long **output_buffer,
802
        long *length,
803
        int arg
804
)
805
 
806
/*                                                                                                                                                      */
807
/*      Description:    converts HEX string in statement buffer into binary             */
808
/*                                      values.  Stores binary result back into the buffer,             */
809
/*                                      overwriting the input text.                                                             */
810
/*                                                                                                                                                      */
811
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
812
/*                                                                                                                                                      */
813
/****************************************************************************/
814
{
815
        int in_index = 0;
816
        int out_index = 0;
817
        int rev_index = 0;
818
        int i = 0;
819
        int j = 0;
820
        char ch = 0;
821
        int data = 0;
822
        long *long_ptr = NULL;
823
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
824
 
825
        while ((status == JAMC_SUCCESS) &&
826
                ((ch = statement_buffer[in_index]) != '\0'))
827
        {
828
                if ((ch >= 'A') && (ch <= 'F'))
829
                {
830
                        data = (int) (ch + 10 - 'A');
831
                }
832
                else if ((ch >= 'a') && (ch <= 'f'))
833
                {
834
                        data = (int) (ch + 10 - 'a');
835
                }
836
                else if ((ch >= '0') && (ch <= '9'))
837
                {
838
                        data = (int) (ch - '0');
839
                }
840
                else
841
                {
842
                        status = JAMC_SYNTAX_ERROR;
843
                }
844
 
845
                if (status == JAMC_SUCCESS)
846
                {
847
                        if (in_index & 1)
848
                        {
849
                                /* odd nibble is lower nibble */
850
                                data |= (statement_buffer[out_index] & 0xf0);
851
                                statement_buffer[out_index] = (char) data;
852
                                ++out_index;
853
                        }
854
                        else
855
                        {
856
                                /* even nibble is upper nibble */
857
                                statement_buffer[out_index] = (char) (data << 4);
858
                        }
859
                }
860
 
861
                ++in_index;
862
        }
863
 
864
        if (status == JAMC_SUCCESS)
865
        {
866
                *length = (long) in_index * 4L;
867
 
868
                if (in_index & 1)
869
                {
870
                        /* odd number of nibbles - do a nibble-shift */
871
                        out_index = in_index / 2;
872
                        while (out_index > 0)
873
                        {
874
                                statement_buffer[out_index] = (char)
875
                                        (((statement_buffer[out_index - 1] & 0x0f) << 4) |
876
                                        ((statement_buffer[out_index] & 0xf0) >> 4));
877
                                --out_index;
878
                        }
879
                        statement_buffer[0] = (char) ((statement_buffer[0] & 0xf0) >> 4);
880
                        ++in_index;
881
                }
882
 
883
                /* reverse the order of binary data */
884
                out_index = in_index / 2;       /* number of bytes */
885
                rev_index = out_index / 2;
886
                while (rev_index > 0)
887
                {
888
                        ch = statement_buffer[rev_index - 1];
889
                        statement_buffer[rev_index - 1] =
890
                                statement_buffer[out_index - rev_index];
891
                        statement_buffer[out_index - rev_index] = ch;
892
                        --rev_index;
893
                }
894
 
895
                out_index = (in_index + 1) / 2;         /* number of bytes */
896
                rev_index = (out_index + 3) / 4;        /* number of longs */
897
 
898
                if (rev_index > 1)
899
                {
900
                        long_ptr = (long *) (((long) statement_buffer) & 0xfffffffcL);
901
                }
902
                else if (arg < JAMC_MAX_LITERAL_ARRAYS)
903
                {
904
                        long_ptr = &jam_literal_array_buffer[arg];
905
                }
906
                else
907
                {
908
                        status = JAMC_INTERNAL_ERROR;
909
                }
910
        }
911
 
912
        if (status == JAMC_SUCCESS)
913
        {
914
                for (i = 0; i < rev_index; ++i)
915
                {
916
                        j = i * 4;
917
                        long_ptr[i] = (
918
                                (((long)statement_buffer[j + 3] << 24L) & 0xff000000L) |
919
                                (((long)statement_buffer[j + 2] << 16L) & 0x00ff0000L) |
920
                                (((long)statement_buffer[j + 1] <<  8L) & 0x0000ff00L) |
921
                                (((long)statement_buffer[j    ]       ) & 0x000000ffL));
922
                }
923
 
924
                if (output_buffer != NULL) *output_buffer = long_ptr;
925
        }
926
 
927
        return (status);
928
}
929
 
930
/****************************************************************************/
931
/*                                                                                                                                                      */
932
 
933
JAM_RETURN_TYPE jam_convert_literal_aca
934
(
935
        char *statement_buffer,
936
        long **output_buffer,
937
        long *length,
938
        int arg
939
)
940
/*                                                                                                                                                      */
941
/*      Description:    Uncompress ASCII ACA data in "statement buffer".                */
942
/*                                      Store resulting uncompressed literal data in global var */
943
/*                                      jam_literal_aca_buffer                                                                  */
944
/*                                                                                                                                                      */
945
/*      Returns:                JAMC_SUCCESS for success, else appropriate error                */
946
/*                                                                                                                                                      */
947
/****************************************************************************/
948
{
949
        int bit = 0;
950
        int value = 0;
951
        int index = 0;
952
        int index2 = 0;
953
        int i = 0;
954
        int j = 0;
955
        int long_count = 0;
956
        long binary_compressed_length = 0L;
957
        long uncompressed_length = 0L;
958
        char *buffer = NULL;
959
        long *long_ptr = NULL;
960
        long out_size = 0L;
961
        long address = 0L;
962
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
963
 
964
        if ((arg < 0) || (arg >= JAMC_MAX_LITERAL_ARRAYS))
965
        {
966
                status = JAMC_INTERNAL_ERROR;
967
        }
968
 
969
        /* remove all white space */
970
        while (statement_buffer[index] != JAMC_NULL_CHAR)
971
        {
972
                if ((!jam_isspace(statement_buffer[index])) &&
973
                        (statement_buffer[index] != JAMC_TAB_CHAR) &&
974
                        (statement_buffer[index] != JAMC_RETURN_CHAR) &&
975
                        (statement_buffer[index] != JAMC_NEWLINE_CHAR))
976
                {
977
                        statement_buffer[index2] = statement_buffer[index];
978
                        ++index2;
979
                }
980
                ++index;
981
        }
982
        statement_buffer[index2] = JAMC_NULL_CHAR;
983
 
984
        /* convert 6-bit encoded characters to binary -- in the same buffer */
985
        index = 0;
986
        while ((status == JAMC_SUCCESS) &&
987
                (jam_isalnum(statement_buffer[index]) ||
988
                (statement_buffer[index] == JAMC_AT_CHAR) ||
989
                (statement_buffer[index] == JAMC_UNDERSCORE_CHAR)))
990
        {
991
                value = jam_6bit_char(statement_buffer[index]);
992
                statement_buffer[index] = 0;
993
 
994
                if (value == -1)
995
                {
996
                        status = JAMC_SYNTAX_ERROR;
997
                }
998
                else
999
                {
1000
                        for (bit = 0; bit < 6; ++bit)
1001
                        {
1002
                                if (value & (1 << (bit % 6)))
1003
                                {
1004
                                        statement_buffer[address >> 3] |= (1L << (address & 7));
1005
                                }
1006
                                else
1007
                                {
1008
                                        statement_buffer[address >> 3] &=
1009
                                                ~(unsigned int) (1 << (address & 7));
1010
                                }
1011
                                ++address;
1012
                        }
1013
                }
1014
 
1015
                ++index;
1016
        }
1017
 
1018
        if ((status == JAMC_SUCCESS) &&
1019
                (statement_buffer[index] != JAMC_NULL_CHAR))
1020
        {
1021
                status = JAMC_SYNTAX_ERROR;
1022
        }
1023
 
1024
        /* Compute length of binary data string in statement_buffer */
1025
        binary_compressed_length = (address >> 3) + ((address & 7) ? 1 : 0);
1026
 
1027
        /* Get uncompressed length from first DWORD of compressed data */
1028
        uncompressed_length = (
1029
                (((long)statement_buffer[3] << 24L) & 0xff000000L) |
1030
                (((long)statement_buffer[2] << 16L) & 0x00ff0000L) |
1031
                (((long)statement_buffer[1] <<  8L) & 0x0000ff00L) |
1032
                (((long)statement_buffer[0]       ) & 0x000000ffL));
1033
 
1034
        /* Allocate memory for literal binary data */
1035
        if (status == JAMC_SUCCESS)
1036
        {
1037
#if PORT==DOS
1038
                if ((uncompressed_length + 4) < 0x10000L)
1039
                {
1040
                        buffer = jam_malloc((unsigned int) (uncompressed_length + 4));
1041
                        long_ptr = (long *) jam_malloc((unsigned int) (uncompressed_length + 4));
1042
                }
1043
#else
1044
                buffer = jam_malloc(uncompressed_length + 4);
1045
                long_ptr = (long *) jam_malloc(uncompressed_length + 4);
1046
#endif
1047
 
1048
                if ((buffer == NULL) || (long_ptr == NULL))
1049
                {
1050
                        status = JAMC_OUT_OF_MEMORY;
1051
                }
1052
        }
1053
 
1054
        /* Uncompress encoded binary into literal binary data */
1055
        out_size = jam_uncompress(
1056
                statement_buffer,
1057
                binary_compressed_length,
1058
                buffer,
1059
                uncompressed_length,
1060
                jam_version);
1061
 
1062
        if (out_size != uncompressed_length)
1063
        {
1064
                status = JAMC_SYNTAX_ERROR;
1065
        }
1066
 
1067
        if (status == JAMC_SUCCESS)
1068
        {
1069
                /*
1070
                *       Convert uncompressed data to array of long integers
1071
                */
1072
                long_count = (out_size + 3) / 4;        /* number of longs */
1073
 
1074
                for (i = 0; i < long_count; ++i)
1075
                {
1076
                        j = i * 4;
1077
                        long_ptr[i] = (
1078
                                (((long)buffer[j + 3] << 24L) & 0xff000000L) |
1079
                                (((long)buffer[j + 2] << 16L) & 0x00ff0000L) |
1080
                                (((long)buffer[j + 1] <<  8L) & 0x0000ff00L) |
1081
                                (((long)buffer[j    ]       ) & 0x000000ffL));
1082
                }
1083
 
1084
                jam_literal_aca_buffer[arg] = long_ptr;
1085
 
1086
                if (output_buffer != NULL) *output_buffer = long_ptr;
1087
 
1088
                if (length != NULL) *length = uncompressed_length * 8L;
1089
        }
1090
 
1091
        if (buffer != NULL) jam_free(buffer);
1092
 
1093
        /* jam_literal_aca_buffer[arg] will be freed later */
1094
 
1095
        return (status);
1096
}
1097
 
1098
/****************************************************************************/
1099
/*                                                                                                                                                      */
1100
 
1101
JAM_RETURN_TYPE jam_get_array_argument
1102
(
1103
        char *statement_buffer,
1104
        JAMS_SYMBOL_RECORD **symbol_record,
1105
        long **literal_array_data,
1106
        long *start_index,
1107
        long *stop_index,
1108
        int arg
1109
)
1110
 
1111
/*                                                                                                                                                      */
1112
/*      Description:    Looks for a sub-range-indexed array argument in the             */
1113
/*                                      statement buffer.  Calls expression parser to evaluate  */
1114
/*                                      the start_index and end_index arguments.                                */
1115
/*                                                                                                                                                      */
1116
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
1117
/*                                                                                                                                                      */
1118
/****************************************************************************/
1119
{
1120
        int index = 0;
1121
        int expr_begin = 0;
1122
        int expr_end = 0;
1123
        int bracket_count = 0;
1124
        long literal_array_length = 0;
1125
        char save_ch = 0;
1126
        JAMS_SYMBOL_RECORD *tmp_symbol_rec = NULL;
1127
        JAMS_HEAP_RECORD *heap_record = NULL;
1128
        JAME_EXPRESSION_TYPE expr_type = JAM_ILLEGAL_EXPR_TYPE;
1129
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
1130
 
1131
        /* first look for literal array constant */
1132
        while ((jam_isspace(statement_buffer[index])) &&
1133
                (index < JAMC_MAX_STATEMENT_LENGTH))
1134
        {
1135
                ++index;        /* skip over white space */
1136
        }
1137
 
1138
        if ((jam_version == 2) && (statement_buffer[index] == JAMC_POUND_CHAR))
1139
        {
1140
                /* literal array, binary representation */
1141
                *symbol_record = NULL;
1142
                ++index;
1143
                while ((jam_isspace(statement_buffer[index])) &&
1144
                        (index < JAMC_MAX_STATEMENT_LENGTH))
1145
                {
1146
                        ++index;        /* skip over white space */
1147
                }
1148
                expr_begin = index;
1149
 
1150
                while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
1151
                        (statement_buffer[index] != JAMC_COMMA_CHAR) &&
1152
                        (statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
1153
                        (index < JAMC_MAX_STATEMENT_LENGTH))
1154
                {
1155
                        ++index;
1156
                }
1157
                while ((index > expr_begin) && jam_isspace(statement_buffer[index - 1]))
1158
                {
1159
                        --index;
1160
                }
1161
                expr_end = index;
1162
                save_ch = statement_buffer[expr_end];
1163
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
1164
                status = jam_convert_literal_binary(&statement_buffer[expr_begin],
1165
                        literal_array_data, &literal_array_length, arg);
1166
                statement_buffer[expr_end] = save_ch;
1167
 
1168
                *start_index = 0L;
1169
                *stop_index = literal_array_length - 1;
1170
        }
1171
        else if ((jam_version == 2) &&
1172
                (statement_buffer[index] == JAMC_DOLLAR_CHAR))
1173
        {
1174
                /* literal array, hex representation */
1175
                *symbol_record = NULL;
1176
                ++index;
1177
                while ((jam_isspace(statement_buffer[index])) &&
1178
                        (index < JAMC_MAX_STATEMENT_LENGTH))
1179
                {
1180
                        ++index;        /* skip over white space */
1181
                }
1182
                expr_begin = index;
1183
 
1184
                while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
1185
                        (statement_buffer[index] != JAMC_COMMA_CHAR) &&
1186
                        (statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
1187
                        (index < JAMC_MAX_STATEMENT_LENGTH))
1188
                {
1189
                        ++index;
1190
                }
1191
                while ((index > expr_begin) && jam_isspace(statement_buffer[index - 1]))
1192
                {
1193
                        --index;
1194
                }
1195
                expr_end = index;
1196
                save_ch = statement_buffer[expr_end];
1197
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
1198
                status = jam_convert_literal_array(&statement_buffer[expr_begin],
1199
                        literal_array_data, &literal_array_length, arg);
1200
                statement_buffer[expr_end] = save_ch;
1201
 
1202
                *start_index = 0L;
1203
                *stop_index = literal_array_length - 1;
1204
        }
1205
        else if ((jam_version == 2) && (statement_buffer[index] == JAMC_AT_CHAR))
1206
        {
1207
                /* literal array, ACA representation */
1208
                *symbol_record = NULL;
1209
                ++index;
1210
                while ((jam_isspace(statement_buffer[index])) &&
1211
                        (index < JAMC_MAX_STATEMENT_LENGTH))
1212
                {
1213
                        ++index;        /* skip over white space */
1214
                }
1215
                expr_begin = index;
1216
 
1217
                while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
1218
                        (statement_buffer[index] != JAMC_COMMA_CHAR) &&
1219
                        (statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
1220
                        (index < JAMC_MAX_STATEMENT_LENGTH))
1221
                {
1222
                        ++index;
1223
                }
1224
                while ((index > expr_begin) && jam_isspace(statement_buffer[index - 1]))
1225
                {
1226
                        --index;
1227
                }
1228
                expr_end = index;
1229
                save_ch = statement_buffer[expr_end];
1230
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
1231
                status = jam_convert_literal_aca(&statement_buffer[expr_begin],
1232
                        literal_array_data, &literal_array_length, arg);
1233
                statement_buffer[expr_end] = save_ch;
1234
 
1235
                *start_index = 0L;
1236
                *stop_index = literal_array_length - 1;
1237
        }
1238
        else if ((jam_version == 2) &&
1239
                (jam_strncmp(&statement_buffer[index], "BOOL(", 5) == 0))
1240
        {
1241
                /*
1242
                *       Convert integer expression to Boolean array
1243
                */
1244
                expr_begin = index + 4;
1245
                while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
1246
                        (statement_buffer[index] != JAMC_COMMA_CHAR) &&
1247
                        (statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
1248
                        (index < JAMC_MAX_STATEMENT_LENGTH))
1249
                {
1250
                        ++index;
1251
                }
1252
 
1253
                expr_end = index;
1254
                ++index;
1255
 
1256
                if (expr_end > expr_begin)
1257
                {
1258
                        save_ch = statement_buffer[expr_end];
1259
                        statement_buffer[expr_end] = JAMC_NULL_CHAR;
1260
                        status = jam_evaluate_expression(
1261
                                &statement_buffer[expr_begin],
1262
                                &jam_literal_array_buffer[arg],
1263
                                &expr_type);
1264
                        statement_buffer[expr_end] = save_ch;
1265
                }
1266
 
1267
                /*
1268
                *       Check for integer expression
1269
                */
1270
                if ((status == JAMC_SUCCESS) &&
1271
                        (expr_type != JAM_INTEGER_EXPR) &&
1272
                        (expr_type != JAM_INT_OR_BOOL_EXPR))
1273
                {
1274
                        status = JAMC_TYPE_MISMATCH;
1275
                }
1276
 
1277
                if (status == JAMC_SUCCESS)
1278
                {
1279
                        *symbol_record = NULL;
1280
                        *literal_array_data = &jam_literal_array_buffer[arg];
1281
                        *start_index = 0L;
1282
                        *stop_index = 31L;
1283
                }
1284
        }
1285
        else if ((jam_version != 2) && (jam_isdigit(statement_buffer[index])))
1286
        {
1287
                /* it is a literal array constant */
1288
                *symbol_record = NULL;
1289
                expr_begin = index;
1290
 
1291
                while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
1292
                        (statement_buffer[index] != JAMC_COMMA_CHAR) &&
1293
                        (statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
1294
                        (index < JAMC_MAX_STATEMENT_LENGTH))
1295
                {
1296
                        ++index;
1297
                }
1298
                while ((index > expr_begin) && jam_isspace(statement_buffer[index - 1]))
1299
                {
1300
                        --index;
1301
                }
1302
                expr_end = index;
1303
                save_ch = statement_buffer[expr_end];
1304
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
1305
                status = jam_convert_literal_array(&statement_buffer[expr_begin],
1306
                        literal_array_data, &literal_array_length, arg);
1307
                statement_buffer[expr_end] = save_ch;
1308
 
1309
                *start_index = 0L;
1310
                *stop_index = literal_array_length - 1;
1311
        }
1312
        else
1313
        {
1314
                /* it is not a literal constant, look for array variable */
1315
                *literal_array_data = NULL;
1316
 
1317
                while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
1318
                        (statement_buffer[index] != JAMC_LBRACKET_CHAR) &&
1319
                        (index < JAMC_MAX_STATEMENT_LENGTH))
1320
                {
1321
                        ++index;
1322
                }
1323
 
1324
                if (statement_buffer[index] != JAMC_LBRACKET_CHAR)
1325
                {
1326
                        status = JAMC_SYNTAX_ERROR;
1327
                }
1328
                else
1329
                {
1330
                        expr_end = index;
1331
                        ++index;
1332
 
1333
                        save_ch = statement_buffer[expr_end];
1334
                        statement_buffer[expr_end] = JAMC_NULL_CHAR;
1335
                        status = jam_get_symbol_record(&statement_buffer[expr_begin],
1336
                                &tmp_symbol_rec);
1337
                        statement_buffer[expr_end] = save_ch;
1338
 
1339
                        if (status == JAMC_SUCCESS)
1340
                        {
1341
                                *symbol_record = tmp_symbol_rec;
1342
 
1343
                                if ((tmp_symbol_rec->type != JAM_BOOLEAN_ARRAY_WRITABLE) &&
1344
                                        (tmp_symbol_rec->type != JAM_BOOLEAN_ARRAY_INITIALIZED))
1345
                                {
1346
                                        status = JAMC_TYPE_MISMATCH;
1347
                                }
1348
                                else
1349
                                {
1350
                                        /* it is a Boolean array variable */
1351
                                        while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
1352
                                                (statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
1353
                                                ((statement_buffer[index] != JAMC_RBRACKET_CHAR) ||
1354
                                                        (bracket_count > 0)) &&
1355
                                                (index < JAMC_MAX_STATEMENT_LENGTH))
1356
                                        {
1357
                                                if (statement_buffer[index] == JAMC_LBRACKET_CHAR)
1358
                                                {
1359
                                                        ++bracket_count;
1360
                                                }
1361
                                                else if (statement_buffer[index] == JAMC_RBRACKET_CHAR)
1362
                                                {
1363
                                                        --bracket_count;
1364
                                                }
1365
 
1366
                                                ++index;
1367
                                        }
1368
 
1369
                                        if (statement_buffer[index] != JAMC_RBRACKET_CHAR)
1370
                                        {
1371
                                                status = JAMC_SYNTAX_ERROR;
1372
                                        }
1373
                                        else
1374
                                        {
1375
                                                statement_buffer[index] = JAMC_NULL_CHAR;
1376
 
1377
                                                status = jam_get_array_subrange(tmp_symbol_rec,
1378
                                                        &statement_buffer[expr_end + 1],
1379
                                                        start_index, stop_index);
1380
                                                statement_buffer[index] = JAMC_RBRACKET_CHAR;
1381
                                                ++index;
1382
 
1383
                                                if (status == JAMC_SUCCESS)
1384
                                                {
1385
                                                        heap_record = (JAMS_HEAP_RECORD *)
1386
                                                                tmp_symbol_rec->value;
1387
 
1388
                                                        if (heap_record == NULL)
1389
                                                        {
1390
                                                                status = JAMC_INTERNAL_ERROR;
1391
                                                        }
1392
                                                        else if ((*start_index < 0) || (*stop_index < 0) ||
1393
                                                                (*start_index >= heap_record->dimension) ||
1394
                                                                (*stop_index >= heap_record->dimension))
1395
                                                        {
1396
                                                                status = JAMC_BOUNDS_ERROR;
1397
                                                        }
1398
                                                        else
1399
                                                        {
1400
                                                                while (jam_isspace(statement_buffer[index]))
1401
                                                                {
1402
                                                                        ++index;
1403
                                                                }
1404
 
1405
                                                                /* there should be no more characters */
1406
                                                                if (statement_buffer[index] != JAMC_NULL_CHAR)
1407
                                                                {
1408
                                                                        status = JAMC_SYNTAX_ERROR;
1409
                                                                }
1410
                                                        }
1411
                                                }
1412
                                        }
1413
                                }
1414
                        }
1415
                }
1416
        }
1417
 
1418
        return (status);
1419
}
1420
 
1421
/****************************************************************************/
1422
/*                                                                                                                                                      */
1423
 
1424
JAM_RETURN_TYPE jam_find_argument
1425
(
1426
        char *statement_buffer,
1427
        int *begin,
1428
        int *end,
1429
        int *delimiter
1430
)
1431
 
1432
/*                                                                                                                                                      */
1433
/*      Description:    Finds the next argument in the statement buffer, where  */
1434
/*                                      the delimiters are COLON or SEMICOLON.  Returns indices */
1435
/*                                      of begin and end of argument, and the delimiter after   */
1436
/*                                      the argument.                                                                                   */
1437
/*                                                                                                                                                      */
1438
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
1439
/*                                                                                                                                                      */
1440
/****************************************************************************/
1441
{
1442
        int index = 0;
1443
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
1444
 
1445
        while ((jam_isspace(statement_buffer[index])) &&
1446
                (index < JAMC_MAX_STATEMENT_LENGTH))
1447
        {
1448
                ++index;        /* skip over white space */
1449
        }
1450
 
1451
        *begin = index;
1452
 
1453
        while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
1454
                (statement_buffer[index] != JAMC_COMMA_CHAR) &&
1455
                (statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
1456
                (index < JAMC_MAX_STATEMENT_LENGTH))
1457
        {
1458
                ++index;
1459
        }
1460
 
1461
        if ((statement_buffer[index] != JAMC_COMMA_CHAR) &&
1462
                (statement_buffer[index] != JAMC_SEMICOLON_CHAR))
1463
        {
1464
                status = JAMC_SYNTAX_ERROR;
1465
        }
1466
        else
1467
        {
1468
                *delimiter = index;     /* delimiter is position of comma or semicolon */
1469
 
1470
                while (jam_isspace(statement_buffer[index - 1]))
1471
                {
1472
                        --index;        /* skip backwards over white space */
1473
                }
1474
 
1475
                *end = index;   /* end is position after last argument character */
1476
        }
1477
 
1478
        return (status);
1479
}
1480
 
1481
/****************************************************************************/
1482
/*                                                                                                                                                      */
1483
 
1484
JAM_RETURN_TYPE jam_process_uses_item
1485
(
1486
        char *block_name
1487
)
1488
 
1489
/*                                                                                                                                                      */
1490
/*      Description:    Checks validity of one block-name from a USES clause.   */
1491
/*                                      If it is a data block name, initialize the data block.  */
1492
/*                                                                                                                                                      */
1493
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
1494
/*                                                                                                                                                      */
1495
/****************************************************************************/
1496
{
1497
        int index = 0;
1498
        char save_ch = 0;
1499
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
1500
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
1501
        long current_position = 0L;
1502
        long return_position = jam_next_statement_position;
1503
        long block_position = -1L;
1504
        char block_buffer[JAMC_MAX_NAME_LENGTH + 1];
1505
        char label_buffer[JAMC_MAX_NAME_LENGTH + 1];
1506
        char *statement_buffer = NULL;
1507
        JAME_INSTRUCTION instruction_code = JAM_ILLEGAL_INSTR;
1508
        BOOL found = FALSE;
1509
        BOOL enddata = FALSE;
1510
        JAMS_STACK_RECORD *original_stack_position = NULL;
1511
        BOOL reuse_statement_buffer = FALSE;
1512
        JAMS_SYMBOL_RECORD *tmp_current_block = jam_current_block;
1513
        JAME_PHASE_TYPE tmp_phase = jam_phase;
1514
        BOOL done = FALSE;
1515
        int exit_code = 0;
1516
 
1517
        statement_buffer = jam_malloc(JAMC_MAX_STATEMENT_LENGTH + 1024);
1518
 
1519
        if (statement_buffer == NULL)
1520
        {
1521
                status = JAMC_OUT_OF_MEMORY;
1522
        }
1523
        else if (jam_isalpha(block_name[index]))
1524
        {
1525
                /* locate block name */
1526
                while ((jam_is_name_char(block_name[index])) &&
1527
                        (index < JAMC_MAX_STATEMENT_LENGTH))
1528
                {
1529
                        ++index;        /* skip over block name */
1530
                }
1531
 
1532
                /*
1533
                *       Look in symbol table for block name
1534
                */
1535
                save_ch = block_name[index];
1536
                block_name[index] = JAMC_NULL_CHAR;
1537
                jam_strcpy(block_buffer, block_name);
1538
                block_name[index] = save_ch;
1539
                status = jam_get_symbol_record(block_buffer, &symbol_record);
1540
 
1541
                if ((status == JAMC_SUCCESS) &&
1542
                        ((symbol_record->type == JAM_PROCEDURE_BLOCK) ||
1543
                        (symbol_record->type == JAM_DATA_BLOCK)))
1544
                {
1545
                        /*
1546
                        *       Name is defined - get the address of the block
1547
                        */
1548
                        block_position = symbol_record->position;
1549
                }
1550
                else if (status == JAMC_UNDEFINED_SYMBOL)
1551
                {
1552
                        /*
1553
                        *       Block name is not defined... may be a forward reference.
1554
                        *       Search through the file to find the symbol.
1555
                        */
1556
                        current_position = jam_current_statement_position;
1557
 
1558
                        status = JAMC_SUCCESS;
1559
 
1560
                        while ((!found) && (status == JAMC_SUCCESS))
1561
                        {
1562
                                /*
1563
                                *       Get statements without executing them
1564
                                */
1565
                                status = jam_get_statement(statement_buffer, label_buffer);
1566
 
1567
                                if ((status == JAMC_SUCCESS) &&
1568
                                        (label_buffer[0] != JAMC_NULL_CHAR) &&
1569
                                        (jam_version != 2))
1570
                                {
1571
                                        /*
1572
                                        *       If there is a label, add it to the symbol table
1573
                                        */
1574
                                        status = jam_add_symbol(JAM_LABEL, label_buffer, 0L,
1575
                                                jam_current_statement_position);
1576
                                }
1577
 
1578
                                /*
1579
                                *       Is this a PROCEDURE or DATA statement?
1580
                                */
1581
                                if (status == JAMC_SUCCESS)
1582
                                {
1583
                                        instruction_code = jam_get_instruction(statement_buffer);
1584
 
1585
                                        switch (instruction_code)
1586
                                        {
1587
                                        case JAM_DATA_INSTR:
1588
                                                status = jam_process_data(statement_buffer);
1589
 
1590
                                                /* check if this is the block we want to process */
1591
                                                if (status == JAMC_SUCCESS)
1592
                                                {
1593
                                                        status = jam_get_symbol_record(block_buffer,
1594
                                                                &symbol_record);
1595
 
1596
                                                        if (status == JAMC_SUCCESS)
1597
                                                        {
1598
                                                                found = TRUE;
1599
                                                                block_position = symbol_record->position;
1600
                                                        }
1601
                                                        else if (status == JAMC_UNDEFINED_SYMBOL)
1602
                                                        {
1603
                                                                /* ignore undefined symbol errors */
1604
                                                                status = JAMC_SUCCESS;
1605
                                                        }
1606
                                                }
1607
                                                break;
1608
 
1609
                                        case JAM_PROCEDURE_INSTR:
1610
                                                status = jam_process_procedure(statement_buffer);
1611
 
1612
                                                /* check if this is the block we want to process */
1613
                                                if (status == JAMC_SUCCESS)
1614
                                                {
1615
                                                        status = jam_get_symbol_record(block_buffer,
1616
                                                                &symbol_record);
1617
 
1618
                                                        if (status == JAMC_SUCCESS)
1619
                                                        {
1620
                                                                found = TRUE;
1621
                                                                block_position = symbol_record->position;
1622
                                                        }
1623
                                                        else if (status == JAMC_UNDEFINED_SYMBOL)
1624
                                                        {
1625
                                                                /* ignore undefined symbol errors */
1626
                                                                status = JAMC_SUCCESS;
1627
                                                        }
1628
                                                }
1629
                                                break;
1630
                                        }
1631
                                }
1632
                        }
1633
 
1634
                        if (!found)
1635
                        {
1636
                                /* label was not found -- report "undefined symbol" */
1637
                                /* rather than "unexpected EOF" */
1638
                                status = JAMC_UNDEFINED_SYMBOL;
1639
 
1640
                                /* seek to location of the ACTION or PROCEDURE statement */
1641
                                /* that caused the error */
1642
                                jam_seek(current_position);
1643
                                jam_current_file_position = current_position;
1644
                                jam_current_statement_position = current_position;
1645
                        }
1646
                }
1647
 
1648
                if ((status == JAMC_SUCCESS) &&
1649
                        ((block_position == (-1L)) || (symbol_record == NULL)))
1650
                {
1651
                        status = JAMC_INTERNAL_ERROR;
1652
                }
1653
 
1654
                if ((status == JAMC_SUCCESS) &&
1655
                        (symbol_record->type != JAM_PROCEDURE_BLOCK) &&
1656
                        (symbol_record->type != JAM_DATA_BLOCK))
1657
                {
1658
                        status = JAMC_SYNTAX_ERROR;
1659
                }
1660
 
1661
                /*
1662
                *       Call a data block to initialize the variables inside
1663
                */
1664
                if ((status == JAMC_SUCCESS) &&
1665
                        (symbol_record->type == JAM_DATA_BLOCK) &&
1666
                        (symbol_record->value == 0))
1667
                {
1668
                        /*
1669
                        *       Push a CALL record onto the stack
1670
                        */
1671
                        if (status == JAMC_SUCCESS)
1672
                        {
1673
                                original_stack_position = jam_peek_stack_record();
1674
                                status = jam_push_callret_record(return_position);
1675
                        }
1676
 
1677
                        /*
1678
                        *       Now seek to the desired position so we can execute that
1679
                        *       statement next
1680
                        */
1681
                        if (status == JAMC_SUCCESS)
1682
                        {
1683
                                if (jam_seek(block_position) == 0)
1684
                                {
1685
                                        jam_current_file_position = block_position;
1686
                                }
1687
                                else
1688
                                {
1689
                                        /* seek failed */
1690
                                        status = JAMC_IO_ERROR;
1691
                                }
1692
                        }
1693
 
1694
                        /*
1695
                        *       Set jam_current_block to the data block about to be executed
1696
                        */
1697
                        if (status == JAMC_SUCCESS)
1698
                        {
1699
                                jam_current_block = symbol_record;
1700
                                jam_phase = JAM_DATA_PHASE;
1701
                        }
1702
 
1703
                        /*
1704
                        *       Get program statements and execute them
1705
                        */
1706
                        while ((!(done)) && (!enddata) && (status == JAMC_SUCCESS))
1707
                        {
1708
                                if (!reuse_statement_buffer)
1709
                                {
1710
                                        status = jam_get_statement
1711
                                        (
1712
                                                statement_buffer,
1713
                                                label_buffer
1714
                                        );
1715
 
1716
                                        if ((status == JAMC_SUCCESS)
1717
                                                && (label_buffer[0] != JAMC_NULL_CHAR))
1718
                                        {
1719
                                                status = jam_add_symbol
1720
                                                (
1721
                                                        JAM_LABEL,
1722
                                                        label_buffer,
1723
                                                        0L,
1724
                                                        jam_current_statement_position
1725
                                                );
1726
                                        }
1727
                                }
1728
                                else
1729
                                {
1730
                                        /* statement buffer will be reused -- clear the flag */
1731
                                        reuse_statement_buffer = FALSE;
1732
                                }
1733
 
1734
                                if (status == JAMC_SUCCESS)
1735
                                {
1736
                                        status = jam_execute_statement
1737
                                        (
1738
                                                statement_buffer,
1739
                                                &done,
1740
                                                &reuse_statement_buffer,
1741
                                                &exit_code
1742
                                        );
1743
 
1744
                                        if ((status == JAMC_SUCCESS) &&
1745
                                                (jam_get_instruction(statement_buffer)
1746
                                                        == JAM_ENDDATA_INSTR) &&
1747
                                                (jam_peek_stack_record() == original_stack_position))
1748
                                        {
1749
                                                enddata = TRUE;
1750
                                        }
1751
                                }
1752
                        }
1753
 
1754
                        if (done && (status == JAMC_SUCCESS))
1755
                        {
1756
                                /* an EXIT statement was processed -- impossible! */
1757
                                status = JAMC_INTERNAL_ERROR;
1758
                        }
1759
 
1760
                        /* indicate that this data block has been initialized */
1761
                        symbol_record->value = 1;
1762
                }
1763
        }
1764
 
1765
        jam_current_block = tmp_current_block;
1766
        jam_phase = tmp_phase;
1767
 
1768
        if (statement_buffer != NULL) jam_free(statement_buffer);
1769
 
1770
        return (status);
1771
}
1772
 
1773
JAM_RETURN_TYPE jam_process_uses_list
1774
(
1775
        char *uses_list
1776
)
1777
{
1778
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
1779
        int name_begin = 0;
1780
        int name_end = 0;
1781
        int index = 0;
1782
        char save_ch = 0;
1783
 
1784
        jam_checking_uses_list = TRUE;
1785
 
1786
        while ((status == JAMC_SUCCESS) &&
1787
                (uses_list[index] != JAMC_SEMICOLON_CHAR) &&
1788
                (uses_list[index] != NULL) &&
1789
                (index < JAMC_MAX_STATEMENT_LENGTH))
1790
        {
1791
                while ((jam_isspace(uses_list[index])) &&
1792
                        (index < JAMC_MAX_STATEMENT_LENGTH))
1793
                {
1794
                        ++index;        /* skip over white space */
1795
                }
1796
 
1797
                name_begin = index;
1798
 
1799
                while ((jam_is_name_char(uses_list[index])) &&
1800
                        (index < JAMC_MAX_STATEMENT_LENGTH))
1801
                {
1802
                        ++index;        /* skip over procedure name */
1803
                }
1804
 
1805
                name_end = index;
1806
 
1807
                while ((jam_isspace(uses_list[index])) &&
1808
                        (index < JAMC_MAX_STATEMENT_LENGTH))
1809
                {
1810
                        ++index;        /* skip over white space */
1811
                }
1812
 
1813
                if ((name_end > name_begin) &&
1814
                        ((uses_list[index] == JAMC_COMMA_CHAR) ||
1815
                        (uses_list[index] == JAMC_SEMICOLON_CHAR)))
1816
                {
1817
                        save_ch = uses_list[name_end];
1818
                        uses_list[name_end] = JAMC_NULL_CHAR;
1819
                        status = jam_process_uses_item(&uses_list[name_begin]);
1820
                        uses_list[name_end] = save_ch;
1821
 
1822
                        if (uses_list[index] == JAMC_COMMA_CHAR)
1823
                        {
1824
                                ++index;        /* skip over comma */
1825
                        }
1826
                }
1827
                else
1828
                {
1829
                        status = JAMC_SYNTAX_ERROR;
1830
                }
1831
        }
1832
 
1833
        if ((status == JAMC_SUCCESS) &&
1834
                (uses_list[index] != JAMC_SEMICOLON_CHAR))
1835
        {
1836
                status = JAMC_SYNTAX_ERROR;
1837
        }
1838
 
1839
        jam_checking_uses_list = FALSE;
1840
 
1841
        return (status);
1842
}
1843
 
1844
/****************************************************************************/
1845
/*                                                                                                                                                      */
1846
 
1847
JAM_RETURN_TYPE jam_call_procedure
1848
(
1849
        char *procedure_name,
1850
        BOOL *done,
1851
        int *exit_code
1852
)
1853
 
1854
/*                                                                                                                                                      */
1855
/*      Description:    Calls the specified procedure, and executes the                 */
1856
/*                                      statements in the procedure.                                                    */
1857
/*                                                                                                                                                      */
1858
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
1859
/*                                                                                                                                                      */
1860
/****************************************************************************/
1861
{
1862
        int index = 0;
1863
        char save_ch = 0;
1864
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
1865
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
1866
        JAME_INSTRUCTION instruction_code = JAM_ILLEGAL_INSTR;
1867
        long current_position = 0L;
1868
        long proc_position = -1L;
1869
        long return_position = jam_next_statement_position;
1870
        char procedure_buffer[JAMC_MAX_NAME_LENGTH + 1];
1871
        char label_buffer[JAMC_MAX_NAME_LENGTH + 1];
1872
        char *statement_buffer = NULL;
1873
        BOOL found = FALSE;
1874
        BOOL endproc = FALSE;
1875
        JAMS_STACK_RECORD *original_stack_position = NULL;
1876
        BOOL reuse_statement_buffer = FALSE;
1877
        JAMS_HEAP_RECORD *heap_record = NULL;
1878
        JAMS_SYMBOL_RECORD *tmp_current_block = jam_current_block;
1879
        JAME_PHASE_TYPE tmp_phase = jam_phase;
1880
 
1881
        statement_buffer = jam_malloc(JAMC_MAX_STATEMENT_LENGTH + 1024);
1882
 
1883
        if (statement_buffer == NULL)
1884
        {
1885
                status = JAMC_OUT_OF_MEMORY;
1886
        }
1887
        else if (jam_isalpha(procedure_name[index]))
1888
        {
1889
                /* locate procedure name */
1890
                while ((jam_is_name_char(procedure_name[index])) &&
1891
                        (index < JAMC_MAX_STATEMENT_LENGTH))
1892
                {
1893
                        ++index;        /* skip over procedure name */
1894
                }
1895
 
1896
                /*
1897
                *       Look in symbol table for procedure name
1898
                */
1899
                save_ch = procedure_name[index];
1900
                procedure_name[index] = JAMC_NULL_CHAR;
1901
                jam_strcpy(procedure_buffer, procedure_name);
1902
                procedure_name[index] = save_ch;
1903
                status = jam_get_symbol_record(procedure_buffer, &symbol_record);
1904
 
1905
                if ((status == JAMC_SUCCESS) &&
1906
                        (symbol_record->type == JAM_PROCEDURE_BLOCK))
1907
                {
1908
                        /*
1909
                        *       Label is defined - get the address for the jump
1910
                        */
1911
                        proc_position = symbol_record->position;
1912
                }
1913
                else if (status == JAMC_UNDEFINED_SYMBOL)
1914
                {
1915
                        /*
1916
                        *       Label is not defined... may be a forward reference.
1917
                        *       Search through the file to find the symbol.
1918
                        */
1919
                        current_position = jam_current_statement_position;
1920
 
1921
                        status = JAMC_SUCCESS;
1922
 
1923
                        while ((!found) && (status == JAMC_SUCCESS))
1924
                        {
1925
                                /*
1926
                                *       Get statements without executing them
1927
                                */
1928
                                status = jam_get_statement(statement_buffer, label_buffer);
1929
 
1930
                                if ((status == JAMC_SUCCESS) &&
1931
                                        (label_buffer[0] != JAMC_NULL_CHAR) &&
1932
                                        (jam_version != 2))
1933
                                {
1934
                                        /*
1935
                                        *       If there is a label, add it to the symbol table
1936
                                        */
1937
                                        status = jam_add_symbol(JAM_LABEL, label_buffer, 0L,
1938
                                                jam_current_statement_position);
1939
                                }
1940
 
1941
                                /*
1942
                                *       Is this a PROCEDURE or DATA statement?
1943
                                */
1944
                                if (status == JAMC_SUCCESS)
1945
                                {
1946
                                        instruction_code = jam_get_instruction(statement_buffer);
1947
 
1948
                                        switch (instruction_code)
1949
                                        {
1950
                                        case JAM_DATA_INSTR:
1951
                                                status = jam_process_data(statement_buffer);
1952
                                                break;
1953
 
1954
                                        case JAM_PROCEDURE_INSTR:
1955
                                                status = jam_process_procedure(statement_buffer);
1956
 
1957
                                                /* check if this is the procedure we want to call */
1958
                                                if (status == JAMC_SUCCESS)
1959
                                                {
1960
                                                        status = jam_get_symbol_record(procedure_buffer,
1961
                                                                &symbol_record);
1962
 
1963
                                                        if (status == JAMC_SUCCESS)
1964
                                                        {
1965
                                                                found = TRUE;
1966
                                                                proc_position = symbol_record->position;
1967
                                                        }
1968
                                                        else if (status == JAMC_UNDEFINED_SYMBOL)
1969
                                                        {
1970
                                                                /* ignore undefined symbol errors */
1971
                                                                status = JAMC_SUCCESS;
1972
                                                        }
1973
                                                }
1974
                                                break;
1975
                                        }
1976
                                }
1977
                        }
1978
 
1979
                        if (!found)
1980
                        {
1981
                                /* procedure was not found -- report "undefined symbol" */
1982
                                /* rather than "unexpected EOF" */
1983
                                status = JAMC_UNDEFINED_SYMBOL;
1984
 
1985
                                /* seek to location of the ACTION or CALL statement */
1986
                                /* that caused the error */
1987
                                jam_seek(current_position);
1988
                                jam_current_file_position = current_position;
1989
                                jam_current_statement_position = current_position;
1990
                        }
1991
                }
1992
 
1993
                if ((status == JAMC_SUCCESS) && (symbol_record->value != 0L))
1994
                {
1995
                        heap_record = (JAMS_HEAP_RECORD *) symbol_record->value;
1996
                        status = jam_process_uses_list((char *) heap_record->data);
1997
                }
1998
 
1999
                /*
2000
                *       Push a CALL record onto the stack
2001
                */
2002
                if ((status == JAMC_SUCCESS) && (proc_position != (-1L)))
2003
                {
2004
                        original_stack_position = jam_peek_stack_record();
2005
                        status = jam_push_callret_record(return_position);
2006
                }
2007
 
2008
                /*
2009
                *       Now seek to the desired position so we can execute that
2010
                *       statement next
2011
                */
2012
                if ((status == JAMC_SUCCESS) && (proc_position != (-1L)))
2013
                {
2014
                        if (jam_seek(proc_position) == 0)
2015
                        {
2016
                                jam_current_file_position = proc_position;
2017
                        }
2018
                        else
2019
                        {
2020
                                /* seek failed */
2021
                                status = JAMC_IO_ERROR;
2022
                        }
2023
                }
2024
        }
2025
 
2026
        /*
2027
        *       Set jam_current_block to the procedure about to be executed
2028
        */
2029
        if (status == JAMC_SUCCESS)
2030
        {
2031
                jam_current_block = symbol_record;
2032
                jam_phase = JAM_PROCEDURE_PHASE;
2033
        }
2034
 
2035
        /*
2036
        *       Get program statements and execute them
2037
        */
2038
        while ((!(*done)) && (!endproc) && (status == JAMC_SUCCESS))
2039
        {
2040
                if (!reuse_statement_buffer)
2041
                {
2042
                        status = jam_get_statement
2043
                        (
2044
                                statement_buffer,
2045
                                label_buffer
2046
                        );
2047
 
2048
                        if ((status == JAMC_SUCCESS)
2049
                                && (label_buffer[0] != JAMC_NULL_CHAR))
2050
                        {
2051
                                status = jam_add_symbol
2052
                                (
2053
                                        JAM_LABEL,
2054
                                        label_buffer,
2055
                                        0L,
2056
                                        jam_current_statement_position
2057
                                );
2058
                        }
2059
                }
2060
                else
2061
                {
2062
                        /* statement buffer will be reused -- clear the flag */
2063
                        reuse_statement_buffer = FALSE;
2064
                }
2065
 
2066
                if (status == JAMC_SUCCESS)
2067
                {
2068
                        status = jam_execute_statement
2069
                        (
2070
                                statement_buffer,
2071
                                done,
2072
                                &reuse_statement_buffer,
2073
                                exit_code
2074
                        );
2075
 
2076
                        if ((status == JAMC_SUCCESS) &&
2077
                                (jam_get_instruction(statement_buffer) == JAM_ENDPROC_INSTR) &&
2078
                                (jam_peek_stack_record() == original_stack_position))
2079
                        {
2080
                                endproc = TRUE;
2081
                        }
2082
                }
2083
        }
2084
 
2085
        jam_current_block = tmp_current_block;
2086
        jam_phase = tmp_phase;
2087
 
2088
        if (statement_buffer != NULL) jam_free(statement_buffer);
2089
 
2090
        return (status);
2091
}
2092
 
2093
JAM_RETURN_TYPE jam_call_procedure_from_action
2094
(
2095
        char *procedure_name,
2096
        BOOL *done,
2097
        int *exit_code
2098
)
2099
{
2100
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
2101
        int index = 0;
2102
        int procname_end = 0;
2103
        int variable_begin = 0;
2104
        int variable_end = 0;
2105
        char save_ch = 0;
2106
        BOOL call_it = FALSE;
2107
        BOOL init_value_set = FALSE;
2108
        long init_value = 0L;
2109
 
2110
        if (jam_isalpha(procedure_name[index]))
2111
        {
2112
                while ((jam_is_name_char(procedure_name[index])) &&
2113
                        (index < JAMC_MAX_STATEMENT_LENGTH))
2114
                {
2115
                        ++index;        /* skip over procedure name */
2116
                }
2117
 
2118
                procname_end = index;
2119
                save_ch = procedure_name[procname_end];
2120
                procedure_name[procname_end] = JAMC_NULL_CHAR;
2121
 
2122
                if (jam_check_init_list(procedure_name, &init_value))
2123
                {
2124
                        init_value_set = TRUE;
2125
                }
2126
 
2127
                procedure_name[procname_end] = save_ch;
2128
 
2129
                while ((jam_isspace(procedure_name[index])) &&
2130
                        (index < JAMC_MAX_STATEMENT_LENGTH))
2131
                {
2132
                        ++index;        /* skip over white space */
2133
                }
2134
 
2135
                if (procedure_name[index] == JAMC_NULL_CHAR)
2136
                {
2137
                        /*
2138
                        *       This is a mandatory procedure -- there is no
2139
                        *       OPTIONAL or RECOMMENDED keyword.  Just call it.
2140
                        */
2141
                        status = JAMC_SUCCESS;
2142
                        call_it = TRUE;
2143
                }
2144
                else
2145
                {
2146
                        variable_begin = index;
2147
 
2148
                        while ((jam_is_name_char(procedure_name[index])) &&
2149
                                (index < JAMC_MAX_STATEMENT_LENGTH))
2150
                        {
2151
                                ++index;        /* skip over procedure name */
2152
                        }
2153
 
2154
                        variable_end = index;
2155
 
2156
                        while ((jam_isspace(procedure_name[index])) &&
2157
                                (index < JAMC_MAX_STATEMENT_LENGTH))
2158
                        {
2159
                                ++index;        /* skip over white space */
2160
                        }
2161
 
2162
                        if (procedure_name[index] == JAMC_NULL_CHAR)
2163
                        {
2164
                                /* examine the keyword */
2165
                                save_ch = procedure_name[variable_end];
2166
                                procedure_name[variable_end] = JAMC_NULL_CHAR;
2167
 
2168
                                if (jam_stricmp(&procedure_name[variable_begin], "OPTIONAL") == 0)
2169
                                {
2170
                                        /* OPTIONAL - don't call it unless specifically requested */
2171
                                        status = JAMC_SUCCESS;
2172
                                        call_it = FALSE;
2173
                                        if (init_value_set && (init_value != 0))
2174
                                        {
2175
                                                /* it was requested -- call it */
2176
                                                call_it = TRUE;
2177
                                        }
2178
                                }
2179
                                else if (jam_stricmp(&procedure_name[variable_begin], "RECOMMENDED") == 0)
2180
                                {
2181
                                        /* RECOMMENDED - call it unless specifically directed otherwise */
2182
                                        status = JAMC_SUCCESS;
2183
                                        call_it = TRUE;
2184
                                        if (init_value_set && (init_value == 0))
2185
                                        {
2186
                                                /* it was declined -- don't call it */
2187
                                                call_it = FALSE;
2188
                                        }
2189
                                }
2190
                                else
2191
                                {
2192
                                        /* the string did not match "OPTIONAL" or "RECOMMENDED" */
2193
                                        status = JAMC_SYNTAX_ERROR;
2194
                                }
2195
 
2196
                                procedure_name[variable_end] = save_ch;
2197
                        }
2198
                        else
2199
                        {
2200
                                /* something else is lurking here -- syntax error */
2201
                                status = JAMC_SYNTAX_ERROR;
2202
                        }
2203
                }
2204
        }
2205
 
2206
        if ((status == JAMC_SUCCESS) && call_it)
2207
        {
2208
                status = jam_call_procedure(procedure_name, done, exit_code);
2209
        }
2210
 
2211
        return (status);
2212
}
2213
 
2214
JAM_RETURN_TYPE jam_call_procedure_from_procedure
2215
(
2216
        char *procedure_name,
2217
        BOOL *done,
2218
        int *exit_code
2219
)
2220
{
2221
        JAM_RETURN_TYPE status = JAMC_SCOPE_ERROR;
2222
        JAMS_HEAP_RECORD *heap_record = NULL;
2223
        char *uses_list = NULL;
2224
        char save_ch = 0;
2225
        int ch_index = 0;
2226
        int name_begin = 0;
2227
        int name_end = 0;
2228
 
2229
        if (jam_version != 2)
2230
        {
2231
                status = JAMC_SUCCESS;
2232
        }
2233
        else
2234
        {
2235
                /*
2236
                *       Check if procedure being called is listed in the
2237
                *       "uses list", or is a recursive call to the calling
2238
                *       procedure itself
2239
                */
2240
                if ((jam_current_block != NULL) &&
2241
                        (jam_current_block->type == JAM_PROCEDURE_BLOCK))
2242
                {
2243
                        heap_record = (JAMS_HEAP_RECORD *) jam_current_block->value;
2244
 
2245
                        if (heap_record != NULL)
2246
                        {
2247
                                uses_list = (char *) heap_record->data;
2248
                        }
2249
 
2250
                        if (jam_stricmp(procedure_name, jam_current_block->name) == 0)
2251
                        {
2252
                                /* any procedure may always call itself */
2253
                                status = JAMC_SUCCESS;
2254
                        }
2255
                }
2256
 
2257
                if ((status != JAMC_SUCCESS) && (uses_list != NULL))
2258
                {
2259
                        name_begin = 0;
2260
                        ch_index = 0;
2261
                        while ((uses_list[ch_index] != JAMC_NULL_CHAR) &&
2262
                                (status != JAMC_SUCCESS))
2263
                        {
2264
                                name_end = 0;
2265
                                while ((uses_list[ch_index] != JAMC_NULL_CHAR) &&
2266
                                        (!jam_is_name_char(uses_list[ch_index])))
2267
                                {
2268
                                        ++ch_index;
2269
                                }
2270
                                if (jam_is_name_char(uses_list[ch_index]))
2271
                                {
2272
                                        name_begin = ch_index;
2273
                                }
2274
                                while ((uses_list[ch_index] != JAMC_NULL_CHAR) &&
2275
                                        (jam_is_name_char(uses_list[ch_index])))
2276
                                {
2277
                                        ++ch_index;
2278
                                }
2279
                                name_end = ch_index;
2280
 
2281
                                if (name_end > name_begin)
2282
                                {
2283
                                        save_ch = uses_list[name_end];
2284
                                        uses_list[name_end] = JAMC_NULL_CHAR;
2285
                                        if (jam_stricmp(&uses_list[name_begin],
2286
                                                procedure_name) == 0)
2287
                                        {
2288
                                                /* symbol is in scope */
2289
                                                status = JAMC_SUCCESS;
2290
                                        }
2291
                                        uses_list[name_end] = save_ch;
2292
                                }
2293
                        }
2294
                }
2295
        }
2296
 
2297
        if (status == JAMC_SUCCESS)
2298
        {
2299
                status = jam_call_procedure(procedure_name, done, exit_code);
2300
        }
2301
 
2302
        return (status);
2303
}
2304
 
2305
/****************************************************************************/
2306
/*                                                                                                                                                      */
2307
 
2308
JAM_RETURN_TYPE jam_process_action
2309
(
2310
        char *statement_buffer,
2311
        BOOL *done,
2312
        int *exit_code
2313
)
2314
 
2315
/*                                                                                                                                                      */
2316
/*      Description:    Processes an ACTION statement.  Calls specified                 */
2317
/*                                      procedure blocks in sequence.                                                   */
2318
/*                                                                                                                                                      */
2319
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
2320
/*                                                                                                                                                      */
2321
/****************************************************************************/
2322
{
2323
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
2324
        BOOL execute = FALSE;
2325
        int index = 0;
2326
        int variable_begin = 0;
2327
        int variable_end = 0;
2328
        char save_ch = 0;
2329
 
2330
        if (jam_version == 0) jam_version = 2;
2331
 
2332
        if (jam_version == 1) status = JAMC_SYNTAX_ERROR;
2333
 
2334
        if ((jam_phase == JAM_UNKNOWN_PHASE) || (jam_phase == JAM_NOTE_PHASE))
2335
        {
2336
                jam_phase = JAM_ACTION_PHASE;
2337
        }
2338
 
2339
        if ((jam_version == 2) && (jam_phase != JAM_ACTION_PHASE))
2340
        {
2341
                status = JAMC_PHASE_ERROR;
2342
        }
2343
 
2344
        index = jam_skip_instruction_name(statement_buffer);
2345
 
2346
        if (jam_isalpha(statement_buffer[index]))
2347
        {
2348
                /*
2349
                *       Get the action name
2350
                */
2351
                variable_begin = index;
2352
                while ((jam_is_name_char(statement_buffer[index])) &&
2353
                        (index < JAMC_MAX_STATEMENT_LENGTH))
2354
                {
2355
                        ++index;        /* skip over variable name */
2356
                }
2357
                variable_end = index;
2358
 
2359
                while ((jam_isspace(statement_buffer[index])) &&
2360
                        (index < JAMC_MAX_STATEMENT_LENGTH))
2361
                {
2362
                        ++index;        /* skip over white space */
2363
                }
2364
 
2365
                save_ch = statement_buffer[variable_end];
2366
                statement_buffer[variable_end] = JAMC_NULL_CHAR;
2367
                if (jam_action == NULL)
2368
                {
2369
                        /*
2370
                        *       If no action name was specified, this is a fatal error
2371
                        */
2372
                        status = JAMC_ACTION_NOT_FOUND;
2373
                }
2374
                else if (jam_stricmp(&statement_buffer[variable_begin],
2375
                        jam_action) == 0)
2376
                {
2377
                        /* this action name matches the desired action name - execute it */
2378
                        execute = TRUE;
2379
                        jam_phase = JAM_PROCEDURE_PHASE;
2380
                }
2381
                statement_buffer[variable_end] = save_ch;
2382
 
2383
                if (execute && (statement_buffer[index] == JAMC_QUOTE_CHAR))
2384
                {
2385
                        /*
2386
                        *       Get the action description string (if there is one)
2387
                        */
2388
                        ++index;        /* step over quote char */
2389
                        variable_begin = index;
2390
 
2391
                        /* find matching quote */
2392
                        while ((statement_buffer[index] != JAMC_QUOTE_CHAR) &&
2393
                                (statement_buffer[index] != JAMC_NULL_CHAR) &&
2394
                                (index < JAMC_MAX_STATEMENT_LENGTH))
2395
                        {
2396
                                ++index;
2397
                        }
2398
 
2399
                        if (statement_buffer[index] == JAMC_QUOTE_CHAR)
2400
                        {
2401
                                variable_end = index;
2402
 
2403
                                ++index;        /* skip over quote character */
2404
 
2405
                                while ((jam_isspace(statement_buffer[index])) &&
2406
                                        (index < JAMC_MAX_STATEMENT_LENGTH))
2407
                                {
2408
                                        ++index;        /* skip over white space */
2409
                                }
2410
                        }
2411
                }
2412
 
2413
                if (execute && (statement_buffer[index] == JAMC_EQUAL_CHAR))
2414
                {
2415
                        ++index;        /* skip over equal character */
2416
 
2417
                        /*
2418
                        *       Call procedures
2419
                        */
2420
                        while ((status == JAMC_SUCCESS) &&
2421
                                (statement_buffer[index] != JAMC_NULL_CHAR) &&
2422
                                (statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
2423
                                (index < JAMC_MAX_STATEMENT_LENGTH))
2424
                        {
2425
                                while ((jam_isspace(statement_buffer[index])) &&
2426
                                        (index < JAMC_MAX_STATEMENT_LENGTH))
2427
                                {
2428
                                        ++index;        /* skip over white space */
2429
                                }
2430
 
2431
                                variable_begin = index;
2432
 
2433
                                while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
2434
                                        (statement_buffer[index] != JAMC_COMMA_CHAR) &&
2435
                                        (statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
2436
                                        (index < JAMC_MAX_STATEMENT_LENGTH))
2437
                                {
2438
                                        ++index;
2439
                                }
2440
 
2441
                                if ((statement_buffer[index] == JAMC_COMMA_CHAR) ||
2442
                                        (statement_buffer[index] == JAMC_SEMICOLON_CHAR))
2443
                                {
2444
                                        variable_end = index;
2445
 
2446
                                        save_ch = statement_buffer[variable_end];
2447
                                        statement_buffer[variable_end] = JAMC_NULL_CHAR;
2448
                                        status = jam_call_procedure_from_action(
2449
                                                &statement_buffer[variable_begin], done, exit_code);
2450
                                        statement_buffer[variable_end] = save_ch;
2451
                                }
2452
 
2453
                                if (statement_buffer[index] == JAMC_COMMA_CHAR)
2454
                                {
2455
                                        ++index;        /* step over comma */
2456
                                }
2457
                        }
2458
 
2459
                        if ((status == JAMC_SUCCESS) && !(*done))
2460
                        {
2461
                                *done = TRUE;
2462
                                *exit_code = 0;  /* success */
2463
                        }
2464
                }
2465
        }
2466
 
2467
        return (status);
2468
}
2469
 
2470
/****************************************************************************/
2471
/*                                                                                                                                                      */
2472
 
2473
JAM_RETURN_TYPE jam_process_boolean
2474
(
2475
        char *statement_buffer
2476
)
2477
 
2478
/*                                                                                                                                                      */
2479
/*      Description:    Processes a BOOLEAN variable declaration statement              */
2480
/*                                                                                                                                                      */
2481
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
2482
/*                                                                                                                                                      */
2483
/****************************************************************************/
2484
{
2485
        int index = 0;
2486
        int variable_begin = 0;
2487
        int variable_end = 0;
2488
        int dim_begin = 0;
2489
        int dim_end = 0;
2490
        int expr_begin = 0;
2491
        int expr_end = 0;
2492
        int delimiter = 0;
2493
        long dim_value = 0L;
2494
        long init_value = 0L;
2495
        char save_ch = 0;
2496
        JAME_EXPRESSION_TYPE expr_type = JAM_ILLEGAL_EXPR_TYPE;
2497
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
2498
        JAMS_HEAP_RECORD *heap_record = NULL;
2499
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
2500
 
2501
        if (jam_version == 0) jam_version = 1;
2502
 
2503
        if ((jam_version == 2) &&
2504
                (jam_phase != JAM_PROCEDURE_PHASE) &&
2505
                (jam_phase != JAM_DATA_PHASE))
2506
        {
2507
                return (JAMC_PHASE_ERROR);
2508
        }
2509
 
2510
        index = jam_skip_instruction_name(statement_buffer);
2511
 
2512
        if (jam_isalpha(statement_buffer[index]))
2513
        {
2514
                /* locate variable name */
2515
                variable_begin = index;
2516
                while ((jam_is_name_char(statement_buffer[index])) &&
2517
                        (index < JAMC_MAX_STATEMENT_LENGTH))
2518
                {
2519
                        ++index;        /* skip over variable name */
2520
                }
2521
                variable_end = index;
2522
 
2523
                while ((jam_isspace(statement_buffer[index])) &&
2524
                        (index < JAMC_MAX_STATEMENT_LENGTH))
2525
                {
2526
                        ++index;        /* skip over white space */
2527
                }
2528
 
2529
                if (statement_buffer[index] == JAMC_LBRACKET_CHAR)
2530
                {
2531
                        /*
2532
                        *       Array declaration
2533
                        */
2534
                        dim_begin = index + 1;
2535
                        while ((statement_buffer[index] != JAMC_RBRACKET_CHAR) &&
2536
                                (index < JAMC_MAX_STATEMENT_LENGTH))
2537
                        {
2538
                                ++index;        /* find matching bracket */
2539
                        }
2540
                        if (statement_buffer[index] == JAMC_RBRACKET_CHAR)
2541
                        {
2542
                                dim_end = index;
2543
                                ++index;
2544
                        }
2545
                        while ((jam_isspace(statement_buffer[index])) &&
2546
                                (index < JAMC_MAX_STATEMENT_LENGTH))
2547
                        {
2548
                                ++index;        /* skip over white space */
2549
                        }
2550
 
2551
                        if (dim_end > dim_begin)
2552
                        {
2553
                                save_ch = statement_buffer[dim_end];
2554
                                statement_buffer[dim_end] = JAMC_NULL_CHAR;
2555
                                status = jam_evaluate_expression(
2556
                                        &statement_buffer[dim_begin], &dim_value, &expr_type);
2557
                                statement_buffer[dim_end] = save_ch;
2558
                        }
2559
 
2560
                        /*
2561
                        *       Check for integer expression
2562
                        */
2563
                        if ((status == JAMC_SUCCESS) &&
2564
                                (expr_type != JAM_INTEGER_EXPR) &&
2565
                                (expr_type != JAM_INT_OR_BOOL_EXPR))
2566
                        {
2567
                                status = JAMC_TYPE_MISMATCH;
2568
                        }
2569
 
2570
                        if (status == JAMC_SUCCESS)
2571
                        {
2572
                                /*
2573
                                *       Add the array name to the symbol table
2574
                                */
2575
                                save_ch = statement_buffer[variable_end];
2576
                                statement_buffer[variable_end] = JAMC_NULL_CHAR;
2577
                                status = jam_add_symbol(JAM_BOOLEAN_ARRAY_WRITABLE,
2578
                                        &statement_buffer[variable_begin], 0L,
2579
                                        jam_current_statement_position);
2580
 
2581
                                /* get a pointer to the symbol record */
2582
                                if (status == JAMC_SUCCESS)
2583
                                {
2584
                                        status = jam_get_symbol_record(
2585
                                                &statement_buffer[variable_begin], &symbol_record);
2586
                                }
2587
                                statement_buffer[variable_end] = save_ch;
2588
                        }
2589
 
2590
                        /*
2591
                        *       Only initialize if array has not been initialized before
2592
                        */
2593
                        if ((status == JAMC_SUCCESS) &&
2594
                                (symbol_record->type == JAM_BOOLEAN_ARRAY_WRITABLE) &&
2595
                                (symbol_record->value == 0))
2596
                        {
2597
                                if (statement_buffer[index] == JAMC_EQUAL_CHAR)
2598
                                {
2599
                                        /*
2600
                                        *       Array has initialization data
2601
                                        */
2602
                                        symbol_record->type = JAM_BOOLEAN_ARRAY_INITIALIZED;
2603
 
2604
                                        status = jam_add_heap_record(symbol_record, &heap_record,
2605
                                                dim_value);
2606
 
2607
                                        if (status == JAMC_SUCCESS)
2608
                                        {
2609
                                                symbol_record->value = (long) heap_record;
2610
 
2611
                                                /*
2612
                                                *       Initialize heap data for array
2613
                                                */
2614
                                                status = jam_read_boolean_array_data(heap_record,
2615
                                                        &statement_buffer[index + 1]);
2616
                                        }
2617
                                }
2618
                                else if (statement_buffer[index] == JAMC_SEMICOLON_CHAR)
2619
                                {
2620
                                        /*
2621
                                        *       Array has no initialization data.
2622
                                        *       Allocate a buffer on the heap:
2623
                                        */
2624
                                        status = jam_add_heap_record(symbol_record, &heap_record,
2625
                                                dim_value);
2626
 
2627
                                        if (status == JAMC_SUCCESS)
2628
                                        {
2629
                                                symbol_record->value = (long) heap_record;
2630
                                        }
2631
                                }
2632
                        }
2633
                }
2634
                else
2635
                {
2636
                        /*
2637
                        *       Scalar variable declaration
2638
                        */
2639
                        if (statement_buffer[index] == JAMC_SEMICOLON_CHAR)
2640
                        {
2641
                                status = JAMC_SUCCESS;
2642
                        }
2643
                        else if (statement_buffer[index] == JAMC_EQUAL_CHAR)
2644
                        {
2645
                                /*
2646
                                *       Evaluate initialization expression
2647
                                */
2648
                                ++index;
2649
                                status = jam_find_argument(&statement_buffer[index],
2650
                                        &expr_begin, &expr_end, &delimiter);
2651
 
2652
                                expr_begin += index;
2653
                                expr_end += index;
2654
                                delimiter += index;
2655
 
2656
                                if ((status == JAMC_SUCCESS) &&
2657
                                        (statement_buffer[delimiter] != JAMC_SEMICOLON_CHAR))
2658
                                {
2659
                                        status = JAMC_SYNTAX_ERROR;
2660
                                }
2661
 
2662
                                if ((status == JAMC_SUCCESS) && (expr_end > expr_begin))
2663
                                {
2664
                                        save_ch = statement_buffer[expr_end];
2665
                                        statement_buffer[expr_end] = JAMC_NULL_CHAR;
2666
                                        status = jam_evaluate_expression(
2667
                                                &statement_buffer[expr_begin], &init_value, &expr_type);
2668
                                        statement_buffer[expr_end] = save_ch;
2669
                                }
2670
 
2671
                                /*
2672
                                *       Check for Boolean expression
2673
                                */
2674
                                if ((status == JAMC_SUCCESS) &&
2675
                                        (expr_type != JAM_BOOLEAN_EXPR) &&
2676
                                        (expr_type != JAM_INT_OR_BOOL_EXPR))
2677
                                {
2678
                                        status = JAMC_TYPE_MISMATCH;
2679
                                }
2680
                        }
2681
 
2682
                        if (status == JAMC_SUCCESS)
2683
                        {
2684
                                /*
2685
                                *       Add the variable name to the symbol table
2686
                                */
2687
                                save_ch = statement_buffer[variable_end];
2688
                                statement_buffer[variable_end] = JAMC_NULL_CHAR;
2689
                                status = jam_add_symbol(JAM_BOOLEAN_SYMBOL,
2690
                                        &statement_buffer[variable_begin],
2691
                                        init_value, jam_current_statement_position);
2692
                                statement_buffer[variable_end] = save_ch;
2693
                        }
2694
                }
2695
        }
2696
 
2697
        return (status);
2698
}
2699
 
2700
/****************************************************************************/
2701
/*                                                                                                                                                      */
2702
 
2703
JAM_RETURN_TYPE jam_process_call_or_goto
2704
(
2705
        char *statement_buffer,
2706
        BOOL call_statement,
2707
        BOOL *done,
2708
        int *exit_code
2709
)
2710
 
2711
/*                                                                                                                                                      */
2712
/*      Description:    Processes a CALL or GOTO statement.  If it is a CALL    */
2713
/*                                      statement, a stack record is pushed onto the stack.             */
2714
/*                                                                                                                                                      */
2715
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
2716
/*                                                                                                                                                      */
2717
/****************************************************************************/
2718
{
2719
        int index = 0;
2720
        int label_begin = 0;
2721
        int label_end = 0;
2722
        char save_ch = 0;
2723
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
2724
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
2725
        JAME_SYMBOL_TYPE symbol_type = JAM_LABEL;
2726
        long current_position = 0L;
2727
        long goto_position = -1L;
2728
        long return_position = jam_next_statement_position;
2729
        char label_buffer[JAMC_MAX_NAME_LENGTH + 1];
2730
        char goto_label[JAMC_MAX_NAME_LENGTH + 1];
2731
        BOOL found = FALSE;
2732
 
2733
        if (jam_version == 0) jam_version = 1;
2734
 
2735
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
2736
        {
2737
                return (JAMC_PHASE_ERROR);
2738
        }
2739
 
2740
        if ((jam_version == 2) && call_statement)
2741
        {
2742
                symbol_type = JAM_PROCEDURE_BLOCK;
2743
        }
2744
 
2745
        index = jam_skip_instruction_name(statement_buffer);
2746
 
2747
        /*
2748
        *       Extract the label name from the statement buffer.
2749
        */
2750
        if (jam_isalpha(statement_buffer[index]) && !found)
2751
        {
2752
                /* locate label name */
2753
                label_begin = index;
2754
                while ((jam_is_name_char(statement_buffer[index])) &&
2755
                        (index < JAMC_MAX_STATEMENT_LENGTH))
2756
                {
2757
                        ++index;        /* skip over label name */
2758
                }
2759
                label_end = index;
2760
 
2761
                save_ch = statement_buffer[label_end];
2762
                statement_buffer[label_end] = JAMC_NULL_CHAR;
2763
                jam_strcpy(goto_label, &statement_buffer[label_begin]);
2764
                statement_buffer[label_end] = save_ch;
2765
 
2766
                while ((jam_isspace(statement_buffer[index])) &&
2767
                        (index < JAMC_MAX_STATEMENT_LENGTH))
2768
                {
2769
                        ++index;        /* skip over white space */
2770
                }
2771
 
2772
                if (statement_buffer[index] == JAMC_SEMICOLON_CHAR)
2773
                {
2774
                        /*
2775
                        *       Look in symbol table for label
2776
                        */
2777
                        save_ch = statement_buffer[label_end];
2778
                        statement_buffer[label_end] = JAMC_NULL_CHAR;
2779
                        status = jam_get_symbol_record(
2780
                                &statement_buffer[label_begin], &symbol_record);
2781
 
2782
                        if ((status == JAMC_SUCCESS) &&
2783
                                (symbol_record->type == symbol_type))
2784
                        {
2785
                                /*
2786
                                *       Label is defined - get the address for the jump
2787
                                */
2788
                                goto_position = symbol_record->position;
2789
                        }
2790
                        else if (status == JAMC_UNDEFINED_SYMBOL)
2791
                        {
2792
                                /*
2793
                                *       Label is not defined... may be a forward reference.
2794
                                *       Search through the file to find the symbol.
2795
                                */
2796
                                current_position = jam_current_statement_position;
2797
 
2798
                                status = JAMC_SUCCESS;
2799
 
2800
                                while ((!found) && (status == JAMC_SUCCESS))
2801
                                {
2802
                                        /*
2803
                                        *       Get statements without executing them
2804
                                        */
2805
                                        status = jam_get_statement(statement_buffer, label_buffer);
2806
 
2807
                                        if ((status == JAMC_SUCCESS) &&
2808
                                                (label_buffer[0] != JAMC_NULL_CHAR))
2809
                                        {
2810
                                                /*
2811
                                                *       If there is a label, add it to the symbol table
2812
                                                */
2813
                                                status = jam_add_symbol(JAM_LABEL, label_buffer, 0L,
2814
                                                        jam_current_statement_position);
2815
 
2816
                                                /*
2817
                                                *       Is it the label we are looking for?
2818
                                                */
2819
                                                if ((status == JAMC_SUCCESS) &&
2820
                                                        (jam_strcmp(label_buffer, goto_label) == 0))
2821
                                                {
2822
                                                        /*
2823
                                                        *       We found the label we were looking for.
2824
                                                        *       Get the address for the jump.
2825
                                                        */
2826
                                                        found = TRUE;
2827
                                                        goto_position = jam_current_statement_position;
2828
                                                }
2829
                                        }
2830
 
2831
                                        /*
2832
                                        *       In Jam 2.0, only search inside current procedure
2833
                                        */
2834
                                        if ((status == JAMC_SUCCESS) && (!found) &&
2835
                                                (jam_version == 2) && (jam_get_instruction(
2836
                                                        statement_buffer) == JAM_ENDPROC_INSTR))
2837
                                        {
2838
                                                status = JAMC_UNDEFINED_SYMBOL;
2839
                                        }
2840
                                }
2841
 
2842
                                if (!found)
2843
                                {
2844
                                        /* label was not found -- report "undefined symbol" */
2845
                                        /* rather than "unexpected EOF" */
2846
                                        status = JAMC_UNDEFINED_SYMBOL;
2847
 
2848
                                        /* seek to location of the CALL or GOTO statement */
2849
                                        /* which caused the error */
2850
                                        jam_seek(current_position);
2851
                                        jam_current_file_position = current_position;
2852
                                        jam_current_statement_position = current_position;
2853
                                }
2854
                        }
2855
 
2856
                        statement_buffer[label_end] = save_ch;
2857
 
2858
                        /*
2859
                        *       If this is a CALL statement (not a GOTO) then push a CALL
2860
                        *       record onto the stack
2861
                        */
2862
                        if ((call_statement) && (status == JAMC_SUCCESS) &&
2863
                                (goto_position != (-1L)) && (jam_version != 2))
2864
                        {
2865
                                status = jam_push_callret_record(return_position);
2866
                        }
2867
 
2868
                        /*
2869
                        *       Now seek to the desired position so we can execute that
2870
                        *       statement next
2871
                        */
2872
                        if ((status == JAMC_SUCCESS) && (goto_position != (-1L)) &&
2873
                                ((jam_version != 2) || (!call_statement)))
2874
                        {
2875
                                if (jam_seek(goto_position) == 0)
2876
                                {
2877
                                        jam_current_file_position = goto_position;
2878
                                }
2879
                                else
2880
                                {
2881
                                        /* seek failed */
2882
                                        status = JAMC_IO_ERROR;
2883
                                }
2884
                        }
2885
 
2886
                        /*
2887
                        *       Call a procedure block in Jam 2.0
2888
                        */
2889
                        if (call_statement && (jam_version == 2))
2890
                        {
2891
                                status = jam_call_procedure_from_procedure(
2892
                                        goto_label, done, exit_code);
2893
                        }
2894
                }
2895
        }
2896
 
2897
        return (status);
2898
}
2899
 
2900
JAM_RETURN_TYPE jam_process_data
2901
(
2902
        char *statement_buffer
2903
)
2904
{
2905
        int index = 0;
2906
        int name_begin = 0;
2907
        int name_end = 0;
2908
        char save_ch = 0;
2909
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
2910
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
2911
 
2912
        if (jam_version == 0) jam_version = 2;
2913
 
2914
        if (jam_version == 1) status = JAMC_SYNTAX_ERROR;
2915
 
2916
        if ((jam_version == 2) &&
2917
                (jam_phase != JAM_PROCEDURE_PHASE) &&
2918
                (jam_phase != JAM_DATA_PHASE))
2919
        {
2920
                status = JAMC_PHASE_ERROR;
2921
        }
2922
 
2923
        if ((jam_version == 2) && (jam_phase == JAM_ACTION_PHASE))
2924
        {
2925
                status = JAMC_ACTION_NOT_FOUND;
2926
        }
2927
 
2928
        if (status == JAMC_SUCCESS)
2929
        {
2930
                index = jam_skip_instruction_name(statement_buffer);
2931
 
2932
                if (jam_isalpha(statement_buffer[index]))
2933
                {
2934
                        /*
2935
                        *       Get the data block name
2936
                        */
2937
                        name_begin = index;
2938
                        while ((jam_is_name_char(statement_buffer[index])) &&
2939
                                (index < JAMC_MAX_STATEMENT_LENGTH))
2940
                        {
2941
                                ++index;        /* skip over data block name */
2942
                        }
2943
                        name_end = index;
2944
 
2945
                        save_ch = statement_buffer[name_end];
2946
                        statement_buffer[name_end] = JAMC_NULL_CHAR;
2947
                        status = jam_add_symbol(JAM_DATA_BLOCK,
2948
                                &statement_buffer[name_begin], 0L,
2949
                                jam_current_statement_position);
2950
 
2951
                        /* get a pointer to the symbol record */
2952
                        if (status == JAMC_SUCCESS)
2953
                        {
2954
                                status = jam_get_symbol_record(
2955
                                        &statement_buffer[name_begin], &symbol_record);
2956
                        }
2957
                        statement_buffer[name_end] = save_ch;
2958
 
2959
                        while ((jam_isspace(statement_buffer[index])) &&
2960
                                (index < JAMC_MAX_STATEMENT_LENGTH))
2961
                        {
2962
                                ++index;        /* skip over white space */
2963
                        }
2964
                }
2965
                else
2966
                {
2967
                        status = JAMC_SYNTAX_ERROR;
2968
                }
2969
 
2970
                if ((status == JAMC_SUCCESS) &&
2971
                        (statement_buffer[index] != JAMC_SEMICOLON_CHAR))
2972
                {
2973
                        status = JAMC_SYNTAX_ERROR;
2974
                }
2975
        }
2976
 
2977
        return (status);
2978
}
2979
 
2980
/****************************************************************************/
2981
/*                                                                                                                                                      */
2982
 
2983
JAM_RETURN_TYPE jam_process_drscan_compare
2984
(
2985
        char *statement_buffer,
2986
        long count_value,
2987
        long *in_data,
2988
        long in_index
2989
)
2990
 
2991
/*                                                                                                                                                      */
2992
/*      Description:    Processes the arguments for the COMPARE version of the  */
2993
/*                                      DRSCAN statement.  Calls jam_swap_dr() to access the    */
2994
/*                                      JTAG hardware interface.                                                                */
2995
/*                                                                                                                                                      */
2996
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
2997
/*                                                                                                                                                      */
2998
/****************************************************************************/
2999
{
3000
 
3001
/* syntax: DRSCAN <length> [, <data>] [COMPARE <array>, <mask>, <result>] ; */
3002
 
3003
        int bit = 0;
3004
        int index = 0;
3005
        int expr_begin = 0;
3006
        int expr_end = 0;
3007
        int delimiter = 0;
3008
        int actual = 0;
3009
        int expected = 0;
3010
        int mask = 0;
3011
        long comp_start_index = 0L;
3012
        long comp_stop_index = 0L;
3013
        long mask_start_index = 0L;
3014
        long mask_stop_index = 0L;
3015
        long start_index = 0;
3016
        char save_ch = 0;
3017
        long *temp_array = NULL;
3018
        BOOL result = TRUE;
3019
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
3020
        JAMS_HEAP_RECORD *heap_record = NULL;
3021
        long *comp_data = NULL;
3022
        long *mask_data = NULL;
3023
        long *literal_array_data = NULL;
3024
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
3025
 
3026
        long* tdi_data = NULL;
3027
 
3028
        if ((jam_strncmp(statement_buffer, "CAPTURE", 7) == 0) &&
3029
                 (jam_isspace(statement_buffer[7]))) {
3030
 
3031
          long stop_index;
3032
 
3033
          /* Next argument should be the capture array */
3034
 
3035
          statement_buffer += 8;
3036
 
3037
          status = jam_find_argument(statement_buffer,
3038
                                                                                  &expr_begin, &expr_end, &delimiter);
3039
 
3040
          if (status == JAMC_SUCCESS)
3041
                 {
3042
                        save_ch = statement_buffer[expr_end];
3043
                        statement_buffer[expr_end] = JAMC_NULL_CHAR;
3044
                        status = jam_get_array_argument(&statement_buffer[expr_begin],
3045
                                                                                                          &symbol_record, &literal_array_data,
3046
                                                                                                          &start_index, &stop_index, 1);
3047
                        statement_buffer[expr_end] = save_ch;
3048
                 }
3049
 
3050
 
3051
 
3052
 
3053
          if ((status == JAMC_SUCCESS) && (literal_array_data != NULL))
3054
                 {
3055
                        /* literal array may not be used for capture buffer */
3056
                        status = JAMC_SYNTAX_ERROR;
3057
                 }
3058
 
3059
          if ((status == JAMC_SUCCESS) &&
3060
                        (stop_index != start_index + count_value - 1))
3061
                 {
3062
                        status = JAMC_BOUNDS_ERROR;
3063
                 }
3064
 
3065
          if (status == JAMC_SUCCESS)
3066
                 {
3067
                        if (symbol_record != NULL)
3068
                          {
3069
                                 heap_record = (JAMS_HEAP_RECORD *)symbol_record->value;
3070
 
3071
                                 if (heap_record != NULL)
3072
                                        {
3073
                                          tdi_data = heap_record->data;
3074
                                        }
3075
                                 else
3076
                                        {
3077
                                          status = JAMC_INTERNAL_ERROR;
3078
                                        }
3079
                          }
3080
                        else
3081
                          {
3082
                                 status = JAMC_INTERNAL_ERROR;
3083
                          }
3084
                 }
3085
 
3086
          if (status == JAMC_SUCCESS) {
3087
                 if (statement_buffer[delimiter] == JAMC_SEMICOLON_CHAR)
3088
                 {
3089
                        status = jam_swap_dr(count_value, in_data, in_index,
3090
                                                                                tdi_data, start_index);
3091
                        return status;
3092
                 } else if (statement_buffer[delimiter] == JAMC_COMMA_CHAR) {
3093
                        statement_buffer = statement_buffer + delimiter+1;
3094
                 } else {
3095
                        status = JAMC_SYNTAX_ERROR;
3096
                        return status;
3097
                 }
3098
          }
3099
 
3100
        }
3101
 
3102
 
3103
 
3104
        if ((jam_strncmp(statement_buffer, "COMPARE", 7) == 0) &&
3105
                 (jam_isspace(statement_buffer[7]))) {
3106
          statement_buffer += 8;
3107
        } else {
3108
          status = JAMC_SYNTAX_ERROR;
3109
          return status;
3110
        }
3111
 
3112
 
3113
 
3114
 
3115
 
3116
 
3117
        /*
3118
        *       Statement buffer should contain the part of the statement string
3119
        *       after the COMPARE keyword.
3120
        *
3121
        *       The first argument should be the compare array.
3122
        */
3123
        status = jam_find_argument(statement_buffer,
3124
                &expr_begin, &expr_end, &delimiter);
3125
 
3126
        if ((status == JAMC_SUCCESS) &&
3127
                (statement_buffer[delimiter] != JAMC_COMMA_CHAR))
3128
        {
3129
                status = JAMC_SYNTAX_ERROR;
3130
        }
3131
 
3132
        if (status == JAMC_SUCCESS)
3133
        {
3134
                save_ch = statement_buffer[expr_end];
3135
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
3136
                status = jam_get_array_argument(&statement_buffer[expr_begin],
3137
                        &symbol_record, &literal_array_data,
3138
                        &comp_start_index, &comp_stop_index, 1);
3139
                statement_buffer[expr_end] = save_ch;
3140
                index = delimiter + 1;
3141
        }
3142
 
3143
        if ((status == JAMC_SUCCESS) &&
3144
                (literal_array_data != NULL) &&
3145
                (comp_start_index == 0) &&
3146
                (comp_stop_index > count_value - 1))
3147
        {
3148
                comp_stop_index = count_value - 1;
3149
        }
3150
 
3151
        if ((status == JAMC_SUCCESS) &&
3152
                (comp_stop_index != comp_start_index + count_value - 1))
3153
        {
3154
                status = JAMC_BOUNDS_ERROR;
3155
        }
3156
 
3157
        if (status == JAMC_SUCCESS)
3158
        {
3159
                if (symbol_record != NULL)
3160
                {
3161
                        heap_record = (JAMS_HEAP_RECORD *)symbol_record->value;
3162
 
3163
                        if (heap_record != NULL)
3164
                        {
3165
                                comp_data = heap_record->data;
3166
                        }
3167
                        else
3168
                        {
3169
                                status = JAMC_INTERNAL_ERROR;
3170
                        }
3171
                }
3172
                else if (literal_array_data != NULL)
3173
                {
3174
                        comp_data = literal_array_data;
3175
                }
3176
                else
3177
                {
3178
                        status = JAMC_INTERNAL_ERROR;
3179
                }
3180
        }
3181
 
3182
        /*
3183
        *       Find the next argument -- should be the mask array
3184
        */
3185
        if (status == JAMC_SUCCESS)
3186
        {
3187
                status = jam_find_argument(&statement_buffer[index],
3188
                        &expr_begin, &expr_end, &delimiter);
3189
 
3190
                expr_begin += index;
3191
                expr_end += index;
3192
                delimiter += index;
3193
        }
3194
 
3195
        if ((status == JAMC_SUCCESS) &&
3196
                (statement_buffer[delimiter] != JAMC_COMMA_CHAR))
3197
        {
3198
                status = JAMC_SYNTAX_ERROR;
3199
        }
3200
 
3201
        if (status == JAMC_SUCCESS)
3202
        {
3203
                save_ch = statement_buffer[expr_end];
3204
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
3205
                status = jam_get_array_argument(&statement_buffer[expr_begin],
3206
                        &symbol_record, &literal_array_data,
3207
                        &mask_start_index, &mask_stop_index, 2);
3208
                statement_buffer[expr_end] = save_ch;
3209
                index = delimiter + 1;
3210
        }
3211
 
3212
        if ((status == JAMC_SUCCESS) &&
3213
                (literal_array_data != NULL) &&
3214
                (mask_start_index == 0) &&
3215
                (mask_stop_index > count_value - 1))
3216
        {
3217
                mask_stop_index = count_value - 1;
3218
        }
3219
 
3220
        if ((status == JAMC_SUCCESS) &&
3221
                (mask_stop_index != mask_start_index + count_value - 1))
3222
        {
3223
                status = JAMC_BOUNDS_ERROR;
3224
        }
3225
 
3226
        if (status == JAMC_SUCCESS)
3227
        {
3228
                if (symbol_record != NULL)
3229
                {
3230
                        heap_record = (JAMS_HEAP_RECORD *)symbol_record->value;
3231
 
3232
                        if (heap_record != NULL)
3233
                        {
3234
                                mask_data = heap_record->data;
3235
                        }
3236
                        else
3237
                        {
3238
                                status = JAMC_INTERNAL_ERROR;
3239
                        }
3240
                }
3241
                else if (literal_array_data != NULL)
3242
                {
3243
                        mask_data = literal_array_data;
3244
                }
3245
                else
3246
                {
3247
                        status = JAMC_INTERNAL_ERROR;
3248
                }
3249
        }
3250
 
3251
        /*
3252
        *       Find the third argument -- should be the result variable
3253
        */
3254
        if (status == JAMC_SUCCESS)
3255
        {
3256
                status = jam_find_argument(&statement_buffer[index],
3257
                        &expr_begin, &expr_end, &delimiter);
3258
 
3259
                expr_begin += index;
3260
                expr_end += index;
3261
                delimiter += index;
3262
        }
3263
 
3264
        if ((status == JAMC_SUCCESS) &&
3265
                (statement_buffer[delimiter] != JAMC_SEMICOLON_CHAR))
3266
        {
3267
                status = JAMC_SYNTAX_ERROR;
3268
        }
3269
 
3270
        /*
3271
        *       Result must be a scalar Boolean variable
3272
        */
3273
        if (status == JAMC_SUCCESS)
3274
        {
3275
                save_ch = statement_buffer[expr_end];
3276
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
3277
                status = jam_get_symbol_record(&statement_buffer[expr_begin],
3278
                        &symbol_record);
3279
                statement_buffer[expr_end] = save_ch;
3280
 
3281
                if ((status == JAMC_SUCCESS) &&
3282
                        (symbol_record->type != JAM_BOOLEAN_SYMBOL))
3283
                {
3284
                        status = JAMC_TYPE_MISMATCH;
3285
                }
3286
        }
3287
 
3288
        /*
3289
        *       Find some free memory on the heap
3290
        */
3291
        if (status == JAMC_SUCCESS)
3292
        {
3293
          if (tdi_data != NULL) {
3294
                 temp_array = tdi_data;
3295
          } else {
3296
                temp_array = jam_get_temp_workspace((count_value >> 3) + 4);
3297
 
3298
                if (temp_array == NULL)
3299
                {
3300
                        status = JAMC_OUT_OF_MEMORY;
3301
                }
3302
                start_index = 0;
3303
          }
3304
        }
3305
 
3306
        /*
3307
        *       Do the JTAG operation, saving the result in temp_array
3308
        */
3309
        if (status == JAMC_SUCCESS)
3310
        {
3311
                status = jam_swap_dr(count_value, in_data, in_index, temp_array,
3312
                                                                        start_index);
3313
        }
3314
 
3315
        /*
3316
        *       Mask the data and do the comparison
3317
        */
3318
        if (status == JAMC_SUCCESS)
3319
        {
3320
          long end_index = start_index + count_value;
3321
                for (bit = start_index; (bit < end_index) && result; ++bit)
3322
                {
3323
                        actual = temp_array[bit >> 5] & (1L << (bit & 0x1f)) ? 1 : 0;
3324
                        expected = comp_data[(bit + comp_start_index) >> 5]
3325
                                & (1L << ((bit + comp_start_index) & 0x1f)) ? 1 : 0;
3326
                        mask = mask_data[(bit + mask_start_index) >> 5]
3327
                                & (1L << ((bit + mask_start_index) & 0x1f)) ? 1 : 0;
3328
 
3329
                        if ((actual & mask) != (expected & mask))
3330
                        {
3331
                                result = FALSE;
3332
                        }
3333
                }
3334
 
3335
                symbol_record->value = result ? 1L : 0L;
3336
        }
3337
 
3338
        if (tdi_data == NULL) {
3339
          if (temp_array != NULL) jam_free_temp_workspace(temp_array);
3340
        }
3341
 
3342
        return (status);
3343
}
3344
 
3345
/****************************************************************************/
3346
/*                                                                                                                                                      */
3347
 
3348
JAM_RETURN_TYPE jam_process_drscan_capture
3349
(
3350
        char *statement_buffer,
3351
        long count_value,
3352
        long *in_data,
3353
        long in_index
3354
)
3355
 
3356
/*                                                                                                                                                      */
3357
/*      Description:    Processes the arguments for the CAPTURE version of the  */
3358
/*                                      DRSCAN statement.  Calls jam_swap_dr() to access the    */
3359
/*                                      JTAG hardware interface.                                                                */
3360
/*                                                                                                                                                      */
3361
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
3362
/*                                                                                                                                                      */
3363
/****************************************************************************/
3364
{
3365
        /* syntax:  DRSCAN <length> [, <data>] [CAPTURE <array>] ; */
3366
 
3367
        int expr_begin = 0;
3368
        int expr_end = 0;
3369
        int delimiter = 0;
3370
        long start_index = 0L;
3371
        long stop_index = 0L;
3372
        char save_ch = 0;
3373
        long *tdi_data = NULL;
3374
        long *literal_array_data = NULL;
3375
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
3376
        JAMS_HEAP_RECORD *heap_record = NULL;
3377
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
3378
 
3379
        /*
3380
        *       Statement buffer should contain the part of the statement string
3381
        *       after the CAPTURE keyword.
3382
        *
3383
        *       The only argument should be the capture array.
3384
        */
3385
        status = jam_find_argument(statement_buffer,
3386
                &expr_begin, &expr_end, &delimiter);
3387
 
3388
        if ((status == JAMC_SUCCESS) &&
3389
                (statement_buffer[delimiter] != JAMC_SEMICOLON_CHAR))
3390
        {
3391
                status = JAMC_SYNTAX_ERROR;
3392
        }
3393
 
3394
        if (status == JAMC_SUCCESS)
3395
        {
3396
                save_ch = statement_buffer[expr_end];
3397
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
3398
                status = jam_get_array_argument(&statement_buffer[expr_begin],
3399
                        &symbol_record, &literal_array_data,
3400
                        &start_index, &stop_index, 1);
3401
                statement_buffer[expr_end] = save_ch;
3402
        }
3403
 
3404
        if ((status == JAMC_SUCCESS) && (literal_array_data != NULL))
3405
        {
3406
                /* literal array may not be used for capture buffer */
3407
                status = JAMC_SYNTAX_ERROR;
3408
        }
3409
 
3410
        if ((status == JAMC_SUCCESS) &&
3411
                (stop_index != start_index + count_value - 1))
3412
        {
3413
                status = JAMC_BOUNDS_ERROR;
3414
        }
3415
 
3416
        if (status == JAMC_SUCCESS)
3417
        {
3418
                if (symbol_record != NULL)
3419
                {
3420
                        heap_record = (JAMS_HEAP_RECORD *)symbol_record->value;
3421
 
3422
                        if (heap_record != NULL)
3423
                        {
3424
                                tdi_data = heap_record->data;
3425
                        }
3426
                        else
3427
                        {
3428
                                status = JAMC_INTERNAL_ERROR;
3429
                        }
3430
                }
3431
                else
3432
                {
3433
                        status = JAMC_INTERNAL_ERROR;
3434
                }
3435
        }
3436
 
3437
        /*
3438
        *       Perform the JTAG operation, capturing data into the heap buffer
3439
        */
3440
        if (status == JAMC_SUCCESS)
3441
        {
3442
                status = jam_swap_dr(count_value, in_data, in_index,
3443
                        tdi_data, start_index);
3444
        }
3445
 
3446
        return (status);
3447
}
3448
 
3449
/****************************************************************************/
3450
/*                                                                                                                                                      */
3451
 
3452
JAM_RETURN_TYPE jam_process_drscan
3453
(
3454
        char *statement_buffer
3455
)
3456
 
3457
/*                                                                                                                                                      */
3458
/*      Description:    Processes DRSCAN statement, which shifts data through   */
3459
/*                                      a data register of the JTAG interface                                   */
3460
/*                                                                                                                                                      */
3461
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
3462
/*                                                                                                                                                      */
3463
/****************************************************************************/
3464
{
3465
        /* syntax:  DRSCAN <length> [, <data>] [CAPTURE <array>] ; */
3466
        /* or:  DRSCAN <length> [, <data>] [COMPARE <array>, <mask>, <result>] ; */
3467
 
3468
        int index = 0;
3469
        int expr_begin = 0;
3470
        int expr_end = 0;
3471
        int delimiter = 0;
3472
        long count_value = 0L;
3473
        long start_index = 0L;
3474
        long stop_index = 0L;
3475
        char save_ch = 0;
3476
        long *tdi_data = NULL;
3477
        long *literal_array_data = NULL;
3478
        JAME_EXPRESSION_TYPE expr_type = JAM_ILLEGAL_EXPR_TYPE;
3479
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
3480
        JAMS_HEAP_RECORD *heap_record = NULL;
3481
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
3482
 
3483
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
3484
        {
3485
                return (JAMC_PHASE_ERROR);
3486
        }
3487
 
3488
        index = jam_skip_instruction_name(statement_buffer);
3489
 
3490
        /* locate length */
3491
        status = jam_find_argument(&statement_buffer[index],
3492
                &expr_begin, &expr_end, &delimiter);
3493
 
3494
        expr_begin += index;
3495
        expr_end += index;
3496
        delimiter += index;
3497
 
3498
        if ((status == JAMC_SUCCESS) &&
3499
                (statement_buffer[delimiter] != JAMC_COMMA_CHAR))
3500
        {
3501
                status = JAMC_SYNTAX_ERROR;
3502
        }
3503
 
3504
        if (status == JAMC_SUCCESS)
3505
        {
3506
                save_ch = statement_buffer[expr_end];
3507
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
3508
                status = jam_evaluate_expression(
3509
                        &statement_buffer[expr_begin], &count_value, &expr_type);
3510
                statement_buffer[expr_end] = save_ch;
3511
        }
3512
 
3513
        /*
3514
        *       Check for integer expression
3515
        */
3516
        if ((status == JAMC_SUCCESS) &&
3517
                (expr_type != JAM_INTEGER_EXPR) &&
3518
                (expr_type != JAM_INT_OR_BOOL_EXPR))
3519
        {
3520
                status = JAMC_TYPE_MISMATCH;
3521
        }
3522
 
3523
        /*
3524
        *       Look for array variable with sub-range index
3525
        */
3526
        if (status == JAMC_SUCCESS)
3527
        {
3528
                index = delimiter + 1;
3529
                status = jam_find_argument(&statement_buffer[index],
3530
                        &expr_begin, &expr_end, &delimiter);
3531
 
3532
                expr_begin += index;
3533
                expr_end += index;
3534
                delimiter += index;
3535
        }
3536
 
3537
        if ((status == JAMC_SUCCESS) &&
3538
                (statement_buffer[delimiter] != JAMC_COMMA_CHAR) &&
3539
                (statement_buffer[delimiter] != JAMC_SEMICOLON_CHAR))
3540
        {
3541
                status = JAMC_SYNTAX_ERROR;
3542
        }
3543
 
3544
        if (status == JAMC_SUCCESS)
3545
        {
3546
                save_ch = statement_buffer[expr_end];
3547
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
3548
                status = jam_get_array_argument(&statement_buffer[expr_begin],
3549
                        &symbol_record, &literal_array_data,
3550
                        &start_index, &stop_index, 0);
3551
                statement_buffer[expr_end] = save_ch;
3552
        }
3553
 
3554
        if ((status == JAMC_SUCCESS) &&
3555
                (literal_array_data != NULL) &&
3556
                (start_index == 0) &&
3557
                (stop_index > count_value - 1))
3558
        {
3559
                stop_index = count_value - 1;
3560
        }
3561
 
3562
        if (status == JAMC_SUCCESS)
3563
        {
3564
                if (symbol_record != NULL)
3565
                {
3566
                        heap_record = (JAMS_HEAP_RECORD *)symbol_record->value;
3567
 
3568
                        if (heap_record != NULL)
3569
                        {
3570
                                tdi_data = heap_record->data;
3571
                        }
3572
                        else
3573
                        {
3574
                                status = JAMC_INTERNAL_ERROR;
3575
                        }
3576
                }
3577
                else if (literal_array_data != NULL)
3578
                {
3579
                        tdi_data = literal_array_data;
3580
                }
3581
                else
3582
                {
3583
                        status = JAMC_INTERNAL_ERROR;
3584
                }
3585
        }
3586
 
3587
        if ((status == JAMC_SUCCESS) &&
3588
                (statement_buffer[delimiter] == JAMC_SEMICOLON_CHAR))
3589
        {
3590
                /*
3591
                *       Do a simple DRSCAN operation -- no capture or compare
3592
                */
3593
                status = jam_do_drscan(count_value, tdi_data, start_index);
3594
        }
3595
        else if ((status == JAMC_SUCCESS) &&
3596
                (statement_buffer[delimiter] == JAMC_COMMA_CHAR))
3597
        {
3598
                /*
3599
                *       Delimiter was a COMMA, so look for CAPTURE or COMPARE keyword
3600
                */
3601
                index = delimiter + 1;
3602
                while (jam_isspace(statement_buffer[index]))
3603
                {
3604
                        ++index;        /* skip over white space */
3605
                }
3606
 
3607
                        /*
3608
                        *       Do a DRSCAN with compare and or capture
3609
                        */
3610
                        status = jam_process_drscan_compare(&statement_buffer[index],
3611
                                count_value, tdi_data, start_index);
3612
        }
3613
        else
3614
                {
3615
                        status = JAMC_SYNTAX_ERROR;
3616
                }
3617
 
3618
        return (status);
3619
}
3620
 
3621
/****************************************************************************/
3622
/*                                                                                                                                                      */
3623
 
3624
JAM_RETURN_TYPE jam_process_drstop(char *statement_buffer)
3625
 
3626
/*                                                                                                                                                      */
3627
/*      Description:    Sets stop-state for DR scan operations                                  */
3628
/*                                                                                                                                                      */
3629
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
3630
/*                                                                                                                                                      */
3631
/****************************************************************************/
3632
{
3633
        int index = 0;
3634
        int expr_begin = 0;
3635
        int expr_end = 0;
3636
        int delimiter = 0;
3637
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
3638
        JAME_JTAG_STATE state = JAM_ILLEGAL_JTAG_STATE;
3639
 
3640
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
3641
        {
3642
                return (JAMC_PHASE_ERROR);
3643
        }
3644
 
3645
        index = jam_skip_instruction_name(statement_buffer);
3646
 
3647
        /*
3648
        *       Get next argument
3649
        */
3650
        status = jam_find_argument(&statement_buffer[index],
3651
                &expr_begin, &expr_end, &delimiter);
3652
 
3653
        expr_begin += index;
3654
        expr_end += index;
3655
        delimiter += index;
3656
 
3657
        if ((status == JAMC_SUCCESS) &&
3658
                (statement_buffer[delimiter] != JAMC_SEMICOLON_CHAR))
3659
        {
3660
                status = JAMC_SYNTAX_ERROR;
3661
        }
3662
 
3663
        if (status == JAMC_SUCCESS)
3664
        {
3665
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
3666
                state = jam_get_jtag_state_from_name(&statement_buffer[expr_begin]);
3667
 
3668
                if (state == JAM_ILLEGAL_JTAG_STATE)
3669
                {
3670
                        status = JAMC_SYNTAX_ERROR;
3671
                }
3672
                else
3673
                {
3674
                        /*
3675
                        *       Set DRSCAN stop state to the specified state
3676
                        */
3677
                        status = jam_set_drstop_state(state);
3678
                }
3679
        }
3680
 
3681
        return (status);
3682
}
3683
 
3684
JAM_RETURN_TYPE jam_process_enddata
3685
(
3686
        char *statement_buffer
3687
)
3688
{
3689
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
3690
 
3691
        if (jam_version == 0) jam_version = 2;
3692
 
3693
        if (jam_version == 1) status = JAMC_SYNTAX_ERROR;
3694
 
3695
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
3696
        {
3697
                status = JAMC_PHASE_ERROR;
3698
        }
3699
 
3700
        statement_buffer = statement_buffer;
3701
 
3702
        return (status);
3703
}
3704
 
3705
/****************************************************************************/
3706
/*                                                                                                                                                      */
3707
 
3708
JAM_RETURN_TYPE jam_process_exit
3709
(
3710
        char *statement_buffer,
3711
        BOOL *done,
3712
        int *exit_code
3713
)
3714
 
3715
/*                                                                                                                                                      */
3716
/*      Description:    This function terminates an JAM program.  The 'done'    */
3717
/*                                      flag is set, halting program execution, and the                 */
3718
/*                                      exit_code value is set as specified in the statement.   */
3719
/*                                                                                                                                                      */
3720
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
3721
/*                                                                                                                                                      */
3722
/****************************************************************************/
3723
{
3724
        int index = 0;
3725
        int expr_begin = 0;
3726
        int expr_end = 0;
3727
        char save_ch = 0;
3728
        long exit_code_value = 0L;
3729
        JAME_EXPRESSION_TYPE expr_type = JAM_ILLEGAL_EXPR_TYPE;
3730
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
3731
 
3732
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
3733
        {
3734
                return (JAMC_PHASE_ERROR);
3735
        }
3736
 
3737
        index = jam_skip_instruction_name(statement_buffer);
3738
 
3739
        /*
3740
        *       Evaluate expression for exit code value
3741
        */
3742
        expr_begin = index;
3743
        while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
3744
                (index < JAMC_MAX_STATEMENT_LENGTH))
3745
        {
3746
                ++index;
3747
        }
3748
        while ((statement_buffer[index] != JAMC_SEMICOLON_CHAR) && (index > 0))
3749
        {
3750
                --index;
3751
        }
3752
        expr_end = index;
3753
 
3754
        if (expr_end > expr_begin)
3755
        {
3756
                save_ch = statement_buffer[expr_end];
3757
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
3758
                status = jam_evaluate_expression(
3759
                        &statement_buffer[expr_begin], &exit_code_value, &expr_type);
3760
                statement_buffer[expr_end] = save_ch;
3761
        }
3762
 
3763
        /*
3764
        *       Check for integer expression
3765
        */
3766
        if ((status == JAMC_SUCCESS) &&
3767
                (expr_type != JAM_INTEGER_EXPR) &&
3768
                (expr_type != JAM_INT_OR_BOOL_EXPR))
3769
        {
3770
                status = JAMC_TYPE_MISMATCH;
3771
        }
3772
 
3773
        /*
3774
        *       Check range of exit code -- must be in range of signed 16-bit number
3775
        *       (from -32767 to 32767) for compatibility with 16-bit systems.
3776
        */
3777
        if (((status == JAMC_SUCCESS) &&
3778
                ((exit_code_value < -32767L))) || (exit_code_value > 32767L))
3779
        {
3780
                status = JAMC_INTEGER_OVERFLOW;
3781
        }
3782
 
3783
        if (status == JAMC_SUCCESS)
3784
        {
3785
                /*
3786
                *       Terminate the program
3787
                */
3788
                *done = TRUE;
3789
                *exit_code = (int) exit_code_value;
3790
        }
3791
 
3792
        return (status);
3793
}
3794
 
3795
/****************************************************************************/
3796
/*                                                                                                                                                      */
3797
 
3798
JAM_RETURN_TYPE jam_process_export
3799
(
3800
        char *statement_buffer
3801
)
3802
 
3803
/*                                                                                                                                                      */
3804
/*      Description:    Exports data outside the JAM interpreter (to the                */
3805
/*                                      calling program)                                                                                */
3806
/*                                                                                                                                                      */
3807
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
3808
/*                                                                                                                                                      */
3809
/****************************************************************************/
3810
{
3811
        int index = 0;
3812
        int key_begin = 0;
3813
        int key_end = 0;
3814
        int expr_begin = 0;
3815
        int expr_end = 0;
3816
        long value = 0L;
3817
        JAME_EXPRESSION_TYPE expr_type = JAM_ILLEGAL_EXPR_TYPE;
3818
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
3819
 
3820
        /* boolean array variables */
3821
        char ba_save_ch = 0;
3822
        int ba_expr_begin = 0;
3823
        int ba_expr_end = 0;
3824
        long ba_start_index = 0L;
3825
        long ba_stop_index = 0L;
3826
        long *ba_literal_array_data = NULL;
3827
        JAMS_SYMBOL_RECORD *ba_symbol_record = NULL;
3828
        JAMS_HEAP_RECORD *ba_heap_record = NULL;
3829
        unsigned char* ba_source_heap_data = NULL;
3830
        /* end of boolean array variables */
3831
 
3832
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
3833
        {
3834
                return (JAMC_PHASE_ERROR);
3835
        }
3836
 
3837
        index = jam_skip_instruction_name(statement_buffer);
3838
 
3839
        /*
3840
        *       Find key string
3841
        */
3842
        key_begin = index;
3843
        while (jam_isspace(statement_buffer[index]) &&
3844
                (index < JAMC_MAX_STATEMENT_LENGTH))
3845
        {
3846
                ++index;
3847
        }
3848
 
3849
        /* the first argument must be a quoted string */
3850
        if (statement_buffer[index] == JAMC_QUOTE_CHAR)
3851
        {
3852
                ++index;        /* step over quote char */
3853
                key_begin = index;
3854
 
3855
                /* find matching quote */
3856
                while ((statement_buffer[index] != JAMC_QUOTE_CHAR) &&
3857
                        (statement_buffer[index] != JAMC_NULL_CHAR) &&
3858
                        (index < JAMC_MAX_STATEMENT_LENGTH))
3859
                {
3860
                        ++index;
3861
                }
3862
 
3863
                if (statement_buffer[index] == JAMC_QUOTE_CHAR)
3864
                {
3865
                        key_end = index;
3866
                        ++index;        /* step over quote char */
3867
 
3868
                        while (jam_isspace(statement_buffer[index]) &&
3869
                                (index < JAMC_MAX_STATEMENT_LENGTH))
3870
                        {
3871
                                ++index;
3872
                        }
3873
 
3874
                        if (statement_buffer[index] == JAMC_COMMA_CHAR)
3875
                        {
3876
                                ++index;        /* step over comma */
3877
                                expr_begin = index;
3878
 
3879
                                /* check if it is a boolean array */
3880
                                while (jam_isspace(statement_buffer[index]) &&
3881
                                        (index < JAMC_MAX_STATEMENT_LENGTH))
3882
                                {
3883
                                        ++index;
3884
                                }
3885
                                ba_expr_begin = index;
3886
                                if (jam_is_name_char(statement_buffer[index]) &&
3887
                                        (index < JAMC_MAX_STATEMENT_LENGTH))
3888
                                {
3889
                                        ++index;
3890
                                        while (jam_is_name_char(statement_buffer[index]) &&
3891
                                                (index < JAMC_MAX_STATEMENT_LENGTH))
3892
                                        {
3893
                                                ++index;
3894
                                        }
3895
                                        while (jam_isspace(statement_buffer[index]) &&
3896
                                                (index < JAMC_MAX_STATEMENT_LENGTH))
3897
                                        {
3898
                                                ++index;
3899
                                        }
3900
                                        if (statement_buffer[index] == JAMC_LBRACKET_CHAR)
3901
                                        {
3902
                                                while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
3903
                                                        (index < JAMC_MAX_STATEMENT_LENGTH))
3904
                                                {
3905
                                                        ++index;
3906
                                                }
3907
                                                while ((statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
3908
                                                        (index > 0))
3909
                                                {
3910
                                                        --index;
3911
                                                }
3912
                                                ba_expr_end = index;
3913
                                                ba_save_ch = statement_buffer[ba_expr_end];
3914
                                                statement_buffer[ba_expr_end] = JAMC_NULL_CHAR;
3915
                                                status = jam_get_array_argument(
3916
                                                        &statement_buffer[ba_expr_begin],
3917
                                                        &ba_symbol_record,
3918
                                                        &ba_literal_array_data,
3919
                                                        &ba_start_index,
3920
                                                        &ba_stop_index, 0);
3921
                                                statement_buffer[ba_expr_end] = ba_save_ch;
3922
 
3923
                                                if (status == JAMC_SUCCESS)
3924
                                                {
3925
                                                        if (ba_symbol_record != NULL)
3926
                                                        {
3927
                                                                if ((ba_symbol_record->type ==
3928
                                                                        JAM_BOOLEAN_ARRAY_WRITABLE) ||
3929
                                                                        (ba_symbol_record->type ==
3930
                                                                        JAM_BOOLEAN_ARRAY_INITIALIZED))
3931
                                                                {
3932
                                                                        ba_heap_record = (JAMS_HEAP_RECORD *)
3933
                                                                                ba_symbol_record->value;
3934
                                                                        if ((ba_start_index < 0L) ||
3935
                                                                                (ba_start_index >= ba_heap_record->dimension) ||
3936
                                                                                (ba_stop_index < 0L) ||
3937
                                                                                (ba_stop_index >= ba_heap_record->dimension))
3938
                                                                        {
3939
                                                                                return JAMC_BOUNDS_ERROR;
3940
                                                                        }
3941
                                                                        ba_source_heap_data = (unsigned char*)ba_heap_record->data;
3942
                                                                        statement_buffer[key_end] = JAMC_NULL_CHAR;
3943
                                                                        jam_export_boolean_array(&statement_buffer[key_begin],
3944
                                                                                &ba_source_heap_data[ba_start_index], ba_stop_index - ba_start_index + 1L);
3945
                                                                        return JAMC_SUCCESS;
3946
                                                                }
3947
                                                                else
3948
                                                                        return JAMC_TYPE_MISMATCH;
3949
                                                        }
3950
                                                        else
3951
                                                        {
3952
                                                                return JAMC_INTERNAL_ERROR;
3953
                                                        }
3954
                                                }
3955
                                                else
3956
                                                {
3957
                                                        return status;
3958
                                                }
3959
                                        }
3960
                                }
3961
                                /* end of boolean array check */
3962
 
3963
                                index = expr_begin;
3964
                                while ((statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
3965
                                        (statement_buffer[index] != JAMC_NULL_CHAR) &&
3966
                                        (index < JAMC_MAX_STATEMENT_LENGTH))
3967
                                {
3968
                                        ++index;
3969
                                }
3970
 
3971
                                if (statement_buffer[index] == JAMC_SEMICOLON_CHAR)
3972
                                {
3973
                                        expr_end = index;
3974
                                        statement_buffer[expr_end] = JAMC_NULL_CHAR;
3975
                                        status = jam_evaluate_expression(
3976
                                                &statement_buffer[expr_begin], &value, &expr_type);
3977
 
3978
                                        /*
3979
                                        *       May be integer or Boolean expression
3980
                                        */
3981
                                        if ((status == JAMC_SUCCESS) &&
3982
                                                (expr_type != JAM_INTEGER_EXPR) &&
3983
                                                (expr_type != JAM_BOOLEAN_EXPR) &&
3984
                                                (expr_type != JAM_INT_OR_BOOL_EXPR))
3985
                                        {
3986
                                                status = JAMC_TYPE_MISMATCH;
3987
                                        }
3988
 
3989
                                        if (status == JAMC_SUCCESS)
3990
                                        {
3991
                                                /*
3992
                                                *       Export the key and value
3993
                                                */
3994
                                                statement_buffer[key_end] = JAMC_NULL_CHAR;
3995
                                                jam_export_integer(&statement_buffer[key_begin], value);
3996
                                        }
3997
                                }
3998
                        }
3999
                }
4000
        }
4001
 
4002
        return (status);
4003
}
4004
 
4005
/****************************************************************************/
4006
/*                                                                                                                                                      */
4007
 
4008
JAM_RETURN_TYPE jam_process_for
4009
(
4010
        char *statement_buffer
4011
)
4012
 
4013
/*                                                                                                                                                      */
4014
/*      Description:    This function processes a FOR statement.  It creates a  */
4015
/*                                      stack record and assigns the start value to the                 */
4016
/*                                      iterator variable                                                                               */
4017
/*                                                                                                                                                      */
4018
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
4019
/*                                                                                                                                                      */
4020
/****************************************************************************/
4021
{
4022
        int index = 0;
4023
        int variable_begin = 0;
4024
        int variable_end = 0;
4025
        int expr_begin = 0;
4026
        int expr_end = 0;
4027
        long start_value = 0L;
4028
        long stop_value = 0L;
4029
        long step_value = 1L;
4030
        char save_ch = 0;
4031
        JAME_EXPRESSION_TYPE expr_type = JAM_ILLEGAL_EXPR_TYPE;
4032
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
4033
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
4034
 
4035
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
4036
        {
4037
                return (JAMC_PHASE_ERROR);
4038
        }
4039
 
4040
        index = jam_skip_instruction_name(statement_buffer);
4041
 
4042
        if (jam_isalpha(statement_buffer[index]))
4043
        {
4044
                /* locate variable name */
4045
                variable_begin = index;
4046
                while ((jam_is_name_char(statement_buffer[index])) &&
4047
                        (index < JAMC_MAX_STATEMENT_LENGTH))
4048
                {
4049
                        ++index;        /* skip over variable name */
4050
                }
4051
                variable_end = index;
4052
 
4053
                while ((jam_isspace(statement_buffer[index])) &&
4054
                        (index < JAMC_MAX_STATEMENT_LENGTH))
4055
                {
4056
                        ++index;        /* skip over white space */
4057
                }
4058
 
4059
                if (statement_buffer[index] == JAMC_EQUAL_CHAR)
4060
                {
4061
                        /*
4062
                        *       Get start value for loop
4063
                        */
4064
                        expr_begin = index + 1;
4065
 
4066
                        expr_end = jam_find_keyword(&statement_buffer[expr_begin], "TO");
4067
 
4068
                        if (expr_end > 0)
4069
                        {
4070
                                expr_end += expr_begin;
4071
                                save_ch = statement_buffer[expr_end];
4072
                                statement_buffer[expr_end] = JAMC_NULL_CHAR;
4073
                                status = jam_evaluate_expression(
4074
                                        &statement_buffer[expr_begin], &start_value, &expr_type);
4075
                                statement_buffer[expr_end] = save_ch;
4076
                                index = expr_end + 2;   /* step over "TO" */
4077
                        }
4078
 
4079
                        /*
4080
                        *       Check for integer expression
4081
                        */
4082
                        if ((status == JAMC_SUCCESS) &&
4083
                                (expr_type != JAM_INTEGER_EXPR) &&
4084
                                (expr_type != JAM_INT_OR_BOOL_EXPR))
4085
                        {
4086
                                status = JAMC_TYPE_MISMATCH;
4087
                        }
4088
 
4089
                        if (status == JAMC_SUCCESS)
4090
                        {
4091
                                /*
4092
                                *       Get stop value for loop
4093
                                */
4094
                                while ((jam_isspace(statement_buffer[index])) &&
4095
                                        (index < JAMC_MAX_STATEMENT_LENGTH))
4096
                                {
4097
                                        ++index;        /* skip over white space */
4098
                                }
4099
 
4100
                                expr_begin = index;
4101
 
4102
                                expr_end = jam_find_keyword(&statement_buffer[expr_begin],
4103
                                        "STEP");
4104
 
4105
                                status = JAMC_SYNTAX_ERROR;
4106
                                if (expr_end > 0)
4107
                                {
4108
                                        /* STEP found */
4109
                                        expr_end += expr_begin;
4110
                                        save_ch = statement_buffer[expr_end];
4111
                                        statement_buffer[expr_end] = JAMC_NULL_CHAR;
4112
                                        status = jam_evaluate_expression(
4113
                                                &statement_buffer[expr_begin], &stop_value, &expr_type);
4114
                                        statement_buffer[expr_end] = save_ch;
4115
                                        index = expr_end + 4;   /* step over "STEP" */
4116
 
4117
                                        /*
4118
                                        *       Check for integer expression
4119
                                        */
4120
                                        if ((status == JAMC_SUCCESS) &&
4121
                                                (expr_type != JAM_INTEGER_EXPR) &&
4122
                                                (expr_type != JAM_INT_OR_BOOL_EXPR))
4123
                                        {
4124
                                                status = JAMC_TYPE_MISMATCH;
4125
                                        }
4126
 
4127
                                        if (status == JAMC_SUCCESS)
4128
                                        {
4129
                                                /*
4130
                                                *       Get step value
4131
                                                */
4132
                                                while ((jam_isspace(statement_buffer[index])) &&
4133
                                                        (index < JAMC_MAX_STATEMENT_LENGTH))
4134
                                                {
4135
                                                        ++index;        /* skip over white space */
4136
                                                }
4137
 
4138
                                                expr_begin = index;
4139
                                                expr_end = 0;
4140
                                                while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
4141
                                                        (statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
4142
                                                        (index < JAMC_MAX_STATEMENT_LENGTH))
4143
                                                {
4144
                                                        ++index;
4145
                                                }
4146
 
4147
                                                if ((statement_buffer[index] == JAMC_SEMICOLON_CHAR))
4148
                                                {
4149
                                                        expr_end = index;
4150
                                                }
4151
 
4152
                                                status = JAMC_SYNTAX_ERROR;
4153
                                                if (expr_end > expr_begin)
4154
                                                {
4155
                                                        save_ch = statement_buffer[expr_end];
4156
                                                        statement_buffer[expr_end] = JAMC_NULL_CHAR;
4157
                                                        status = jam_evaluate_expression(
4158
                                                                &statement_buffer[expr_begin],
4159
                                                                &step_value, &expr_type);
4160
                                                        statement_buffer[expr_end] = save_ch;
4161
                                                }
4162
 
4163
                                                /* step value zero is illegal */
4164
                                                if ((status == JAMC_SUCCESS) && (step_value == 0))
4165
                                                {
4166
                                                        status = JAMC_SYNTAX_ERROR;
4167
                                                }
4168
 
4169
                                                /*
4170
                                                *       Check for integer expression
4171
                                                */
4172
                                                if ((status == JAMC_SUCCESS) &&
4173
                                                        (expr_type != JAM_INTEGER_EXPR) &&
4174
                                                        (expr_type != JAM_INT_OR_BOOL_EXPR))
4175
                                                {
4176
                                                        status = JAMC_TYPE_MISMATCH;
4177
                                                }
4178
                                        }
4179
                                }
4180
                                else
4181
                                {
4182
                                        /* STEP not found -- look for semicolon */
4183
                                        while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
4184
                                                (statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
4185
                                                (index < JAMC_MAX_STATEMENT_LENGTH))
4186
                                        {
4187
                                                ++index;
4188
                                        }
4189
 
4190
                                        if (statement_buffer[index] == JAMC_SEMICOLON_CHAR)
4191
                                        {
4192
                                                expr_end = index;
4193
                                        }
4194
 
4195
                                        /*
4196
                                        *       Get stop value for loop
4197
                                        */
4198
                                        status = JAMC_SYNTAX_ERROR;
4199
                                        if (expr_end > expr_begin)
4200
                                        {
4201
                                                save_ch = statement_buffer[expr_end];
4202
                                                statement_buffer[expr_end] = JAMC_NULL_CHAR;
4203
                                                status = jam_evaluate_expression(
4204
                                                        &statement_buffer[expr_begin], &stop_value,
4205
                                                        &expr_type);
4206
                                                statement_buffer[expr_end] = save_ch;
4207
                                        }
4208
 
4209
                                        /*
4210
                                        *       Step value defaults to one
4211
                                        */
4212
                                        step_value = 1L;
4213
 
4214
                                        /*
4215
                                        *       Check for integer expression
4216
                                        */
4217
                                        if ((status == JAMC_SUCCESS) &&
4218
                                                (expr_type != JAM_INTEGER_EXPR) &&
4219
                                                (expr_type != JAM_INT_OR_BOOL_EXPR))
4220
                                        {
4221
                                                status = JAMC_TYPE_MISMATCH;
4222
                                        }
4223
                                }
4224
                        }
4225
                }
4226
        }
4227
 
4228
        /*
4229
        *       We have extracted the variable name and the start, stop, and
4230
        *       step values from the statement buffer.  Now set the variable
4231
        *       to the start value and push a stack record onto the stack.
4232
        */
4233
        if (status == JAMC_SUCCESS)
4234
        {
4235
                /*
4236
                *       Find the variable (must be an integer)
4237
                */
4238
                status = JAMC_SYNTAX_ERROR;
4239
                save_ch = statement_buffer[variable_end];
4240
                statement_buffer[variable_end] = JAMC_NULL_CHAR;
4241
                status = jam_get_symbol_record(&statement_buffer[variable_begin],
4242
                        &symbol_record);
4243
 
4244
                if ((status == JAMC_SUCCESS) &&
4245
                        (symbol_record->type != JAM_INTEGER_SYMBOL))
4246
                {
4247
                        status = JAMC_TYPE_MISMATCH;
4248
                }
4249
 
4250
                if (status == JAMC_SUCCESS)
4251
                {
4252
                        /*
4253
                        *       Set the variable to the start value
4254
                        */
4255
                        status = jam_set_symbol_value(
4256
                                JAM_INTEGER_SYMBOL,
4257
                                &statement_buffer[variable_begin],
4258
                                start_value);
4259
                }
4260
                statement_buffer[variable_end] = save_ch;
4261
        }
4262
 
4263
        if (status == JAMC_SUCCESS)
4264
        {
4265
                /*
4266
                *       Push a record onto the stack
4267
                */
4268
                status = jam_push_fornext_record(symbol_record,
4269
                        jam_next_statement_position, stop_value, step_value);
4270
        }
4271
 
4272
        return (status);
4273
}
4274
 
4275
/****************************************************************************/
4276
/*                                                                                                                                                      */
4277
 
4278
JAM_RETURN_TYPE jam_process_frequency
4279
(
4280
        char *statement_buffer
4281
)
4282
 
4283
/*                                                                                                                                                      */
4284
/*      Description:    This function processes a FREQUENCY statement.  If the  */
4285
/*                                      specified frequency (in cycles per second) is less than */
4286
/*                                      the expected frequency of an ISA parallel port about    */
4287
/*                                      (200 KHz) then delays will be added to each clock cycle.*/
4288
/*                                                                                                                                                      */
4289
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
4290
/*                                                                                                                                                      */
4291
/****************************************************************************/
4292
{
4293
        int index = 0;
4294
        int ret = 0;
4295
        int expr_begin = 0;
4296
        int expr_end = 0;
4297
        long expr_value = 0L;
4298
        char save_ch = 0;
4299
        JAME_EXPRESSION_TYPE expr_type = JAM_ILLEGAL_EXPR_TYPE;
4300
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
4301
 
4302
        if (jam_version == 0) jam_version = 2;
4303
 
4304
        if (jam_version != 2) status = JAMC_SYNTAX_ERROR;
4305
 
4306
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
4307
        {
4308
                status = JAMC_PHASE_ERROR;
4309
        }
4310
 
4311
        if (status == JAMC_SUCCESS)
4312
        {
4313
                index = jam_skip_instruction_name(statement_buffer);
4314
 
4315
                while (jam_isspace(statement_buffer[index]) &&
4316
                        (index < JAMC_MAX_STATEMENT_LENGTH))
4317
                {
4318
                        ++index;
4319
                }
4320
 
4321
                expr_begin = index;
4322
 
4323
                while ((statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
4324
                        (index < JAMC_MAX_STATEMENT_LENGTH))
4325
                {
4326
                        ++index;
4327
                }
4328
 
4329
                expr_end = index;
4330
 
4331
                if (statement_buffer[index] == JAMC_SEMICOLON_CHAR)
4332
                {
4333
                        if (expr_end > expr_begin)
4334
                        {
4335
                                save_ch = statement_buffer[expr_end];
4336
                                statement_buffer[expr_end] = JAMC_NULL_CHAR;
4337
                                status = jam_evaluate_expression(
4338
                                        &statement_buffer[expr_begin], &expr_value, &expr_type);
4339
                                statement_buffer[expr_end] = save_ch;
4340
 
4341
                                if (status == JAMC_SUCCESS)
4342
                                {
4343
                                        ret = jam_set_frequency(expr_value);
4344
                                }
4345
                        }
4346
                        else
4347
                        {
4348
                                ret = jam_set_frequency(-1L);   /* set default frequency */
4349
                        }
4350
                }
4351
                else
4352
                {
4353
                        /* semicolon not found */
4354
                        status = JAMC_SYNTAX_ERROR;
4355
                }
4356
 
4357
                if ((status == JAMC_SUCCESS) && (ret != 0))
4358
                {
4359
                        /* return code from jam_set_frequency() indicates an error */
4360
                        status = JAMC_BOUNDS_ERROR;
4361
                }
4362
        }
4363
 
4364
        return (status);
4365
}
4366
 
4367
/****************************************************************************/
4368
/*                                                                                                                                                      */
4369
 
4370
JAM_RETURN_TYPE jam_process_if
4371
(
4372
        char *statement_buffer,
4373
        BOOL *reuse_statement_buffer
4374
)
4375
 
4376
/*                                                                                                                                                      */
4377
/*      Description:    Processes an IF (conditional) statement.  If the                */
4378
/*                                      condition is true, then the input stream pointer is             */
4379
/*                                      set to the position of the statement to be executed             */
4380
/*                                      (whatever follows the THEN keyword) which will be               */
4381
/*                                      fetched normally and processed as the next statement.   */
4382
/*                                                                                                                                                      */
4383
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
4384
/*                                                                                                                                                      */
4385
/****************************************************************************/
4386
{
4387
        int index = 0;
4388
        int expr_begin = 0;
4389
        int expr_end = 0;
4390
        long conditional_value = 0L;
4391
        int then_index = 0L;
4392
        char save_ch = 0;
4393
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
4394
        JAME_EXPRESSION_TYPE expr_type = JAM_ILLEGAL_EXPR_TYPE;
4395
 
4396
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
4397
        {
4398
                return (JAMC_PHASE_ERROR);
4399
        }
4400
 
4401
        index = jam_skip_instruction_name(statement_buffer);
4402
 
4403
        /*
4404
        *       Evaluate conditional expression
4405
        */
4406
        expr_begin = index;
4407
        then_index = jam_find_keyword(&statement_buffer[expr_begin], "THEN");
4408
 
4409
        if (then_index > 0)
4410
        {
4411
                expr_end = expr_begin + then_index;
4412
 
4413
                if (expr_end > expr_begin)
4414
                {
4415
                        save_ch = statement_buffer[expr_end];
4416
                        statement_buffer[expr_end] = JAMC_NULL_CHAR;
4417
                        status = jam_evaluate_expression(
4418
                                &statement_buffer[expr_begin], &conditional_value, &expr_type);
4419
                        statement_buffer[expr_end] = save_ch;
4420
                }
4421
 
4422
                /*
4423
                *       Check for Boolean expression
4424
                */
4425
                if ((status == JAMC_SUCCESS) &&
4426
                        (expr_type != JAM_BOOLEAN_EXPR) &&
4427
                        (expr_type != JAM_INT_OR_BOOL_EXPR))
4428
                {
4429
                        status = JAMC_TYPE_MISMATCH;
4430
                }
4431
 
4432
                if (status == JAMC_SUCCESS)
4433
                {
4434
                        if (conditional_value)
4435
                        {
4436
                                index = expr_end + 4;
4437
                                while ((jam_isspace(statement_buffer[index])) &&
4438
                                        (index < JAMC_MAX_STATEMENT_LENGTH))
4439
                                {
4440
                                        ++index;        /* skip over white space */
4441
                                }
4442
 
4443
                                /*
4444
                                *       Copy whatever appears after "THEN" to beginning of buffer
4445
                                *       so it can be reused.
4446
                                */
4447
                                jam_strcpy(statement_buffer, &statement_buffer[index]);
4448
                                *reuse_statement_buffer = TRUE;
4449
                        }
4450
                        /*
4451
                        *       (else do nothing if conditional value is false)
4452
                        */
4453
                }
4454
        }
4455
 
4456
        return (status);
4457
}
4458
 
4459
/****************************************************************************/
4460
/*                                                                                                                                                      */
4461
 
4462
JAM_RETURN_TYPE jam_process_integer
4463
(
4464
        char *statement_buffer
4465
)
4466
 
4467
/*                                                                                                                                                      */
4468
/*      Description:    Processes a INTEGER variable declaration statement              */
4469
/*                                                                                                                                                      */
4470
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
4471
/*                                                                                                                                                      */
4472
/****************************************************************************/
4473
{
4474
        int index = 0;
4475
        int variable_begin = 0;
4476
        int variable_end = 0;
4477
        int dim_begin = 0;
4478
        int dim_end = 0;
4479
        int expr_begin = 0;
4480
        int expr_end = 0;
4481
        long dim_value = 0L;
4482
        long init_value = 0L;
4483
        char save_ch = 0;
4484
        JAME_EXPRESSION_TYPE expr_type = JAM_ILLEGAL_EXPR_TYPE;
4485
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
4486
        JAMS_HEAP_RECORD *heap_record = NULL;
4487
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
4488
 
4489
        if ((jam_version == 2) &&
4490
                (jam_phase != JAM_PROCEDURE_PHASE) &&
4491
                (jam_phase != JAM_DATA_PHASE))
4492
        {
4493
                return (JAMC_PHASE_ERROR);
4494
        }
4495
 
4496
        index = jam_skip_instruction_name(statement_buffer);
4497
 
4498
        if (jam_isalpha(statement_buffer[index]))
4499
        {
4500
                /* locate variable name */
4501
                variable_begin = index;
4502
                while ((jam_is_name_char(statement_buffer[index])) &&
4503
                        (index < JAMC_MAX_STATEMENT_LENGTH))
4504
                {
4505
                        ++index;        /* skip over variable name */
4506
                }
4507
                variable_end = index;
4508
 
4509
                while ((jam_isspace(statement_buffer[index])) &&
4510
                        (index < JAMC_MAX_STATEMENT_LENGTH))
4511
                {
4512
                        ++index;        /* skip over white space */
4513
                }
4514
 
4515
                if (statement_buffer[index] == JAMC_LBRACKET_CHAR)
4516
                {
4517
                        /*
4518
                        *       Array declaration
4519
                        */
4520
                        dim_begin = index + 1;
4521
                        while ((statement_buffer[index] != JAMC_RBRACKET_CHAR) &&
4522
                                (index < JAMC_MAX_STATEMENT_LENGTH))
4523
                        {
4524
                                ++index;        /* find matching bracket */
4525
                        }
4526
                        if (statement_buffer[index] == JAMC_RBRACKET_CHAR)
4527
                        {
4528
                                dim_end = index;
4529
                                ++index;
4530
                        }
4531
                        while ((jam_isspace(statement_buffer[index])) &&
4532
                                (index < JAMC_MAX_STATEMENT_LENGTH))
4533
                        {
4534
                                ++index;        /* skip over white space */
4535
                        }
4536
 
4537
                        if (dim_end > dim_begin)
4538
                        {
4539
                                save_ch = statement_buffer[dim_end];
4540
                                statement_buffer[dim_end] = JAMC_NULL_CHAR;
4541
                                status = jam_evaluate_expression(
4542
                                        &statement_buffer[dim_begin], &dim_value, &expr_type);
4543
                                statement_buffer[dim_end] = save_ch;
4544
                        }
4545
 
4546
                        /*
4547
                        *       Check for integer expression
4548
                        */
4549
                        if ((status == JAMC_SUCCESS) &&
4550
                                (expr_type != JAM_INTEGER_EXPR) &&
4551
                                (expr_type != JAM_INT_OR_BOOL_EXPR))
4552
                        {
4553
                                status = JAMC_TYPE_MISMATCH;
4554
                        }
4555
 
4556
                        if (status == JAMC_SUCCESS)
4557
                        {
4558
                                /*
4559
                                *       Add the array name to the symbol table
4560
                                */
4561
                                save_ch = statement_buffer[variable_end];
4562
                                statement_buffer[variable_end] = JAMC_NULL_CHAR;
4563
                                status = jam_add_symbol(JAM_INTEGER_ARRAY_WRITABLE,
4564
                                        &statement_buffer[variable_begin], 0L,
4565
                                        jam_current_statement_position);
4566
 
4567
                                /* get a pointer to the symbol record */
4568
                                if (status == JAMC_SUCCESS)
4569
                                {
4570
                                        status = jam_get_symbol_record(
4571
                                                &statement_buffer[variable_begin], &symbol_record);
4572
                                }
4573
                                statement_buffer[variable_end] = save_ch;
4574
                        }
4575
 
4576
                        if ((status == JAMC_SUCCESS) &&
4577
                                (symbol_record->type == JAM_INTEGER_ARRAY_WRITABLE) &&
4578
                                (symbol_record->value == 0))
4579
                        {
4580
                                if (statement_buffer[index] == JAMC_EQUAL_CHAR)
4581
                                {
4582
                                        /*
4583
                                        *       Array has initialization data:  read it in.
4584
                                        */
4585
                                        status = jam_add_heap_record(symbol_record, &heap_record,
4586
                                                dim_value);
4587
 
4588
                                        if (status == JAMC_SUCCESS)
4589
                                        {
4590
                                                symbol_record->value = (long) heap_record;
4591
 
4592
                                                status = jam_read_integer_array_data(heap_record,
4593
                                                        &statement_buffer[index + 1]);
4594
                                        }
4595
                                }
4596
                                else if (statement_buffer[index] == JAMC_SEMICOLON_CHAR)
4597
                                {
4598
                                        /*
4599
                                        *       Array has no initialization data.
4600
                                        *       Allocate a buffer on the heap:
4601
                                        */
4602
                                        status = jam_add_heap_record(symbol_record, &heap_record,
4603
                                                dim_value);
4604
 
4605
                                        if (status == JAMC_SUCCESS)
4606
                                        {
4607
                                                symbol_record->value = (long) heap_record;
4608
                                        }
4609
                                }
4610
                        }
4611
                        else
4612
                        {
4613
                                /* this should be end of the statement */
4614
                                if (status == JAMC_SUCCESS) status = JAMC_SYNTAX_ERROR;
4615
                        }
4616
                }
4617
                else
4618
                {
4619
                        /*
4620
                        *       Scalar variable declaration
4621
                        */
4622
                        if (statement_buffer[index] == JAMC_SEMICOLON_CHAR)
4623
                        {
4624
                                status = JAMC_SUCCESS;
4625
                        }
4626
                        else if (statement_buffer[index] == JAMC_EQUAL_CHAR)
4627
                        {
4628
                                /*
4629
                                *       Evaluate initialization expression
4630
                                */
4631
                                expr_begin = index + 1;
4632
                                while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
4633
                                        (index < JAMC_MAX_STATEMENT_LENGTH))
4634
                                {
4635
                                        ++index;
4636
                                }
4637
                                while ((statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
4638
                                        (index > 0))
4639
                                {
4640
                                        --index;
4641
                                }
4642
                                expr_end = index;
4643
 
4644
                                if (expr_end > expr_begin)
4645
                                {
4646
                                        save_ch = statement_buffer[expr_end];
4647
                                        statement_buffer[expr_end] = JAMC_NULL_CHAR;
4648
                                        status = jam_evaluate_expression(
4649
                                                &statement_buffer[expr_begin], &init_value, &expr_type);
4650
                                        statement_buffer[expr_end] = save_ch;
4651
                                }
4652
 
4653
                                /*
4654
                                *       Check for integer expression
4655
                                */
4656
                                if ((status == JAMC_SUCCESS) &&
4657
                                        (expr_type != JAM_INTEGER_EXPR) &&
4658
                                        (expr_type != JAM_INT_OR_BOOL_EXPR))
4659
                                {
4660
                                        status = JAMC_TYPE_MISMATCH;
4661
                                }
4662
                        }
4663
 
4664
                        if (status == JAMC_SUCCESS)
4665
                        {
4666
                                /*
4667
                                *       Add the variable name to the symbol table
4668
                                */
4669
                                save_ch = statement_buffer[variable_end];
4670
                                statement_buffer[variable_end] = JAMC_NULL_CHAR;
4671
                                status = jam_add_symbol(JAM_INTEGER_SYMBOL,
4672
                                        &statement_buffer[variable_begin],
4673
                                        init_value, jam_current_statement_position);
4674
                                statement_buffer[variable_end] = save_ch;
4675
                        }
4676
                }
4677
        }
4678
 
4679
        return (status);
4680
}
4681
 
4682
/****************************************************************************/
4683
/*                                                                                                                                                      */
4684
 
4685
JAM_RETURN_TYPE jam_process_irscan_compare
4686
(
4687
        char *statement_buffer,
4688
        long count_value,
4689
        long *in_data,
4690
        long in_index
4691
)
4692
 
4693
/*                                                                                                                                                      */
4694
/*      Description:    Processes the arguments for the COMPARE version of the  */
4695
/*                                      IRSCAN statement.  Calls jam_swap_ir() to access the    */
4696
/*                                      JTAG hardware interface.                                                                */
4697
/*                                                                                                                                                      */
4698
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
4699
/*                                                                                                                                                      */
4700
/****************************************************************************/
4701
{
4702
 
4703
/* syntax: IRSCAN <length> [, <data>] [COMPARE <array>, <mask>, <result>] ; */
4704
 
4705
        int bit = 0;
4706
        int index = 0;
4707
        int expr_begin = 0;
4708
        int expr_end = 0;
4709
        int delimiter = 0;
4710
        int actual = 0;
4711
        int expected = 0;
4712
        int mask = 0;
4713
        long comp_start_index = 0L;
4714
        long comp_stop_index = 0L;
4715
        long mask_start_index = 0L;
4716
        long mask_stop_index = 0L;
4717
        char save_ch = 0;
4718
        long *temp_array = NULL;
4719
        BOOL result = TRUE;
4720
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
4721
        JAMS_HEAP_RECORD *heap_record = NULL;
4722
        long *comp_data = NULL;
4723
        long *mask_data = NULL;
4724
        long *literal_array_data = NULL;
4725
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
4726
 
4727
        /*
4728
        *       Statement buffer should contain the part of the statement string
4729
        *       after the COMPARE keyword.
4730
        *
4731
        *       The first argument should be the compare array.
4732
        */
4733
        status = jam_find_argument(statement_buffer,
4734
                &expr_begin, &expr_end, &delimiter);
4735
 
4736
        if ((status == JAMC_SUCCESS) &&
4737
                (statement_buffer[delimiter] != JAMC_COMMA_CHAR))
4738
        {
4739
                status = JAMC_SYNTAX_ERROR;
4740
        }
4741
 
4742
        if (status == JAMC_SUCCESS)
4743
        {
4744
                save_ch = statement_buffer[expr_end];
4745
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
4746
                status = jam_get_array_argument(&statement_buffer[expr_begin],
4747
                        &symbol_record, &literal_array_data,
4748
                        &comp_start_index, &comp_stop_index, 1);
4749
                statement_buffer[expr_end] = save_ch;
4750
                index = delimiter + 1;
4751
        }
4752
 
4753
        if ((status == JAMC_SUCCESS) &&
4754
                (literal_array_data != NULL) &&
4755
                (comp_start_index == 0) &&
4756
                (comp_stop_index > count_value - 1))
4757
        {
4758
                comp_stop_index = count_value - 1;
4759
        }
4760
 
4761
        if ((status == JAMC_SUCCESS) &&
4762
                (comp_stop_index != comp_start_index + count_value - 1))
4763
        {
4764
                status = JAMC_BOUNDS_ERROR;
4765
        }
4766
 
4767
        if (status == JAMC_SUCCESS)
4768
        {
4769
                if (symbol_record != NULL)
4770
                {
4771
                        heap_record = (JAMS_HEAP_RECORD *)symbol_record->value;
4772
 
4773
                        if (heap_record != NULL)
4774
                        {
4775
                                comp_data = heap_record->data;
4776
                        }
4777
                        else
4778
                        {
4779
                                status = JAMC_INTERNAL_ERROR;
4780
                        }
4781
                }
4782
                else if (literal_array_data != NULL)
4783
                {
4784
                        comp_data = literal_array_data;
4785
                }
4786
                else
4787
                {
4788
                        status = JAMC_INTERNAL_ERROR;
4789
                }
4790
        }
4791
 
4792
        /*
4793
        *       Find the next argument -- should be the mask array
4794
        */
4795
        if (status == JAMC_SUCCESS)
4796
        {
4797
                status = jam_find_argument(&statement_buffer[index],
4798
                        &expr_begin, &expr_end, &delimiter);
4799
 
4800
                expr_begin += index;
4801
                expr_end += index;
4802
                delimiter += index;
4803
        }
4804
 
4805
        if ((status == JAMC_SUCCESS) &&
4806
                (statement_buffer[delimiter] != JAMC_COMMA_CHAR))
4807
        {
4808
                status = JAMC_SYNTAX_ERROR;
4809
        }
4810
 
4811
        if (status == JAMC_SUCCESS)
4812
        {
4813
                save_ch = statement_buffer[expr_end];
4814
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
4815
                status = jam_get_array_argument(&statement_buffer[expr_begin],
4816
                        &symbol_record, &literal_array_data,
4817
                        &mask_start_index, &mask_stop_index, 2);
4818
                statement_buffer[expr_end] = save_ch;
4819
                index = delimiter + 1;
4820
        }
4821
 
4822
        if ((status == JAMC_SUCCESS) &&
4823
                (literal_array_data != NULL) &&
4824
                (mask_start_index == 0) &&
4825
                (mask_stop_index > count_value - 1))
4826
        {
4827
                mask_stop_index = count_value - 1;
4828
        }
4829
 
4830
        if ((status == JAMC_SUCCESS) &&
4831
                (mask_stop_index != mask_start_index + count_value - 1))
4832
        {
4833
                status = JAMC_BOUNDS_ERROR;
4834
        }
4835
 
4836
        if (status == JAMC_SUCCESS)
4837
        {
4838
                if (symbol_record != NULL)
4839
                {
4840
                        heap_record = (JAMS_HEAP_RECORD *)symbol_record->value;
4841
 
4842
                        if (heap_record != NULL)
4843
                        {
4844
                                mask_data = heap_record->data;
4845
                        }
4846
                        else
4847
                        {
4848
                                status = JAMC_INTERNAL_ERROR;
4849
                        }
4850
                }
4851
                else if (literal_array_data != NULL)
4852
                {
4853
                        mask_data = literal_array_data;
4854
                }
4855
                else
4856
                {
4857
                        status = JAMC_INTERNAL_ERROR;
4858
                }
4859
        }
4860
 
4861
        /*
4862
        *       Find the third argument -- should be the result variable
4863
        */
4864
        if (status == JAMC_SUCCESS)
4865
        {
4866
                status = jam_find_argument(&statement_buffer[index],
4867
                        &expr_begin, &expr_end, &delimiter);
4868
 
4869
                expr_begin += index;
4870
                expr_end += index;
4871
                delimiter += index;
4872
        }
4873
 
4874
        if ((status == JAMC_SUCCESS) &&
4875
                (statement_buffer[delimiter] != JAMC_SEMICOLON_CHAR))
4876
        {
4877
                status = JAMC_SYNTAX_ERROR;
4878
        }
4879
 
4880
        /*
4881
        *       Result must be a scalar Boolean variable
4882
        */
4883
        if (status == JAMC_SUCCESS)
4884
        {
4885
                save_ch = statement_buffer[expr_end];
4886
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
4887
                status = jam_get_symbol_record(&statement_buffer[expr_begin],
4888
                        &symbol_record);
4889
                statement_buffer[expr_end] = save_ch;
4890
 
4891
                if ((status == JAMC_SUCCESS) &&
4892
                        (symbol_record->type != JAM_BOOLEAN_SYMBOL))
4893
                {
4894
                        status = JAMC_TYPE_MISMATCH;
4895
                }
4896
        }
4897
 
4898
        /*
4899
        *       Find some free memory on the heap
4900
        */
4901
        if (status == JAMC_SUCCESS)
4902
        {
4903
                temp_array = jam_get_temp_workspace((count_value >> 3) + 4);
4904
 
4905
                if (temp_array == NULL)
4906
                {
4907
                        status = JAMC_OUT_OF_MEMORY;
4908
                }
4909
        }
4910
 
4911
        /*
4912
        *       Do the JTAG operation, saving the result in temp_array
4913
        */
4914
        if (status == JAMC_SUCCESS)
4915
        {
4916
                status = jam_swap_ir(count_value, in_data, in_index, temp_array, 0);
4917
        }
4918
 
4919
        /*
4920
        *       Mask the data and do the comparison
4921
        */
4922
        if (status == JAMC_SUCCESS)
4923
        {
4924
                for (bit = 0; (bit < count_value) && result; ++bit)
4925
                {
4926
                        actual = temp_array[bit >> 5] & (1L << (bit & 0x1f)) ? 1 : 0;
4927
                        expected = comp_data[(bit + comp_start_index) >> 5]
4928
                                & (1L << ((bit + comp_start_index) & 0x1f)) ? 1 : 0;
4929
                        mask = mask_data[(bit + mask_start_index) >> 5]
4930
                                & (1L << ((bit + mask_start_index) & 0x1f)) ? 1 : 0;
4931
 
4932
                        if ((actual & mask) != (expected & mask))
4933
                        {
4934
                                result = FALSE;
4935
                        }
4936
                }
4937
 
4938
                symbol_record->value = result ? 1L : 0L;
4939
        }
4940
 
4941
        if (temp_array != NULL) jam_free_temp_workspace(temp_array);
4942
 
4943
        return (status);
4944
}
4945
 
4946
/****************************************************************************/
4947
/*                                                                                                                                                      */
4948
 
4949
JAM_RETURN_TYPE jam_process_irscan_capture
4950
(
4951
        char *statement_buffer,
4952
        long count_value,
4953
        long *in_data,
4954
        long in_index
4955
)
4956
 
4957
/*                                                                                                                                                      */
4958
/*      Description:    Processes the arguments for the CAPTURE version of the  */
4959
/*                                      IRSCAN statement.  Calls jam_swap_ir() to access the    */
4960
/*                                      JTAG hardware interface.                                                                */
4961
/*                                                                                                                                                      */
4962
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
4963
/*                                                                                                                                                      */
4964
/****************************************************************************/
4965
{
4966
        /* syntax:  IRSCAN <length> [, <data>] [CAPTURE <array>] ; */
4967
 
4968
        int expr_begin = 0;
4969
        int expr_end = 0;
4970
        int delimiter = 0;
4971
        long start_index = 0L;
4972
        long stop_index = 0L;
4973
        char save_ch = 0;
4974
        long *tdi_data = NULL;
4975
        long *literal_array_data = NULL;
4976
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
4977
        JAMS_HEAP_RECORD *heap_record = NULL;
4978
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
4979
 
4980
        /*
4981
        *       Statement buffer should contain the part of the statement string
4982
        *       after the CAPTURE keyword.
4983
        *
4984
        *       The only argument should be the capture array.
4985
        */
4986
        status = jam_find_argument(statement_buffer,
4987
                &expr_begin, &expr_end, &delimiter);
4988
 
4989
        if ((status == JAMC_SUCCESS) &&
4990
                (statement_buffer[delimiter] != JAMC_SEMICOLON_CHAR))
4991
        {
4992
                status = JAMC_SYNTAX_ERROR;
4993
        }
4994
 
4995
        if (status == JAMC_SUCCESS)
4996
        {
4997
                save_ch = statement_buffer[expr_end];
4998
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
4999
                status = jam_get_array_argument(&statement_buffer[expr_begin],
5000
                        &symbol_record, &literal_array_data,
5001
                        &start_index, &stop_index, 1);
5002
                statement_buffer[expr_end] = save_ch;
5003
        }
5004
 
5005
        if ((status == JAMC_SUCCESS) && (literal_array_data != NULL))
5006
        {
5007
                /* literal array may not be used for capture buffer */
5008
                status = JAMC_SYNTAX_ERROR;
5009
        }
5010
 
5011
        if ((status == JAMC_SUCCESS) &&
5012
                (stop_index != start_index + count_value - 1))
5013
        {
5014
                status = JAMC_BOUNDS_ERROR;
5015
        }
5016
 
5017
        if (status == JAMC_SUCCESS)
5018
        {
5019
                if (symbol_record != NULL)
5020
                {
5021
                        heap_record = (JAMS_HEAP_RECORD *)symbol_record->value;
5022
 
5023
                        if (heap_record != NULL)
5024
                        {
5025
                                tdi_data = heap_record->data;
5026
                        }
5027
                        else
5028
                        {
5029
                                status = JAMC_INTERNAL_ERROR;
5030
                        }
5031
                }
5032
                else
5033
                {
5034
                        status = JAMC_INTERNAL_ERROR;
5035
                }
5036
        }
5037
 
5038
        /*
5039
        *       Perform the JTAG operation, capturing data into the heap buffer
5040
        */
5041
        if (status == JAMC_SUCCESS)
5042
        {
5043
                status = jam_swap_ir(count_value, in_data, in_index,
5044
                        tdi_data, start_index);
5045
        }
5046
 
5047
        return (status);
5048
}
5049
 
5050
/****************************************************************************/
5051
/*                                                                                                                                                      */
5052
 
5053
JAM_RETURN_TYPE jam_process_irscan
5054
(
5055
        char *statement_buffer
5056
)
5057
 
5058
/*                                                                                                                                                      */
5059
/*      Description:    Processes IRSCAN statement, which shifts data through   */
5060
/*                                      an instruction register of the JTAG interface                   */
5061
/*                                                                                                                                                      */
5062
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
5063
/*                                                                                                                                                      */
5064
/****************************************************************************/
5065
{
5066
        /* syntax:  IRSCAN <length> [, <data>] [CAPTURE <array>] ; */
5067
        /* or:  IRSCAN <length> [, <data>] [COMPARE <array>, <mask>, <result>] ; */
5068
 
5069
        int index = 0;
5070
        int expr_begin = 0;
5071
        int expr_end = 0;
5072
        int delimiter = 0L;
5073
        long count_value = 0L;
5074
        long start_index = 0L;
5075
        long stop_index = 0L;
5076
        char save_ch = 0;
5077
        long *tdi_data = NULL;
5078
        long *literal_array_data = NULL;
5079
        JAME_EXPRESSION_TYPE expr_type = JAM_ILLEGAL_EXPR_TYPE;
5080
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
5081
        JAMS_HEAP_RECORD *heap_record = NULL;
5082
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
5083
 
5084
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
5085
        {
5086
                return (JAMC_PHASE_ERROR);
5087
        }
5088
 
5089
        index = jam_skip_instruction_name(statement_buffer);
5090
 
5091
        /* locate length */
5092
        status = jam_find_argument(&statement_buffer[index],
5093
                &expr_begin, &expr_end, &delimiter);
5094
 
5095
        expr_begin += index;
5096
        expr_end += index;
5097
        delimiter += index;
5098
 
5099
        if ((status == JAMC_SUCCESS) &&
5100
                (statement_buffer[delimiter] != JAMC_COMMA_CHAR))
5101
        {
5102
                status = JAMC_SYNTAX_ERROR;
5103
        }
5104
 
5105
        if (status == JAMC_SUCCESS)
5106
        {
5107
                save_ch = statement_buffer[expr_end];
5108
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
5109
                status = jam_evaluate_expression(
5110
                        &statement_buffer[expr_begin], &count_value, &expr_type);
5111
                statement_buffer[expr_end] = save_ch;
5112
        }
5113
 
5114
        /*
5115
        *       Check for integer expression
5116
        */
5117
        if ((status == JAMC_SUCCESS) &&
5118
                (expr_type != JAM_INTEGER_EXPR) &&
5119
                (expr_type != JAM_INT_OR_BOOL_EXPR))
5120
        {
5121
                status = JAMC_TYPE_MISMATCH;
5122
        }
5123
 
5124
        /*
5125
        *       Look for array variable with sub-range index
5126
        */
5127
        if (status == JAMC_SUCCESS)
5128
        {
5129
                index = delimiter + 1;
5130
                status = jam_find_argument(&statement_buffer[index],
5131
                        &expr_begin, &expr_end, &delimiter);
5132
 
5133
                expr_begin += index;
5134
                expr_end += index;
5135
                delimiter += index;
5136
        }
5137
 
5138
        if ((status == JAMC_SUCCESS) &&
5139
                (statement_buffer[delimiter] != JAMC_COMMA_CHAR) &&
5140
                (statement_buffer[delimiter] != JAMC_SEMICOLON_CHAR))
5141
        {
5142
                status = JAMC_SYNTAX_ERROR;
5143
        }
5144
 
5145
        if (status == JAMC_SUCCESS)
5146
        {
5147
                save_ch = statement_buffer[expr_end];
5148
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
5149
                status = jam_get_array_argument(&statement_buffer[expr_begin],
5150
                        &symbol_record, &literal_array_data,
5151
                        &start_index, &stop_index, 0);
5152
                statement_buffer[expr_end] = save_ch;
5153
        }
5154
 
5155
        if ((status == JAMC_SUCCESS) &&
5156
                (literal_array_data != NULL) &&
5157
                (start_index == 0) &&
5158
                (stop_index > count_value - 1))
5159
        {
5160
                stop_index = count_value - 1;
5161
        }
5162
 
5163
        if (status == JAMC_SUCCESS)
5164
        {
5165
                if (symbol_record != NULL)
5166
                {
5167
                        heap_record = (JAMS_HEAP_RECORD *)symbol_record->value;
5168
 
5169
                        if (heap_record != NULL)
5170
                        {
5171
                                tdi_data = heap_record->data;
5172
                        }
5173
                        else
5174
                        {
5175
                                status = JAMC_INTERNAL_ERROR;
5176
                        }
5177
                }
5178
                else if (literal_array_data != NULL)
5179
                {
5180
                        tdi_data = literal_array_data;
5181
                }
5182
                else
5183
                {
5184
                        status = JAMC_INTERNAL_ERROR;
5185
                }
5186
        }
5187
 
5188
        if ((status == JAMC_SUCCESS) &&
5189
                (statement_buffer[delimiter] == JAMC_SEMICOLON_CHAR))
5190
        {
5191
                /*
5192
                *       Do a simple IRSCAN operation -- no capture or compare
5193
                */
5194
                status = jam_do_irscan(count_value, tdi_data, start_index);
5195
        }
5196
        else if ((status == JAMC_SUCCESS) &&
5197
                (statement_buffer[delimiter] == JAMC_COMMA_CHAR))
5198
        {
5199
                /*
5200
                *       Delimiter was a COMMA, so look for CAPTURE or COMPARE keyword
5201
                */
5202
                index = delimiter + 1;
5203
                while (jam_isspace(statement_buffer[index]))
5204
                {
5205
                        ++index;        /* skip over white space */
5206
                }
5207
 
5208
                if ((jam_strncmp(&statement_buffer[index], "CAPTURE", 7) == 0) &&
5209
                        (jam_isspace(statement_buffer[index + 7])))
5210
                {
5211
                        /*
5212
                        *       Do an IRSCAN with capture
5213
                        */
5214
                        status = jam_process_irscan_capture(&statement_buffer[index + 8],
5215
                                count_value, tdi_data, start_index);
5216
                }
5217
                else if ((jam_strncmp(&statement_buffer[index], "COMPARE", 7) == 0) &&
5218
                        (jam_isspace(statement_buffer[index + 7])))
5219
                {
5220
                        /*
5221
                        *       Do an IRSCAN with compare
5222
                        */
5223
                        status = jam_process_irscan_compare(&statement_buffer[index + 8],
5224
                                count_value, tdi_data, start_index);
5225
                }
5226
                else
5227
                {
5228
                        status = JAMC_SYNTAX_ERROR;
5229
                }
5230
        }
5231
 
5232
        return (status);
5233
}
5234
 
5235
/****************************************************************************/
5236
/*                                                                                                                                                      */
5237
 
5238
JAM_RETURN_TYPE jam_process_irstop
5239
(
5240
        char *statement_buffer
5241
)
5242
 
5243
/*                                                                                                                                                      */
5244
/*      Description:    Sets stop-state for IR scan operations                                  */
5245
/*                                                                                                                                                      */
5246
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
5247
/*                                                                                                                                                      */
5248
/****************************************************************************/
5249
{
5250
        int index = 0;
5251
        int expr_begin = 0;
5252
        int expr_end = 0;
5253
        int delimiter = 0;
5254
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
5255
        JAME_JTAG_STATE state = JAM_ILLEGAL_JTAG_STATE;
5256
 
5257
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
5258
        {
5259
                return (JAMC_PHASE_ERROR);
5260
        }
5261
 
5262
        index = jam_skip_instruction_name(statement_buffer);
5263
 
5264
        /*
5265
        *       Get next argument
5266
        */
5267
        status = jam_find_argument(&statement_buffer[index],
5268
                &expr_begin, &expr_end, &delimiter);
5269
 
5270
        expr_begin += index;
5271
        expr_end += index;
5272
        delimiter += index;
5273
 
5274
        if ((status == JAMC_SUCCESS) &&
5275
                (statement_buffer[delimiter] != JAMC_SEMICOLON_CHAR))
5276
        {
5277
                status = JAMC_SYNTAX_ERROR;
5278
        }
5279
 
5280
        if (status == JAMC_SUCCESS)
5281
        {
5282
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
5283
                state = jam_get_jtag_state_from_name(&statement_buffer[expr_begin]);
5284
 
5285
                if (state == JAM_ILLEGAL_JTAG_STATE)
5286
                {
5287
                        status = JAMC_SYNTAX_ERROR;
5288
                }
5289
                else
5290
                {
5291
                        /*
5292
                        *       Set IRSCAN stop state to the specified state
5293
                        */
5294
                        status = jam_set_irstop_state(state);
5295
                }
5296
        }
5297
 
5298
        return (status);
5299
}
5300
 
5301
/****************************************************************************/
5302
/*                                                                                                                                                      */
5303
 
5304
JAM_RETURN_TYPE jam_copy_array_subrange
5305
(
5306
        long *source_heap_data,
5307
        long source_subrange_begin,
5308
        long source_subrange_end,
5309
        long *dest_heap_data,
5310
        long dest_subrange_begin,
5311
        long dest_subrange_end
5312
)
5313
 
5314
/*                                                                                                                                                      */
5315
/*      Description:    Copies bits from one BOOLEAN array buffer to another    */
5316
/*                                                                                                                                                      */
5317
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
5318
/*                                                                                                                                                      */
5319
/****************************************************************************/
5320
{
5321
        long source_length = 1 + source_subrange_end - source_subrange_begin;
5322
        long dest_length = 1 + dest_subrange_end - dest_subrange_begin;
5323
        long length = source_length;
5324
        long index = 0L;
5325
        long source_index = 0L;
5326
        long dest_index = 0L;
5327
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
5328
 
5329
        /* find minimum of source_length and dest_length */
5330
        if (length > dest_length) length = dest_length;
5331
 
5332
        if (length <= 0L)
5333
        {
5334
                status = JAMC_BOUNDS_ERROR;
5335
        }
5336
        else
5337
        {
5338
                /* copy the bits */
5339
                for (index = 0L; index < length; ++index)
5340
                {
5341
                        source_index = index + source_subrange_begin;
5342
                        dest_index = index + dest_subrange_begin;
5343
 
5344
                        if (source_heap_data[source_index >> 5] &
5345
                                (1L << (source_index & 0x1f)))
5346
                        {
5347
                                /* set a single bit */
5348
                                dest_heap_data[dest_index >> 5] |=
5349
                                        (1L << (dest_index & 0x1f));
5350
                        }
5351
                        else
5352
                        {
5353
                                /* clear a single bit */
5354
                                dest_heap_data[dest_index >> 5] &=
5355
                                        (~(unsigned long)(1L << (dest_index & 0x1f)));
5356
                        }
5357
                }
5358
        }
5359
 
5360
        return (status);
5361
}
5362
 
5363
BOOL jam_check_assignment
5364
(
5365
        char *statement_buffer
5366
)
5367
{
5368
        BOOL assignment = FALSE;
5369
        int index = 0;
5370
        char save_ch = 0;
5371
        int variable_begin = 0;
5372
        int variable_end = 0;
5373
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
5374
 
5375
        while ((jam_is_name_char(statement_buffer[index])) &&
5376
                (index < JAMC_MAX_STATEMENT_LENGTH))
5377
        {
5378
                ++index;        /* skip over variable name */
5379
        }
5380
 
5381
        if (index < JAMC_MAX_NAME_LENGTH)
5382
        {
5383
                /* check if this is a variable name */
5384
                variable_end = index;
5385
                save_ch = statement_buffer[variable_end];
5386
                statement_buffer[variable_end] = JAMC_NULL_CHAR;
5387
 
5388
                if (jam_get_symbol_record(&statement_buffer[variable_begin],
5389
                        &symbol_record) == JAMC_SUCCESS)
5390
                {
5391
                        if ((symbol_record->type == JAM_INTEGER_SYMBOL) ||
5392
                                (symbol_record->type == JAM_BOOLEAN_SYMBOL) ||
5393
                                (symbol_record->type == JAM_INTEGER_ARRAY_WRITABLE) ||
5394
                                (symbol_record->type == JAM_BOOLEAN_ARRAY_WRITABLE) ||
5395
                                (symbol_record->type == JAM_INTEGER_ARRAY_INITIALIZED) ||
5396
                                (symbol_record->type == JAM_BOOLEAN_ARRAY_INITIALIZED))
5397
                        {
5398
                                assignment = TRUE;
5399
                        }
5400
                }
5401
 
5402
                statement_buffer[variable_end] = save_ch;
5403
        }
5404
 
5405
        return (assignment);
5406
}
5407
 
5408
/****************************************************************************/
5409
/*                                                                                                                                                      */
5410
 
5411
JAM_RETURN_TYPE jam_process_assignment
5412
(
5413
        char *statement_buffer,
5414
        BOOL let
5415
)
5416
 
5417
/*                                                                                                                                                      */
5418
/*      Description:    Processes a LET (assignment) statement.                                 */
5419
/*                                                                                                                                                      */
5420
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
5421
/*                                                                                                                                                      */
5422
/****************************************************************************/
5423
{
5424
        int index = 0;
5425
        int variable_begin = 0;
5426
        int variable_end = 0;
5427
        int dim_begin = 0;
5428
        int dim_end = 0;
5429
        int expr_begin = 0;
5430
        int expr_end = 0;
5431
        int bracket_count = 0;
5432
        long dim_value = 0L;
5433
        long assign_value = 0L;
5434
        char save_ch = 0;
5435
        long source_subrange_begin = 0L;
5436
        long source_subrange_end = 0L;
5437
        long dest_subrange_begin = 0L;
5438
        long dest_subrange_end = 0L;
5439
        BOOL is_array = FALSE;
5440
        BOOL full_array = FALSE;
5441
        BOOL array_subrange = FALSE;
5442
        long *source_heap_data = NULL;
5443
        long *dest_heap_data = NULL;
5444
        long *literal_array_data = NULL;
5445
        JAME_EXPRESSION_TYPE assign_type = JAM_ILLEGAL_EXPR_TYPE;
5446
        JAME_EXPRESSION_TYPE expr_type = JAM_ILLEGAL_EXPR_TYPE;
5447
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
5448
        JAMS_HEAP_RECORD *heap_record = NULL;
5449
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
5450
 
5451
 
5452
        if (let & (jam_version == 0)) jam_version = 1;
5453
 
5454
        if ((!let) & (jam_version == 0)) jam_version = 2;
5455
 
5456
        if (((!let) & (jam_version == 1)) || (let & (jam_version == 2)))
5457
        {
5458
                return (JAMC_SYNTAX_ERROR);
5459
        }
5460
 
5461
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
5462
        {
5463
                return (JAMC_PHASE_ERROR);
5464
        }
5465
 
5466
        if (let)
5467
        {
5468
                index = jam_skip_instruction_name(statement_buffer);
5469
        }
5470
 
5471
        if (jam_isalpha(statement_buffer[index]))
5472
        {
5473
                /* locate variable name */
5474
                variable_begin = index;
5475
                while ((jam_is_name_char(statement_buffer[index])) &&
5476
                        (index < JAMC_MAX_STATEMENT_LENGTH))
5477
                {
5478
                        ++index;        /* skip over variable name */
5479
                }
5480
                variable_end = index;
5481
 
5482
                while ((jam_isspace(statement_buffer[index])) &&
5483
                        (index < JAMC_MAX_STATEMENT_LENGTH))
5484
                {
5485
                        ++index;        /* skip over white space */
5486
                }
5487
 
5488
                status = JAMC_SUCCESS;
5489
 
5490
                if (statement_buffer[index] == JAMC_LBRACKET_CHAR)
5491
                {
5492
                        /*
5493
                        *       Assignment to array element
5494
                        */
5495
                        ++index;
5496
                        is_array = TRUE;
5497
                        dim_begin = index;
5498
                        while ((jam_isspace(statement_buffer[dim_begin])) &&
5499
                                (dim_begin < JAMC_MAX_STATEMENT_LENGTH))
5500
                        {
5501
                                ++dim_begin;    /* skip over white space */
5502
                        }
5503
                        while (((statement_buffer[index] != JAMC_RBRACKET_CHAR) ||
5504
                                (bracket_count > 0)) &&
5505
                                (index < JAMC_MAX_STATEMENT_LENGTH))
5506
                        {
5507
                                if (statement_buffer[index] == JAMC_LBRACKET_CHAR)
5508
                                {
5509
                                        ++bracket_count;
5510
                                }
5511
                                else if (statement_buffer[index] == JAMC_RBRACKET_CHAR)
5512
                                {
5513
                                        --bracket_count;
5514
                                }
5515
 
5516
                                ++index;        /* find matching bracket */
5517
                        }
5518
                        if (statement_buffer[index] == JAMC_RBRACKET_CHAR)
5519
                        {
5520
                                dim_end = index;
5521
                        }
5522
 
5523
                        if (dim_end == dim_begin)
5524
                        {
5525
                                /* full array notation */
5526
                                full_array = TRUE;
5527
                        }
5528
                        else if (dim_end > dim_begin)
5529
                        {
5530
                                /* look for ".." in array index expression */
5531
                                index = dim_begin;
5532
                                while ((index < dim_end) && !array_subrange)
5533
                                {
5534
                                        if ((statement_buffer[index] == JAMC_PERIOD_CHAR) &&
5535
                                                (statement_buffer[index + 1] == JAMC_PERIOD_CHAR))
5536
                                        {
5537
                                                array_subrange = TRUE;
5538
                                        }
5539
                                        ++index;
5540
                                }
5541
                        }
5542
                        else
5543
                        {
5544
                                /* right bracket not found */
5545
                                status = JAMC_SYNTAX_ERROR;
5546
                        }
5547
 
5548
                        if (status == JAMC_SUCCESS)
5549
                        {
5550
                                index = dim_end + 1;
5551
                                while ((jam_isspace(statement_buffer[index])) &&
5552
                                        (index < JAMC_MAX_STATEMENT_LENGTH))
5553
                                {
5554
                                        ++index;        /* skip over white space */
5555
                                }
5556
 
5557
                                /* get pointer to symbol record */
5558
                                save_ch = statement_buffer[variable_end];
5559
                                statement_buffer[variable_end] = JAMC_NULL_CHAR;
5560
                                status = jam_get_symbol_record(
5561
                                        &statement_buffer[variable_begin], &symbol_record);
5562
                                statement_buffer[variable_end] = save_ch;
5563
 
5564
                                /* check array type */
5565
                                if (status == JAMC_SUCCESS)
5566
                                {
5567
                                        switch (symbol_record->type)
5568
                                        {
5569
                                        case JAM_INTEGER_ARRAY_WRITABLE:
5570
                                                assign_type = JAM_INTEGER_EXPR;
5571
                                                break;
5572
 
5573
                                        case JAM_BOOLEAN_ARRAY_WRITABLE:
5574
                                                assign_type = JAM_BOOLEAN_EXPR;
5575
                                                break;
5576
 
5577
                                        case JAM_INTEGER_ARRAY_INITIALIZED:
5578
                                        case JAM_BOOLEAN_ARRAY_INITIALIZED:
5579
                                                status = JAMC_ASSIGN_TO_CONST;
5580
                                                break;
5581
 
5582
                                        default:
5583
                                                status = JAMC_TYPE_MISMATCH;
5584
                                                break;
5585
                                        }
5586
                                }
5587
 
5588
                                /* get pointer to heap record */
5589
                                if (status == JAMC_SUCCESS)
5590
                                {
5591
                                        heap_record = (JAMS_HEAP_RECORD *) symbol_record->value;
5592
 
5593
                                        if (heap_record == NULL)
5594
                                        {
5595
                                                status = JAMC_INTERNAL_ERROR;
5596
                                        }
5597
                                        else
5598
                                        {
5599
                                                dest_heap_data = heap_record->data;
5600
                                        }
5601
                                }
5602
                        }
5603
 
5604
                        if (status == JAMC_SUCCESS)
5605
                        {
5606
                                if (full_array || array_subrange)
5607
                                {
5608
                                        if (assign_type == JAM_BOOLEAN_EXPR)
5609
                                        {
5610
                                                if (full_array)
5611
                                                {
5612
                                                        dest_subrange_begin = 0L;
5613
                                                        dest_subrange_end = heap_record->dimension - 1L;
5614
                                                        array_subrange = TRUE;
5615
                                                }
5616
                                                else
5617
                                                {
5618
                                                        save_ch = statement_buffer[dim_end];
5619
                                                        statement_buffer[dim_end] = JAMC_NULL_CHAR;
5620
                                                        status = jam_get_array_subrange(symbol_record,
5621
                                                                &statement_buffer[dim_begin],
5622
                                                                &dest_subrange_begin, &dest_subrange_end);
5623
                                                        statement_buffer[dim_end] = save_ch;
5624
 
5625
                                                        /* check array bounds */
5626
                                                        if ((status == JAMC_SUCCESS) &&
5627
                                                                ((dest_subrange_begin < 0L) ||
5628
                                                                (dest_subrange_begin >= heap_record->dimension)
5629
                                                                || (dest_subrange_end < 0L) ||
5630
                                                                (dest_subrange_end >= heap_record->dimension)))
5631
                                                        {
5632
                                                                status = JAMC_BOUNDS_ERROR;
5633
                                                        }
5634
                                                }
5635
                                        }
5636
                                        else
5637
                                        {
5638
                                                /* can't assign to an integer array */
5639
                                                status = JAMC_SYNTAX_ERROR;
5640
                                        }
5641
                                }
5642
                                else
5643
                                {
5644
                                        /* assign to array element */
5645
                                        save_ch = statement_buffer[dim_end];
5646
                                        statement_buffer[dim_end] = JAMC_NULL_CHAR;
5647
                                        status = jam_evaluate_expression(
5648
                                                &statement_buffer[dim_begin], &dim_value, &expr_type);
5649
                                        statement_buffer[dim_end] = save_ch;
5650
 
5651
                                        /*
5652
                                        *       Check for integer expression
5653
                                        */
5654
                                        if ((status == JAMC_SUCCESS) &&
5655
                                                (expr_type != JAM_INTEGER_EXPR) &&
5656
                                                (expr_type != JAM_INT_OR_BOOL_EXPR))
5657
                                        {
5658
                                                status = JAMC_TYPE_MISMATCH;
5659
                                        }
5660
                                }
5661
                        }
5662
                }
5663
                else
5664
                {
5665
                        /*
5666
                        *       Get type of variable on left-hand-side
5667
                        */
5668
                        save_ch = statement_buffer[variable_end];
5669
                        statement_buffer[variable_end] = JAMC_NULL_CHAR;
5670
                        status = jam_get_symbol_record(
5671
                                &statement_buffer[variable_begin], &symbol_record);
5672
                        statement_buffer[variable_end] = save_ch;
5673
 
5674
                        if (status == JAMC_SUCCESS)
5675
                        {
5676
                                switch (symbol_record->type)
5677
                                {
5678
                                case JAM_INTEGER_SYMBOL:
5679
                                        assign_type = JAM_INTEGER_EXPR;
5680
                                        break;
5681
 
5682
                                case JAM_BOOLEAN_SYMBOL:
5683
                                        assign_type = JAM_BOOLEAN_EXPR;
5684
                                        break;
5685
 
5686
                                default:
5687
                                        status = JAMC_TYPE_MISMATCH;
5688
                                        break;
5689
                                }
5690
                        }
5691
                }
5692
 
5693
                /*
5694
                *       Evaluate assignment expression
5695
                */
5696
                if (status == JAMC_SUCCESS)
5697
                {
5698
                        status = JAMC_SYNTAX_ERROR;
5699
 
5700
                        if (statement_buffer[index] == JAMC_EQUAL_CHAR)
5701
                        {
5702
                                /*
5703
                                *       Evaluate assignment expression
5704
                                */
5705
                                expr_begin = index + 1;
5706
                                while ((jam_isspace(statement_buffer[expr_begin])) &&
5707
                                        (expr_begin < JAMC_MAX_STATEMENT_LENGTH))
5708
                                {
5709
                                        ++expr_begin;   /* skip over white space */
5710
                                }
5711
                                while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
5712
                                        (index < JAMC_MAX_STATEMENT_LENGTH))
5713
                                {
5714
                                        ++index;
5715
                                }
5716
                                while ((statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
5717
                                        (index > 0))
5718
                                {
5719
                                        --index;
5720
                                }
5721
                                expr_end = index;
5722
 
5723
                                if (expr_end > expr_begin)
5724
                                {
5725
                                        if (array_subrange)
5726
                                        {
5727
                                                symbol_record = NULL;
5728
                                                save_ch = statement_buffer[expr_end];
5729
                                                statement_buffer[expr_end] = JAMC_NULL_CHAR;
5730
                                                status = jam_get_array_argument(
5731
                                                        &statement_buffer[expr_begin],
5732
                                                        &symbol_record,
5733
                                                        &literal_array_data,
5734
                                                        &source_subrange_begin,
5735
                                                        &source_subrange_end, 0);
5736
                                                statement_buffer[expr_end] = save_ch;
5737
 
5738
                                                if (status == JAMC_SUCCESS)
5739
                                                {
5740
                                                        if (symbol_record != NULL)
5741
                                                        {
5742
                                                                if ((symbol_record->type ==
5743
                                                                        JAM_BOOLEAN_ARRAY_WRITABLE) ||
5744
                                                                        (symbol_record->type ==
5745
                                                                        JAM_BOOLEAN_ARRAY_INITIALIZED))
5746
                                                                {
5747
                                                                        heap_record = (JAMS_HEAP_RECORD *)
5748
                                                                                symbol_record->value;
5749
 
5750
                                                                        /* check array bounds */
5751
                                                                        if ((source_subrange_begin < 0L) ||
5752
                                                                                (source_subrange_begin >=
5753
                                                                                        heap_record->dimension) ||
5754
                                                                                (source_subrange_end < 0L) ||
5755
                                                                                (source_subrange_end >=
5756
                                                                                        heap_record->dimension))
5757
                                                                        {
5758
                                                                                status = JAMC_BOUNDS_ERROR;
5759
                                                                        }
5760
                                                                        else
5761
                                                                        {
5762
                                                                                source_heap_data = heap_record->data;
5763
                                                                        }
5764
                                                                }
5765
                                                                else
5766
                                                                {
5767
                                                                        status = JAMC_TYPE_MISMATCH;
5768
                                                                }
5769
                                                        }
5770
                                                        else if (literal_array_data != NULL)
5771
                                                        {
5772
                                                                source_heap_data = literal_array_data;
5773
                                                        }
5774
                                                        else
5775
                                                        {
5776
                                                                status = JAMC_INTERNAL_ERROR;
5777
                                                        }
5778
                                                }
5779
                                        }
5780
                                        else
5781
                                        {
5782
                                                save_ch = statement_buffer[expr_end];
5783
                                                statement_buffer[expr_end] = JAMC_NULL_CHAR;
5784
                                                status = jam_evaluate_expression(
5785
                                                        &statement_buffer[expr_begin],
5786
                                                        &assign_value, &expr_type);
5787
                                                statement_buffer[expr_end] = save_ch;
5788
                                        }
5789
                                }
5790
                        }
5791
                }
5792
 
5793
                if (status == JAMC_SUCCESS)
5794
                {
5795
                        /*
5796
                        *       Check type of expression against type of variable
5797
                        *       being assigned
5798
                        */
5799
                        if (array_subrange)
5800
                        {
5801
                                /* copy array data */
5802
                                status = jam_copy_array_subrange(
5803
                                        source_heap_data,
5804
                                        source_subrange_begin,
5805
                                        source_subrange_end,
5806
                                        dest_heap_data,
5807
                                        dest_subrange_begin,
5808
                                        dest_subrange_end);
5809
                        }
5810
                        else if ((expr_type != JAM_ILLEGAL_EXPR_TYPE) &&
5811
                                (assign_type != JAM_ILLEGAL_EXPR_TYPE) &&
5812
                                ((expr_type == assign_type) ||
5813
                                (expr_type == JAM_INT_OR_BOOL_EXPR)))
5814
                        {
5815
                                /*
5816
                                *       Set the variable to the computed value
5817
                                */
5818
                                if (is_array)
5819
                                {
5820
                                        /* check array bounds */
5821
                                        if ((dim_value >= 0) &&
5822
                                                (dim_value < heap_record->dimension))
5823
                                        {
5824
                                                if (assign_type == JAM_INTEGER_EXPR)
5825
                                                {
5826
                                                        dest_heap_data[dim_value] = assign_value;
5827
                                                }
5828
                                                else if (assign_type == JAM_BOOLEAN_EXPR)
5829
                                                {
5830
                                                        if (assign_value == 0)
5831
                                                        {
5832
                                                                /* clear a single bit */
5833
                                                                dest_heap_data[dim_value >> 5] &=
5834
                                                                        (~(unsigned long)(1L << (dim_value & 0x1f)));
5835
                                                        }
5836
                                                        else
5837
                                                        {
5838
                                                                /* set a single bit */
5839
                                                                dest_heap_data[dim_value >> 5] |=
5840
                                                                        (1L << (dim_value & 0x1f));
5841
                                                        }
5842
                                                }
5843
                                                else
5844
                                                {
5845
                                                        status = JAMC_INTERNAL_ERROR;
5846
                                                }
5847
                                        }
5848
                                        else
5849
                                        {
5850
                                                status = JAMC_BOUNDS_ERROR;
5851
                                        }
5852
                                }
5853
                                else
5854
                                {
5855
                                        symbol_record->value = assign_value;
5856
                                }
5857
                        }
5858
                        else
5859
                        {
5860
                                status = JAMC_TYPE_MISMATCH;
5861
                        }
5862
                }
5863
        }
5864
 
5865
        return (status);
5866
}
5867
 
5868
/****************************************************************************/
5869
/*                                                                                                                                                      */
5870
 
5871
JAM_RETURN_TYPE jam_process_next
5872
(
5873
        char *statement_buffer
5874
)
5875
 
5876
/*                                                                                                                                                      */
5877
/*      Description:    Processes a NEXT statement.  The NEXT statement is              */
5878
/*                                      used to mark the bottom of a FOR loop.  When a NEXT             */
5879
/*                                      statement is processed, there must be a corresponding   */
5880
/*                                      FOR loop stack record on top of the stack.                              */
5881
/*                                                                                                                                                      */
5882
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
5883
/*                                                                                                                                                      */
5884
/****************************************************************************/
5885
{
5886
        int index = 0;
5887
        int variable_begin = 0;
5888
        int variable_end = 0;
5889
        char save_ch = 0;
5890
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
5891
        JAMS_STACK_RECORD *stack_record = NULL;
5892
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
5893
 
5894
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
5895
        {
5896
                return (JAMC_PHASE_ERROR);
5897
        }
5898
 
5899
        index = jam_skip_instruction_name(statement_buffer);
5900
 
5901
        if (jam_isalpha(statement_buffer[index]))
5902
        {
5903
                /* locate variable name */
5904
                variable_begin = index;
5905
                while ((jam_is_name_char(statement_buffer[index])) &&
5906
                        (index < JAMC_MAX_STATEMENT_LENGTH))
5907
                {
5908
                        ++index;        /* skip over variable name */
5909
                }
5910
                variable_end = index;
5911
 
5912
                while ((jam_isspace(statement_buffer[index])) &&
5913
                        (index < JAMC_MAX_STATEMENT_LENGTH))
5914
                {
5915
                        ++index;        /* skip over white space */
5916
                }
5917
 
5918
                if (statement_buffer[index] == JAMC_SEMICOLON_CHAR)
5919
                {
5920
                        /*
5921
                        *       Look in symbol table for iterator variable
5922
                        */
5923
                        save_ch = statement_buffer[variable_end];
5924
                        statement_buffer[variable_end] = JAMC_NULL_CHAR;
5925
                        status = jam_get_symbol_record(
5926
                                &statement_buffer[variable_begin], &symbol_record);
5927
                        statement_buffer[variable_end] = save_ch;
5928
 
5929
                        if ((status == JAMC_SUCCESS) &&
5930
                                (symbol_record->type != JAM_INTEGER_SYMBOL))
5931
                        {
5932
                                status = JAMC_TYPE_MISMATCH;
5933
                        }
5934
                }
5935
 
5936
                if (status == JAMC_SUCCESS)
5937
                {
5938
                        /*
5939
                        *       Get stack record at top of stack
5940
                        */
5941
                        stack_record = jam_peek_stack_record();
5942
 
5943
                        /*
5944
                        *       Compare iterator to stack record
5945
                        */
5946
                        if ((stack_record == NULL) ||
5947
                                (stack_record->type != JAM_STACK_FOR_NEXT) ||
5948
                                (stack_record->iterator != symbol_record))
5949
                        {
5950
                                status = JAMC_NEXT_UNEXPECTED;
5951
                        }
5952
                        else
5953
                        {
5954
                                /*
5955
                                *       Check if loop has run to completion
5956
                                */
5957
                                if (((stack_record->step_value > 0) &&
5958
                                        (symbol_record->value >= stack_record->stop_value)) ||
5959
                                        ((stack_record->step_value < 0) &&
5960
                                        (symbol_record->value <= stack_record->stop_value)))
5961
                                {
5962
                                        /*
5963
                                        *       Loop has run to completion -- pop the stack record.
5964
                                        *       (Do not jump back to FOR statement position.)
5965
                                        */
5966
                                        status = jam_pop_stack_record();
5967
                                }
5968
                                else
5969
                                {
5970
                                        /*
5971
                                        *       Increment (or step) the iterator variable
5972
                                        */
5973
                                        symbol_record->value += stack_record->step_value;
5974
 
5975
                                        /*
5976
                                        *       Jump back to the top of the loop
5977
                                        */
5978
                                        if (jam_seek(stack_record->for_position) == 0)
5979
                                        {
5980
                                                jam_current_file_position =
5981
                                                        stack_record->for_position;
5982
                                                status = JAMC_SUCCESS;
5983
                                        }
5984
                                        else
5985
                                        {
5986
                                                status = JAMC_IO_ERROR;
5987
                                        }
5988
                                }
5989
                        }
5990
                }
5991
        }
5992
 
5993
        return (status);
5994
}
5995
 
5996
/****************************************************************************/
5997
/*                                                                                                                                                      */
5998
 
5999
JAM_RETURN_TYPE jam_process_padding
6000
(
6001
        char *statement_buffer
6002
)
6003
 
6004
/*                                                                                                                                                      */
6005
/*      Description:    Processes a PADDING statement.  This sets the number    */
6006
/*                                      of padding bits to be used before and after the data    */
6007
/*                                      indicated for each DRSCAN and IRSCAN operation.                 */
6008
/*                                                                                                                                                      */
6009
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
6010
/*                                                                                                                                                      */
6011
/****************************************************************************/
6012
{
6013
        int index = 0;
6014
        int argc = 0;
6015
        int expr_begin = 0;
6016
        int expr_end = 0;
6017
        int delimiter = 0;
6018
        char save_ch = 0;
6019
        long padding[4] = {0};
6020
        JAME_EXPRESSION_TYPE expr_type = JAM_ILLEGAL_EXPR_TYPE;
6021
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
6022
 
6023
        if (jam_version == 0) jam_version = 1;
6024
 
6025
        if (jam_version == 2)
6026
        {
6027
                /* The PADDING statement is not supported in Jam 2.0 */
6028
                status = JAMC_SYNTAX_ERROR;
6029
        }
6030
 
6031
        index = jam_skip_instruction_name(statement_buffer);
6032
 
6033
        for (argc = 0; (argc < 4) && (status == JAMC_SUCCESS); ++argc)
6034
        {
6035
                status = jam_find_argument(&statement_buffer[index],
6036
                        &expr_begin, &expr_end, &delimiter);
6037
 
6038
                if (status == JAMC_SUCCESS)
6039
                {
6040
                        padding[argc] = -1L;
6041
 
6042
                        expr_begin += index;
6043
                        expr_end += index;
6044
                        delimiter += index;
6045
 
6046
                        if (((argc < 3) &&
6047
                                (statement_buffer[delimiter] == JAMC_COMMA_CHAR)) ||
6048
                                ((argc == 3) &&
6049
                                (statement_buffer[delimiter] == JAMC_SEMICOLON_CHAR)))
6050
                        {
6051
                                save_ch = statement_buffer[expr_end];
6052
                                statement_buffer[expr_end] = JAMC_NULL_CHAR;
6053
                                status = jam_evaluate_expression(
6054
                                        &statement_buffer[expr_begin], &padding[argc], &expr_type);
6055
                                statement_buffer[expr_end] = save_ch;
6056
 
6057
                                /*
6058
                                *       Check for integer expression
6059
                                */
6060
                                if ((status == JAMC_SUCCESS) &&
6061
                                        (expr_type != JAM_INTEGER_EXPR) &&
6062
                                        (expr_type != JAM_INT_OR_BOOL_EXPR))
6063
                                {
6064
                                        status = JAMC_TYPE_MISMATCH;
6065
                                }
6066
 
6067
                                /*
6068
                                *       Check the range -- padding value must be between 0 and 1000
6069
                                */
6070
                                if ((status == JAMC_SUCCESS) &&
6071
                                        ((padding[argc] < 0L) || (padding[argc] > 1000L)))
6072
                                {
6073
                                        status = JAMC_SYNTAX_ERROR;
6074
                                }
6075
                                else
6076
                                {
6077
                                        index = expr_end + 1;
6078
                                }
6079
                        }
6080
                        else
6081
                        {
6082
                                status = JAMC_SYNTAX_ERROR;
6083
                        }
6084
                }
6085
        }
6086
 
6087
        /*
6088
        *       Store the new padding values
6089
        */
6090
        if (status == JAMC_SUCCESS)
6091
        {
6092
                status = jam_set_dr_preamble((int) padding[0], 0, NULL);
6093
 
6094
                if (status == JAMC_SUCCESS)
6095
                {
6096
                        status = jam_set_dr_postamble((int) padding[1], 0, NULL);
6097
                }
6098
 
6099
                if (status == JAMC_SUCCESS)
6100
                {
6101
                        status = jam_set_ir_preamble((int) padding[2], 0, NULL);
6102
                }
6103
 
6104
                if (status == JAMC_SUCCESS)
6105
                {
6106
                        status = jam_set_ir_postamble((int) padding[3], 0, NULL);
6107
                }
6108
        }
6109
 
6110
        return (status);
6111
}
6112
 
6113
/****************************************************************************/
6114
/*                                                                                                                                                      */
6115
 
6116
JAM_RETURN_TYPE jam_process_pop
6117
(
6118
        char *statement_buffer
6119
)
6120
 
6121
/*                                                                                                                                                      */
6122
/*      Description:    Pops a data element (integer or Boolean) from the               */
6123
/*                                      internal stack.  The data value is stored in the                */
6124
/*                                      variable specified.  If the type of data is not                 */
6125
/*                                      compatible with the variable type, a type mismatch              */
6126
/*                                      error results.                                                                                  */
6127
/*                                                                                                                                                      */
6128
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
6129
/*                                                                                                                                                      */
6130
/****************************************************************************/
6131
{
6132
        int index = 0;
6133
        long push_value = 0L;
6134
        long dim_value = 0L;
6135
        int variable_begin = 0;
6136
        int variable_end = 0;
6137
        int dim_begin = 0;
6138
        int dim_end = 0;
6139
        int bracket_count = 0;
6140
        char save_ch = 0;
6141
        BOOL is_array = FALSE;
6142
        long *heap_data = NULL;
6143
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
6144
        JAMS_STACK_RECORD *stack_record = NULL;
6145
        JAMS_HEAP_RECORD *heap_record = NULL;
6146
        JAME_EXPRESSION_TYPE assign_type = JAM_ILLEGAL_EXPR_TYPE;
6147
        JAME_EXPRESSION_TYPE value_type = JAM_ILLEGAL_EXPR_TYPE;
6148
        JAME_EXPRESSION_TYPE expr_type = JAM_ILLEGAL_EXPR_TYPE;
6149
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
6150
 
6151
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
6152
        {
6153
                return (JAMC_PHASE_ERROR);
6154
        }
6155
 
6156
        index = jam_skip_instruction_name(statement_buffer);
6157
 
6158
        /*
6159
        *       Get the variable name
6160
        */
6161
        if (jam_isalpha(statement_buffer[index]))
6162
        {
6163
                variable_begin = index;
6164
                while ((jam_is_name_char(statement_buffer[index])) &&
6165
                        (index < JAMC_MAX_STATEMENT_LENGTH))
6166
                {
6167
                        ++index;        /* skip over variable name */
6168
                }
6169
                variable_end = index;
6170
 
6171
                while ((jam_isspace(statement_buffer[index])) &&
6172
                        (index < JAMC_MAX_STATEMENT_LENGTH))
6173
                {
6174
                        ++index;        /* skip over white space */
6175
                }
6176
 
6177
                if (statement_buffer[index] == JAMC_LBRACKET_CHAR)
6178
                {
6179
                        /*
6180
                        *       Pop value into array element
6181
                        */
6182
                        ++index;
6183
                        is_array = TRUE;
6184
                        dim_begin = index;
6185
                        while (((statement_buffer[index] != JAMC_RBRACKET_CHAR) ||
6186
                                (bracket_count > 0)) &&
6187
                                (index < JAMC_MAX_STATEMENT_LENGTH))
6188
                        {
6189
                                if (statement_buffer[index] == JAMC_LBRACKET_CHAR)
6190
                                {
6191
                                        ++bracket_count;
6192
                                }
6193
                                else if (statement_buffer[index] == JAMC_RBRACKET_CHAR)
6194
                                {
6195
                                        --bracket_count;
6196
                                }
6197
 
6198
                                ++index;        /* find matching bracket */
6199
                        }
6200
                        if (statement_buffer[index] == JAMC_RBRACKET_CHAR)
6201
                        {
6202
                                dim_end = index;
6203
                                ++index;
6204
                        }
6205
                        while ((jam_isspace(statement_buffer[index])) &&
6206
                                (index < JAMC_MAX_STATEMENT_LENGTH))
6207
                        {
6208
                                ++index;        /* skip over white space */
6209
                        }
6210
 
6211
                        if (dim_end > dim_begin)
6212
                        {
6213
                                save_ch = statement_buffer[dim_end];
6214
                                statement_buffer[dim_end] = JAMC_NULL_CHAR;
6215
                                status = jam_evaluate_expression(
6216
                                        &statement_buffer[dim_begin], &dim_value, &expr_type);
6217
                                statement_buffer[dim_end] = save_ch;
6218
                        }
6219
 
6220
                        /*
6221
                        *       Check for integer expression
6222
                        */
6223
                        if ((status == JAMC_SUCCESS) &&
6224
                                (expr_type != JAM_INTEGER_EXPR) &&
6225
                                (expr_type != JAM_INT_OR_BOOL_EXPR))
6226
                        {
6227
                                status = JAMC_TYPE_MISMATCH;
6228
                        }
6229
 
6230
                        if (status == JAMC_SUCCESS)
6231
                        {
6232
                                /* get pointer to symbol record */
6233
                                save_ch = statement_buffer[variable_end];
6234
                                statement_buffer[variable_end] = JAMC_NULL_CHAR;
6235
                                status = jam_get_symbol_record(
6236
                                        &statement_buffer[variable_begin], &symbol_record);
6237
                                statement_buffer[variable_end] = save_ch;
6238
 
6239
                                /* check array type */
6240
                                if (status == JAMC_SUCCESS)
6241
                                {
6242
                                        switch (symbol_record->type)
6243
                                        {
6244
                                        case JAM_INTEGER_ARRAY_WRITABLE:
6245
                                                assign_type = JAM_INTEGER_EXPR;
6246
                                                break;
6247
 
6248
                                        case JAM_BOOLEAN_ARRAY_WRITABLE:
6249
                                                assign_type = JAM_BOOLEAN_EXPR;
6250
                                                break;
6251
 
6252
                                        case JAM_INTEGER_ARRAY_INITIALIZED:
6253
                                        case JAM_BOOLEAN_ARRAY_INITIALIZED:
6254
                                                status = JAMC_ASSIGN_TO_CONST;
6255
                                                break;
6256
 
6257
                                        default:
6258
                                                status = JAMC_TYPE_MISMATCH;
6259
                                                break;
6260
                                        }
6261
                                }
6262
 
6263
                                /* get pointer to heap record */
6264
                                if (status == JAMC_SUCCESS)
6265
                                {
6266
                                        heap_record = (JAMS_HEAP_RECORD *) symbol_record->value;
6267
 
6268
                                        if (heap_record == NULL)
6269
                                        {
6270
                                                status = JAMC_INTERNAL_ERROR;
6271
                                        }
6272
                                        else
6273
                                        {
6274
                                                heap_data = &heap_record->data[0];
6275
                                        }
6276
                                }
6277
                        }
6278
                }
6279
                else
6280
                {
6281
                        /*
6282
                        *       Poping value into scalar (not array) variable
6283
                        */
6284
                        if (statement_buffer[index] == JAMC_SEMICOLON_CHAR)
6285
                        {
6286
                                /*
6287
                                *       Get variable type
6288
                                */
6289
                                save_ch = statement_buffer[variable_end];
6290
                                statement_buffer[variable_end] = JAMC_NULL_CHAR;
6291
                                status = jam_get_symbol_record(
6292
                                        &statement_buffer[variable_begin], &symbol_record);
6293
                                statement_buffer[variable_end] = save_ch;
6294
 
6295
                                if (status == JAMC_SUCCESS)
6296
                                {
6297
                                        switch (symbol_record->type)
6298
                                        {
6299
                                        case JAM_INTEGER_SYMBOL:
6300
                                                assign_type = JAM_INTEGER_EXPR;
6301
                                                break;
6302
 
6303
                                        case JAM_BOOLEAN_SYMBOL:
6304
                                                assign_type = JAM_BOOLEAN_EXPR;
6305
                                                break;
6306
 
6307
                                        default:
6308
                                                status = JAMC_TYPE_MISMATCH;
6309
                                                break;
6310
                                        }
6311
                                }
6312
                        }
6313
                        else
6314
                        {
6315
                                status = JAMC_SYNTAX_ERROR;
6316
                        }
6317
                }
6318
 
6319
                /*
6320
                *       Get stack record at top of stack
6321
                */
6322
                stack_record = jam_peek_stack_record();
6323
 
6324
                /*
6325
                *       Check that stack record corresponds to a PUSH statement
6326
                */
6327
                if ((stack_record != NULL) &&
6328
                        (stack_record->type == JAM_STACK_PUSH_POP))
6329
                {
6330
                        /*
6331
                        *       Stack record is the correct type -- pop it off the stack.
6332
                        */
6333
                        push_value = stack_record->push_value;
6334
                        status = jam_pop_stack_record();
6335
 
6336
                        /*
6337
                        *       Now set the variable to the push value
6338
                        */
6339
                        if (status == JAMC_SUCCESS)
6340
                        {
6341
                                /*
6342
                                *       Check type of expression against type of variable
6343
                                *       being assigned
6344
                                */
6345
                                if ((push_value == 0) || (push_value == 1))
6346
                                {
6347
                                        value_type = JAM_INT_OR_BOOL_EXPR;
6348
                                }
6349
                                else value_type = JAM_INTEGER_EXPR;
6350
 
6351
                                if ((assign_type != JAM_ILLEGAL_EXPR_TYPE) &&
6352
                                        ((value_type == assign_type) ||
6353
                                        (value_type == JAM_INT_OR_BOOL_EXPR)))
6354
                                {
6355
                                        /*
6356
                                        *       Set the variable to the computed value
6357
                                        */
6358
                                        if (is_array)
6359
                                        {
6360
                                                if (assign_type == JAM_INTEGER_EXPR)
6361
                                                {
6362
                                                        heap_data[dim_value] = push_value;
6363
                                                }
6364
                                                else if (assign_type == JAM_BOOLEAN_EXPR)
6365
                                                {
6366
                                                        if (push_value == 0)
6367
                                                        {
6368
                                                                /* clear a single bit */
6369
                                                                heap_data[dim_value >> 5] &=
6370
                                                                        (~(unsigned long)(1L << (dim_value & 0x1f)));
6371
                                                        }
6372
                                                        else
6373
                                                        {
6374
                                                                /* set a single bit */
6375
                                                                heap_data[dim_value >> 5] |=
6376
                                                                        (1L << (dim_value & 0x1f));
6377
                                                        }
6378
                                                }
6379
                                                else status = JAMC_INTERNAL_ERROR;
6380
                                        }
6381
                                        else
6382
                                        {
6383
                                                symbol_record->value = push_value;
6384
                                        }
6385
                                }
6386
                                else
6387
                                {
6388
                                        status = JAMC_TYPE_MISMATCH;
6389
                                }
6390
                        }
6391
                }
6392
                else
6393
                {
6394
                        /*
6395
                        *       Top of stack did not have a PUSH/POP record
6396
                        */
6397
                        status = JAMC_POP_UNEXPECTED;
6398
                }
6399
        }
6400
 
6401
        return (status);
6402
}
6403
 
6404
/****************************************************************************/
6405
/*                                                                                                                                                      */
6406
 
6407
JAM_RETURN_TYPE jam_process_pre_post
6408
(
6409
        JAME_INSTRUCTION instruction_code,
6410
        char *statement_buffer
6411
)
6412
 
6413
/*                                                                                                                                                      */
6414
/*      Description:    Processes the PREDR, PREIR, POSTDR, and POSTIR                  */
6415
/*                                      statements.  These statements together replace the              */
6416
/*                                      PADDING statement from the JAM 1.0 language spec.               */
6417
/*                                                                                                                                                      */
6418
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
6419
/*                                                                                                                                                      */
6420
/****************************************************************************/
6421
{
6422
        int index = 0;
6423
        int expr_begin = 0;
6424
        int expr_end = 0;
6425
        int delimiter = 0;
6426
        char save_ch = 0;
6427
        long count = 0L;
6428
        long start_index = 0L;
6429
        long stop_index = 0L;
6430
        long *literal_array_data = NULL;
6431
        long *padding_data = NULL;
6432
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
6433
        JAMS_HEAP_RECORD *heap_record = NULL;
6434
        JAME_EXPRESSION_TYPE expr_type = JAM_ILLEGAL_EXPR_TYPE;
6435
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
6436
 
6437
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
6438
        {
6439
                return (JAMC_PHASE_ERROR);
6440
        }
6441
 
6442
        index = jam_skip_instruction_name(statement_buffer);
6443
 
6444
        /*
6445
        *       First, get the count value
6446
        */
6447
        status = jam_find_argument(&statement_buffer[index],
6448
                &expr_begin, &expr_end, &delimiter);
6449
 
6450
        expr_begin += index;
6451
        expr_end += index;
6452
        delimiter += index;
6453
 
6454
        if (status == JAMC_SUCCESS)
6455
        {
6456
                save_ch = statement_buffer[expr_end];
6457
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
6458
                status = jam_evaluate_expression(
6459
                        &statement_buffer[expr_begin], &count, &expr_type);
6460
                statement_buffer[expr_end] = save_ch;
6461
 
6462
                /*
6463
                *       Check for integer expression
6464
                */
6465
                if ((status == JAMC_SUCCESS) &&
6466
                        (expr_type != JAM_INTEGER_EXPR) &&
6467
                        (expr_type != JAM_INT_OR_BOOL_EXPR))
6468
                {
6469
                        status = JAMC_TYPE_MISMATCH;
6470
                }
6471
 
6472
                /*
6473
                *       Check the range -- count value must be between 0 and 1000
6474
                */
6475
                if ((status == JAMC_SUCCESS) &&
6476
                        ((count < 0L) || (count > 1000L)))
6477
                {
6478
                        status = JAMC_SYNTAX_ERROR;
6479
                }
6480
        }
6481
 
6482
        /*
6483
        *       Second, get the optional padding data pattern (Boolean array)
6484
        */
6485
        if (status == JAMC_SUCCESS)
6486
        {
6487
                if (statement_buffer[delimiter] == JAMC_COMMA_CHAR)
6488
                {
6489
                        expr_begin = delimiter + 1;
6490
                        expr_end = expr_begin;
6491
                        while ((jam_isspace(statement_buffer[expr_begin])) &&
6492
                                (expr_begin < JAMC_MAX_STATEMENT_LENGTH))
6493
                        {
6494
                                ++expr_begin;   /* skip over white space */
6495
                        }
6496
                        while ((statement_buffer[expr_end] != JAMC_NULL_CHAR) &&
6497
                                (expr_end < JAMC_MAX_STATEMENT_LENGTH))
6498
                        {
6499
                                ++expr_end;
6500
                        }
6501
                        while ((statement_buffer[expr_end] != JAMC_SEMICOLON_CHAR) &&
6502
                                (expr_end > 0))
6503
                        {
6504
                                --expr_end;
6505
                        }
6506
 
6507
                        if (expr_end > expr_begin)
6508
                        {
6509
                                save_ch = statement_buffer[expr_end];
6510
                                statement_buffer[expr_end] = JAMC_NULL_CHAR;
6511
                                status = jam_get_array_argument(
6512
                                        &statement_buffer[expr_begin],
6513
                                        &symbol_record,
6514
                                        &literal_array_data,
6515
                                        &start_index,
6516
                                        &stop_index,
6517
                                        0);
6518
                                statement_buffer[expr_end] = save_ch;
6519
 
6520
                                if ((status == JAMC_SUCCESS) &&
6521
                                        (stop_index < (start_index + count - 1)))
6522
                                {
6523
                                        status = JAMC_BOUNDS_ERROR;
6524
                                }
6525
 
6526
                                if (status == JAMC_SUCCESS)
6527
                                {
6528
                                        if (symbol_record != NULL)
6529
                                        {
6530
                                                heap_record = (JAMS_HEAP_RECORD *)symbol_record->value;
6531
 
6532
                                                if (heap_record != NULL)
6533
                                                {
6534
                                                        padding_data = heap_record->data;
6535
                                                }
6536
                                                else
6537
                                                {
6538
                                                        status = JAMC_INTERNAL_ERROR;
6539
                                                }
6540
                                        }
6541
                                        else if (literal_array_data != NULL)
6542
                                        {
6543
                                                padding_data = literal_array_data;
6544
                                        }
6545
                                        else
6546
                                        {
6547
                                                status = JAMC_INTERNAL_ERROR;
6548
                                        }
6549
                                }
6550
                        }
6551
                        else
6552
                        {
6553
                                status = JAMC_SYNTAX_ERROR;
6554
                        }
6555
                }
6556
                else if (statement_buffer[delimiter] != JAMC_SEMICOLON_CHAR)
6557
                {
6558
                        status = JAMC_SYNTAX_ERROR;
6559
                }
6560
        }
6561
 
6562
        /*
6563
        *       Store the new padding value
6564
        */
6565
        if (status == JAMC_SUCCESS)
6566
        {
6567
                switch (instruction_code)
6568
                {
6569
                case JAM_POSTDR_INSTR:
6570
                        status = jam_set_dr_postamble((int) count, (int) start_index,
6571
                                padding_data);
6572
                        break;
6573
 
6574
                case JAM_POSTIR_INSTR:
6575
                        status = jam_set_ir_postamble((int) count, (int) start_index,
6576
                                padding_data);
6577
                        break;
6578
 
6579
                case JAM_PREDR_INSTR:
6580
                        status = jam_set_dr_preamble((int) count, (int) start_index,
6581
                                padding_data);
6582
                        break;
6583
 
6584
                case JAM_PREIR_INSTR:
6585
                        status = jam_set_ir_preamble((int) count, (int) start_index,
6586
                                padding_data);
6587
                        break;
6588
 
6589
                default:
6590
                        status = JAMC_INTERNAL_ERROR;
6591
                        break;
6592
                }
6593
        }
6594
 
6595
        return (status);
6596
}
6597
 
6598
/****************************************************************************/
6599
/*                                                                                                                                                      */
6600
 
6601
JAM_RETURN_TYPE jam_process_print
6602
(
6603
        char *statement_buffer
6604
)
6605
 
6606
/*                                                                                                                                                      */
6607
/*      Description:    Processes a PRINT statement.  Only constant literal             */
6608
/*                                      strings and INTEGER or BOOLEAN expressions are                  */
6609
/*                                      supported.                                                                                              */
6610
/*                                                                                                                                                      */
6611
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
6612
/*                                                                                                                                                      */
6613
/****************************************************************************/
6614
{
6615
        int index = 0;
6616
        int dest_index = 0;
6617
        char *text_buffer = NULL;
6618
        int expr_begin = 0;
6619
        int expr_end = 0;
6620
        char save_ch = 0;
6621
        long expr_value = 0L;
6622
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
6623
 
6624
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
6625
        {
6626
                return (JAMC_PHASE_ERROR);
6627
        }
6628
 
6629
        text_buffer = jam_malloc(JAMC_MAX_STATEMENT_LENGTH + 1024);
6630
 
6631
        if (text_buffer == NULL)
6632
        {
6633
                status = JAMC_OUT_OF_MEMORY;
6634
        }
6635
        else
6636
        {
6637
                index = jam_skip_instruction_name(statement_buffer);
6638
        }
6639
 
6640
        while ((status == JAMC_SUCCESS) &&
6641
                (statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
6642
                (index < JAMC_MAX_STATEMENT_LENGTH))
6643
        {
6644
                /*
6645
                *       Get arguments from statement and concatenate onto string
6646
                */
6647
                if (statement_buffer[index] == JAMC_QUOTE_CHAR)
6648
                {
6649
                        /*
6650
                        *       Argument is explicit string - copy it
6651
                        */
6652
                        ++index;
6653
                        while ((statement_buffer[index] != JAMC_QUOTE_CHAR) &&
6654
                                (index < JAMC_MAX_STATEMENT_LENGTH) &&
6655
                                (dest_index < JAMC_MAX_STATEMENT_LENGTH))
6656
                        {
6657
                                text_buffer[dest_index++] = statement_buffer[index++];
6658
                        }
6659
                        text_buffer[dest_index] = '\0';
6660
 
6661
                        if (statement_buffer[index] == JAMC_QUOTE_CHAR)
6662
                        {
6663
                                /* skip over terminating quote character */
6664
                                ++index;
6665
                        }
6666
                        else
6667
                        {
6668
                                /* terminating quote character not found */
6669
                                status = JAMC_SYNTAX_ERROR;
6670
                        }
6671
                }
6672
                else if ((statement_buffer[index] == 'C') &&
6673
                        (statement_buffer[index + 1] == 'H') &&
6674
                        (statement_buffer[index + 2] == 'R') &&
6675
                        (statement_buffer[index + 3] == JAMC_DOLLAR_CHAR) &&
6676
                        (statement_buffer[index + 4] == JAMC_LPAREN_CHAR))
6677
                {
6678
                        /*
6679
                        *       Convert integer expression to character code
6680
                        */
6681
                        index += 4;     /* skip over CHR$, point to left parenthesis */
6682
                        expr_begin = index;
6683
                        expr_end = 0;
6684
 
6685
                        while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
6686
                                (statement_buffer[index] != JAMC_COMMA_CHAR) &&
6687
                                (statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
6688
                                (index < JAMC_MAX_STATEMENT_LENGTH))
6689
                        {
6690
                                ++index;
6691
                        }
6692
 
6693
                        if ((statement_buffer[index] == JAMC_COMMA_CHAR) ||
6694
                                (statement_buffer[index] == JAMC_SEMICOLON_CHAR))
6695
                        {
6696
                                expr_end = index;
6697
                        }
6698
 
6699
                        if (expr_end > expr_begin)
6700
                        {
6701
                                save_ch = statement_buffer[expr_end];
6702
                                statement_buffer[expr_end] = JAMC_NULL_CHAR;
6703
                                status = jam_evaluate_expression(
6704
                                        &statement_buffer[expr_begin], &expr_value, NULL);
6705
                                statement_buffer[expr_end] = save_ch;
6706
                        }
6707
                        else
6708
                        {
6709
                                status = JAMC_SYNTAX_ERROR;
6710
                        }
6711
 
6712
                        /*
6713
                        *       Allow any seven-bit character code (zero to 127)
6714
                        */
6715
                        if ((status == JAMC_SUCCESS) &&
6716
                                ((expr_value < 0) || (expr_value > 127)))
6717
                        {
6718
                                /* character code out of range */
6719
 
6720
                                /* instead of flagging an error, force the value to 127 */
6721
                                expr_value = 127;
6722
                        }
6723
 
6724
                        if ((status == JAMC_SUCCESS) &&
6725
                                (dest_index >= JAMC_MAX_STATEMENT_LENGTH))
6726
                        {
6727
                                /* no space in output buffer */
6728
                                status = JAMC_SYNTAX_ERROR;
6729
                        }
6730
 
6731
                        if (status == JAMC_SUCCESS)
6732
                        {
6733
                                /*
6734
                                *       Put the character code directly into the output buffer
6735
                                */
6736
                                text_buffer[dest_index++] = (char) expr_value;
6737
                                text_buffer[dest_index] = '\0';
6738
                        }
6739
                }
6740
                else
6741
                {
6742
                        /*
6743
                        *       Process it as an integer expression
6744
                        */
6745
                        expr_begin = index;
6746
                        expr_end = 0;
6747
                        status = JAMC_SYNTAX_ERROR;
6748
 
6749
                        while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
6750
                                (statement_buffer[index] != JAMC_COMMA_CHAR) &&
6751
                                (statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
6752
                                (index < JAMC_MAX_STATEMENT_LENGTH))
6753
                        {
6754
                                ++index;
6755
                        }
6756
 
6757
                        if ((statement_buffer[index] == JAMC_COMMA_CHAR) ||
6758
                                (statement_buffer[index] == JAMC_SEMICOLON_CHAR))
6759
                        {
6760
                                expr_end = index;
6761
                        }
6762
 
6763
                        if (expr_end > expr_begin)
6764
                        {
6765
                                save_ch = statement_buffer[expr_end];
6766
                                statement_buffer[expr_end] = JAMC_NULL_CHAR;
6767
                                status = jam_evaluate_expression(
6768
                                        &statement_buffer[expr_begin], &expr_value, NULL);
6769
                                statement_buffer[expr_end] = save_ch;
6770
                        }
6771
 
6772
                        if (status == JAMC_SUCCESS)
6773
                        {
6774
                                /*
6775
                                *       Convert integer and concatenate to output string
6776
                                */
6777
                                jam_ltoa(&text_buffer[dest_index], expr_value);
6778
 
6779
                                /* advance pointer to new end of string */
6780
                                while ((text_buffer[dest_index] != JAMC_NULL_CHAR) &&
6781
                                        (dest_index < JAMC_MAX_STATEMENT_LENGTH))
6782
                                {
6783
                                        ++dest_index;
6784
                                }
6785
                        }
6786
                }
6787
 
6788
                if (status == JAMC_SUCCESS)
6789
                {
6790
                        while ((jam_isspace(statement_buffer[index])) &&
6791
                                (index < JAMC_MAX_STATEMENT_LENGTH))
6792
                        {
6793
                                ++index;        /* skip over white space */
6794
                        }
6795
 
6796
                        if (statement_buffer[index] == JAMC_COMMA_CHAR)
6797
                        {
6798
                                /*
6799
                                *       Skip over comma and white space to process next argument
6800
                                */
6801
                                ++index;
6802
                                while ((jam_isspace(statement_buffer[index])) &&
6803
                                        (index < JAMC_MAX_STATEMENT_LENGTH))
6804
                                {
6805
                                        ++index;        /* skip over white space */
6806
                                }
6807
                        }
6808
                        else if (statement_buffer[index] != JAMC_SEMICOLON_CHAR)
6809
                        {
6810
                                /*
6811
                                *       If no comma to seperate arguments, statement must be
6812
                                *       terminated by a semicolon
6813
                                */
6814
                                status = JAMC_SYNTAX_ERROR;
6815
                        }
6816
                }
6817
        }
6818
 
6819
        if (status == JAMC_SUCCESS)
6820
        {
6821
                jam_message(text_buffer);
6822
        }
6823
 
6824
        if (text_buffer != NULL) jam_free(text_buffer);
6825
 
6826
        return (status);
6827
}
6828
 
6829
/****************************************************************************/
6830
/*                                                                                                                                                      */
6831
 
6832
JAM_RETURN_TYPE jam_process_procedure
6833
(
6834
        char *statement_buffer
6835
)
6836
 
6837
/*                                                                                                                                                      */
6838
/*      Description:    Initializes a procedure block.  This function does not  */
6839
/*                                      actually execute the procedure, it merely adds it to    */
6840
/*                                      the symbol table so it may be executed later.                   */
6841
/*                                                                                                                                                      */
6842
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
6843
/*                                                                                                                                                      */
6844
/****************************************************************************/
6845
{
6846
        int index = 0;
6847
        int procname_begin = 0;
6848
        int procname_end = 0;
6849
        char save_ch = 0;
6850
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
6851
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
6852
        JAMS_HEAP_RECORD *heap_record = NULL;
6853
 
6854
        if (jam_version == 0) jam_version = 2;
6855
 
6856
        if (jam_version == 1) status = JAMC_SYNTAX_ERROR;
6857
 
6858
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
6859
        {
6860
                status = JAMC_PHASE_ERROR;
6861
        }
6862
 
6863
        if ((jam_version == 2) && (jam_phase == JAM_ACTION_PHASE))
6864
        {
6865
                status = JAMC_ACTION_NOT_FOUND;
6866
        }
6867
 
6868
        if (status == JAMC_SUCCESS)
6869
        {
6870
                index = jam_skip_instruction_name(statement_buffer);
6871
 
6872
                if (jam_isalpha(statement_buffer[index]))
6873
                {
6874
                        /*
6875
                        *       Get the procedure name
6876
                        */
6877
                        procname_begin = index;
6878
                        while ((jam_is_name_char(statement_buffer[index])) &&
6879
                                (index < JAMC_MAX_STATEMENT_LENGTH))
6880
                        {
6881
                                ++index;        /* skip over procedure name */
6882
                        }
6883
                        procname_end = index;
6884
 
6885
                        save_ch = statement_buffer[procname_end];
6886
                        statement_buffer[procname_end] = JAMC_NULL_CHAR;
6887
                        status = jam_add_symbol(JAM_PROCEDURE_BLOCK,
6888
                                &statement_buffer[procname_begin], 0L,
6889
                                jam_current_statement_position);
6890
                        /* get a pointer to the symbol record */
6891
                        if (status == JAMC_SUCCESS)
6892
                        {
6893
                                status = jam_get_symbol_record(
6894
                                        &statement_buffer[procname_begin], &symbol_record);
6895
                        }
6896
                        statement_buffer[procname_end] = save_ch;
6897
 
6898
                        while ((jam_isspace(statement_buffer[index])) &&
6899
                                (index < JAMC_MAX_STATEMENT_LENGTH))
6900
                        {
6901
                                ++index;        /* skip over white space */
6902
                        }
6903
                }
6904
                else
6905
                {
6906
                        status = JAMC_SYNTAX_ERROR;
6907
                }
6908
        }
6909
 
6910
        if (status == JAMC_SUCCESS)
6911
        {
6912
                /*
6913
                *       Get list of USES blocks
6914
                */
6915
                if (statement_buffer[index] != JAMC_SEMICOLON_CHAR)
6916
                {
6917
                        if ((jam_strncmp(&statement_buffer[index], "USES", 4) == 0) &&
6918
                                (jam_isspace(statement_buffer[index + 4])))
6919
                        {
6920
                                /*
6921
                                *       Get list of USES blocks
6922
                                */
6923
                                index += 4;     /* skip over USES keyword */
6924
 
6925
                                while ((jam_isspace(statement_buffer[index])) &&
6926
                                        (index < JAMC_MAX_STATEMENT_LENGTH))
6927
                                {
6928
                                        ++index;        /* skip over white space */
6929
                                }
6930
 
6931
                                if (symbol_record->value == 0)
6932
                                {
6933
                                        status = jam_add_heap_record(symbol_record, &heap_record,
6934
                                                jam_strlen(&statement_buffer[index]) + 1);
6935
 
6936
                                        if (status == JAMC_SUCCESS)
6937
                                        {
6938
                                                symbol_record->value = (long) heap_record;
6939
                                                jam_strcpy((char *) heap_record->data,
6940
                                                        &statement_buffer[index]);
6941
                                        }
6942
                                }
6943
                                else
6944
                                {
6945
                                        heap_record = (JAMS_HEAP_RECORD *) symbol_record->value;
6946
                                }
6947
 
6948
                                /*
6949
                                *       Ignore the USES clause -- it will be processed later
6950
                                */
6951
                                while ((statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
6952
                                        (statement_buffer[index] != JAMC_NULL_CHAR) &&
6953
                                        (index < JAMC_MAX_STATEMENT_LENGTH))
6954
                                {
6955
                                        ++index;
6956
                                }
6957
                        }
6958
                        else
6959
                        {
6960
                                /* error: expected USES keyword */
6961
                                status = JAMC_SYNTAX_ERROR;
6962
                        }
6963
                }
6964
        }
6965
 
6966
        return (status);
6967
}
6968
 
6969
/****************************************************************************/
6970
/*                                                                                                                                                      */
6971
 
6972
JAM_RETURN_TYPE jam_process_push
6973
(
6974
        char *statement_buffer
6975
)
6976
 
6977
/*                                                                                                                                                      */
6978
/*      Description:    Pushes an integer or Boolean value onto the stack               */
6979
/*                                                                                                                                                      */
6980
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
6981
/*                                                                                                                                                      */
6982
/****************************************************************************/
6983
{
6984
        int index = 0;
6985
        int expr_begin = 0;
6986
        int expr_end = 0;
6987
        char save_ch = 0;
6988
        long push_value = 0L;
6989
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
6990
 
6991
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
6992
        {
6993
                return (JAMC_PHASE_ERROR);
6994
        }
6995
 
6996
        index = jam_skip_instruction_name(statement_buffer);
6997
 
6998
        /*
6999
        *       Evaluate expression for the PUSH value
7000
        */
7001
        expr_begin = index;
7002
        while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
7003
                (index < JAMC_MAX_STATEMENT_LENGTH))
7004
        {
7005
                ++index;
7006
        }
7007
        while ((statement_buffer[index] != JAMC_SEMICOLON_CHAR) && (index > 0))
7008
        {
7009
                --index;
7010
        }
7011
        expr_end = index;
7012
 
7013
        if (expr_end > expr_begin)
7014
        {
7015
                save_ch = statement_buffer[expr_end];
7016
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
7017
                status = jam_evaluate_expression(
7018
                        &statement_buffer[expr_begin], &push_value, NULL);
7019
                statement_buffer[expr_end] = save_ch;
7020
        }
7021
 
7022
        /*
7023
        *       Push the value onto the stack
7024
        */
7025
        if (status == JAMC_SUCCESS)
7026
        {
7027
                status = jam_push_pushpop_record(push_value);
7028
        }
7029
 
7030
        return (status);
7031
}
7032
 
7033
/****************************************************************************/
7034
/*                                                                                                                                                      */
7035
 
7036
JAM_RETURN_TYPE jam_process_return
7037
(
7038
        char *statement_buffer,
7039
        BOOL endproc
7040
)
7041
 
7042
/*                                                                                                                                                      */
7043
/*      Description:    Returns from subroutine by popping the return address   */
7044
/*                                      off the stack                                                                                   */
7045
/*                                                                                                                                                      */
7046
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
7047
/*                                                                                                                                                      */
7048
/****************************************************************************/
7049
{
7050
        int index = 0;
7051
        long return_position = 0L;
7052
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
7053
        JAMS_STACK_RECORD *stack_record = NULL;
7054
 
7055
        if ((jam_version == 0) && endproc) jam_version = 2;
7056
 
7057
        if ((jam_version == 0) && !endproc) jam_version = 1;
7058
 
7059
        if ((jam_version == 2) && !endproc)
7060
        {
7061
                /* Jam 2.0 does not support the RETURN statement */
7062
                return (JAMC_SYNTAX_ERROR);
7063
        }
7064
 
7065
        index = jam_skip_instruction_name(statement_buffer);
7066
 
7067
        /*
7068
        *       The semicolon must be next.
7069
        */
7070
        if (statement_buffer[index] == JAMC_SEMICOLON_CHAR)
7071
        {
7072
                /*
7073
                *       Get stack record at top of stack
7074
                */
7075
                stack_record = jam_peek_stack_record();
7076
 
7077
                /*
7078
                *       Check that stack record corresponds to a CALL statement
7079
                */
7080
                if ((stack_record != NULL) &&
7081
                        (stack_record->type == JAM_STACK_CALL_RETURN))
7082
                {
7083
                        /*
7084
                        *       Stack record is the correct type -- pop it off the stack.
7085
                        */
7086
                        return_position = stack_record->return_position;
7087
                        status = jam_pop_stack_record();
7088
 
7089
                        /*
7090
                        *       Now jump to the return address
7091
                        */
7092
                        if (status == JAMC_SUCCESS)
7093
                        {
7094
                                if (jam_seek(return_position) == 0)
7095
                                {
7096
                                        jam_current_file_position = return_position;
7097
                                }
7098
                                else
7099
                                {
7100
                                        /* seek failed */
7101
                                        status = JAMC_IO_ERROR;
7102
                                }
7103
                        }
7104
                }
7105
                else
7106
                {
7107
                        status = JAMC_RETURN_UNEXPECTED;
7108
                }
7109
        }
7110
 
7111
        return (status);
7112
}
7113
 
7114
/****************************************************************************/
7115
/*                                                                                                                                                      */
7116
 
7117
JAM_RETURN_TYPE jam_find_state_argument
7118
(
7119
        char *statement_buffer,
7120
        int *begin,
7121
        int *end,
7122
        int *delimiter
7123
)
7124
 
7125
/*                                                                                                                                                      */
7126
/*      Description:    Special version of jam_find_argument() for state paths. */
7127
/*                                      Valid delimiters are whitespace, COMMA, or SEMICOLON.   */
7128
/*                                      Returns indices of begin and end of argument, and the   */
7129
/*                                      delimiter after the argument.                                                   */
7130
/*                                                                                                                                                      */
7131
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
7132
/*                                                                                                                                                      */
7133
/****************************************************************************/
7134
{
7135
        int index = 0;
7136
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
7137
 
7138
        while ((jam_isspace(statement_buffer[index])) &&
7139
                (index < JAMC_MAX_STATEMENT_LENGTH))
7140
        {
7141
                ++index;        /* skip over white space */
7142
        }
7143
 
7144
        *begin = index;
7145
 
7146
        /* loop until white space or comma or semicolon */
7147
        while ((!jam_isspace(statement_buffer[index])) &&
7148
                (statement_buffer[index] != JAMC_NULL_CHAR) &&
7149
                (statement_buffer[index] != JAMC_COMMA_CHAR) &&
7150
                (statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
7151
                (index < JAMC_MAX_STATEMENT_LENGTH))
7152
        {
7153
                ++index;
7154
        }
7155
 
7156
        if ((!jam_isspace(statement_buffer[index])) &&
7157
                (statement_buffer[index] != JAMC_COMMA_CHAR) &&
7158
                (statement_buffer[index] != JAMC_SEMICOLON_CHAR))
7159
        {
7160
                status = JAMC_SYNTAX_ERROR;
7161
        }
7162
        else
7163
        {
7164
                *end = index;   /* end is position after last argument character */
7165
 
7166
                *delimiter = index;     /* delimiter is position of comma or semicolon */
7167
 
7168
                /* check whether a comma or semicolon comes after the white space */
7169
                while ((jam_isspace(statement_buffer[index])) &&
7170
                        (statement_buffer[index] != JAMC_NULL_CHAR) &&
7171
                        (index < JAMC_MAX_STATEMENT_LENGTH))
7172
                {
7173
                        ++index;
7174
                }
7175
 
7176
                if ((statement_buffer[index] == JAMC_COMMA_CHAR) ||
7177
                        (statement_buffer[index] == JAMC_SEMICOLON_CHAR))
7178
                {
7179
                        *delimiter = index;     /* send the real delimiter */
7180
                }
7181
 
7182
        }
7183
 
7184
        return (status);
7185
}
7186
 
7187
/****************************************************************************/
7188
/*                                                                                                                                                      */
7189
 
7190
JAM_RETURN_TYPE jam_process_state
7191
(
7192
        char *statement_buffer
7193
)
7194
 
7195
/*                                                                                                                                                      */
7196
/*      Description:    Forces JTAG chain to specified state, or through                */
7197
/*                                      specified sequence of states                                                    */
7198
/*                                                                                                                                                      */
7199
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
7200
/*                                                                                                                                                      */
7201
/****************************************************************************/
7202
{
7203
        int index = 0;
7204
        int expr_begin = 0;
7205
        int expr_end = 0;
7206
        int delimiter = 0;
7207
        char save_ch = 0;
7208
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
7209
        JAME_JTAG_STATE state = JAM_ILLEGAL_JTAG_STATE;
7210
 
7211
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
7212
        {
7213
                return (JAMC_PHASE_ERROR);
7214
        }
7215
 
7216
        index = jam_skip_instruction_name(statement_buffer);
7217
 
7218
        do
7219
        {
7220
                /*
7221
                *       Get next argument
7222
                */
7223
                status = jam_find_state_argument(&statement_buffer[index],
7224
                        &expr_begin, &expr_end, &delimiter);
7225
 
7226
                if (status == JAMC_SUCCESS)
7227
                {
7228
                        expr_begin += index;
7229
                        expr_end += index;
7230
                        delimiter += index;
7231
 
7232
                        save_ch = statement_buffer[expr_end];
7233
                        statement_buffer[expr_end] = JAMC_NULL_CHAR;
7234
                        state = jam_get_jtag_state_from_name(&statement_buffer[expr_begin]);
7235
 
7236
                        if (state == JAM_ILLEGAL_JTAG_STATE)
7237
                        {
7238
                                status = JAMC_SYNTAX_ERROR;
7239
                        }
7240
                        else
7241
                        {
7242
                                /*
7243
                                *       Go to the specified state
7244
                                */
7245
                                status = jam_goto_jtag_state(state);
7246
                                index = delimiter + 1;
7247
                        }
7248
 
7249
                        statement_buffer[expr_end] = save_ch;
7250
                }
7251
        }
7252
        while ((status == JAMC_SUCCESS) &&
7253
                ((jam_isspace(statement_buffer[delimiter])) ||
7254
                (statement_buffer[delimiter] == JAMC_COMMA_CHAR)));
7255
 
7256
        if ((status == JAMC_SUCCESS) &&
7257
                (statement_buffer[delimiter] != JAMC_SEMICOLON_CHAR))
7258
        {
7259
                status = JAMC_SYNTAX_ERROR;
7260
        }
7261
 
7262
        return (status);
7263
}
7264
 
7265
/****************************************************************************/
7266
/*                                                                                                                                                      */
7267
 
7268
JAM_RETURN_TYPE jam_process_trst
7269
(
7270
        char *statement_buffer
7271
)
7272
 
7273
/*                                                                                                                                                      */
7274
/*      Description:    Asserts the TRST signal to the JTAG hardware interface. */
7275
/*                                      NOTE: this does not guarantee a chain reset, because    */
7276
/*                                      some devices in the chain may not use the TRST signal.  */
7277
/*                                                                                                                                                      */
7278
/*                                      TRST <integer-expr> CYCLES;             -or-                                    */
7279
/*                                      TRST <integer-expr> USEC;               -or-                                    */
7280
/*                                      TRST <integer-expr> CYCLES, <integer-expr> USEC;                */
7281
/*                                                                                                                                                      */
7282
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
7283
/*                                                                                                                                                      */
7284
/****************************************************************************/
7285
{
7286
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
7287
 
7288
        if (jam_version == 0) jam_version = 2;
7289
 
7290
        if (jam_version == 1) status = JAMC_SYNTAX_ERROR;
7291
 
7292
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
7293
        {
7294
                status = JAMC_PHASE_ERROR;
7295
        }
7296
 
7297
        /* assert TRST...  NOT IMPLEMENTED YET! */
7298
 
7299
        status = jam_process_wait(statement_buffer);
7300
 
7301
        /* release TRST...  NOT IMPLEMENTED YET! */
7302
 
7303
        return (status);
7304
}
7305
 
7306
/****************************************************************************/
7307
/*                                                                                                                                                      */
7308
 
7309
JAM_RETURN_TYPE jam_process_vector_capture
7310
(
7311
        char *statement_buffer,
7312
        int signal_count,
7313
        long *dir_vector,
7314
        long *data_vector
7315
)
7316
 
7317
/*                                                                                                                                                      */
7318
/*      Description:    Applies signals to non-JTAG hardware interface, reads   */
7319
/*                                      back signals from hardware, and stores values in the    */
7320
/*                                      capture array.  The syntax for the entire statement is: */
7321
/*                                                                                                                                                      */
7322
/*                                      VECTOR <dir>, <data>, CAPTURE <capture> ;                               */
7323
/*                                                                                                                                                      */
7324
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
7325
/*                                                                                                                                                      */
7326
/****************************************************************************/
7327
{
7328
        int expr_begin = 0;
7329
        int expr_end = 0;
7330
        int delimiter = 0;
7331
        long start_index = 0L;
7332
        long stop_index = 0L;
7333
        char save_ch = 0;
7334
        long *capture_buffer = NULL;
7335
        long *literal_array_data = NULL;
7336
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
7337
        JAMS_HEAP_RECORD *heap_record = NULL;
7338
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
7339
 
7340
        /*
7341
        *       Statement buffer should contain the part of the statement string
7342
        *       after the CAPTURE keyword.
7343
        *
7344
        *       The only argument should be the capture array.
7345
        */
7346
        status = jam_find_argument(statement_buffer,
7347
                &expr_begin, &expr_end, &delimiter);
7348
 
7349
        if ((status == JAMC_SUCCESS) &&
7350
                (statement_buffer[delimiter] != JAMC_SEMICOLON_CHAR))
7351
        {
7352
                status = JAMC_SYNTAX_ERROR;
7353
        }
7354
 
7355
        if (status == JAMC_SUCCESS)
7356
        {
7357
                save_ch = statement_buffer[expr_end];
7358
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
7359
                status = jam_get_array_argument(&statement_buffer[expr_begin],
7360
                        &symbol_record, &literal_array_data,
7361
                        &start_index, &stop_index, 2);
7362
                statement_buffer[expr_end] = save_ch;
7363
        }
7364
 
7365
        if ((status == JAMC_SUCCESS) && (literal_array_data != NULL))
7366
        {
7367
                /* literal array may not be used for capture buffer */
7368
                status = JAMC_SYNTAX_ERROR;
7369
        }
7370
 
7371
        if ((status == JAMC_SUCCESS) &&
7372
                (stop_index != start_index + signal_count - 1))
7373
        {
7374
                status = JAMC_BOUNDS_ERROR;
7375
        }
7376
 
7377
        if (status == JAMC_SUCCESS)
7378
        {
7379
                if (symbol_record != NULL)
7380
                {
7381
                        heap_record = (JAMS_HEAP_RECORD *)symbol_record->value;
7382
 
7383
                        if (heap_record != NULL)
7384
                        {
7385
                                capture_buffer = heap_record->data;
7386
                        }
7387
                        else
7388
                        {
7389
                                status = JAMC_INTERNAL_ERROR;
7390
                        }
7391
                }
7392
                else
7393
                {
7394
                        status = JAMC_INTERNAL_ERROR;
7395
                }
7396
        }
7397
 
7398
        /*
7399
        *       Perform the VECTOR operation, capturing data into the heap buffer
7400
        */
7401
        if (status == JAMC_SUCCESS)
7402
        {
7403
                if (jam_vector_io(signal_count, dir_vector, data_vector,
7404
                        capture_buffer) != signal_count)
7405
                {
7406
                        status = JAMC_INTERNAL_ERROR;
7407
                }
7408
        }
7409
 
7410
        return (status);
7411
}
7412
 
7413
/****************************************************************************/
7414
/*                                                                                                                                                      */
7415
 
7416
JAM_RETURN_TYPE jam_process_vector_compare
7417
(
7418
        char *statement_buffer,
7419
        int signal_count,
7420
        long *dir_vector,
7421
        long *data_vector
7422
)
7423
 
7424
/*                                                                                                                                                      */
7425
/*      Description:    Applies signals to non-JTAG hardware interface, reads   */
7426
/*                                      back signals from hardware, and compares values to the  */
7427
/*                                      expected values.  Result is stored in a BOOLEAN                 */
7428
/*                                      variable.  The syntax for the entire statement is:              */
7429
/*                                                                                                                                                      */
7430
/*                      VECTOR <dir>, <data>, COMPARE <expected>, <mask>, <result> ;    */
7431
/*                                                                                                                                                      */
7432
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
7433
/*                                                                                                                                                      */
7434
/****************************************************************************/
7435
{
7436
        int bit = 0;
7437
        int index = 0;
7438
        int expr_begin = 0;
7439
        int expr_end = 0;
7440
        int delimiter = 0;
7441
        int actual = 0;
7442
        int expected = 0;
7443
        int mask = 0;
7444
        long comp_start_index = 0L;
7445
        long comp_stop_index = 0L;
7446
        long mask_start_index = 0L;
7447
        long mask_stop_index = 0L;
7448
        char save_ch = 0;
7449
        long *temp_array = NULL;
7450
        BOOL result = TRUE;
7451
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
7452
        JAMS_HEAP_RECORD *heap_record = NULL;
7453
        long *comp_data = NULL;
7454
        long *mask_data = NULL;
7455
        long *literal_array_data = NULL;
7456
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
7457
 
7458
        /*
7459
        *       Statement buffer should contain the part of the statement string
7460
        *       after the COMPARE keyword.
7461
        *
7462
        *       The first argument should be the compare array.
7463
        */
7464
        status = jam_find_argument(statement_buffer,
7465
                &expr_begin, &expr_end, &delimiter);
7466
 
7467
        if ((status == JAMC_SUCCESS) &&
7468
                (statement_buffer[delimiter] != JAMC_COMMA_CHAR))
7469
        {
7470
                status = JAMC_SYNTAX_ERROR;
7471
        }
7472
 
7473
        if (status == JAMC_SUCCESS)
7474
        {
7475
                save_ch = statement_buffer[expr_end];
7476
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
7477
                status = jam_get_array_argument(&statement_buffer[expr_begin],
7478
                        &symbol_record, &literal_array_data,
7479
                        &comp_start_index, &comp_stop_index, 2);
7480
                statement_buffer[expr_end] = save_ch;
7481
                index = delimiter + 1;
7482
        }
7483
 
7484
        if ((status == JAMC_SUCCESS) &&
7485
                (literal_array_data != NULL) &&
7486
                (comp_start_index == 0) &&
7487
                (comp_stop_index > signal_count - 1))
7488
        {
7489
                comp_stop_index = signal_count - 1;
7490
        }
7491
 
7492
        if ((status == JAMC_SUCCESS) &&
7493
                (comp_stop_index != comp_start_index + signal_count - 1))
7494
        {
7495
                status = JAMC_BOUNDS_ERROR;
7496
        }
7497
 
7498
        if (status == JAMC_SUCCESS)
7499
        {
7500
                if (symbol_record != NULL)
7501
                {
7502
                        heap_record = (JAMS_HEAP_RECORD *)symbol_record->value;
7503
 
7504
                        if (heap_record != NULL)
7505
                        {
7506
                                comp_data = heap_record->data;
7507
                        }
7508
                        else
7509
                        {
7510
                                status = JAMC_INTERNAL_ERROR;
7511
                        }
7512
                }
7513
                else if (literal_array_data != NULL)
7514
                {
7515
                        comp_data = literal_array_data;
7516
                }
7517
                else
7518
                {
7519
                        status = JAMC_INTERNAL_ERROR;
7520
                }
7521
        }
7522
 
7523
        /*
7524
        *       Find the next argument -- should be the mask array
7525
        */
7526
        if (status == JAMC_SUCCESS)
7527
        {
7528
                status = jam_find_argument(&statement_buffer[index],
7529
                        &expr_begin, &expr_end, &delimiter);
7530
 
7531
                expr_begin += index;
7532
                expr_end += index;
7533
                delimiter += index;
7534
        }
7535
 
7536
        if ((status == JAMC_SUCCESS) &&
7537
                (statement_buffer[delimiter] != JAMC_COMMA_CHAR))
7538
        {
7539
                status = JAMC_SYNTAX_ERROR;
7540
        }
7541
 
7542
        if (status == JAMC_SUCCESS)
7543
        {
7544
                save_ch = statement_buffer[expr_end];
7545
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
7546
                status = jam_get_array_argument(&statement_buffer[expr_begin],
7547
                        &symbol_record, &literal_array_data,
7548
                        &mask_start_index, &mask_stop_index, 3);
7549
                statement_buffer[expr_end] = save_ch;
7550
                index = delimiter + 1;
7551
        }
7552
 
7553
        if ((status == JAMC_SUCCESS) &&
7554
                (literal_array_data != NULL) &&
7555
                (mask_start_index == 0) &&
7556
                (mask_stop_index > signal_count - 1))
7557
        {
7558
                mask_stop_index = signal_count - 1;
7559
        }
7560
 
7561
        if ((status == JAMC_SUCCESS) &&
7562
                (mask_stop_index != mask_start_index + signal_count - 1))
7563
        {
7564
                status = JAMC_BOUNDS_ERROR;
7565
        }
7566
 
7567
        if (status == JAMC_SUCCESS)
7568
        {
7569
                if (symbol_record != NULL)
7570
                {
7571
                        heap_record = (JAMS_HEAP_RECORD *)symbol_record->value;
7572
 
7573
                        if (heap_record != NULL)
7574
                        {
7575
                                mask_data = heap_record->data;
7576
                        }
7577
                        else
7578
                        {
7579
                                status = JAMC_INTERNAL_ERROR;
7580
                        }
7581
                }
7582
                else if (literal_array_data != NULL)
7583
                {
7584
                        mask_data = literal_array_data;
7585
                }
7586
                else
7587
                {
7588
                        status = JAMC_INTERNAL_ERROR;
7589
                }
7590
        }
7591
 
7592
        /*
7593
        *       Find the third argument -- should be the result variable
7594
        */
7595
        if (status == JAMC_SUCCESS)
7596
        {
7597
                status = jam_find_argument(&statement_buffer[index],
7598
                        &expr_begin, &expr_end, &delimiter);
7599
 
7600
                expr_begin += index;
7601
                expr_end += index;
7602
                delimiter += index;
7603
        }
7604
 
7605
        if ((status == JAMC_SUCCESS) &&
7606
                (statement_buffer[delimiter] != JAMC_SEMICOLON_CHAR))
7607
        {
7608
                status = JAMC_SYNTAX_ERROR;
7609
        }
7610
 
7611
        /*
7612
        *       Result must be a scalar Boolean variable
7613
        */
7614
        if (status == JAMC_SUCCESS)
7615
        {
7616
                save_ch = statement_buffer[expr_end];
7617
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
7618
                status = jam_get_symbol_record(&statement_buffer[expr_begin],
7619
                        &symbol_record);
7620
                statement_buffer[expr_end] = save_ch;
7621
 
7622
                if ((status == JAMC_SUCCESS) &&
7623
                        (symbol_record->type != JAM_BOOLEAN_SYMBOL))
7624
                {
7625
                        status = JAMC_TYPE_MISMATCH;
7626
                }
7627
        }
7628
 
7629
        /*
7630
        *       Find some free memory on the heap
7631
        */
7632
        if (status == JAMC_SUCCESS)
7633
        {
7634
                temp_array = jam_get_temp_workspace((signal_count >> 3) + 4);
7635
 
7636
                if (temp_array == NULL)
7637
                {
7638
                        status = JAMC_OUT_OF_MEMORY;
7639
                }
7640
        }
7641
 
7642
        /*
7643
        *       Do the VECTOR operation, saving the result in temp_array
7644
        */
7645
        if (status == JAMC_SUCCESS)
7646
        {
7647
                if (jam_vector_io(signal_count, dir_vector, data_vector,
7648
                        temp_array) != signal_count)
7649
                {
7650
                        status = JAMC_INTERNAL_ERROR;
7651
                }
7652
        }
7653
 
7654
        /*
7655
        *       Mask the data and do the comparison
7656
        */
7657
        if (status == JAMC_SUCCESS)
7658
        {
7659
                for (bit = 0; (bit < signal_count) && result; ++bit)
7660
                {
7661
                        actual = temp_array[bit >> 5] & (1L << (bit & 0x1f)) ? 1 : 0;
7662
                        expected = comp_data[(bit + comp_start_index) >> 5]
7663
                                & (1L << ((bit + comp_start_index) & 0x1f)) ? 1 : 0;
7664
                        mask = mask_data[(bit + mask_start_index) >> 5]
7665
                                & (1L << ((bit + mask_start_index) & 0x1f)) ? 1 : 0;
7666
 
7667
                        if ((actual & mask) != (expected & mask))
7668
                        {
7669
                                result = FALSE;
7670
                        }
7671
                }
7672
 
7673
                symbol_record->value = result ? 1L : 0L;
7674
        }
7675
 
7676
        if (temp_array != NULL) jam_free_temp_workspace(temp_array);
7677
 
7678
        return (status);
7679
}
7680
 
7681
/****************************************************************************/
7682
/*                                                                                                                                                      */
7683
 
7684
JAM_RETURN_TYPE jam_process_vector
7685
(
7686
        char *statement_buffer
7687
)
7688
 
7689
/*                                                                                                                                                      */
7690
/*      Description:    Applies signals to non-JTAG hardware interface.  There  */
7691
/*                                      are three versions:  output only, compare, and capture. */
7692
/*                                                                                                                                                      */
7693
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
7694
/*                                                                                                                                                      */
7695
/****************************************************************************/
7696
{
7697
        /* syntax:  VECTOR <dir>, <data>; */
7698
        /* or:      VECTOR <dir>, <data>, CAPTURE <capture> ; */
7699
        /* or:      VECTOR <dir>, <data>, COMPARE <expected>, <mask>, <result> ; */
7700
 
7701
        int index = 0;
7702
        int expr_begin = 0;
7703
        int expr_end = 0;
7704
        int delimiter = 0;
7705
        long dir_start_index = 0L;
7706
        long dir_stop_index = 0L;
7707
        long data_start_index = 0L;
7708
        long data_stop_index = 0L;
7709
        char save_ch = 0;
7710
        long *dir_vector = NULL;
7711
        long *data_vector = NULL;
7712
        long *literal_array_data = NULL;
7713
        JAMS_SYMBOL_RECORD *symbol_record = NULL;
7714
        JAMS_HEAP_RECORD *heap_record = NULL;
7715
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
7716
 
7717
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
7718
        {
7719
                return (JAMC_PHASE_ERROR);
7720
        }
7721
 
7722
        index = jam_skip_instruction_name(statement_buffer);
7723
 
7724
        /*
7725
        *       Get direction vector
7726
        */
7727
        status = jam_find_argument(&statement_buffer[index],
7728
                &expr_begin, &expr_end, &delimiter);
7729
 
7730
        expr_begin += index;
7731
        expr_end += index;
7732
        delimiter += index;
7733
 
7734
        if ((status == JAMC_SUCCESS) &&
7735
                (statement_buffer[delimiter] != JAMC_COMMA_CHAR))
7736
        {
7737
                status = JAMC_SYNTAX_ERROR;
7738
        }
7739
 
7740
        if (status == JAMC_SUCCESS)
7741
        {
7742
                save_ch = statement_buffer[expr_end];
7743
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
7744
                status = jam_get_array_argument(&statement_buffer[expr_begin],
7745
                        &symbol_record, &literal_array_data,
7746
                        &dir_start_index, &dir_stop_index, 0);
7747
                statement_buffer[expr_end] = save_ch;
7748
        }
7749
 
7750
        if (status == JAMC_SUCCESS)
7751
        {
7752
                if (symbol_record != NULL)
7753
                {
7754
                        heap_record = (JAMS_HEAP_RECORD *)symbol_record->value;
7755
 
7756
                        if (heap_record != NULL)
7757
                        {
7758
                                dir_vector = heap_record->data;
7759
                        }
7760
                        else
7761
                        {
7762
                                status = JAMC_INTERNAL_ERROR;
7763
                        }
7764
                }
7765
                else if (literal_array_data != NULL)
7766
                {
7767
                        dir_vector = literal_array_data;
7768
                }
7769
                else
7770
                {
7771
                        status = JAMC_INTERNAL_ERROR;
7772
                }
7773
        }
7774
 
7775
        /*
7776
        *       Get data vector
7777
        */
7778
        if (status == JAMC_SUCCESS)
7779
        {
7780
                index = delimiter + 1;
7781
                status = jam_find_argument(&statement_buffer[index],
7782
                        &expr_begin, &expr_end, &delimiter);
7783
 
7784
                expr_begin += index;
7785
                expr_end += index;
7786
                delimiter += index;
7787
        }
7788
 
7789
        if ((status == JAMC_SUCCESS) &&
7790
                (statement_buffer[delimiter] != JAMC_COMMA_CHAR) &&
7791
                (statement_buffer[delimiter] != JAMC_SEMICOLON_CHAR))
7792
        {
7793
                status = JAMC_SYNTAX_ERROR;
7794
        }
7795
 
7796
        if (status == JAMC_SUCCESS)
7797
        {
7798
                save_ch = statement_buffer[expr_end];
7799
                statement_buffer[expr_end] = JAMC_NULL_CHAR;
7800
                status = jam_get_array_argument(&statement_buffer[expr_begin],
7801
                        &symbol_record, &literal_array_data,
7802
                        &data_start_index, &data_stop_index, 1);
7803
                statement_buffer[expr_end] = save_ch;
7804
        }
7805
 
7806
        if (status == JAMC_SUCCESS)
7807
        {
7808
                if (symbol_record != NULL)
7809
                {
7810
                        heap_record = (JAMS_HEAP_RECORD *)symbol_record->value;
7811
 
7812
                        if (heap_record != NULL)
7813
                        {
7814
                                data_vector = heap_record->data;
7815
                        }
7816
                        else
7817
                        {
7818
                                status = JAMC_INTERNAL_ERROR;
7819
                        }
7820
                }
7821
                else if (literal_array_data != NULL)
7822
                {
7823
                        data_vector = literal_array_data;
7824
                }
7825
                else
7826
                {
7827
                        status = JAMC_INTERNAL_ERROR;
7828
                }
7829
        }
7830
 
7831
        if ((status == JAMC_SUCCESS) &&
7832
                (statement_buffer[delimiter] == JAMC_SEMICOLON_CHAR))
7833
        {
7834
                /*
7835
                *       Do a simple VECTOR operation -- no capture or compare
7836
                */
7837
                if (jam_vector_io(jam_vector_signal_count,
7838
                        dir_vector, data_vector, NULL) != jam_vector_signal_count)
7839
                {
7840
                        status = JAMC_INTERNAL_ERROR;
7841
                }
7842
        }
7843
        else if ((status == JAMC_SUCCESS) &&
7844
                (statement_buffer[delimiter] == JAMC_COMMA_CHAR))
7845
        {
7846
                /*
7847
                *       Delimiter was a COMMA, so look for CAPTURE or COMPARE keyword
7848
                */
7849
                index = delimiter + 1;
7850
                while (jam_isspace(statement_buffer[index]))
7851
                {
7852
                        ++index;        /* skip over white space */
7853
                }
7854
 
7855
                if ((jam_strncmp(&statement_buffer[index], "CAPTURE", 7) == 0) &&
7856
                        (jam_isspace(statement_buffer[index + 7])))
7857
                {
7858
                        /*
7859
                        *       Do a VECTOR with capture
7860
                        */
7861
                        status = jam_process_vector_capture(&statement_buffer[index + 8],
7862
                                jam_vector_signal_count, dir_vector, data_vector);
7863
                }
7864
                else if ((jam_strncmp(&statement_buffer[index], "COMPARE", 7) == 0) &&
7865
                        (jam_isspace(statement_buffer[index + 7])))
7866
                {
7867
                        /*
7868
                        *       Do a VECTOR with compare
7869
                        */
7870
                        status = jam_process_vector_compare(&statement_buffer[index + 8],
7871
                                jam_vector_signal_count, dir_vector, data_vector);
7872
                }
7873
                else
7874
                {
7875
                        status = JAMC_SYNTAX_ERROR;
7876
                }
7877
        }
7878
 
7879
        return (status);
7880
}
7881
 
7882
/****************************************************************************/
7883
/*                                                                                                                                                      */
7884
 
7885
#define JAMC_MAX_VECTOR_SIGNALS 256
7886
 
7887
JAM_RETURN_TYPE jam_process_vmap
7888
(
7889
        char *statement_buffer
7890
)
7891
 
7892
/*                                                                                                                                                      */
7893
/*      Description:    Sets signal mapping for non-JTAG hardware interface.    */
7894
/*                                                                                                                                                      */
7895
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
7896
/*                                                                                                                                                      */
7897
/****************************************************************************/
7898
{
7899
        int index = 0;
7900
        int signal_count = 0;
7901
        char *signal_names[JAMC_MAX_VECTOR_SIGNALS];
7902
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
7903
 
7904
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
7905
        {
7906
                return (JAMC_PHASE_ERROR);
7907
        }
7908
 
7909
        index = jam_skip_instruction_name(statement_buffer);
7910
 
7911
        while ((statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
7912
                (status == JAMC_SUCCESS) &&
7913
                (index < JAMC_MAX_STATEMENT_LENGTH) &&
7914
                (signal_count < JAMC_MAX_VECTOR_SIGNALS))
7915
        {
7916
                /*
7917
                *       Get signal names from statement, add NULL terminination characters,
7918
                *       and save a pointer to each name
7919
                */
7920
                if (statement_buffer[index] == JAMC_QUOTE_CHAR)
7921
                {
7922
                        ++index;
7923
                        signal_names[signal_count] = &statement_buffer[index];
7924
                        while ((statement_buffer[index] != JAMC_QUOTE_CHAR) &&
7925
                                (index < JAMC_MAX_STATEMENT_LENGTH))
7926
                        {
7927
                                ++index;
7928
                        }
7929
                        if (statement_buffer[index] == JAMC_QUOTE_CHAR)
7930
                        {
7931
                                statement_buffer[index] = JAMC_NULL_CHAR;
7932
                                ++index;
7933
 
7934
                                if (*signal_names[signal_count] == JAMC_NULL_CHAR)
7935
                                {
7936
                                        /* check for empty string */
7937
                                        status = JAMC_SYNTAX_ERROR;
7938
                                }
7939
                                else
7940
                                {
7941
                                        ++signal_count;
7942
                                }
7943
                        }
7944
                        else
7945
                        {
7946
                                /* terminating quote character not found */
7947
                                status = JAMC_SYNTAX_ERROR;
7948
                        }
7949
                }
7950
                else
7951
                {
7952
                        /* argument is not a quoted string */
7953
                        status = JAMC_SYNTAX_ERROR;
7954
                }
7955
 
7956
                if (status == JAMC_SUCCESS)
7957
                {
7958
                        while ((jam_isspace(statement_buffer[index])) &&
7959
                                (index < JAMC_MAX_STATEMENT_LENGTH))
7960
                        {
7961
                                ++index;        /* skip over white space */
7962
                        }
7963
 
7964
                        if (statement_buffer[index] == JAMC_COMMA_CHAR)
7965
                        {
7966
                                /*
7967
                                *       Skip over comma and white space to process next argument
7968
                                */
7969
                                ++index;
7970
                                while ((jam_isspace(statement_buffer[index])) &&
7971
                                        (index < JAMC_MAX_STATEMENT_LENGTH))
7972
                                {
7973
                                        ++index;        /* skip over white space */
7974
                                }
7975
                        }
7976
                        else if (statement_buffer[index] != JAMC_SEMICOLON_CHAR)
7977
                        {
7978
                                /*
7979
                                *       If no comma to seperate arguments, statement must be
7980
                                *       terminated by a semicolon
7981
                                */
7982
                                status = JAMC_SYNTAX_ERROR;
7983
                        }
7984
                }
7985
        }
7986
 
7987
        if ((status == JAMC_SUCCESS) &&
7988
                (statement_buffer[index] != JAMC_SEMICOLON_CHAR))
7989
        {
7990
                /* exceeded statement buffer length or signal count limit */
7991
                status = JAMC_SYNTAX_ERROR;
7992
        }
7993
 
7994
        if (status == JAMC_SUCCESS)
7995
        {
7996
                if (jam_version == 2)
7997
                {
7998
                        /* For Jam 2.0, reverse the order of the signal names */
7999
                        for (index = signal_count / 2; index > 0; --index)
8000
                        {
8001
                                signal_names[signal_count] = signal_names[index - 1];
8002
                                signal_names[index - 1] = signal_names[signal_count - index];
8003
                                signal_names[signal_count - index] = signal_names[signal_count];
8004
                        }
8005
                }
8006
 
8007
                if (jam_vector_map(signal_count, signal_names) == signal_count)
8008
                {
8009
                        jam_vector_signal_count = signal_count;
8010
                }
8011
                else
8012
                {
8013
                        status = JAMC_VECTOR_MAP_FAILED;
8014
                        jam_vector_signal_count = 0;
8015
                }
8016
        }
8017
 
8018
        return (status);
8019
}
8020
 
8021
/****************************************************************************/
8022
/*                                                                                                                                                      */
8023
 
8024
JAM_RETURN_TYPE jam_process_wait_cycles
8025
(
8026
        char *statement_buffer,
8027
        JAME_JTAG_STATE wait_state
8028
)
8029
 
8030
/*                                                                                                                                                      */
8031
/*      Description:    Causes JTAG hardware to loop in the specified stable    */
8032
/*                                      state for the specified number of TCK clock cycles.             */
8033
/*                                                                                                                                                      */
8034
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
8035
/*                                                                                                                                                      */
8036
/****************************************************************************/
8037
{
8038
        long cycles = 0L;
8039
        JAME_EXPRESSION_TYPE expr_type = JAM_ILLEGAL_EXPR_TYPE;
8040
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
8041
 
8042
        /*
8043
        *       Call parser to evaluate expression
8044
        */
8045
        status = jam_evaluate_expression(statement_buffer, &cycles, &expr_type);
8046
 
8047
        /*
8048
        *       Check for integer expression
8049
        */
8050
        if ((status == JAMC_SUCCESS) &&
8051
                (expr_type != JAM_INTEGER_EXPR) &&
8052
                (expr_type != JAM_INT_OR_BOOL_EXPR))
8053
        {
8054
                status = JAMC_TYPE_MISMATCH;
8055
        }
8056
 
8057
        /*
8058
        *       Do the JTAG hardware operation
8059
        */
8060
        if (status == JAMC_SUCCESS)
8061
        {
8062
                status = jam_do_wait_cycles(cycles, wait_state);
8063
        }
8064
 
8065
        return (status);
8066
}
8067
 
8068
/****************************************************************************/
8069
/*                                                                                                                                                      */
8070
 
8071
JAM_RETURN_TYPE jam_process_wait_microseconds
8072
(
8073
        char *statement_buffer,
8074
        JAME_JTAG_STATE wait_state
8075
)
8076
 
8077
/*                                                                                                                                                      */
8078
/*      Description:    Causes JTAG hardware to sit in the specified stable             */
8079
/*                                      state for the specified duration of real time.                  */
8080
/*                                                                                                                                                      */
8081
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
8082
/*                                                                                                                                                      */
8083
/****************************************************************************/
8084
{
8085
        long microseconds = 0L;
8086
        JAME_EXPRESSION_TYPE expr_type = JAM_ILLEGAL_EXPR_TYPE;
8087
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
8088
 
8089
        /*
8090
        *       Call parser to evaluate expression
8091
        */
8092
        status = jam_evaluate_expression(statement_buffer, &microseconds,
8093
                &expr_type);
8094
 
8095
        /*
8096
        *       Check for integer expression
8097
        */
8098
        if ((status == JAMC_SUCCESS) &&
8099
                (expr_type != JAM_INTEGER_EXPR) &&
8100
                (expr_type != JAM_INT_OR_BOOL_EXPR))
8101
        {
8102
                status = JAMC_TYPE_MISMATCH;
8103
        }
8104
 
8105
        /*
8106
        *       Do the JTAG hardware operation
8107
        */
8108
        if (status == JAMC_SUCCESS)
8109
        {
8110
                status = jam_do_wait_microseconds(microseconds, wait_state);
8111
        }
8112
 
8113
        return (status);
8114
}
8115
 
8116
/****************************************************************************/
8117
/*                                                                                                                                                      */
8118
 
8119
JAM_RETURN_TYPE jam_process_wait
8120
(
8121
        char *statement_buffer
8122
)
8123
 
8124
/*                                                                                                                                                      */
8125
/*      Description:    Processes WAIT statement                                                                */
8126
/*                                                                                                                                                      */
8127
/*                                      syntax: WAIT [<wait-state>,] [<integer-expr> CYCLES,]   */
8128
/*                                                               [<integer-expr> USEC,] [<end-state>];          */
8129
/*                                                                                                                                                      */
8130
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
8131
/*                                                                                                                                                      */
8132
/****************************************************************************/
8133
{
8134
        int index = 0;
8135
        int expr_begin = 0;
8136
        int expr_end = 0;
8137
        int delimiter = 0;
8138
        char save_ch = 0;
8139
        BOOL found_wait_state = FALSE;
8140
        BOOL found_condition = FALSE;
8141
        BOOL found_end_state = FALSE;
8142
        JAME_JTAG_STATE state = JAM_ILLEGAL_JTAG_STATE;
8143
        JAME_JTAG_STATE wait_state = IDLE;
8144
        JAME_JTAG_STATE end_state = IDLE;
8145
        JAM_RETURN_TYPE status = JAMC_SYNTAX_ERROR;
8146
 
8147
        if ((jam_version == 2) && (jam_phase != JAM_PROCEDURE_PHASE))
8148
        {
8149
                return (JAMC_PHASE_ERROR);
8150
        }
8151
 
8152
        index = jam_skip_instruction_name(statement_buffer);
8153
 
8154
        do
8155
        {
8156
                /*
8157
                *       Get next argument
8158
                */
8159
                status = jam_find_argument(&statement_buffer[index],
8160
                        &expr_begin, &expr_end, &delimiter);
8161
 
8162
                if (status == JAMC_SUCCESS)
8163
                {
8164
                        expr_begin += index;
8165
                        expr_end += index;
8166
                        delimiter += index;
8167
 
8168
                        save_ch = statement_buffer[expr_end];
8169
                        statement_buffer[expr_end] = JAMC_NULL_CHAR;
8170
                        state = jam_get_jtag_state_from_name(&statement_buffer[expr_begin]);
8171
 
8172
                        if (state == JAM_ILLEGAL_JTAG_STATE)
8173
                        {
8174
                                /* first argument was not a JTAG state name */
8175
                                index = expr_end - 1;
8176
                                while ((index > expr_begin) &&
8177
                                        (!jam_isspace(statement_buffer[index])))
8178
                                {
8179
                                        --index;
8180
                                }
8181
                                if ((index > expr_begin) &&
8182
                                        (jam_isspace(statement_buffer[index])))
8183
                                {
8184
                                        ++index;
8185
 
8186
                                        if (jam_strcmp(&statement_buffer[index], "CYCLES") == 0)
8187
                                        {
8188
                                                statement_buffer[index] = JAMC_NULL_CHAR;
8189
                                                status = jam_process_wait_cycles(
8190
                                                        &statement_buffer[expr_begin], wait_state);
8191
                                                statement_buffer[index] = 'C';
8192
                                        }
8193
                                        else if (jam_strcmp(&statement_buffer[index], "USEC") == 0)
8194
                                        {
8195
                                                statement_buffer[index] = JAMC_NULL_CHAR;
8196
                                                status = jam_process_wait_microseconds(
8197
                                                        &statement_buffer[expr_begin], wait_state);
8198
                                                statement_buffer[index] = 'U';
8199
                                        }
8200
                                        else
8201
                                        {
8202
                                                status = JAMC_SYNTAX_ERROR;
8203
                                        }
8204
 
8205
                                        found_condition = TRUE;
8206
                                }
8207
 
8208
                                index = delimiter + 1;
8209
                        }
8210
                        else
8211
                        {
8212
                                /* argument was a JTAG state name */
8213
                                if ((!found_condition) && (!found_wait_state))
8214
                                {
8215
                                        wait_state = state;
8216
                                        found_wait_state = TRUE;
8217
                                }
8218
                                else if ((found_condition) && (!found_end_state))
8219
                                {
8220
                                        end_state = state;
8221
                                        found_end_state = TRUE;
8222
                                }
8223
                                else
8224
                                {
8225
                                        status = JAMC_SYNTAX_ERROR;
8226
                                }
8227
 
8228
                                index = delimiter + 1;
8229
                        }
8230
 
8231
                        statement_buffer[expr_end] = save_ch;
8232
                }
8233
        }
8234
        while ((status == JAMC_SUCCESS) &&
8235
                (statement_buffer[delimiter] == JAMC_COMMA_CHAR));
8236
 
8237
        if ((status == JAMC_SUCCESS) &&
8238
                (statement_buffer[delimiter] != JAMC_SEMICOLON_CHAR))
8239
        {
8240
                status = JAMC_SYNTAX_ERROR;
8241
        }
8242
 
8243
        if ((status == JAMC_SUCCESS) && (!found_condition))
8244
        {
8245
                /* there must have been at least one condition argument */
8246
                status = JAMC_SYNTAX_ERROR;
8247
        }
8248
 
8249
        /*
8250
        *       If end state was specified, go there
8251
        */
8252
        if ((status == JAMC_SUCCESS) && (end_state != IDLE))
8253
        {
8254
                status = jam_goto_jtag_state(end_state);
8255
        }
8256
 
8257
        return (status);
8258
}
8259
 
8260
void jam_free_literal_aca_buffers(void)
8261
{
8262
        int i;
8263
 
8264
        for (i = 0; i < JAMC_MAX_LITERAL_ARRAYS; ++i)
8265
        {
8266
                if (jam_literal_aca_buffer[i] != NULL)
8267
                {
8268
                        jam_free(jam_literal_aca_buffer[i]);
8269
                        jam_literal_aca_buffer[i] = NULL;
8270
                }
8271
        }
8272
}
8273
 
8274
/****************************************************************************/
8275
/*                                                                                                                                                      */
8276
 
8277
JAM_RETURN_TYPE jam_execute_statement
8278
(
8279
        char *statement_buffer,
8280
        BOOL *done,
8281
        BOOL *reuse_statement_buffer,
8282
        int *exit_code
8283
)
8284
 
8285
/*                                                                                                                                                      */
8286
/*      Description:    Processes a statement by calling the processing                 */
8287
/*                                      sub-function which corresponds to the instruction type  */
8288
/*                                                                                                                                                      */
8289
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
8290
/*                                                                                                                                                      */
8291
/****************************************************************************/
8292
{
8293
        JAME_INSTRUCTION instruction_code = JAM_ILLEGAL_INSTR;
8294
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
8295
 
8296
        instruction_code = jam_get_instruction(statement_buffer);
8297
 
8298
        switch (instruction_code)
8299
        {
8300
        case JAM_ACTION_INSTR:
8301
                status = jam_process_action(statement_buffer, done, exit_code);
8302
                break;
8303
 
8304
        case JAM_BOOLEAN_INSTR:
8305
                status = jam_process_boolean(statement_buffer);
8306
                break;
8307
 
8308
        case JAM_CALL_INSTR:
8309
                status = jam_process_call_or_goto(statement_buffer, TRUE, done,
8310
                        exit_code);
8311
                break;
8312
 
8313
        case JAM_CRC_INSTR:
8314
                status = JAMC_PHASE_ERROR;
8315
                break;
8316
 
8317
        case JAM_DATA_INSTR:
8318
                status = jam_process_data(statement_buffer);
8319
                break;
8320
 
8321
        case JAM_DRSCAN_INSTR:
8322
                status = jam_process_drscan(statement_buffer);
8323
                break;
8324
 
8325
        case JAM_DRSTOP_INSTR:
8326
                status = jam_process_drstop(statement_buffer);
8327
                break;
8328
 
8329
        case JAM_ENDDATA_INSTR:
8330
                status = jam_process_return(statement_buffer, TRUE);
8331
                break;
8332
 
8333
        case JAM_ENDPROC_INSTR:
8334
                status = jam_process_return(statement_buffer, TRUE);
8335
                break;
8336
 
8337
        case JAM_EXIT_INSTR:
8338
                status = jam_process_exit(statement_buffer, done, exit_code);
8339
                break;
8340
 
8341
        case JAM_EXPORT_INSTR:
8342
                status = jam_process_export(statement_buffer);
8343
                break;
8344
 
8345
        case JAM_FOR_INSTR:
8346
                status = jam_process_for(statement_buffer);
8347
                break;
8348
 
8349
        case JAM_FREQUENCY_INSTR:
8350
                status = jam_process_frequency(statement_buffer);
8351
                break;
8352
 
8353
        case JAM_GOTO_INSTR:
8354
                status = jam_process_call_or_goto(statement_buffer, FALSE, done,
8355
                        exit_code);
8356
                break;
8357
 
8358
        case JAM_IF_INSTR:
8359
                status = jam_process_if(statement_buffer, reuse_statement_buffer);
8360
                break;
8361
 
8362
        case JAM_INTEGER_INSTR:
8363
                status = jam_process_integer(statement_buffer);
8364
                break;
8365
 
8366
        case JAM_IRSCAN_INSTR:
8367
                status = jam_process_irscan(statement_buffer);
8368
                break;
8369
 
8370
        case JAM_IRSTOP_INSTR:
8371
                status = jam_process_irstop(statement_buffer);
8372
                break;
8373
 
8374
        case JAM_LET_INSTR:
8375
                status = jam_process_assignment(statement_buffer, TRUE);
8376
                break;
8377
 
8378
        case JAM_NEXT_INSTR:
8379
                status = jam_process_next(statement_buffer);
8380
                break;
8381
 
8382
        case JAM_NOTE_INSTR:
8383
                /* ignore NOTE statements during execution */
8384
                if (jam_phase == JAM_UNKNOWN_PHASE)
8385
                {
8386
                        jam_phase = JAM_NOTE_PHASE;
8387
                }
8388
                if ((jam_version == 2) && (jam_phase != JAM_NOTE_PHASE))
8389
                {
8390
                        status = JAMC_PHASE_ERROR;
8391
                }
8392
                break;
8393
 
8394
        case JAM_PADDING_INSTR:
8395
                status = jam_process_padding(statement_buffer);
8396
                break;
8397
 
8398
        case JAM_POP_INSTR:
8399
                status = jam_process_pop(statement_buffer);
8400
                break;
8401
 
8402
        case JAM_POSTDR_INSTR:
8403
        case JAM_POSTIR_INSTR:
8404
        case JAM_PREDR_INSTR:
8405
        case JAM_PREIR_INSTR:
8406
                status = jam_process_pre_post(instruction_code, statement_buffer);
8407
                break;
8408
 
8409
        case JAM_PRINT_INSTR:
8410
                status = jam_process_print(statement_buffer);
8411
                break;
8412
 
8413
        case JAM_PROCEDURE_INSTR:
8414
                status = jam_process_procedure(statement_buffer);
8415
                break;
8416
 
8417
        case JAM_PUSH_INSTR:
8418
                status = jam_process_push(statement_buffer);
8419
                break;
8420
 
8421
        case JAM_REM_INSTR:
8422
                /* ignore REM statements during execution */
8423
                break;
8424
 
8425
        case JAM_RETURN_INSTR:
8426
                status = jam_process_return(statement_buffer, FALSE);
8427
                break;
8428
 
8429
        case JAM_STATE_INSTR:
8430
                status = jam_process_state(statement_buffer);
8431
                break;
8432
 
8433
        case JAM_TRST_INSTR:
8434
                status = jam_process_trst(statement_buffer);
8435
                break;
8436
 
8437
        case JAM_VECTOR_INSTR:
8438
                status = jam_process_vector(statement_buffer);
8439
                break;
8440
 
8441
        case JAM_VMAP_INSTR:
8442
                status = jam_process_vmap(statement_buffer);
8443
                break;
8444
 
8445
        case JAM_WAIT_INSTR:
8446
                status = jam_process_wait(statement_buffer);
8447
                break;
8448
 
8449
        default:
8450
                if ((jam_version == 2) && (jam_check_assignment(statement_buffer)))
8451
                {
8452
                        status = jam_process_assignment(statement_buffer, FALSE);
8453
                }
8454
                else
8455
                {
8456
                        status = JAMC_SYNTAX_ERROR;
8457
                }
8458
                break;
8459
        }
8460
 
8461
        jam_free_literal_aca_buffers();
8462
 
8463
        return (status);
8464
}
8465
 
8466
/****************************************************************************/
8467
/*                                                                                                                                                      */
8468
 
8469
long jam_get_line_of_position
8470
(
8471
        long position
8472
)
8473
 
8474
/*                                                                                                                                                      */
8475
/*      Description:    Determines the line number in the input stream which    */
8476
/*                                      corresponds to the given position (offset) in the               */
8477
/*                                      stream.  This is used for error reporting.                              */
8478
/*                                                                                                                                                      */
8479
/*      Returns:                line number, or zero if it could not be determined              */
8480
/*                                                                                                                                                      */
8481
/****************************************************************************/
8482
{
8483
        long line = 0L;
8484
        long index = 0L;
8485
        int ch;
8486
 
8487
        if (jam_seek(0L) == 0)
8488
        {
8489
                ++line; /* first line is line 1, not zero */
8490
 
8491
                for (index = 0; index < position; ++index)
8492
                {
8493
                        ch = jam_getc();
8494
 
8495
                        if (ch == JAMC_NEWLINE_CHAR)
8496
                        {
8497
                                ++line;
8498
                        }
8499
                }
8500
        }
8501
 
8502
        return (line);
8503
}
8504
 
8505
/****************************************************************************/
8506
/*                                                                                                                                                      */
8507
JAM_RETURN_TYPE jam_execute
8508
(
8509
        char *program,
8510
        long program_size,
8511
        char *workspace,
8512
        long workspace_size,
8513
        char *action,
8514
        char **init_list,
8515
        int reset_jtag,
8516
        long *error_line,
8517
        int *exit_code,
8518
        int *format_version
8519
)
8520
/*                                                                                                                                                      */
8521
/*      Description:    This is the main entry point for executing a JAM                */
8522
/*                                      program.  It returns after execution has terminated.    */
8523
/*                                      The program data is not passed into this function,              */
8524
/*                                      but is accessed through the jam_getc() function.                */
8525
/*                                                                                                                                                      */
8526
/*      Return:                 JAMC_SUCCESS for successful execution, otherwise one    */
8527
/*                                      of the error codes listed in <jamexprt.h>                               */
8528
/*                                                                                                                                                      */
8529
/****************************************************************************/
8530
{
8531
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
8532
        char *statement_buffer = NULL;
8533
        char label_buffer[JAMC_MAX_NAME_LENGTH + 1];
8534
        BOOL done = FALSE;
8535
        BOOL reuse_statement_buffer = FALSE;
8536
        int i = 0;
8537
 
8538
        jam_program = program;
8539
        jam_program_size = program_size;
8540
        jam_workspace = workspace;
8541
        jam_workspace_size = workspace_size;
8542
        jam_action = action;
8543
        jam_init_list = init_list;
8544
 
8545
        jam_current_file_position = 0L;
8546
        jam_current_statement_position = 0L;
8547
        jam_next_statement_position = 0L;
8548
        jam_vector_signal_count = 0;
8549
        jam_version = 0;
8550
        jam_phase = JAM_UNKNOWN_PHASE;
8551
        jam_current_block = NULL;
8552
 
8553
        for (i = 0; i < JAMC_MAX_LITERAL_ARRAYS; ++i)
8554
        {
8555
                jam_literal_aca_buffer[i] = NULL;
8556
        }
8557
 
8558
        /*
8559
        *       Ensure that workspace is DWORD aligned
8560
        */
8561
        if (jam_workspace != NULL)
8562
        {
8563
                jam_workspace_size -= (((long)jam_workspace) & 3L);
8564
                jam_workspace_size &= (~3L);
8565
                jam_workspace = (char *) (((long)jam_workspace + 3L) & (~3L));
8566
        }
8567
 
8568
        /*
8569
        *       Initialize symbol table and stack
8570
        */
8571
        status = jam_init_symbol_table();
8572
 
8573
        if (status == JAMC_SUCCESS)
8574
        {
8575
                status = jam_init_stack();
8576
        }
8577
 
8578
        if (status == JAMC_SUCCESS)
8579
        {
8580
                status = jam_init_jtag();
8581
        }
8582
 
8583
        if (status == JAMC_SUCCESS)
8584
        {
8585
                status = jam_init_heap();
8586
        }
8587
 
8588
        if (status == JAMC_SUCCESS)
8589
        {
8590
                status = jam_seek(0L);
8591
        }
8592
 
8593
        if (status == JAMC_SUCCESS)
8594
        {
8595
                statement_buffer = jam_malloc(JAMC_MAX_STATEMENT_LENGTH + 1024);
8596
 
8597
                if (statement_buffer == NULL)
8598
                {
8599
                        status = JAMC_OUT_OF_MEMORY;
8600
                }
8601
        }
8602
 
8603
        /*
8604
        *       Get program statements and execute them
8605
        */
8606
        while ((!done) && (status == JAMC_SUCCESS))
8607
        {
8608
                if (!reuse_statement_buffer)
8609
                {
8610
                        status = jam_get_statement
8611
                        (
8612
                                statement_buffer,
8613
                                label_buffer
8614
                        );
8615
 
8616
                        if ((status == JAMC_SUCCESS)
8617
                                && (label_buffer[0] != JAMC_NULL_CHAR))
8618
                        {
8619
                                status = jam_add_symbol
8620
                                (
8621
                                        JAM_LABEL,
8622
                                        label_buffer,
8623
                                        0L,
8624
                                        jam_current_statement_position
8625
                                );
8626
                        }
8627
                }
8628
                else
8629
                {
8630
                        /* statement buffer will be reused -- clear the flag */
8631
                        reuse_statement_buffer = FALSE;
8632
                }
8633
 
8634
                if (status == JAMC_SUCCESS)
8635
                {
8636
                        status = jam_execute_statement
8637
                        (
8638
                                statement_buffer,
8639
                                &done,
8640
                                &reuse_statement_buffer,
8641
                                exit_code
8642
                        );
8643
                }
8644
        }
8645
 
8646
        if ((status != JAMC_SUCCESS) && (error_line != NULL))
8647
        {
8648
                *error_line = jam_get_line_of_position(
8649
                        jam_current_statement_position);
8650
        }
8651
 
8652
        jam_free_literal_aca_buffers();
8653
        jam_free_jtag_padding_buffers(reset_jtag);
8654
        jam_free_heap();
8655
        jam_free_stack();
8656
        jam_free_symbol_table();
8657
 
8658
        if (statement_buffer != NULL) jam_free(statement_buffer);
8659
 
8660
        if (format_version != NULL) *format_version = jam_version;
8661
 
8662
        return (status);
8663
}

powered by: WebSVN 2.1.0

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