Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
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
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1996
32
    		 Crown Copyright (c) 1996
3
 
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
Line 102... Line 132...
102
    supported, but the cc conventions are default on the HP.  NeXT
132
    supported, but the cc conventions are default on the HP.  NeXT
103
    cc is gcc.
133
    cc is gcc.
104
*/
134
*/
105
 
135
 
106
#ifdef hp_cc_conventions
136
#ifdef hp_cc_conventions
107
int cc_conventions = 1 ;
137
int cc_conventions = 1;
108
#else
138
#else
109
int cc_conventions = 0 ;
139
int cc_conventions = 0;
110
#endif
140
#endif
111
 
141
 
112
bool reused_parameter
142
bool
113
    PROTO_N ( ( e ) )
-
 
114
    PROTO_T ( exp e )
143
reused_parameter(exp e)
115
{
144
{
116
   bool reused = 0 ;
145
	bool reused = 0;
117
   exp def, ident_exp ;
146
	exp def, ident_exp;
118
   def = son ( e ) ;
147
	def = son(e);
119
   if ( name ( def ) == name_tag ) {
148
	if (name(def) == name_tag) {
120
      ident_exp = son ( def ) ;
149
		ident_exp = son(def);
121
      if ( ! isvar ( ident_exp ) ) {
150
		if (! isvar(ident_exp)) {
122
         /* This an obtain_tag of a parameter */
151
			/* This an obtain_tag of a parameter */
123
         if ( name( son( ident_exp ) ) == formal_callee_tag) {
152
			if (name(son(ident_exp)) == formal_callee_tag) {
124
            reused = cur_proc_use_same_callees ;
153
				reused = cur_proc_use_same_callees;
125
         }
154
			}
126
         else {
155
			else {
127
            /* caller parameter */
156
				/* caller parameter */
128
            reused = cur_proc_has_tail_call ;
157
				reused = cur_proc_has_tail_call;
129
         }
158
			}
130
      }
159
		}
131
   }
160
	}
132
   return reused ;
161
	return reused;
133
}
162
}
134
 
163
 
135
/*
164
/*
136
    CAN THE VALUE OF AN EXPRESSION BE PUT INTO A REGISTER?
165
    CAN THE VALUE OF AN EXPRESSION BE PUT INTO A REGISTER?
137
 
166
 
138
    This routine returns 1 if the expression e can be put into a register.
167
    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.
168
    It has to have its visible flag false, and to be of a suitable shape.
140
*/
169
*/
141
 
170
 
142
bool regable
171
bool
143
    PROTO_N ( ( e ) )
-
 
144
    PROTO_T ( exp e )
172
regable(exp e)
145
{
173
{
146
    shape sha ;
174
	shape sha;
147
    char n ;
175
	char n;
148
    long sz ;
176
	long sz;
149
 
177
 
150
    if ( isvis ( e ) ) return ( 0 ) ;
178
	if (isvis(e)) {
-
 
179
		return (0);
-
 
180
	}
151
 
181
 
152
    sha = sh ( son ( e ) ) ;
182
	sha = sh(son(e));
153
    n = name ( sha ) ;
183
	n = name(sha);
154
    if ( n == realhd || n == doublehd ) return ( 1 ) ;
184
	if (n == realhd || n == doublehd) {
-
 
185
		return (1);
-
 
186
	}
155
 
187
 
156
    sz = shape_size ( sha ) ;
188
	sz = shape_size(sha);
157
 
189
 
158
    return ( n != cpdhd && n != nofhd && sz <= 32 ) ;
190
	return (n != cpdhd && n != nofhd && sz <= 32);
159
}
191
}
160
 
192
 
161
 
193
 
162
/*
194
/*
163
    DOES AN EXP HAVE NO SIDE EFFECTS?
195
    DOES AN EXP HAVE NO SIDE EFFECTS?
164
 
196
 
165
    This routine returns 1 if e has no side effects.
197
    This routine returns 1 if e has no side effects.
166
*/
198
*/
167
 
