1 
2 /********************************************
3 code.h
4 copyright 1991, Michael D. Brennan
5 
6 This is a source file for mawk, an implementation of
7 the AWK programming language.
8 
9 Mawk is distributed without warranty under the terms of
10 the GNU General Public License, version 2, 1991.
11 ********************************************/
12 
13 
14 /* $Log: code.h,v $
15  * Revision 1.5  1995/06/18  19:42:15  mike
16  * Remove some redundant declarations and add some prototypes
17  *
18  * Revision 1.4  1994/12/13  00:13:01  mike
19  * delete A statement to delete all of A at once
20  *
21  * Revision 1.3  1993/12/01  14:25:06  mike
22  * reentrant array loops
23  *
24  * Revision 1.2  1993/07/22  00:04:01  mike
25  * new op code _LJZ _LJNZ
26  *
27  * Revision 1.1.1.1  1993/07/03  18:58:10  mike
28  * move source to cvs
29  *
30  * Revision 5.3  1993/01/14  13:11:11  mike
31  * code2() -> xcode2()
32  *
33  * Revision 5.2  1993/01/07  02:50:33  mike
34  * relative vs absolute code
35  *
36  * Revision 5.1  1991/12/05  07:59:07  brennan
37  * 1.1 pre-release
38  *
39 */
40 
41 
42 /*  code.h  */
43 
44 #ifndef  CODE_H
45 #define  CODE_H
46 
47 #ifndef _AWKA_EXE_H
48 
49 #include "memory.h"
50 
51 #define  PAGESZ        512
52         /* number of code instructions allocated at one time */
53 #define  CODEWARN        16
54 
55 /* coding scope */
56 #define   SCOPE_MAIN    0
57 #define   SCOPE_BEGIN   1
58 #define   SCOPE_END     2
59 #define   SCOPE_FUNCT   3
60 
61 
62 typedef struct {
63 INST *base, *limit, *warn, *ptr ;
64 } CODEBLOCK ;
65 
66 extern CODEBLOCK active_code ;
67 extern CODEBLOCK *main_code_p, *begin_code_p, *end_code_p ;
68 
69 extern INST *main_start, *begin_start, *end_start  ;
70 extern unsigned main_size, begin_size  ;
71 extern INST *execution_start ;
72 extern INST *next_label ;  /* next statements jump to here */
73 extern int dump_code_flag ;
74 
75 #define code_ptr  active_code.ptr
76 #define code_base active_code.base
77 #define code_warn active_code.warn
78 #define code_limit active_code.limit
79 #define code_offset (code_ptr-code_base)
80 
81 #define INST_BYTES(x) (sizeof(INST)*(unsigned)(x))
82 
83 extern  CELL  eval_stack[] ;
84 extern int exit_code ;
85 
86 
code1(int x)87 static void code1(int x) {
88   code_ptr -> lineno = token_lineno ;
89   code_ptr -> file = pfile_name ;
90   code_ptr++ -> op = x ;
91 }
92 
93 /* shutup picky compilers */
94 #define  code2(x,p)  xcode2(x,(PTR)(p))
95 
96 void  PROTO(xcode2, (int, PTR)) ;
97 void  PROTO(code2op, (int, int)) ;
98 INST *PROTO(code_shrink, (CODEBLOCK*, unsigned*)) ;
99 void  PROTO(code_grow, (void)) ;
100 void  PROTO(set_code, (void)) ;
101 void  PROTO(be_setup, (int)) ;
102 void  PROTO(dump_code, (void)) ;
103 
104 #endif  /* _AWKA_EXE_H */
105 
106 /*  the machine opcodes  */
107 /* to avoid confusion with a ptr FE_PUSHA must have op code 0 */
108 /* unfortunately enums are less portable than defines */
109 
110 #define FE_PUSHA     0
111 
112 #define _ABORT       1
113 #define _ABORT0      2
114 #define A_CAT        3
115 #define A_DEL        4
116 #define A_PUSHA      5
117 #define A_TEST       6
118 #define _ADD         7
119 #define _ADD_ASG     8
120 #define AE_PUSHA     9
121 #define AE_PUSHI    10
122 #define ALOOP       11
123 #define _ASSIGN     12
124 #define _BREAK      13
125 #define _BUILTIN    14
126 #define _CALL       15
127 #define _CAT        16
128 #define _CLEANUP    17
129 #define _COLON      18
130 #define _CONTINUE   19
131 #define DEL_A       20
132 #define _DIV        21
133 #define _DIV_ASG    22
134 #define _EQ         23
135 #define _ELSE       24
136 #define _EXIT       25
137 #define _EXIT0      26
138 #define F_ADD_ASG   27
139 #define F_ASSIGN    28
140 #define F_DIV_ASG   29
141 #define F_MOD_ASG   30
142 #define F_MUL_ASG   31
143 #define F_POST_DEC  32
144 #define F_POST_INC  33
145 #define F_POW_ASG   34
146 #define F_PRE_DEC   35
147 #define F_PRE_INC   36
148 #define F_PUSHA     37
149 #define F_PUSHI     38
150 #define F_SUB_ASG   39
151 #define _FE_PUSHA   40
152 #define FE_PUSHI    41
153 #define _HALT       42
154 #define _GOTO       43
155 #define _GT         44
156 #define _GTE        45
157 #define _JMAIN      46
158 #define _JMP        47
159 #define _JNZ        48
160 #define _JZ         49
161 #define L_PUSHA     50
162 #define L_PUSHI     51
163 #define LA_PUSHA    52
164 #define LAE_PUSHA   53
165 #define LAE_PUSHI   54
166 #define _LJNZ       55
167 #define _LJZ        56
168 #define _LT         57
169 #define _LTE        58
170 #define _MATCH      59
171 #define _MATCH0     60
172 #define _MATCH1     61
173 #define _MATCH2     62
174 #define _MOD        63
175 #define _MOD_ASG    64
176 #define _MUL        65
177 #define _MUL_ASG    66
178 #define _NEQ        67
179 #define _NEXT       68
180 #define _NEXTFILE   69
181 #define NF_PUSHI    70
182 #define _NOT        71
183 #define OL_GL       72
184 #define OL_GL_NR    73
185 #define _OMAIN      74
186 #define _POP        75
187 #define POP_AL      76
188 #define _POST_DEC   77
189 #define _POST_INC   78
190 #define _POW        79
191 #define _POW_ASG    80
192 #define _PRE_DEC    81
193 #define _PRE_INC    82
194 #define _PRINT      83
195 #define _PRINTF     84
196 #define _PUSHA      85
197 #define _PUSHC      86
198 #define _PUSHD      87
199 #define _PUSHI      88
200 #define _PUSHINT    89
201 #define _PUSHS      90
202 #define _QMARK      91
203 #define _RANGE      92
204 #define _RET        93
205 #define _RET0       94
206 #define SET_ALOOP   95
207 #define _STOP       96
208 #define _SUB        97
209 #define _SUB_ASG    98
210 #define _TEST       99
211 #define _UMINUS     100
212 #define _UPLUS      101
213 #define _ALENGTH    102
214 #undef _AND  /* this shuts-up the cygnus compiler */
215 #define _AND        103
216 #define _ARGCOUNT   104
217 #define _ARGVAL     105
218 #define _ASCII      106
219 #define _ASORT      107
220 #define _ATAN2      108
221 #define _CHAR       109
222 #define _CLOSE      110
223 #define _COMPL      111
224 #define _COS        112
225 #define _EXP        113
226 #define _FFLUSH     114
227 #define _GENSUB     115
228 #define _GETLINE    116
229 #define a_GMTIME    117
230 #define _GSUB       118
231 #define _INDEX      119
232 #define a_INT       120
233 #define _LEFT       121
234 #define _LENGTH     122
235 #define a_LOCALTIME 123
236 #define _LOG        124
237 #define _LSHIFT     125
238 #define _LTRIM      126
239 #define _MAX        127
240 #define _MIN        128
241 #define a_MKTIME    129
242 #define _OR         130
243 #define _RAND       131
244 #define _RIGHT      132
245 #define _RSHIFT     133
246 #define _RTRIM      134
247 #define _SIN        135
248 #define _SPLIT      136
249 #define _SPRINTF    137
250 #define _SQRT       138
251 #define _SRAND      139
252 #define a_STRFTIME  140
253 #define _SUB_BI     141
254 #define _SUBSTR     142
255 #define _SYSTEM     143
256 #define _SYSTIME    144
257 #define a_TIME      145
258 #define _TOLOWER    146
259 #define _TOTITLE    147
260 #define _TOUPPER    148
261 #define _TRIM       149
262 #define _XOR        150
263 
264 #define CODE_MIN 0
265 #define CODE_MAX 100
266 
267 #define BI_MIN 101
268 #define BI_MAX 149
269 
270 #define _FUNCTION   151
271 #define _BEGIN      152
272 #define _MAIN       153
273 #define _END        154
274 #define END_CODE    155
275 
276 #endif  /* CODE_H */
277