Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – /branches/algol60/src/installers/680x0/common/tests.c – Rev 7

Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
7 7u83 2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * 1. Redistributions of source code must retain the above copyright notice,
9
 *    this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
11
 *    this list of conditions and the following disclaimer in the documentation
12
 *    and/or other materials provided with the distribution.
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific, prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 * $Id$
30
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1996
33
 
34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
42
 
43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
45
 
46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
49
 
50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
53
 
54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
/*
60
			    VERSION INFORMATION
61
			    ===================
62
 
63
--------------------------------------------------------------------------
64
$Header: /u/g/release/CVSROOT/Source/src/installers/680x0/common/tests.c,v 1.1.1.1 1998/01/17 15:55:50 release Exp $
65
--------------------------------------------------------------------------
66
$Log: tests.c,v $
67
 * Revision 1.1.1.1  1998/01/17  15:55:50  release
68
 * First version to be checked into rolling release.
69
 *
70
Revision 1.2  1997/11/09 14:15:09  ma
71
Removed issigned. Use is_signed instead.
72
 
73
Revision 1.1.1.1  1997/10/13 12:42:59  ma
74
First version.
75
 
76
Revision 1.5  1997/10/13 08:50:11  ma
77
Made all pl_tests for general proc & exception handling pass.
78
 
79
Revision 1.4  1997/09/25 06:45:35  ma
80
All general_proc tests passed
81
 
82
Revision 1.3  1997/04/20 11:30:39  ma
83
Introduced gcproc.c & general_proc.[ch].
84
Added cases for apply_general_proc next to apply_proc in all files.
85
 
86
Revision 1.2  1997/03/20 12:46:24  ma
87
Now tag ids are kept in unsigned chars (MAX tag id > 127).
88
 
89
Revision 1.1.1.1  1997/03/14 07:50:18  ma
90
Imported from DRA
91
 
92
 * Revision 1.1.1.1  1996/09/20  10:56:59  john
93
 *
94
 * Revision 1.2  1996/07/05  14:26:52  john
95
 * Changes for spec 3.1
96
 *
97
 * Revision 1.1.1.1  1996/03/26  15:45:17  john
98
 *
99
 * Revision 1.3  94/02/21  16:04:20  16:04:20  ra (Robert Andrews)
100
 * A number of values which were previously bool are now int.
101
 *
102
 * Revision 1.2  93/05/24  16:00:03  16:00:03  ra (Robert Andrews)
103
 * The optimisation which check_anyway is designed to test for has
104
 * returned.  Some tuning is required.
105
 *
106
 * Revision 1.1  93/02/22  17:16:44  17:16:44  ra (Robert Andrews)
107
 * Initial revision
108
 *
109
--------------------------------------------------------------------------
110
*/
111
 
112
 
113
#include "config.h"
114
#include "common_types.h"
115
#include "assembler.h"
116
#include "exp.h"
117
#include "expmacs.h"
118
#include "shapemacs.h"
119
#include "tags.h"
120
#include "tests.h"
121
#include "is_worth.h"
122
#ifndef tdf3
123
#include "68k_globals.h"
124
#endif
125
 
126
 
127
/*
128
    CC CONVENTIONS
129
 
130
    HP cc has different conventions to gcc on certain points, most
131
    noticably on the alignment of bitfields.  Both conventions are
132
    supported, but the cc conventions are default on the HP.  NeXT
133
    cc is gcc.
134
*/
135
 
136
#ifdef hp_cc_conventions
7 7u83 137
int cc_conventions = 1;
2 7u83 138
#else
7 7u83 139
int cc_conventions = 0;
2 7u83 140
#endif
141
 