199
 
168
bool no_side
200
bool
169
    PROTO_N ( ( e ) )
-
 
170
    PROTO_T ( exp e )
201
no_side(exp e)
171
{
202
{
172
    int n = name ( e ) ;
203
	int n = name(e);
173
    if ( n == ident_tag ) {
204
	if (n == ident_tag) {
174
	return ( no_side ( son ( e ) ) && (no_side ( bro ( son ( e ) ) ) ) ) ;
205
		return (no_side(son(e)) && (no_side(bro(son(e)))));
175
    }
206
	}
176
    return ( is_a ( n ) || n == test_tag ||
-
 
177
	     n == ass_tag || n == testbit_tag ) ;
207
	return (is_a(n) || n == test_tag || n == ass_tag || n == testbit_tag);
178
}
208
}
179
 
209
 
180
    char n ;
210
    char n;
181
 
211
 
182
/*
212
/*
183
    IS AN EXP A PUSHABLE PROCEDURE ARGUMENT?
213
    IS AN EXP A PUSHABLE PROCEDURE ARGUMENT?
184
 
214
 
185
    Can the expression e be pushed directly onto the stack when it is
215
    Can the expression e be pushed directly onto the stack when it is
186
    the parameter of a procedure?
216
    the parameter of a procedure?
187
*/
217
*/
188
 
218
 
189
bool push_arg
219
bool
190
    PROTO_N ( ( e ) )
-
 
191
    PROTO_T ( exp e )
220
push_arg(exp e)
192
{
221
{
193
    unsigned char n = name ( e ) ;
222
	unsigned char n = name(e);
194
 
223
 
195
    if ( is_a ( n ) ) return ( 1 ) ;
224
	if (is_a(n)) {
-
 
225
		return (1);
-
 
226
	}
196
    if ( n == apply_tag || n == apply_general_tag ) return ( reg_result ( sh ( e ) ) ) ;
227
	if (n == apply_tag || n == apply_general_tag) {
-
 
228
		return (reg_result(sh(e)));
-
 
229
	}
197
    if ( n == ident_tag ) {
230
	if (n == ident_tag) {
198
	return ( push_arg ( son ( e ) ) && push_arg ( bro ( son ( e ) ) ) ) ;
231
		return (push_arg(son(e)) && push_arg(bro(son(e))));
199
    }
232
	}
200
    return ( 0 ) ;
233
	return (0);
201
}
234
}
202
 
235
 
203
 
236
 
204
#if 0
237
#if 0
205
 
238
 
Line 212... Line 245...
212
 
245
 
213
#ifndef PTR_VOID_MIN
246
#ifndef PTR_VOID_MIN
214
#define PTR_VOID_MIN	10
247
#define PTR_VOID_MIN	10
215
#endif
248
#endif
216
 
249
 
217
bool is_ptr_void
250
bool
218
    PROTO_N ( ( sha ) )
-
 
219
    PROTO_T ( shape sha )
251
is_ptr_void(shape sha)
220
{
252
{
221
    bool go ;
253
	bool go;
222
    int ptrs = 0 ;
254
	int ptrs = 0;
223
    exp t = son ( sha ) ;
255
	exp t = son(sha);
224
    if ( t == nilexp ) return ( 0 ) ;
256
	if (t == nilexp) {
-
 
257
		return (0);
-
 
258
	}
225
    do {
259
	do {
226
	go = ( last ( t ) ? 0 : 1 ) ;
260
		go = (last(t) ? 0 : 1);
227
	if ( name ( sh ( t ) ) != ptrhd ) return ( 0 ) ;
261
		if (name(sh(t)) != ptrhd) {
-
 
262
			return (0);
-
 
263
		}
228
	ptrs++ ;
264
		ptrs++;
229
	t = bro ( t ) ;
265
		t = bro(t);
230
    } while ( go ) ;
266
	} while (go);
231
    if ( ptrs < PTR_VOID_MIN ) return ( 0 ) ;
267
	if (ptrs < PTR_VOID_MIN) {
-
 
268
		return (0);
-
 
269
	}
232
#ifdef PTR_VOID_MAX
270
#ifdef PTR_VOID_MAX
233
    if ( ptrs > PTR_VOID_MAX ) return ( 0 ) ;
271
	if (ptrs > PTR_VOID_MAX) {
-
 
272
		return (0);
-
 
273
	}
234
#endif
274
#endif
235
    return ( 1 ) ;
275
	return (1);
236
}
276
}
237
 
