Subversion Repositories tendra.SVN

Rev

Rev 2 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1996
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
			    VERSION INFORMATION
31
			    ===================
32
 
33
--------------------------------------------------------------------------
34
$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 $
35
--------------------------------------------------------------------------
36
$Log: tests.c,v $
37
 * Revision 1.1.1.1  1998/01/17  15:55:50  release
38
 * First version to be checked into rolling release.
39
 *
40
Revision 1.2  1997/11/09 14:15:09  ma
41
Removed issigned. Use is_signed instead.
42
 
43
Revision 1.1.1.1  1997/10/13 12:42:59  ma
44
First version.
45
 
46
Revision 1.5  1997/10/13 08:50:11  ma
47
Made all pl_tests for general proc & exception handling pass.
48
 
49
Revision 1.4  1997/09/25 06:45:35  ma
50
All general_proc tests passed
51
 
52
Revision 1.3  1997/04/20 11:30:39  ma
53
Introduced gcproc.c & general_proc.[ch].
54
Added cases for apply_general_proc next to apply_proc in all files.
55
 
56
Revision 1.2  1997/03/20 12:46:24  ma
57
Now tag ids are kept in unsigned chars (MAX tag id > 127).
58
 
59
Revision 1.1.1.1  1997/03/14 07:50:18  ma
60
Imported from DRA
61
 
62
 * Revision 1.1.1.1  1996/09/20  10:56:59  john
63
 *
64
 * Revision 1.2  1996/07/05  14:26:52  john
65
 * Changes for spec 3.1
66
 *
67
 * Revision 1.1.1.1  1996/03/26  15:45:17  john
68
 *
69
 * Revision 1.3  94/02/21  16:04:20  16:04:20  ra (Robert Andrews)
70
 * A number of values which were previously bool are now int.
71
 *
72
 * Revision 1.2  93/05/24  16:00:03  16:00:03  ra (Robert Andrews)
73
 * The optimisation which check_anyway is designed to test for has
74
 * returned.  Some tuning is required.
75
 *
76
 * Revision 1.1  93/02/22  17:16:44  17:16:44  ra (Robert Andrews)
77
 * Initial revision
78
 *
79
--------------------------------------------------------------------------
80
*/
81
 
82
 
83
#include "config.h"
84
#include "common_types.h"
85
#include "assembler.h"
86
#include "exp.h"
87
#include "expmacs.h"
88
#include "shapemacs.h"
89
#include "tags.h"
90
#include "tests.h"
91
#include "is_worth.h"
92
#ifndef tdf3
93
#include "68k_globals.h"
94
#endif
95
 
96
 
97
/*
98
    CC CONVENTIONS
99
 
100
    HP cc has different conventions to gcc on certain points, most
101
    noticably on the alignment of bitfields.  Both conventions are
102
    supported, but the cc conventions are default on the HP.  NeXT
103
    cc is gcc.
104
*/
105
 
106
#ifdef hp_cc_conventions
107
int cc_conventions = 1 ;
108
#else
109
int cc_conventions = 0 ;
110
#endif
111
 
112
bool reused_parameter
113
    PROTO_N ( ( e ) )
114
    PROTO_T ( exp e )
115
{
116
   bool reused = 0 ;
117
   exp def, ident_exp ;
118
   def = son ( e ) ;
119
   if ( name ( def ) == name_tag ) {
120
      ident_exp = son ( def ) ;
121
      if ( ! isvar ( ident_exp ) ) {
122
         /* This an obtain_tag of a parameter */
123
         if ( name( son( ident_exp ) ) == formal_callee_tag) {
124
            reused = cur_proc_use_same_callees ;
125
         }
126
         else {
127
            /* caller parameter */
128
            reused = cur_proc_has_tail_call ;
129
         }
130
      }
131
   }
132
   return reused ;
133
}
134
 
