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/tendra4/src/installers/680x0/common/trans.c – Rev 2

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
/*
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/trans.c,v 1.1.1.1 1998/01/17 15:55:49 release Exp $
35
--------------------------------------------------------------------------
36
$Log: trans.c,v $
37
 * Revision 1.1.1.1  1998/01/17  15:55:49  release
38
 * First version to be checked into rolling release.
39
 *
40
Revision 1.2  1997/10/29 10:22:31  ma
41
Replaced use_alloca with has_alloca.
42
 
43
Revision 1.1.1.1  1997/10/13 12:43:00  ma
44
First version.
45
 
46
Revision 1.6  1997/10/13 08:50:13  ma
47
Made all pl_tests for general proc & exception handling pass.
48
 
49
Revision 1.5  1997/09/25 06:45:36  ma
50
All general_proc tests passed
51
 
52
Revision 1.4  1997/06/18 12:04:59  ma
53
Merged with Input Baseline changes.
54
 
55
Revision 1.3  1997/06/18 10:09:45  ma
56
Checking in before merging with Input Baseline changes.
57
 
58
Revision 1.2  1997/04/20 11:30:40  ma
59
Introduced gcproc.c & general_proc.[ch].
60
Added cases for apply_general_proc next to apply_proc in all files.
61
 
62
Revision 1.1.1.1  1997/03/14 07:50:19  ma
63
Imported from DRA
64
 
65
 * Revision 1.1.1.1  1996/09/20  10:56:59  john
66
 *
67
 * Revision 1.2  1996/07/05  14:28:02  john
68
 * Changes for spec 3.1
69
 *
70
 * Revision 1.1.1.1  1996/03/26  15:45:18  john
71
 *
72
 * Revision 1.3  94/02/21  16:05:07  16:05:07  ra (Robert Andrews)
73
 * Just declare scan2 traditionally.
74
 *
75
 * Revision 1.2  93/11/19  16:23:34  16:23:34  ra (Robert Andrews)
76
 * Reformatted mark_unaliased.
77
 *
78
 * Revision 1.1  93/02/22  17:16:50  17:16:50  ra (Robert Andrews)
79
 * Initial revision
80
 *
81
--------------------------------------------------------------------------
82
*/
83
 
84
 
85
#include "config.h"
86
#include "common_types.h"
87
#include "expmacs.h"
88
#include "exp.h"
89
#include "flags.h"
90
#include "instrs.h"
91
#include "installglob.h"
92
#include "shapemacs.h"
93
#include "evaluate.h"
94
#include "mach.h"
95
#include "mach_ins.h"
96
#include "mach_op.h"
97
#include "weights.h"
98
#include "mach.h"
99
#include "where.h"
100
#include "coder.h"
101
#include "codex.h"
102
#include "optimise.h"
103
#include "output.h"
104
#include "tests.h"
105
#include "tags.h"
106
#include "utility.h"
107
#if have_diagnostics
108
#include "xdb_basics.h"
109
#endif
110
extern dec *sort_decs PROTO_S ( ( dec * ) ) ;
111
static void output_all_exps PROTO_S ( ( void ) ) ;
112
 
113
/*
114
    INCLUDE DEBUGGING ROUTINES
115
 
116
    These are used to aid in debugging.
117
 
118
*/
119
#ifdef EBUG
120
/*
121
#include <misc/debug>
122
*/
123
void breakpoint PROTO_Z () {}
124
#endif
125
 
126
#ifndef tdf3
127
#include "general_proc.h"
128
#include "68k_globals.h"
129
int need_dummy_double = 0 ;
130
#endif
131
 
132
/*
133
    LOCAL AND GLOBAL NAME PREFIXES
134
*/
135
 
136
char *local_prefix = "L" ;
137
char *name_prefix = "_" ;
138
 
139
 
140
/*
141
    EXTERNAL POSITIONS
142
*/
143
 
144
static long crt_ext_off = 64 ;
145
static long crt_ext_pt = 10 ;
146
 
147
 
148
/*
149
    MARK AN EXPRESSION AS BEING STATIC AND UNALIASED
150
*/
151
 
152
static void mark_unaliased
153
    PROTO_N ( ( e ) )
154
    PROTO_T ( exp e )
