Subversion Repositories tendra.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
33
/*
34
			    VERSION INFORMATION
35
			    ===================
36
 
37
--------------------------------------------------------------------------
38
$Header: /u/g/release/CVSROOT/Source/src/installers/sparc/common/sparctrans.c,v 1.4 1998/03/11 11:03:59 pwe Exp $
39
--------------------------------------------------------------------------
40
$Log: sparctrans.c,v $
41
 * Revision 1.4  1998/03/11  11:03:59  pwe
42
 * DWARF optimisation info
43
 *
44
 * Revision 1.3  1998/02/06  17:04:37  release
45
 * Last minute pre-release polishing.
46
 *
47
 * Revision 1.2  1998/01/21  10:30:12  pwe
48
 * labdiff change
49
 *
50
 * Revision 1.1.1.1  1998/01/17  15:55:55  release
51
 * First version to be checked into rolling release.
52
 *
53
 * Revision 1.15  1997/12/05  10:38:59  pwe
54
 * system identification
55
 *
56
 * Revision 1.14  1997/10/28  10:19:10  pwe
57
 * extra diags
58
 *
59
 * Revision 1.13  1997/10/10  18:33:02  pwe
60
 * prep ANDF-DE revision
61
 *
62
 * Revision 1.12  1997/08/23  13:54:36  pwe
63
 * initial ANDF-DE
64
 *
65
 * Revision 1.11  1997/06/02  08:42:37  pwe
66
 * diags visibility
67
 *
68
 * Revision 1.10  1997/04/17  11:59:59  pwe
69
 * dwarf2 support
70
 *
71
 * Revision 1.9  1997/02/18  11:48:27  pwe
72
 * NEWDIAGS for debugging optimised code
73
 *
74
 * Revision 1.8  1996/08/15  15:34:54  pwe
75
 * mod for PWE ownership
76
 *
77
 * Revision 1.7  1996/03/18  09:02:17  john
78
 * Changed dynamic init default.
79
 *
80
 * Revision 1.6  1996/02/21  15:10:38  john
81
 * dynamic initialisations turned on by default
82
 *
83
 * Revision 1.5  1995/12/15  10:27:46  john
84
 * Added dynamic initialisations on SunOS
85
 *
86
 * Revision 1.4  1995/11/24  11:41:53  john
87
 * Fix for postludes
88
 *
89
 * Revision 1.3  1995/06/27  09:12:17  john
90
 * Reformatting
91
 *
92
 * Revision 1.2  1995/03/14  17:54:41  john
93
 * Changed default optimisation level
94
 *
95
 * Revision 1.1.1.1  1995/03/13  10:18:57  john
96
 * Entered into CVS
97
 *
98
 * Revision 1.7  1994/10/26  13:44:06  djch
99
 * added switches -i[idas] to give runtime control of inlining choices
100
 *
101
 * Revision 1.6  1994/07/07  16:11:33  djch
102
 * Jul94 tape
103
 *
104
 * Revision 1.5  1994/07/04  08:30:49  djch
105
 * Changes to argument values and names, in conformance to new man page for all
106
 * installers.
107
 *
108
 * Revision 1.4  1994/05/24  13:13:53  djch
109
 * hacked -O to provide flpt overflow off, and -O? to be optimization
110
 *
111
 * Revision 1.3  1994/05/13  13:11:23  djch
112
 * Incorporates improvements from expt version
113
 * included debug.h to get enums to suport printing tag and shape names
114
 * changed default to do inlining and foralls, made their switches toggle...
115
 *
116
 * Revision 1.2  1994/05/03  15:13:39  djch
117
 * removed the -R flag (inner procs now in the common section)
118
 *
119
 * Revision 1.10  94/02/21  16:13:24  16:13:24  ra (Robert Andrews)
120
 * A couple of flags have changed.
121
 * 
122
 * Revision 1.9  93/11/19  16:31:27  16:31:27  ra (Robert Andrews)
123
 * Changed version number to 0.10.
124
 * 
125
 * Revision 1.8  93/09/27  14:55:41  14:55:41  ra (Robert Andrews)
126
 * The values of name_prefix, local_prefix and lab_prefix (which is new)
127
 * vary according to the target machine.
128
 * 
129
 * Revision 1.7  93/08/27  11:38:14  11:38:14  ra (Robert Andrews)
130
 * A couple of lint-like changes.  The definitions of local_prefix and
131
 * name_prefix are now not duplicated (see machine.c).
132
 * 
133
 * Revision 1.6  93/08/18  11:17:03  11:17:03  ra (Robert Andrews)
134
 * Changed method of specifying target machine (see config.h).
135
 * 
136
 * Revision 1.5  93/08/13  14:46:34  14:46:34  ra (Robert Andrews)
137
 * Removed a couple of comments.
138
 * 
139
 * Revision 1.4  93/07/14  11:22:15  11:22:15  ra (Robert Andrews)
140
 * Add options to set library_key.
141
 * 
142
 * Revision 1.3  93/07/05  18:28:24  18:28:24  ra (Robert Andrews)
143
 * Made distinction between the System V assembler and the System V ABI.
144
 * Added support for PIC (switched on using the -D option).
145
 * 
146
 * Revision 1.2  93/06/29  14:34:22  14:34:22  ra (Robert Andrews)
147
 * Slight reorganisation.  Error messages now use sparctrans (the variable).
148
 * The version number has also changed.
149
 * 
150
 * Revision 1.1  93/06/24  14:59:26  14:59:26  ra (Robert Andrews)
151
 * Initial revision
152
 * 
153
--------------------------------------------------------------------------
154
*/
155
 