277
 
238
#endif
278
#endif
239
 
279
 
240
 
280
 
Line 244... Line 284...
244
    This routine is designed to test whether a given shape is compound,
284
    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
285
    and thus likely to cause problems when it is the parameter of a
246
    procedure.
286
    procedure.
247
*/
287
*/
248
 
288
 
249
bool cpd_param
289
bool
250
    PROTO_N ( ( sha ) )
-
 
251
    PROTO_T ( shape sha )
290
cpd_param(shape sha)
252
{
291
{
253
    char n = name ( sha ) ;
292
	char n = name(sha);
254
    if ( !cc_conventions || n == bitfhd ) {
293
	if (!cc_conventions || n == bitfhd) {
255
	long sz = shape_size ( sha ) ;
294
		long sz = shape_size(sha);
256
	if ( sz <= 32 ) return ( 0 ) ;
295
		if (sz <= 32) {
-
 
296
			return (0);
257
    }
297
		}
258
    return ( n == cpdhd || n == nofhd || n == bitfhd
-
 
259
 
298
	}
260
            || n == s64hd || n == u64hd
299
	return (n == cpdhd || n == nofhd || n == bitfhd || n == s64hd ||
261
 
-
 
262
            ) ;
300
		n == u64hd);
263
}
301
}
264
 
302
 
265
 
303
 
266
/*
304
/*
267
    DOES A PROCEDURE RETURN A RESULT OF A GIVEN SHAPE IN A REGISTER?
305
    DOES A PROCEDURE RETURN A RESULT OF A GIVEN SHAPE IN A REGISTER?
Line 273... Line 311...
273
    register.  This routine works out whether or not a procedure
311
    register.  This routine works out whether or not a procedure
274
    delivering a result of shape sha will use the first method.
312
    delivering a result of shape sha will use the first method.
275
*/
313
*/
276
 
314
 
277
 
315
 
278
int reg_result
316
int
279
    PROTO_N ( ( sha ) )
-
 
280
    PROTO_T ( shape sha )
317
reg_result(shape sha)
281
{
318
{
282
    char n = name ( sha ) ;
319
	char n = name(sha);
283
    if ( cc_conventions ) {
320
	if (cc_conventions) {
284
	/* HP cc doesn't return any tuples, unions etc in a register */
321
		/* HP cc doesn't return any tuples, unions etc in a register */
285
	return ( n != cpdhd && n != nofhd ) ;
322
		return (n != cpdhd && n != nofhd);
286
    } else {
323
	} else {
287
	/* Return anything of size <= 32 or 64 in a register */
324
		/* Return anything of size <= 32 or 64 in a register */
288
	long sz = shape_size ( sha ) ;
325
		long sz = shape_size(sha);
289
	return ( sz <= 32 || sz == 64 ) ;
326
		return (sz <= 32 || sz == 64);
290
    }
327
	}
291
}
328
}
292
 
329
 
293
 
330
 
294
/*
331
/*
295
    IS A SHAPE OF VARIABLE SIZE?
332
    IS A SHAPE OF VARIABLE SIZE?
296
 
333
 
297
    This routine returns 1 if sha involves an array.
334
    This routine returns 1 if sha involves an array.
298
*/
335
*/
299
 
336
 
300
bool varsize
337
bool
301
    PROTO_N ( ( sha ) )
-
 
302
    PROTO_T ( shape sha )