155
{
156
    exp p = pt ( e ) ;
157
    bool ca = 1 ;
158
    while ( p != nilexp && ca ) {
159
	exp q = bro ( p ) ;
160
	if ( q == nilexp ) {
161
	    ca = 0 ;
162
	} else if ( !( last ( p ) && name ( q ) == cont_tag ) &&
163
		    !( !last ( p ) && last ( q ) &&
164
		       name ( bro ( q ) ) == ass_tag ) ) {
165
	    ca = 0 ;
166
	}
167
	p = pt ( p ) ;
168
    }
169
    if ( ca ) setcaonly ( e ) ;
170
    return ;
171
}
172
 
173
 
174
/*
175
    PROCESS THE TDF
176
 
177
    This routine gets all the TDF read into the correct operand form
178
    and applies the dead variable and register allocation analysis.
179
*/
180
 
181
void translate_capsule
182
    PROTO_Z ()
183
{
184
    dec *d ;
185
 
186
    /* Fix procedure handling (copied from trans386) */
187
    d = top_def;
188
#if 0
189
    while (d != (dec *) 0) {
190
    exp crt_exp = d -> dec_u.dec_val.dec_exp;
191
    exp idval;
192
      if (!(d -> dec_u.dec_val.dec_var) && (name(sh(crt_exp)) != prokhd ||
193
           ( idval = son(crt_exp) ,
194
             idval != nilexp && name(idval) != null_tag &&
195
               name(idval) != proc_tag && name(idval) != general_proc_tag )) ){
196
	/* make variable, and change all uses to contents */
197
        exp p = pt(crt_exp);
198
        if (d -> dec_u.dec_val.extnamed)
199
          sh(crt_exp) = f_pointer(f_alignment(sh(crt_exp)));
200
	else
201
          setvar(crt_exp);
202
        while (p != nilexp) {
203
          exp np = pt(p);
204
          exp* ptr = refto (father(p), p);
205
          exp c = getexp (sh(p), bro(p), last(p), p, nilexp, 0, 0, cont_tag);
206
          setfather (c, p);
207
          if (no(p) != 0) {
208
            exp r = getexp (sh(p), c, 1, p, nilexp, 0, no(p), reff_tag);
209
            no(p) = 0;
210
            son(c) = r;
211
            setfather (r, p);
212
          }
213
          *ptr = c;
214
          p = np;
215
        }
216
      }
217
      d = d->def_next;
218
    }
219
#endif
220
 
221
 
222
    make_transformations () ;
223
 
224
#ifndef EBUG
225
    opt_all_exps () ;
226
#endif
227
 
228
    /* Mark static unaliases declarations */
229
    if ( !separate_units ) {
230
	for ( d = top_def ; d ; d = d->def_next ) {
231
	    exp c = d->dec_u.dec_val.dec_exp ;
232
	    if ( son ( c ) != nilexp &&
233
		 !( d->dec_u.dec_val.extnamed ) && isvar ( c ) ) {
234
		mark_unaliased ( c ) ;
235
	    }
236
	}
237
    }
238
 
239
    /* Mark locations for all globals */
240
    for ( d = top_def ; d ; d = d->def_next ) {
241
	if ( d->dec_u.dec_val.processed ) {
242
	    exp c = d->dec_u.dec_val.dec_exp ;
243
	    ptno ( c ) = crt_ext_pt++ ;
244
	    no ( c ) = crt_ext_off ;
245
	    crt_ext_off += shape_size ( d->dec_u.dec_val.dec_shape ) ;
246
	}
247
    }
248
 
249
    /* Output all code */
250
    output_all_exps () ;
251
 
252
    return ;
253
}
254
 
255
 
256
/*
257
    TRANSLATE A SINGLE TAG DEFINITION
258
*/
259
 
260
void translate_tagdef
261
    PROTO_Z ()
262
{
263
    return ;
264
}
265
 
266
 
267
/*
268
    TRANSLATE A SINGLE UNIT
269
*/
270
 
271
void translate_unit
272
    PROTO_Z ()
273
{
274
    if ( separate_units ) {
275
	dec *d ;
276
	translate_capsule () ;
277
	d = top_def ;
278
	while ( d ) {
279
	    exp c = d->dec_u.dec_val.dec_exp ;
280
	    no ( c ) = 0 ;
281
	    pt ( c ) = nilexp ;
282
	    d = d->def_next ;
283
	}
284
	crt_repeat = nilexp ;
285
	repeat_list = nilexp ;
286
    }
287
    return ;
288
}
289
 