156
 
157
#define SPARCTRANS_CODE
158
#include "config.h"
159
#include "release.h"
160
#include "flags.h"
161
#include "tempdecs.h"
162
#include "comment.h"
163
#include "translat.h"
164
#include "main_reads.h"	
165
#include "basicread.h"
166
#include "addrtypes.h"
167
#include "makecode.h"
168
#include "flpt.h"
169
#include "exptypes.h"
170
#include "exp.h"
171
#include "installglob.h"
172
#include "out.h"
173
#include "externs.h"
174
#include "special.h"
175
#include "labels.h"
176
 
177
#include "target_v.h"
178
#include "reader_v.h"
179
#include "construct_v.h"
180
#ifdef NEWDIAGS
181
#include "diag_v.h"
182
#include "dg_version.h"
183
#endif
184
#ifdef NEWDWARF
185
#include "dw2_iface.h"
186
#include "dw2_vsn.h"
187
#include "dw2_abbrev.h"
188
#include "dw2_common.h"
189
static bool dump_abbrev = 0 ;
190
#endif
191
 
192
#if DWARF
193
#include "dwarf_mc.h"
194
#endif
195
 
196
extern int good_trans ;
197
 
198
#include "debug.h"
199
/*
200
  IDENTIFIER PREFIXES
201
*/
202
 
203
char *local_prefix = "", *name_prefix = "" ;
204
 
205
 
206
/*
207
  LOCAL FLAGS
208
*/
209
 
210
extern int redo_structparams ;
211
bool do_tlrecursion = 0 ;
212
#if 0
213
bool do_innerprocs = 0 ;
214
#endif
215
 
216
extern int crit_inline;
217
extern int crit_decs;
218
extern int crit_decsatapp;
219
extern int show_inlining;
220
 
221
int do_dynamic_init=1;    /* Only applies to SunOS */
222
 
223
/*
224
  OPEN INPUT AND OUTPUT FILES
225
*/
226
 
227
static void open_files 
228
    PROTO_N ( ( infname, outfname ) )
229
    PROTO_T ( char * infname X char * outfname ){
230
 
231
  if ( !initreader ( infname ) ) {
232
    fprintf ( stderr, "%s : cannot open input file %s\n",
233
	      sparctrans, infname ) ;
234
    exit ( EXIT_FAILURE ) ;
235
  }
236
 
237
  if ( strcmp ( outfname, "-" ) == 0 ) {
238
    /* "-" by convention means stdout */
239
    as_file = stdout ;
240
  } 
241
  else {
242
    as_file = fopen ( outfname, "w" ) ;
243
    if ( as_file == NULL ) {
244
      fprintf ( stderr, "%s : cannot open output file %s\n",
245
		sparctrans, outfname ) ;
246
      exit ( EXIT_FAILURE ) ;
247
    }
248
  }
249
  return ;
250
}
251
 