338
varsize(shape sha)
303
{
339
{
304
    return ( name ( sha ) == nofhd ? 1 : 0 ) ;
340
	return (name(sha) == nofhd ? 1 : 0);
305
}
341
}
306
 
342
 
307
#if 0
343
#if 0
308
Use is_signed macro instead
344
Use is_signed macro instead
309
 
345
 
Line 312... Line 348...
312
 
348
 
313
    This routine returns 1 if the integer variety shape sha is signed
349
    This routine returns 1 if the integer variety shape sha is signed
314
    and 0 otherwise.
350
    and 0 otherwise.
315
*/
351
*/
316
 
352
 
317
bool issigned
353
bool
318
    PROTO_N ( ( sha ) )
-
 
319
    PROTO_T ( shape sha )
354
issigned(shape sha)
320
{
355
{
321
    char n = name ( sha ) ;
356
	char n = name(sha);
322
    if ( n == ucharhd || n == uwordhd || n == ulonghd ) return ( 0 ) ;
357
	if (n == ucharhd || n == uwordhd || n == ulonghd) {
-
 
358
		return (0);
-
 
359
	}
323
    return ( 1 ) ;
360
	return (1);
324
}
361
}
325
#endif
362
#endif
326
 
363
 
327
/*
364
/*
328
    CHECK ON DECLARATION FOR PARAMETER SUBSTITUTION
365
    CHECK ON DECLARATION FOR PARAMETER SUBSTITUTION
329
 
366
 
330
    This routine checks if the declaration e should be substituted
367
    This routine checks if the declaration e should be substituted
331
    for all its uses or not.
368
    for all its uses or not.
332
*/
369
*/
333
 
370
 
334
int do_sub_params = 1 ;
371
int do_sub_params = 1;
335
 
372
 
336
int check_anyway
373
int
337
    PROTO_N ( ( e ) )
-
 
338
    PROTO_T ( exp e )
374
check_anyway(exp e)
339
{
375
{
340
#ifndef tdf3
376
#ifndef tdf3
341
   return 0 ;
377
	return 0;
342
#else
378
#else
343
    if ( do_sub_params ) {
379
	if (do_sub_params) {
344
	setmarked ( e ) ;
380
		setmarked(e);
345
	if ( no ( e ) > 2 ) return ( 1 ) ;
381
		if (no(e) > 2) {
-
 
382
			return (1);
346
    }
383
		}
-
 
384
	}
347
    return ( 0 ) ;
385
	return (0);
348
#endif
386
#endif
349
}
387
}
350
 
388
 
351
 
389
 
352
/*
390
/*
353
    IS IT WORTH EXTRACTING A CONSTANT?
391
    IS IT WORTH EXTRACTING A CONSTANT?
354
*/
392
*/
355
 
393
 
356
int is_worth
394
int
357
    PROTO_N ( ( c ) )
-
 
358
    PROTO_T ( exp c )
395
is_worth(exp c)
359
{
396
{
360
  unsigned char cnam = name ( c ) ;
397
	unsigned char cnam = name(c);
361
  return ( ( !is_o ( cnam ) && cnam != clear_tag ) ||
398
	return ((!is_o(cnam) && cnam != clear_tag) ||
362
      /* ignore simple things unless ... */
399
		/* ignore simple things unless ... */
363
      ( cnam == cont_tag && name ( son ( c ) ) == cont_tag &&
400
		(cnam == cont_tag && name(son(c)) == cont_tag &&
364
	name ( son ( son ( c ) ) )  == name_tag ) ||
401
		 name(son(son(c))) == name_tag) ||
365
      ( cnam == name_tag && isparam ( son ( c ) ) && !isvar ( son ( c ) ) &&
402
		(cnam == name_tag && isparam(son(c)) && !isvar(son(c)) &&
366
	shape_size ( sh ( c ) ) <= 32 && name ( sh ( c ) ) != shrealhd ) ) ;
403
		 shape_size(sh(c)) <= 32 && name(sh(c)) != shrealhd));
367
}
404
}