290
 
291
/*
292
    ENCODE A PROCEDURE
293
 
294
    The procedure with declaration d, name id, definition c and body s
295
    is encoded.
296
*/
297
 
298
static void code_proc
299
    PROTO_N ( ( d, id, c, s ) )
300
    PROTO_T ( dec *d X char *id X exp c X exp s )
301
{
302
    diag_global *di = d->dec_u.dec_val.diag_info ;
303
    int reg_res = ( has_struct_res ( s ) ? 0 : 1 ) ;
304
    int is_ext = ( d->dec_u.dec_val.extnamed ? 1 : 0 ) ;
305
 
306
    area ( ptext ) ;
307
 
308
    cur_proc_dec = d ;
309
    cur_proc_callees_size = 0 ;
310
    cur_proc_has_vcallees = 0 ;
311
 
312
    /* Code procedure body */
313
#if 0
314
    if ( name ( s ) == proc_tag )
315
    cproc ( s, id, -1, is_ext, reg_res, di ) ;
316
    else
317
#endif
318
    gcproc ( s, id, -1, is_ext, reg_res, di) ;
319
 
320
 
321
    d -> dec_u.dec_val.index = cur_proc_env_size ; /* for use in constant evaluation */
322
 
323
    output_env_size(d, cur_proc_env_size);
324
}
325
 
326
 
327
/*
328
    ENCODE A CONSTANT
329
 
330
    The constant with declaration d, name id, definition c and body s
331
    is encoded.
332
*/
333
 
334
static void code_const
335
    PROTO_N ( ( d ) )
336
    PROTO_T ( dec *d )
337
{
338
   exp c = d->dec_u.dec_val.dec_exp ;
339
   exp s = son ( c ) ;
340
   char *id = d->dec_u.dec_val.dec_id ;
341
 
342
   diag_global *di = d->dec_u.dec_val.diag_info ;
343
   area ( isvar ( c ) ? pdata : ptext ) ;
344
#ifndef no_align_directives
345
   make_instr ( m_as_align4, null, null, 0 ) ;
346
#endif
347
   evaluate ( s, L_1 , id, !isvar ( c ), 1, di ) ;
348
}
349
 
350
 
351
/*
352
    ENCODE THE CONSTANTS IN const_list
353
 
354
    All auxiliary constants are formed into a list, const_list.  This
355
    routine applies evaluate to each element of this list.
356
*/
357
 
358
static void code_const_list
359
    PROTO_Z ()
360
{
361
    while ( const_list != nilexp ) {
362
	exp t = const_list ;
363
	exp s = son ( t ) ;
364
	bool b = ( name ( s ) != res_tag ) ;
365
	const_list = bro ( const_list ) ;
366
	if ( name ( s ) == proc_tag || name ( s ) == general_proc_tag ) {
367
	    char *id = alloc_nof ( char, 30 ) ;
368
	    sprintf ( id, "%s%ld", local_prefix, no ( t ) ) ;
369
	    gcproc ( s, null, no ( t ), 0, 1, null ) ;
370
	} else {
371
	    area ( b ? pdata : ptext ) ;
372
	    evaluate ( s, no ( t ), null, b, 0, null ) ;
373
	}
374
    }
375
    return ;
376
}
377
 
378
/*
379
   CONST_READY
380
 
381
   Returns TRUE if it is possible to evaluate the value of the constant now
382
*/
383
 
384
static int const_ready
385
    PROTO_N ( (e) )
386
    PROTO_T ( exp e )
387
{
388
  unsigned char  n = name (e);
389
  if (n == env_size_tag)
390
    return (brog(son(son(e))) -> dec_u.dec_val.processed);
391
  if (n == env_offset_tag)
392
    return (ismarked(son(e)));
393
  if (n == name_tag || son(e) == nilexp)
394
    return 1;
395
  e = son(e);
396
  while (!last(e)) {
397
    if (!const_ready(e))
398
      return 0;
399
    e = bro(e);
400
  }
401
  return (const_ready(e));
402
}
403
 
404
typedef struct delayedconst{
405
   dec* This;
406
   struct delayedconst* next;
407
} delayed_const ;
408
 