7 7u83 142
bool
143
reused_parameter(exp e)
2 7u83 144
{
7 7u83 145
	bool reused = 0;
146
	exp def, ident_exp;
147
	def = son(e);
148
	if (name(def) == name_tag) {
149
		ident_exp = son(def);
150
		if (! isvar(ident_exp)) {
151
			/* This an obtain_tag of a parameter */
152
			if (name(son(ident_exp)) == formal_callee_tag) {
153
				reused = cur_proc_use_same_callees;
154
			}
155
			else {
156
				/* caller parameter */
157
				reused = cur_proc_has_tail_call;
158
			}
159
		}
160
	}
161
	return reused;
2 7u83 162
}
163
 
164
/*
165
    CAN THE VALUE OF AN EXPRESSION BE PUT INTO A REGISTER?
166
 
167
    This routine returns 1 if the expression e can be put into a register.
168
    It has to have its visible flag false, and to be of a suitable shape.
169
*/
170
 
7 7u83 171
bool
172
regable(exp e)
2 7u83 173
{
7 7u83 174
	shape sha;
175
	char n;
176
	long sz;
2 7u83 177
 
7 7u83 178
	if (isvis(e)) {
179
		return (0);
180
	}
2 7u83 181
 
7 7u83 182
	sha = sh(son(e));
183
	n = name(sha);
184
	if (n == realhd || n == doublehd) {
185
		return (1);
186
	}
2 7u83 187
 
7 7u83 188
	sz = shape_size(sha);
2 7u83 189
 
7 7u83 190
	return (n != cpdhd && n != nofhd && sz <= 32);
2 7u83 191
}
192
 
193
 
194
/*
195
    DOES AN EXP HAVE NO SIDE EFFECTS?
196
 
197
    This routine returns 1 if e has no side effects.
198
*/
199
 
7 7u83 200
bool
201
no_side(exp e)
2 7u83 202
{
7 7u83 203
	int n = name(e);
204
	if (n == ident_tag) {
205
		return (no_side(son(e)) && (no_side(bro(son(e)))));
206
	}
207
	return (is_a(n) || n == test_tag || n == ass_tag || n == testbit_tag);
2 7u83 208
}
209
 
7 7u83 210
    char n;
2 7u83 211
 
212
/*
213
    IS AN EXP A PUSHABLE PROCEDURE ARGUMENT?
214
 
215
    Can the expression e be pushed directly onto the stack when it is
216
    the parameter of a procedure?
217
*/
218
 
7 7u83 219
bool
220
push_arg(exp e)
2 7u83 221
{
7 7u83 222
	unsigned char n = name(e);
2 7u83 223
 
7 7u83 224
	if (is_a(n)) {
225
		return (1);
226
	}
227
	if (n == apply_tag || n == apply_general_tag) {
228
		return (reg_result(sh(e)));
229
	}
230
	if (n == ident_tag) {
231
		return (push_arg(son(e)) && push_arg(bro(son(e))));
232
	}
233
	return (0);
2 7u83 234
}
235
 
236
 
237
#if 0
238
 
239
/*
240
    IS A UNION ACTUALLY POINTER VOID?
241
 
242
    No longer used.
243
*/
244
 
245
 
246
#ifndef PTR_VOID_MIN
247
#define PTR_VOID_MIN	10
248
#endif
249
 
7 7u83 250
bool
251
is_ptr_void(shape sha)
2 7u83 252
{
7 7u83 253
	bool go;
254
	int ptrs = 0;
255
	exp t = son(sha);
256
	if (t == nilexp) {
257
		return (0);
258
	}
259
	do {
260
		go = (last(t) ? 0 : 1);
261
		if (name(sh(t)) != ptrhd) {
262
			return (0);
263
		}
264
		ptrs++;
265
		t = bro(t);
266
	} while (go);
267
	if (ptrs < PTR_VOID_MIN) {
268
		return (0);
269
	}
2 7u83 270
#ifdef PTR_VOID_MAX
7 7u83 271
	if (ptrs > PTR_VOID_MAX) {
272
		return (0);
273
	}
2 7u83 274
#endif
7 7u83 275
	return (1);
2 7u83 276
}
277
 
278
#endif
279
 
280
 