135
/*
136
    CAN THE VALUE OF AN EXPRESSION BE PUT INTO A REGISTER?
137
 
138
    This routine returns 1 if the expression e can be put into a register.
139
    It has to have its visible flag false, and to be of a suitable shape.
140
*/
141
 
142
bool regable
143
    PROTO_N ( ( e ) )
144
    PROTO_T ( exp e )
145
{
146
    shape sha ;
147
    char n ;
148
    long sz ;
149
 
150
    if ( isvis ( e ) ) return ( 0 ) ;
151
 
152
    sha = sh ( son ( e ) ) ;
153
    n = name ( sha ) ;
154
    if ( n == realhd || n == doublehd ) return ( 1 ) ;
155
 
156
    sz = shape_size ( sha ) ;
157
 
158
    return ( n != cpdhd && n != nofhd && sz <= 32 ) ;
159
}
160
 
161
 
162
/*
163
    DOES AN EXP HAVE NO SIDE EFFECTS?
164
 
165
    This routine returns 1 if e has no side effects.
166
*/
167
 
168
bool no_side
169
    PROTO_N ( ( e ) )
170
    PROTO_T ( exp e )
171
{
172
    int n = name ( e ) ;
173
    if ( n == ident_tag ) {
174
	return ( no_side ( son ( e ) ) && (no_side ( bro ( son ( e ) ) ) ) ) ;
175
    }
176
    return ( is_a ( n ) || n == test_tag ||
177
	     n == ass_tag || n == testbit_tag ) ;
178
}
179
 
180
    char n ;
181
 
182
/*
183
    IS AN EXP A PUSHABLE PROCEDURE ARGUMENT?
184
 
185
    Can the expression e be pushed directly onto the stack when it is
186
    the parameter of a procedure?
187
*/
188
 
189
bool push_arg
190
    PROTO_N ( ( e ) )
191
    PROTO_T ( exp e )
192
{
193
    unsigned char n = name ( e ) ;
194
 
195
    if ( is_a ( n ) ) return ( 1 ) ;
196
    if ( n == apply_tag || n == apply_general_tag ) return ( reg_result ( sh ( e ) ) ) ;
197
    if ( n == ident_tag ) {
198
	return ( push_arg ( son ( e ) ) && push_arg ( bro ( son ( e ) ) ) ) ;
199
    }
200
    return ( 0 ) ;
201
}
202
 
203
 
204
#if 0
205
 
206
/*
207
    IS A UNION ACTUALLY POINTER VOID?
208
 
209
    No longer used.
210
*/
211
 
212
 
213
#ifndef PTR_VOID_MIN
214
#define PTR_VOID_MIN	10
215
#endif
216
 
217
bool is_ptr_void
218
    PROTO_N ( ( sha ) )
219
    PROTO_T ( shape sha )
220
{
221
    bool go ;
222
    int ptrs = 0 ;
223
    exp t = son ( sha ) ;
224
    if ( t == nilexp ) return ( 0 ) ;
225
    do {
226
	go = ( last ( t ) ? 0 : 1 ) ;
227
	if ( name ( sh ( t ) ) != ptrhd ) return ( 0 ) ;
228
	ptrs++ ;
229
	t = bro ( t ) ;
230
    } while ( go ) ;
231
    if ( ptrs < PTR_VOID_MIN ) return ( 0 ) ;
232
#ifdef PTR_VOID_MAX
233
    if ( ptrs > PTR_VOID_MAX ) return ( 0 ) ;
234
#endif
235
    return ( 1 ) ;
236
}
237
 
238
#endif
239
 
240
 
241
/*
242
    IS A SHAPE COMPOUND?
243
 
244
    This routine is designed to test whether a given shape is compound,
245
    and thus likely to cause problems when it is the parameter of a
246
    procedure.
247
*/
248
 
249
bool cpd_param
250
    PROTO_N ( ( sha ) )
251
    PROTO_T ( shape sha )