409
static delayed_const* delayed_const_list = 0;
410
 
411
static void eval_if_ready
412
    PROTO_N ( ( d ) )
413
    PROTO_T ( dec *d )
414
{
415
   exp c = d->dec_u.dec_val.dec_exp ;
416
   if ( const_ready( c ) ) {
417
      code_const ( d ) ;
418
   }
419
   else {
420
      delayed_const* p = (delayed_const*)xmalloc (sizeof(delayed_const));
421
      p->This = d;
422
      p->next = delayed_const_list;
423
      delayed_const_list = p;
424
   }
425
}
426
 
427
void eval_delayed_const_list
428
    PROTO_Z ()
429
{
430
   delayed_const* p;
431
   bool done = 0;
432
   while (! done) {
433
      done = 1;
434
      for (p = delayed_const_list; p; p = p->next) {
435
         dec* d = p->This;
436
         if ( !d->dec_u.dec_val.processed ) {
437
            exp c = d->dec_u.dec_val.dec_exp ;
438
            if ( const_ready( c ) ) {
439
               code_const ( d ) ;
440
               d->dec_u.dec_val.processed = 1 ;
441
            }
442
            done = 0;
443
         }
444
      }
445
   }
446
}
447
 
448
 
449
/*
450
    OUTPUT ALL THE ENCODED EXPRESSIONS
451
 
452
    This routine scans through all the declarations encoding suitably.
453
*/
454
 
455
static void output_all_exps
456
    PROTO_Z ()
457
{
458
    dec *d = top_def ;
459
    if ( diagnose ) d = sort_decs ( d ) ;
460
 
461
    area ( ptext ) ;
462
 
463
    /* Clear any existing output */
464
    output_all () ;
465
    free_all_ins () ;
466
 
467
    /* Scan through the declarations */
468
    while ( d ) {
469
 
470
	if ( !d->dec_u.dec_val.processed ) {
471
	    exp c = d->dec_u.dec_val.dec_exp ;
472
	    exp s = son ( c ) ;
473
	    char *id = d->dec_u.dec_val.dec_id ;
474
 
475
	    init_output () ;
476
 
477
	    if ( s != nilexp ) {
478
		if ( name ( s ) == proc_tag ||
479
                    name ( s ) == general_proc_tag) {
480
		    code_proc ( d, id, c, s ) ;
481
		    code_const_list () ;
482
                    d->dec_u.dec_val.processed = 1 ;
483
		} else {
484
		    eval_if_ready ( d ) ;
485
		    code_const_list () ;
486
		}
487
	    } else {
488
		shape sha = d->dec_u.dec_val.dec_shape ;
489
		long sz = round ( shape_size ( sha ) / 8, 4 ) ;
490
		area ( ptext ) ;
491
		if ( !is_local ( id ) && isvar ( c ) &&
492
		     varsize ( sha ) && !reserved ( id ) ) {
493
		    if ( sz ) {
494
			mach_op *op1 = make_extern_data ( id, 0 ) ;
495
			mach_op *op2 = make_int_data ( sz ) ;
496
			make_instr ( m_as_common, op1, op2, 0 ) ;
497
		    }
498
		} else {
499
		    if ( is_local ( id ) && no ( c ) ) {
500
			mach_op *op1 = make_extern_data ( id, 0 ) ;
501
			mach_op *op2 = make_int_data ( sz ) ;
502
			make_instr ( m_as_local, op1, op2, 0 ) ;
503
		    }
504
		}
505
                d->dec_u.dec_val.processed = 1 ;
506
	    }
507
 
508
	    output_all () ;
509
	    free_all_ins () ;
510
	}
511
	d = d->def_next ;
512
    }
513
 
514
    eval_delayed_const_list();
515
    output_all () ;
516
    free_all_ins () ;
517
 
518
    /* Add final touches */
519
    init_output () ;
520
    if ( need_dummy_double )  {
521
       mach_op *op1 = make_extern_data ("___m68k_dummy_double", 0 ) ;
522
       mach_op *op2 = make_int_data ( 8 ) ;
523
       make_instr ( m_as_common, op1, op2, 0 ) ;
524
    }
525
 
526
    if ( do_profile ) profile_hack () ;
527
 
528
    area ( pdata ) ;
529
    output_all () ;
530
    free_all_ins () ;
531
    return ;
532
}