252
 
253
/*
254
  MAIN ROUTINE
255
*/
256
 
257
int main 
258
    PROTO_N ( ( argc, argv ) )
259
    PROTO_T ( int argc X char ** argv )
260
{
261
  int a = 1 ;
262
  char *arg ;
263
  char *infname ;
264
  char *outfname ;
265
  bool errflg = 0 ;
266
 
267
  /* initialise executable name */
268
  sparctrans = argv [0] ;
269
  for ( arg = sparctrans ; *arg ; arg++ ) {
270
    if ( *arg == '/' ) sparctrans = arg + 1 ;
271
  }
272
 
273
  /* initialise output file */
274
  as_file = stdout ;
275
 
276
  /* errors messages are output on stdout, ensure they get out */
277
  setbuf ( stdout, NULL ) ;
278
  setbuf ( stderr, NULL ) ;
279
 
280
  /* set defaults for options */
281
  do_inlining = 1 ;			/* do inline */
282
  do_special_fns = 1 ;			/* do special functions */
283
  do_loopconsts = 1 ;			/* do loop constant extraction */
284
  do_foralls = 1;			/* do do foralls optimisation */
285
  do_unroll = 1;			/* do unroll loops */
286
 
287
  redo_structfns = 0 ;			/* structure results are normal */
288
  redo_structparams = 1 ;		/* structure parameters are odd */
289
  diagnose = 0 ;			/* not in diagnostics mode */
290
#ifdef NEWDIAGS
291
  diag_visible = 0;
292
  extra_diags = 0;
293
#endif
294
#ifdef NEWDWARF
295
  dwarf2 = 0;
296
#endif
297
  do_profile = 0 ;			/* not in profiling mode */
298
  PIC_code = 0 ;			/* don't do PIC */
299
  do_alloca = 1 ;			/* inline alloca */
300
  tempdecopt = 1 ;			/* do the tempdec optimisation */
301
  sysV_abi = SYSV_ABI ;			/* SYSV version */
302
  sysV_assembler = SYSV_AS ;		/* SYSV version */
303
  optim_level = 2 ;			/* default, equivalent to -O2 */
304
  g_reg_max = ( sysV_abi ? 4 : 7 ) ;	/* number of G registers */
305
 
306
 
307
  flpt_const_overflow_fail = 1;		/* constant floating point arithmetic
308
					   fails installation, if overflow */
309
  strict_fl_div = 1;			/* don't mult by 1/constant */
310
  round_after_flop = 0;			/* don't round every time */
311
  do_dynamic_init = 1;                  /* Only applies to SunOS*/
312
 
313
#define GET_0_1 ((arg[2] == '1') ? 1 : 0)
314
    /* process program arguments */
315
    while ( a < argc && ( arg = argv [a], arg [0] == '-' ) ) {
316
      switch ( arg [1] ) {
317
	case 'A' : do_alloca = GET_0_1 ; break ;
318
	case 'B' : flpt_const_overflow_fail = GET_0_1; break;	
319
	case 'C' : do_loopconsts = GET_0_1; break ;
320
	case 'D' : PIC_code = GET_0_1 ; break ;
321
	case 'E' : extra_checks = 0 ; break ;
322
	case 'F' : do_foralls = GET_0_1 ; break ;
323
	case 'H' : {
324
	  diagnose = 1 ;
325
#ifdef NEWDIAGS
326
	  if (arg[2] != 'O')
327
	    diag_visible = 1;
328
#endif
329
	  break ;
330
	}
331
	case 'I' : do_inlining = GET_0_1 ; break ;
332
#ifdef NEWDWARF
333
        case 'J' : 
334
	  diagnose = 1;
335
	  extra_diags = 1;
336
	  dwarf2 = 1;
337
	  break;
338
#endif
339
	case 'K' : break;
340
	case 'M' : strict_fl_div = GET_0_1 ; break ;
341
	case 'N' : do_prom = 1 ; break ;
342
	case 'O' : {
343
	  /* optimisation level */
344
	  optim_level = atoi ( arg + 2 ) ;
345
	  if ( optim_level < 0 ) optim_level = 0 ;
346
	  if ( optim_level > 4 ) optim_level = 4 ;
347
	  break ;
348
	}
349
 
350
	case 'P' : do_profile = 1 ; break ;	      
351
	case 'Q' : exit(EXIT_SUCCESS); break;
352
	case 'R' : round_after_flop = GET_0_1; break;
353
#ifdef NEWDWARF
354
	case 'T' :
355
	  dump_abbrev = 1;
356
	  diagnose = 1;
357
	  extra_diags = 1;
358
	  dwarf2 = 1;
359
	  break;
360
#endif
361
	case 'U' : do_unroll = GET_0_1; break;
362
 
363
	case 'V':
364
	IGNORE fprintf(stderr, "DERA ANDF Sparc translator (TDF version %d.%d)\n",
365
		      MAJOR_VERSION, MINOR_VERSION);
366
	IGNORE fprintf(stderr, "reader %d.%d: ", reader_version,
367
		      reader_revision);
368
	IGNORE fprintf(stderr, "construct %d.%d: ", construct_version,
369
		      construct_revision);
370
	IGNORE fprintf(stderr, "target %d.%d: ", target_version,
371
		      target_revision);
372
#if (DWARF == 1)
373
	IGNORE fprintf(stderr, "dwarf %d.%d: ", DWARF_MAJOR,
374
		      DWARF_MINOR);
375
#endif
376
#ifdef NEWDIAGS
377
	IGNORE fprintf(stderr, "diag_info %d.%d:\n%s   ", diag_version,
378
		 diag_revision, DG_VERSION);
379
#endif
380
#ifdef NEWDWARF
381
	IGNORE fprintf(stderr, "dwarf2 %d.%d: ", DWARF2_MAJOR,
382
		 DWARF2_MINOR);
383
#endif
384
	IGNORE fprintf(stderr, "\n");
385
	IGNORE fprintf(stderr, "system %s: ", target_system);
386
#ifdef __DATE__
387
	IGNORE fprintf(stderr, "installer compilation %s", __DATE__);
388
#endif
389
	IGNORE fprintf(stderr, "\n");
390
#ifdef RELEASE
391
	IGNORE fprintf(stderr, "release: %s\n",RELEASE);
392
#endif
393
	break;
394
 
395
	case 'W' : break;
396
	case 'X' : {
397
	  /* disable all optimisations */
398
	  optim_level = 0 ;
399
	  tempdecopt = 0 ;
400
	  do_inlining = 0 ;
401
	  do_loopconsts = 0 ;
402
	  do_foralls = 0 ;
403
	  do_tlrecursion = 0 ;
404
	  do_unroll = 0;
405
	  break ;
406
	}
407
	case 'Z' : report_versions = 1 ; break ;
408
 
409
/* undocumented sparc specific flags below here */
410
 
411
	case 'a' : sysV_abi = 1 ; g_reg_max = 4 ; break ;
412
	case 'c' : do_comment = 1 ; break ;
413
	case 'g' : library_key = 2 ; break ;
414
	case 'l' : library_key = 1 ; break ;
415
	case 'i':
416
	switch (arg[2]) {
417
	  case 'i':
418
	  crit_inline = atoi(arg+3);
419
	  break;
420
	  case 'd':
421
	  crit_decs = atoi(arg+3);
422
	  break;
423
	  case 'a':
424
	  crit_decsatapp = atoi(arg+3);
425
	  break;
426
	  case 's':
427
	  fprintf(stderr,"count %d decs %d decs@app %d\n",
428
		  crit_inline, crit_decs, crit_decsatapp);
429
	  show_inlining = 1;
430
	  break;
431
	  default:
432
	  fprintf(stderr,"Incorrect inline option %c\n",arg[2]);
433
	}
434
	break;
435
	case 'r' : {
436
	  /* number of G registers */
437
	  g_reg_max = atoi ( arg + 2 ) ;
438
	  if ( g_reg_max < 4 ) g_reg_max = 4 ;
439
	  if ( g_reg_max > 7 ) g_reg_max = 7 ;
440
	  break ;
441
	}
442
	case 't' : tempdecopt = 0 ; break ;
443
 
444
	case 'u' : {
445
	  separate_units = 1 ;
446
#if 0	
447
	  current_alloc_size = first_alloc_size ;
448
#endif	
449
	  case 'n': {
450
	    do_dynamic_init = GET_0_1;
451
	  }
452
	  break ;
453
	}
454
 
455
	default : {
456
	  fprintf ( stderr, "%s : unknown option, %s\n",
457
		    sparctrans, arg ) ;
458
	  break ;
459
	}
460
      }
461
      a++ ;
462
    }
463
 
464
    /* we expect two further filename arguments */
465
    if ( argc == a + 2 ) {
466
      infname = argv [a] ;
467
      outfname = argv [ a + 1 ] ;
468
    } 
469
    else if ( argc == a + 1 ) {
470
      infname = argv [a] ;
471
      outfname = "-" ;
472
    } 
473
    else {
474
      if ( argc == a )
475
	fprintf ( stderr, "%s : input file missing\n", sparctrans );
476
      errflg = 1 ;
477
    }
478
 
479
    /* check ABI conformance */
480
    if ( sysV_abi && ( g_reg_max > 4 ) ) {
481
      fprintf ( stderr, "%s : -r%d conflicts with SYSV ABI\n",
482
		sparctrans, g_reg_max ) ;
483
    }
484
 
485
    /* quit if arguments were wrong */
486
    if ( errflg ) {
487
      exit ( EXIT_FAILURE ) ;
488
    }
489
 
490
    /* switch off certain optimisations in diagnostics mode */
491
#ifdef NEWDIAGS
492
    if ( diag_visible ) {
493
#else
494
    if ( diagnose ) {
495
#endif
496
      optim_level = 0 ;
497
      tempdecopt = 0 ;
498
      do_inlining = 0 ;
499
      do_loopconsts = 0 ;
500
      do_foralls = 0 ;
501
      all_variables_visible = 1;	/* set vis flag for all declarations */
502
    }	
503
 
504
    /* initialise nowhere */
505
    setregalt ( nowhere.answhere, 0 ) ;
506
    nowhere.ashwhere.ashsize = 0 ;
507
    nowhere.ashwhere.ashsize = 0 ;
508
 
509
    /* initialise name prefixes and label numbers */
510
    name_prefix = ( sysV_assembler ? "" : "_" ) ;
511
    local_prefix = ( sysV_assembler ? ".." : "$$" ) ;
512
    lab_prefix = ( sysV_assembler ? ".L" : "L." ) ;
513
    crt_labno = 101 ;
514
 
515
    /* other initialisation routines */
516
    init_flpt () ;
517
#include "inits.h"
518
    top_def = null ;
519
 
520
    /* main decoding routines */
521
    open_files ( infname, outfname ) ;
522
    init_translator () ;
523
#ifdef NEWDWARF
524
    if ( dump_abbrev ) {
525
	/* Dump abbreviations table */
526
	do_abbreviations () ;
527
	dwarf2_prelude () ;
528
	make_dwarf_common () ;
529
	dwarf2_postlude () ;
530
    } else
531
#endif
532
    d_capsule () ;
533
    exit_translator () ;
534
    if ( good_trans ) exit ( EXIT_FAILURE ) ;
535
 
536
    /* check for output errors and close the output file */
537
    if ( ferror ( as_file ) != 0 || fclose ( as_file ) != 0 ) {
538
      fprintf ( stderr, "%s : output file error, %s\n",
539
		sparctrans, outfname ) ;
540
      exit ( EXIT_FAILURE ) ;
541
    }
542
 
543
    /* success */
544
    exit ( EXIT_SUCCESS ) ;
545
#ifdef lint
546
    return ( 0 ) ;
547
#endif
548
}