252
{
253
    char n = name ( sha ) ;
254
    if ( !cc_conventions || n == bitfhd ) {
255
	long sz = shape_size ( sha ) ;
256
	if ( sz <= 32 ) return ( 0 ) ;
257
    }
258
    return ( n == cpdhd || n == nofhd || n == bitfhd
259
 
260
            || n == s64hd || n == u64hd
261
 
262
            ) ;
263
}
264
 
265
 
266
/*
267
    DOES A PROCEDURE RETURN A RESULT OF A GIVEN SHAPE IN A REGISTER?
268
 
269
    cc has two ways of getting results from procedures.  Firstly in the
270
    register D0 (or D0 and D1 in certain cases) and secondly in a section
271
    of memory the address of which is passed in at the start of the
272
    procedure in the A1 register and returned at the end in the D0
273
    register.  This routine works out whether or not a procedure
274
    delivering a result of shape sha will use the first method.
275
*/
276
 
277
 
278
int reg_result
279
    PROTO_N ( ( sha ) )
280
    PROTO_T ( shape sha )
281
{
282
    char n = name ( sha ) ;
283
    if ( cc_conventions ) {
284
	/* HP cc doesn't return any tuples, unions etc in a register */
285
	return ( n != cpdhd && n != nofhd ) ;
286
    } else {
287
	/* Return anything of size <= 32 or 64 in a register */
288
	long sz = shape_size ( sha ) ;
289
	return ( sz <= 32 || sz == 64 ) ;
290
    }
291
}
292
 
293
 
294
/*
295
    IS A SHAPE OF VARIABLE SIZE?
296
 
297
    This routine returns 1 if sha involves an array.
298
*/
299
 
300
bool varsize
301
    PROTO_N ( ( sha ) )
302
    PROTO_T ( shape sha )
303
{
304
    return ( name ( sha ) == nofhd ? 1 : 0 ) ;
305
}
306
 
307
#if 0
308
Use is_signed macro instead
309
 
310
/*
311
    IS A SHAPE SIGNED?
312
 
313
    This routine returns 1 if the integer variety shape sha is signed
314
    and 0 otherwise.
315
*/
316
 
317
bool issigned
318
    PROTO_N ( ( sha ) )
319
    PROTO_T ( shape sha )
320
{
321
    char n = name ( sha ) ;
322
    if ( n == ucharhd || n == uwordhd || n == ulonghd ) return ( 0 ) ;
323
    return ( 1 ) ;
324
}
325
#endif
326
 
327
/*
328
    CHECK ON DECLARATION FOR PARAMETER SUBSTITUTION
329
 
330
    This routine checks if the declaration e should be substituted
331
    for all its uses or not.
332
*/
333
 
334
int do_sub_params = 1 ;
335
 
336
int check_anyway
337
    PROTO_N ( ( e ) )
338
    PROTO_T ( exp e )
339
{
340
#ifndef tdf3
341
   return 0 ;
342
#else
343
    if ( do_sub_params ) {
344
	setmarked ( e ) ;
345
	if ( no ( e ) > 2 ) return ( 1 ) ;
346
    }
347
    return ( 0 ) ;
348
#endif
349
}
350
 
351
 
352
/*
353
    IS IT WORTH EXTRACTING A CONSTANT?
354
*/
355
 
356
int is_worth
357
    PROTO_N ( ( c ) )
358
    PROTO_T ( exp c )
359
{
360
  unsigned char cnam = name ( c ) ;
361
  return ( ( !is_o ( cnam ) && cnam != clear_tag ) ||
362
      /* ignore simple things unless ... */
363
      ( cnam == cont_tag && name ( son ( c ) ) == cont_tag &&
364
	name ( son ( son ( c ) ) )  == name_tag ) ||
365
      ( cnam == name_tag && isparam ( son ( c ) ) && !isvar ( son ( c ) ) &&
366
	shape_size ( sh ( c ) ) <= 32 && name ( sh ( c ) ) != shrealhd ) ) ;
367
}