281
/*
282
    IS A SHAPE COMPOUND?
283
 
284
    This routine is designed to test whether a given shape is compound,
285
    and thus likely to cause problems when it is the parameter of a
286
    procedure.
287
*/
288
 
7 7u83 289
bool
290
cpd_param(shape sha)
2 7u83 291
{
7 7u83 292
	char n = name(sha);
293
	if (!cc_conventions || n == bitfhd) {
294
		long sz = shape_size(sha);
295
		if (sz <= 32) {
296
			return (0);
297
		}
298
	}
299
	return (n == cpdhd || n == nofhd || n == bitfhd || n == s64hd ||
300
		n == u64hd);
2 7u83 301
}
302
 
303
 
304
/*
305
    DOES A PROCEDURE RETURN A RESULT OF A GIVEN SHAPE IN A REGISTER?
306
 
307
    cc has two ways of getting results from procedures.  Firstly in the
308
    register D0 (or D0 and D1 in certain cases) and secondly in a section
309
    of memory the address of which is passed in at the start of the
310
    procedure in the A1 register and returned at the end in the D0
311
    register.  This routine works out whether or not a procedure
312
    delivering a result of shape sha will use the first method.
313
*/
314
 
315
 
7 7u83 316
int
317
reg_result(shape sha)
2 7u83 318
{
7 7u83 319
	char n = name(sha);
320
	if (cc_conventions) {
321
		/* HP cc doesn't return any tuples, unions etc in a register */
322
		return (n != cpdhd && n != nofhd);
323
	} else {
324
		/* Return anything of size <= 32 or 64 in a register */
325
		long sz = shape_size(sha);
326
		return (sz <= 32 || sz == 64);
327
	}
2 7u83 328
}
329
 
330
 
331
/*
332
    IS A SHAPE OF VARIABLE SIZE?
333
 
334
    This routine returns 1 if sha involves an array.
335
*/
336
 
7 7u83 337
bool
338
varsize(shape sha)
2 7u83 339
{
7 7u83 340
	return (name(sha) == nofhd ? 1 : 0);
2 7u83 341
}
342
 
343
#if 0
344
Use is_signed macro instead
345
 
346
/*
347
    IS A SHAPE SIGNED?
348
 
349
    This routine returns 1 if the integer variety shape sha is signed
350
    and 0 otherwise.
351
*/
352
 
7 7u83 353
bool
354
issigned(shape sha)
2 7u83 355
{
7 7u83 356
	char n = name(sha);
357
	if (n == ucharhd || n == uwordhd || n == ulonghd) {
358
		return (0);
359
	}
360
	return (1);
2 7u83 361
}
362
#endif
363
 
364
/*
365
    CHECK ON DECLARATION FOR PARAMETER SUBSTITUTION
366
 
367
    This routine checks if the declaration e should be substituted
368
    for all its uses or not.
369
*/
370
 
7 7u83 371
int do_sub_params = 1;
2 7u83 372
 
7 7u83 373
int
374
check_anyway(exp e)
2 7u83 375
{
376
#ifndef tdf3
7 7u83 377
	return 0;
2 7u83 378
#else
7 7u83 379
	if (do_sub_params) {
380
		setmarked(e);
381
		if (no(e) > 2) {
382
			return (1);
383
		}
384
	}
385
	return (0);
2 7u83 386
#endif
387
}
388
 
389
 
390
/*
391
    IS IT WORTH EXTRACTING A CONSTANT?
392
*/
393
 
7 7u83 394
int
395
is_worth(exp c)
2 7u83 396
{
7 7u83 397
	unsigned char cnam = name(c);
398
	return ((!is_o(cnam) && cnam != clear_tag) ||
399
		/* ignore simple things unless ... */
400
		(cnam == cont_tag && name(son(c)) == cont_tag &&
401
		 name(son(son(c))) == name_tag) ||
402
		(cnam == name_tag && isparam(son(c)) && !isvar(son(c)) &&
403
		 shape_size(sh(c)) <= 32 && name(sh(c)) != shrealhd));
2 7u83 404
}