2 |
7u83 |
1 |
/*
|
|
|
2 |
Crown Copyright (c) 1997
|
|
|
3 |
|
|
|
4 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
5 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
6 |
acting through the Defence Evaluation and Research Agency
|
|
|
7 |
(DERA). It is made available to Recipients with a
|
|
|
8 |
royalty-free licence for its use, reproduction, transfer
|
|
|
9 |
to other parties and amendment for any purpose not excluding
|
|
|
10 |
product development provided that any such use et cetera
|
|
|
11 |
shall be deemed to be acceptance of the following conditions:-
|
|
|
12 |
|
|
|
13 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
14 |
reproduced upon any copies or amended versions of it;
|
|
|
15 |
|
|
|
16 |
(2) Any amended version of it shall be clearly marked to
|
|
|
17 |
show both the nature of and the organisation responsible
|
|
|
18 |
for the relevant amendment or amendments;
|
|
|
19 |
|
|
|
20 |
(3) Its onward transfer from a recipient to another
|
|
|
21 |
party shall be deemed to be that party's acceptance of
|
|
|
22 |
these conditions;
|
|
|
23 |
|
|
|
24 |
(4) DERA gives no warranty or assurance as to its
|
|
|
25 |
quality or suitability for any purpose and DERA accepts
|
|
|
26 |
no liability whatsoever in relation to any use to which
|
|
|
27 |
it may be put.
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
/*
|
|
|
32 |
$Log: spec_tok.c,v $
|
|
|
33 |
* Revision 1.1.1.1 1998/01/17 15:56:03 release
|
|
|
34 |
* First version to be checked into rolling release.
|
|
|
35 |
*
|
|
|
36 |
* Revision 1.6 1996/10/24 15:51:21 wfs
|
|
|
37 |
* Added "~alloc_size" special token. Minor change to alloca_tag - only need
|
|
|
38 |
* one word for storage of pointer. Major change to round_tag (rounding to
|
|
|
39 |
* unsigned chars) in the fix of avs bug.
|
|
|
40 |
*
|
|
|
41 |
* Revision 1.5 1996/08/30 09:02:33 wfs
|
|
|
42 |
* Various fixes of bugs arising from avs and pl_tdf tests.
|
|
|
43 |
*
|
|
|
44 |
* Revision 1.4 1996/08/06 10:50:13 wfs
|
|
|
45 |
* bug fixes to pic code, enum diagnostics enabled.
|
|
|
46 |
*
|
|
|
47 |
* Revision 1.3 1996/02/14 17:19:22 wfs
|
|
|
48 |
* "next_caller_offset" and "next_callee_offset" have become special tokens
|
|
|
49 |
* defined in "spec_tok.c". Bug fix to a "and_tag" optimization in
|
|
|
50 |
* "oprators.c". A few bug fixes in "makecode.c" arising from the variable
|
|
|
51 |
* caller tests. "promote_pars" defined in "config.h".
|
|
|
52 |
*
|
|
|
53 |
* Revision 1.2 1995/12/18 13:12:33 wfs
|
|
|
54 |
* Put hppatrans uder cvs control. Major Changes made since last release
|
|
|
55 |
* include:
|
|
|
56 |
* (i) PIC code generation.
|
|
|
57 |
* (ii) Profiling.
|
|
|
58 |
* (iii) Dynamic Initialization.
|
|
|
59 |
* (iv) Debugging of Exception Handling and Diagnostics.
|
|
|
60 |
*
|
|
|
61 |
* Revision 5.0 1995/08/25 13:42:58 wfs
|
|
|
62 |
* Preperation for August 25 Glue release
|
|
|
63 |
*
|
|
|
64 |
* Revision 3.4 1995/08/25 10:30:56 wfs
|
|
|
65 |
* *** empty log message ***
|
|
|
66 |
*
|
|
|
67 |
* Revision 3.4 1995/08/25 10:30:56 wfs
|
|
|
68 |
* *** empty log message ***
|
|
|
69 |
*
|
|
|
70 |
* Revision 3.1 95/04/10 16:28:10 16:28:10 wfs (William Simmonds)
|
|
|
71 |
* Apr95 tape version.
|
|
|
72 |
*
|
|
|
73 |
* Revision 3.0 95/03/30 11:18:58 11:18:58 wfs (William Simmonds)
|
|
|
74 |
* Mar95 tape version with CRCR95_178 bug fix.
|
|
|
75 |
*
|
|
|
76 |
* Revision 2.0 95/03/15 15:28:47 15:28:47 wfs (William Simmonds)
|
|
|
77 |
* spec 3.1 changes implemented, tests outstanding.
|
|
|
78 |
*
|
|
|
79 |
* Revision 1.1 95/01/11 13:18:17 13:18:17 wfs (William Simmonds)
|
|
|
80 |
* Initial revision
|
|
|
81 |
*
|
|
|
82 |
*/
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
/*
|
|
|
86 |
^^^ 21/12/92 jmf Added ~div as special token
|
|
|
87 |
^^^ 26/03/93 jmf Changes for new spec 2.1
|
|
|
88 |
^^^ 24/05/93 jmf Added ~alloca as special token, not alloc
|
|
|
89 |
^^^ 10/06/93 jmf Change long to int, remove extern declarations.
|
|
|
90 |
^^^ 19/08/93 jmf Put arith_type, promote, sign_promote, convert
|
|
|
91 |
^^^ into c_arith-type.h in machine directories.
|
|
|
92 |
^^^ 19/08/93 jmf Set crt_lno in exp_to_source
|
|
|
93 |
^^^ 23/09/93 jmf Use natmacs.h
|
|
|
94 |
*/
|
|
|
95 |
|
|
|
96 |
#include "config.h"
|
|
|
97 |
#include "common_types.h"
|
|
|
98 |
#include "basicread.h"
|
|
|
99 |
#include "tags.h"
|
|
|
100 |
#include "exp.h"
|
|
|
101 |
#include "expmacs.h"
|
|
|
102 |
#include "diag_fns.h"
|
|
|
103 |
#include "flags.h"
|
|
|
104 |
#include "check.h"
|
|
|
105 |
#include "me_fns.h"
|
|
|
106 |
#include "externs.h"
|
|
|
107 |
#include "installglob.h"
|
|
|
108 |
#include "messages_r.h"
|
|
|
109 |
#include "main_reads.h"
|
|
|
110 |
#include "install_fns.h"
|
|
|
111 |
#include "c_arith_type.h"
|
|
|
112 |
#include "natmacs.h"
|
|
|
113 |
#include "shapemacs.h"
|
|
|
114 |
#include "spec_tok.h"
|
|
|
115 |
#include "szs_als.h"
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
/* intercepts specially defined tokens */
|
|
|
119 |
|
|
|
120 |
tokval special_token
|
|
|
121 |
PROTO_N ( (t, pars, sortcode, done) )
|
|
|
122 |
PROTO_T ( token t X bitstream pars X int sortcode X int * done )
|
|
|
123 |
{
|
|
|
124 |
tokval tkv;
|
|
|
125 |
UNUSED(sortcode);
|
|
|
126 |
|
|
|
127 |
if (t -> tok_name == (char*)0) {
|
|
|
128 |
SET(tkv); /* call looks at done to see if result is meaningful */
|
|
|
129 |
return tkv;
|
|
|
130 |
|
|
|
131 |
};
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
/* Added for VARARGS */
|
|
|
135 |
|
|
|
136 |
if (!strcmp(t -> tok_name,"ansi.stdarg.__va_start")) {
|
|
|
137 |
exp arg1;
|
|
|
138 |
exp id;
|
|
|
139 |
exp env_o;
|
|
|
140 |
place old_place;
|
|
|
141 |
old_place = keep_place();
|
|
|
142 |
set_place(pars);
|
|
|
143 |
arg1 = hold_check(d_exp());
|
|
|
144 |
set_place(old_place);
|
|
|
145 |
if (name(arg1) != name_tag) failer("Not a tag in va_start");
|
|
|
146 |
id = son(arg1);
|
|
|
147 |
|
|
|
148 |
env_o = getexp(f_offset(frame_alignment, f_alignment(sh(arg1))),
|
|
|
149 |
nilexp, 0, id, nilexp, 0, 0, env_offset_tag);
|
|
|
150 |
setvis(id);
|
|
|
151 |
setenvoff(id);
|
|
|
152 |
tkv.tk_exp = hold_check(f_add_to_ptr(f_add_to_ptr(f_current_env(), env_o),f_shape_offset(sh(arg1))));
|
|
|
153 |
kill_exp(arg1,arg1);
|
|
|
154 |
*done = 1;
|
|
|
155 |
return tkv;
|
|
|
156 |
}
|
|
|
157 |
/* end of addition for VARARGS */
|
|
|
158 |
|
|
|
159 |
#if is80x86
|
|
|
160 |
if (!strcmp(t -> tok_name, "~div")) {
|
|
|
161 |
exp arg1, arg2;
|
|
|
162 |
place old_place;
|
|
|
163 |
old_place = keep_place();
|
|
|
164 |
set_place(pars);
|
|
|
165 |
arg1 = hold_check(d_exp());
|
|
|
166 |
arg2 = hold_check(d_exp());
|
|
|
167 |
|
|
|
168 |
set_place(old_place);
|
|
|
169 |
tkv.tk_exp = me_b2(arg1, arg2, div0_tag);
|
|
|
170 |
*done = 1;
|
|
|
171 |
return tkv;
|
|
|
172 |
};
|
|
|
173 |
if (!strcmp(t -> tok_name, "~arith_type")) {
|
|
|
174 |
int a, b;
|
|
|
175 |
place old_place;
|
|
|
176 |
signed_nat sn;
|
|
|
177 |
old_place = keep_place();
|
|
|
178 |
set_place(pars);
|
|
|
179 |
sn = d_signed_nat();
|
|
|
180 |
a = snatint(sn);
|
|
|
181 |
sn = d_signed_nat();
|
|
|
182 |
b = snatint(sn);
|
|
|
183 |
set_place(old_place);
|
|
|
184 |
snatint(sn) = arith_type(a, b);
|
|
|
185 |
tkv.tk_signed_nat = sn;
|
|
|
186 |
*done = 1;
|
|
|
187 |
return tkv;
|
|
|
188 |
};
|
|
|
189 |
if (!strcmp(t -> tok_name, "~promote")) {
|
|
|
190 |
int a;
|
|
|
191 |
place old_place;
|
|
|
192 |
signed_nat sn;
|
|
|
193 |
old_place = keep_place();
|
|
|
194 |
set_place(pars);
|
|
|
195 |
sn = d_signed_nat();
|
|
|
196 |
a = snatint(sn);
|
|
|
197 |
set_place(old_place);
|
|
|
198 |
snatint(sn) = promote(a);
|
|
|
199 |
tkv.tk_signed_nat = sn;
|
|
|
200 |
*done = 1;
|
|
|
201 |
return tkv;
|
|
|
202 |
};
|
|
|
203 |
if (!strcmp(t -> tok_name, "~sign_promote")) {
|
|
|
204 |
int a;
|
|
|
205 |
place old_place;
|
|
|
206 |
signed_nat sn;
|
|
|
207 |
old_place = keep_place();
|
|
|
208 |
set_place(pars);
|
|
|
209 |
sn = d_signed_nat();
|
|
|
210 |
a = snatint(sn);
|
|
|
211 |
set_place(old_place);
|
|
|
212 |
snatint(sn) = sign_promote(a);
|
|
|
213 |
tkv.tk_signed_nat = sn;
|
|
|
214 |
*done = 1;
|
|
|
215 |
return tkv;
|
|
|
216 |
};
|
|
|
217 |
if (!strcmp(t -> tok_name, "~convert")) {
|
|
|
218 |
int a;
|
|
|
219 |
place old_place;
|
|
|
220 |
signed_nat sn;
|
|
|
221 |
old_place = keep_place();
|
|
|
222 |
set_place(pars);
|
|
|
223 |
sn = d_signed_nat();
|
|
|
224 |
a = snatint(sn);
|
|
|
225 |
set_place(old_place);
|
|
|
226 |
tkv.tk_variety = convert((unsigned)a);
|
|
|
227 |
*done = 1;
|
|
|
228 |
return tkv;
|
|
|
229 |
};
|
|
|
230 |
#endif
|
|
|
231 |
|
|
|
232 |
#if ishppa
|
|
|
233 |
if (!strcmp(t -> tok_name,"~next_caller_offset")) {
|
|
|
234 |
exp arg1, arg2;
|
|
|
235 |
shape sha1, sha2, sha3;
|
|
|
236 |
place old_place;
|
|
|
237 |
old_place = keep_place();
|
|
|
238 |
set_place(pars);
|
|
|
239 |
arg1 = hold_check(d_exp());
|
|
|
240 |
sha1 = d_shape();
|
|
|
241 |
sha2 = d_shape();
|
|
|
242 |
set_place(old_place);
|
|
|
243 |
sha3 = (shape_size(sha2)>64 ? f_pointer(f_alignment(sha2)) :
|
|
|
244 |
(shape_size(sha2)<32 ? swordsh : sha2));
|
|
|
245 |
arg2 = hold_check(f_offset_pad(f_parameter_alignment(sha3),
|
|
|
246 |
f_shape_offset(sha3)));
|
|
|
247 |
if ((shape_size(sha1)<=32 || shape_size(sha1)>64) && shape_size(sha3)==64)
|
|
|
248 |
{
|
|
|
249 |
arg1 = hold_check(f_offset_pad(f_parameter_alignment(realsh),arg1));
|
|
|
250 |
}
|
|
|
251 |
tkv.tk_exp = hold_check(me_b3(f_offset(al1_of(sh(arg1)),
|
|
|
252 |
al2_of(sh(arg2))),
|
|
|
253 |
arg1,arg2,offset_subtract_tag));
|
|
|
254 |
*done = 1;
|
|
|
255 |
|
|
|
256 |
if (shape_size(sha2)>64)
|
|
|
257 |
{
|
|
|
258 |
al2_of(sh(tkv.tk_exp))->al.sh_hd = nofhd+1;
|
|
|
259 |
}
|
|
|
260 |
|
|
|
261 |
return tkv;
|
|
|
262 |
}
|
|
|
263 |
|
|
|
264 |
if (!strcmp(t -> tok_name,"~next_callee_offset")) {
|
|
|
265 |
exp arg1, arg2, off;
|
|
|
266 |
shape sha1, sha2;
|
|
|
267 |
place old_place;
|
|
|
268 |
old_place = keep_place();
|
|
|
269 |
set_place(pars);
|
|
|
270 |
arg1 = hold_check(d_exp());
|
|
|
271 |
sha1 = d_shape();
|
|
|
272 |
sha2 = d_shape();
|
|
|
273 |
set_place(old_place);
|
|
|
274 |
arg2 = hold_check(f_offset_pad(f_parameter_alignment(sha1),
|
|
|
275 |
f_shape_offset(sha1)));
|
|
|
276 |
off = hold_check(me_b3(f_offset(al1_of(sh(arg1)),
|
|
|
277 |
al2_of(sh(arg2))),
|
|
|
278 |
arg1,arg2,offset_add_tag));
|
|
|
279 |
if (shape_align(sha1) < shape_align(sha2))
|
|
|
280 |
{
|
|
|
281 |
tkv.tk_exp = hold_check(f_offset_pad(f_parameter_alignment(sha2),off));
|
|
|
282 |
}
|
|
|
283 |
else
|
|
|
284 |
{
|
|
|
285 |
tkv.tk_exp = off;
|
|
|
286 |
}
|
|
|
287 |
*done = 1;
|
|
|
288 |
return tkv;
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
if (!strcmp(t -> tok_name,"~alloc_size")) {
|
|
|
292 |
exp off,off1,arg1;
|
|
|
293 |
place old_place;
|
|
|
294 |
old_place = keep_place();
|
|
|
295 |
set_place(pars);
|
|
|
296 |
arg1 = hold_check(d_exp());
|
|
|
297 |
set_place(old_place);
|
|
|
298 |
off1 = hold_check(f_offset_pad(SLONG_ALIGN,arg1));
|
|
|
299 |
off = hold_check(me_b3(f_offset(al1_of(sh(off1)),
|
|
|
300 |
SLONG_ALIGN),
|
|
|
301 |
off1,f_shape_offset(slongsh),offset_add_tag));
|
|
|
302 |
tkv.tk_exp = hold_check(f_offset_pad(const_al512,off));
|
|
|
303 |
*done = 1;
|
|
|
304 |
return tkv;
|
|
|
305 |
}
|
|
|
306 |
|
|
|
307 |
#endif
|
|
|
308 |
|
|
|
309 |
if (!strcmp(t -> tok_name, "~alloca")) {
|
|
|
310 |
exp arg1;
|
|
|
311 |
place old_place;
|
|
|
312 |
old_place = keep_place();
|
|
|
313 |
set_place(pars);
|
|
|
314 |
arg1 = hold_check(d_exp());
|
|
|
315 |
set_place(old_place);
|
|
|
316 |
tkv.tk_exp = hold_check(me_u3(f_pointer(long_to_al(8)),
|
|
|
317 |
arg1, alloca_tag));
|
|
|
318 |
*done = 1;
|
|
|
319 |
has_alloca = 1;
|
|
|
320 |
return tkv;
|
|
|
321 |
};
|
|
|
322 |
|
|
|
323 |
if (!strcmp(t -> tok_name, "~exp_to_source") ||
|
|
|
324 |
!strcmp(t -> tok_name, "~diag_id_scope") ||
|
|
|
325 |
!strcmp(t -> tok_name, "~diag_type_scope") ||
|
|
|
326 |
!strcmp(t -> tok_name, "~diag_tag_scope")) {
|
|
|
327 |
|
|
|
328 |
place old_place;
|
|
|
329 |
old_place = keep_place();
|
|
|
330 |
set_place(pars);
|
|
|
331 |
tkv.tk_exp = hold_check(d_exp());
|
|
|
332 |
*done = 1;
|
|
|
333 |
|
|
|
334 |
if (!diagnose)
|
|
|
335 |
{
|
|
|
336 |
set_place(old_place);
|
|
|
337 |
return tkv;
|
|
|
338 |
};
|
|
|
339 |
|
|
|
340 |
if (!strcmp(t -> tok_name, "~exp_to_source"))
|
|
|
341 |
{exp r;
|
|
|
342 |
diag_info * di = read_exp_to_source();
|
|
|
343 |
crt_lno = natint(di -> data.source.end.line_no);
|
|
|
344 |
crt_charno = natint(di -> data.source.end.char_off);
|
|
|
345 |
crt_flnm = di -> data.source.beg.file->file.ints.chars;
|
|
|
346 |
r = getexp(sh(tkv.tk_exp), nilexp, 0, tkv.tk_exp, nilexp,
|
|
|
347 |
1, 0, diagnose_tag);
|
|
|
348 |
setfather(r, tkv.tk_exp);
|
|
|
349 |
dno(r) = di;
|
|
|
350 |
tkv.tk_exp = r;
|
|
|
351 |
set_place(old_place);
|
|
|
352 |
return tkv;
|
|
|
353 |
};
|
|
|
354 |
|
|
|
355 |
if (!strcmp(t -> tok_name, "~diag_id_scope"))
|
|
|
356 |
{exp r;
|
|
|
357 |
diag_info * di = read_diag_id_scope();
|
|
|
358 |
r = getexp(sh(tkv.tk_exp), nilexp, 0, tkv.tk_exp, nilexp,
|
|
|
359 |
2, 0, diagnose_tag);
|
|
|
360 |
setfather(r, tkv.tk_exp);
|
|
|
361 |
dno(r) = di;
|
|
|
362 |
tkv.tk_exp = r;
|
|
|
363 |
set_place(old_place);
|
|
|
364 |
return tkv;
|
|
|
365 |
};
|
|
|
366 |
|
|
|
367 |
if (!strcmp(t -> tok_name, "~diag_type_scope"))
|
|
|
368 |
{exp r;
|
|
|
369 |
diag_info * di = read_diag_type_scope();
|
|
|
370 |
r = getexp(sh(tkv.tk_exp), nilexp, 0, tkv.tk_exp, nilexp,
|
|
|
371 |
3, 0, diagnose_tag);
|
|
|
372 |
setfather(r, tkv.tk_exp);
|
|
|
373 |
dno(r) = di;
|
|
|
374 |
tkv.tk_exp = r;
|
|
|
375 |
set_place(old_place);
|
|
|
376 |
return tkv;
|
|
|
377 |
};
|
|
|
378 |
|
|
|
379 |
if (!strcmp(t -> tok_name, "~diag_tag_scope"))
|
|
|
380 |
{exp r;
|
|
|
381 |
diag_info * di = read_diag_tag_scope();
|
|
|
382 |
r = getexp(sh(tkv.tk_exp), nilexp, 0, tkv.tk_exp, nilexp,
|
|
|
383 |
4, 0, diagnose_tag);
|
|
|
384 |
setfather(r, tkv.tk_exp);
|
|
|
385 |
dno(r) = di;
|
|
|
386 |
tkv.tk_exp = r;
|
|
|
387 |
set_place(old_place);
|
|
|
388 |
return tkv;
|
|
|
389 |
};
|
|
|
390 |
|
|
|
391 |
|
|
|
392 |
};
|
|
|
393 |
|
|
|
394 |
SET(tkv); /* call looks at done to see if result is meaningful */
|
|
|
395 |
return tkv;
|
|
|
396 |
}
|
|
|
397 |
|
|
|
398 |
|
|
|
399 |
|