Pristine Ack-5.5
[Ack-5.5.git] / util / ceg / EM_parser / common / action.c
1 #include "decl.h"
2 #include <alloc.h>
3
4 /* This file contains some routines needed in "pars.g" to handle the  action-
5  * grammarrule. The assembler-instructions are handeld in blocks rather than
6  * one at a time. So these routines provide saving and removing of assembler-
7  * instructions.
8  */
9
10 char **as_instructions;     /* The buffer(?) where the instructions are saved */
11
12 int quantum = 0,            /* Max. nr. of instructions in as_instructions[] */
13     nr_instr,               /* Number of saved instructions */
14     first_action,           /* Is this block of assembler-instr. the first after
15                              * a '==>'?
16                              */
17     last_action;            /* Is this block followed by a '.' ? */
18
19
20 init_as_block()
21 {
22         nr_instr = 0;
23
24         if ( quantum == 0) {
25                 quantum = 16;
26                 as_instructions = (char **)Malloc( quantum*sizeof( char *));
27         }
28 }
29
30
31 save_as( instr)
32 char *instr;
33
34 /* Save a copy of 'instr'
35  */
36 {
37         if ( nr_instr == quantum) {
38                 quantum *= 2;
39                 as_instructions = (char **) Realloc( (char *) as_instructions,
40                                            quantum*sizeof( char *));
41         }
42
43         as_instructions[nr_instr++] = Salloc( instr, strlen( instr) + 1);
44 }
45
46 do_block_assemble()
47 {
48         int i;
49
50         if ( nr_instr > 0) {
51                 block_assemble( as_instructions, nr_instr,
52                                 first_action, last_action);
53
54                 for ( i=0; i<nr_instr; i++)
55                         free( as_instructions[i]);
56         }
57 }