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) 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
$Log: hppatrans.c,v $
33
 * Revision 1.1.1.1  1998/01/17  15:56:04  release
34
 * First version to be checked into rolling release.
35
 *
36
 * Revision 1.6  1996/04/18  11:09:12  wfs
37
 * Fixed a bug in "needscan.c" where "locptr_tag" was being wrapped around
38
 * the wrong exps.
39
 *
40
 * Revision 1.5  1996/01/30  15:36:29  wfs
41
 * Added the dynamic initialization files "dyn_begin.s" and "dyn_end.s" to
42
 * the hppatrans repository. The bl_install and bl_update scripts were
43
 * expanded to deal with these new "initcode" files.
44
 *
45
 * Revision 1.4  1996/01/08  12:01:50  wfs
46
 * Cosmetic changes to usage message in "hppatrans.c". "issparc" set to 0 in
47
 * "config.h". Change to "scan()" regarding the passing of 64 bit int params.
48
 *
49
 * Revision 1.3  1995/12/20  12:11:18  wfs
50
 * "-v" option disabled. "ManualPages" put under cvs control.
51
 *
52
 * Revision 1.2  1995/12/18  13:11:35  wfs
53
 * Put hppatrans uder cvs control. Major Changes made since last release
54
 * include:
55
 * (i) PIC code generation.
56
 * (ii) Profiling.
57
 * (iii) Dynamic Initialization.
58
 * (iv) Debugging of Exception Handling and Diagnostics.
59
 *
60
 * Revision 5.5  1995/10/30  12:57:56  wfs
61
 * Standardized the format of the warning messages.
62
 *
63
 * Revision 5.4  1995/10/25  14:32:46  wfs
64
 * Removed a few commented out instructions.
65
 *
66
 * Revision 5.3  1995/10/20  13:55:38  wfs
67
 * Changes for gcc compilation.
68
 *
69
 * Revision 5.2  1995/09/25  10:17:42  wfs
70
 * Added "#ifdef _SYMTAB_INCLUDED" provisios around any code which refers
71
 * to "hpux-symtab.h". We cannot legally distribute this header file.
72
 *
73
 * Revision 5.1  1995/09/15  12:29:03  wfs
74
 * Minor changes made to stop gcc compiler from complaining + changed
75
 * messages citing "hppatrans" to "trans".
76
 *
77
 * Revision 5.0  1995/08/25  13:42:58  wfs
78
 * Preperation for August 25 Glue release
79
 *
80
 * Revision 3.4  1995/08/25  11:22:17  wfs
81
 * Name of installer occuring in messages changed from "hppatrans" to
82
 * "trans"
83
 *
84
 * Revision 3.4  1995/08/25  11:22:17  wfs
85
 * Name of installer occuring in messages changed from "hppatrans" to
86
 * "trans"
87
 *
88
 * Revision 3.3  1995/08/25  09:36:12  wfs
89
 * some superflous code removed ( includingincluding the SunOS "-G" option).
90
 * minor alterations for diagnostics stuff.
91
 *
92
 * Revision 3.1  95/04/10  16:26:49  16:26:49  wfs (William Simmonds)
93
 * Apr95 tape version.
94
 * 
95
 * Revision 3.0  95/03/30  11:17:27  11:17:27  wfs (William Simmonds)
96
 * Mar95 tape version with CRCR95_178 bug fix.
97
 * 
98
 * Revision 2.0  95/03/15  15:27:34  15:27:34  wfs (William Simmonds)
99
 * spec 3.1 changes implemented, tests outstanding.
100
 * 
101
 * Revision 1.1  95/01/17  13:58:43  13:58:43  wfs (William Simmonds)
102
 * Initial revision
103
 * 
104
*/
105
 
106
 
107
 
108
#define HPPATRANS_CODE
109
#include "config.h"		/* for PROTO_S () */
110
#include "flags.h"		/* for option flags */
111
#include "tempdecs.h"		/* for tempdecopt */
112
#include "comment.h"		/* for do_comment */
113
#include "translat.h"		/* for optim_level, translate () */
114
#include "main_reads.h"		/* for d_capsule */
115
#include "basicread.h"	/* for good_trans */
116
#include "addrtypes.h"		/* for where */
117
#include "makecode.h"		/* for nowhere */
118
#include "flpt.h"
119
#include "exptypes.h"
120
#include "exp.h"		/* for current_alloc_size */
121
#include "installglob.h"	/* for top_def */
122
#include "out.h"
123
#include "installtypes.h"
124
#include "version.h"
125
#include "reader_v.h"
126
#include "construct_v.h"
127
#include "externs.h"
128
#include "hppadiags.h"
129
#include "frames.h"
130
 
131
#ifdef __DATE__
132
#define compile_date __DATE__
133
#else
134
#define compile_date "unknown date"
135
#endif
136
 
137
extern int good_trans;
138
int OPTIM=1;
139
int gdb,xdb,gcc_assembler;
140
 
141
#define GET_0_1 ( (arg[2]=='0') ? 0 : 1 )
142
 
143
char *local_prefix, *name_prefix;
144
 
145
bool do_tlrecursion = 0;	/* eventually to be moved to flagsdescs.h */
146
 
147
 
148
 
149
/* only advertise options in manual page, other debugging options available as well */
150
static char usage_mess[] = "usage ( s = 0|1 ): trans [-As] [-Bs] [-Cs] [-D] [-d] [-Es] [-Fs] [-Gs] [-H] [-h] [-Is] [-K] [-Ms] [-O] [-P] [-Q] [-Rs] [-T] [-Us] [-V] [-v] [-W] [-X] [-Z] TDF-capsule output-as-file\n";
151
 
152
static int init_trans PROTO_S ( ( char *, char * ) ) ; /* forward reference */
153
 
154
int main 
155
    PROTO_N ( ( argc, argv ) )
156
    PROTO_T ( int argc X char ** argv )
157
{
158
  int a=1;
159
  char *arg;
160
  bool errflg = 0;
161
  bool versionflg = 0;
162
  char *infname=(char*)0;
163
  char *outfname=(char*)0;
164
 
165
 
166
  /* initialise output file */
167
  outf = stdout ;
168
 
169
  /* errors messages are output on stdout, ensure they get out */
170
  setbuf(stdout, NULL);
171
 
172
   /* set defaults for options */
173
 
174
   do_unroll = 1;                   /* do unroll loops */		
175
   do_inlining = 1;                /* do inline */		
176
   do_special_fns = 1;            /* do special functions */
177
   do_loopconsts = 1;	         /* remove constants from loops */
178
   do_foralls = 1;	        /* do foralls optimisation */
179
   gcc_assembler = 0; 
180
   xdb = 0;
181
   gdb = 0;
182
   OPTIM = 1;
183
 
184
  redo_structfns = 0;	  /* procs delivering structs recast to extra param */
185
  redo_structparams = 1; /* struct and union value parameters indirected   */
186
  diagnose = 0;		/* -H option for diagnostics */
187
  do_profile = 0;      /* -P option for profiling info */
188
  do_alloca = 1;      /* inline alloca       */
189
  PIC_code = 0;
190
 
191
  /* from tempdecs.c */
192
  tempdecopt = 1;		/* unset by -T option */
193
 
194
  /* from comment.c */
195
  do_comment = 0;		/* implement -C option */
196
 
197
  /* from translat.c */
198
  optim_level = 2;		/* default equiv to -O2 */
199
 
200
 
201
   /* process program args */
202
   while ( a < argc && ( arg = argv[a], arg[0] == '-' ) )
203
     {
204
       switch ( arg[1] )
205
	 {
206
	 case 'A' : do_alloca = GET_0_1; break;
207
	 case 'B' : flpt_const_overflow_fail = GET_0_1; break;
208
	 case 'C' : do_loopconsts = GET_0_1; break;
209
	 case 'D' :
210
           {
211
             /* -D emulates cc's +Z flag */
212
             PIC_code = GET_0_1;
213
             plusZ = 1;
214
             break;
215
	   }
216
	 case 'd' :
217
           {
218
             /* -d emulates cc's +z flag */
219
             PIC_code = GET_0_1;
220
             plusZ = 0;
221
             break;
222
	   }
223
	 case 'E' : extra_checks = 0; break;
224
	 case 'F' : do_foralls = GET_0_1; break;
225
	 case 'G' : gcc_assembler = GET_0_1; break;
226
	 case 'H' :
227
	   {
228
#ifdef _SYMTAB_INCLUDED
229
	        diagnose = 1;
230
                xdb = 1;  
231
#else
232
	        fprintf(stderr,"trans warning: XDB diagnostics not supported on this version of hppatrans, -H option ignored\n");
233
                xdb = 0;
234
                diagnose = 0;
235
#endif
236
	     break;
237
	   }
238
         case 'h':
239
	   {
240
              diagnose = 1;
241
              gdb = 1;
242
              gcc_assembler = 1;
243
	   }
244
	 case 'I': do_inlining = GET_0_1; break;
245
	 case 'K' : break;
246
	 case 'M' : strict_fl_div = GET_0_1; break;
247
	 case 'O' : /* optim_level not applicable to hp_pa */ break;
248
	 case 'P' :
249
           {
250
	     do_profile = 1;
251
	     break;
252
           }
253
	 case 'Q' : exit( EXIT_SUCCESS ); break;
254
	 case 'R' : round_after_flop = GET_0_1; break;
255
	 case 'T' : /* tempdecopt = 0, not applicable to hp_pa */ break;
256
	 case 'U' : do_unroll = GET_0_1; break;
257
	 case 'V' :
258
	   {
259
	     /* print version number */
260
	     fprintf(stderr,"DERA TDF->HP PA-RISC translator %d.%d: (TDF %d.%d)\nreader %d.%d:\nconstruct %d.%d:\ntranslator compilation date = %s\n ",
261
		    MAJOR,MINOR,MAJOR_VERSION,MINOR_VERSION,
262
		    reader_version,reader_revision,construct_version,
263
		    construct_revision,compile_date);
264
	     versionflg = 1;
265
	     break;
266
	   }
267
	 case 'W' : break;
268
	 case 'X' :
269
	   {
270
	     /* disable all optimisations */
271
	     tempdecopt = 0;
272
	     do_inlining = 0;
273
	     do_loopconsts = 0;
274
	     do_foralls = 0;
275
	     do_tlrecursion = 0;
276
	     do_unroll = 0;
277
	     break;
278
	   }
279
	 case 'Z' : report_versions = 1; break;
280
	 case '?' : default:
281
           {
282
    	     fprintf ( stderr, "%s : unknown option, \"%s\"\n", "trans", arg );
283
             errflg = 1; break;
284
           }
285
	 }  /* switch */
286
       a++;
287
     }
288
 
289
   /* we expect two further filename arguments */
290
   if ( argc == a+2 )
291
     {
292
       infname = argv[a] ;
293
       outfname = argv[a+1] ;
294
     }
295
   else if ( argc == a+1 )
296
     {
297
       infname = argv [a] ;
298
       outfname = "-" ;
299
     }
300
   else { errflg = 1; } ;
301
 
302
   if (errflg)
303
     {
304
       if (!versionflg)		/* no complaints for -v */
305
	 fprintf(stderr, usage_mess);
306
       exit ( EXIT_FAILURE ) ;
307
     }
308
 
309
   if (do_profile && PIC_code)
310
   {
311
      fprintf(stderr,"hppatrans warning: \"-P\" and \"-D\" are mutually exclusive. \"-P\" ignored.\n");
312
      do_profile = 0;
313
   }
314
 
315
   /* Switch off certain optimisations when in diagnostics mode. */
316
   if (diagnose)
317
   {
318
      optim_level = 0;
319
      tempdecopt = 0;
320
      do_inlining = 0;
321
      do_loopconsts = 0;
322
      do_foralls = 0;
323
      do_tlrecursion = 0;
324
      do_unroll = 0;
325
      OPTIM = 0;
326
      if (gdb)
327
         gcc_assembler = 1;
328
   }
329
 
330
   /* init nowhere */
331
  setregalt(nowhere.answhere, 0);
332
  nowhere.ashwhere.ashsize = 0;
333
  nowhere.ashwhere.ashsize = 0;
334
 
335
  local_prefix = "$";		/* Label prefix */
336
  crt_labno = 101;		/* First label; avoid conflict with reg nos */
337
				/* (and backward compatibility) */
338
 
339
   name_prefix = "";
340
 
341
  init_flpt();			/* initialise the floating point array */
342
#include "inits.h"		/* initialise common parts of translator */
343
  top_def = (dec *) 0;
344
 
345
  if ( diagnose )
346
  {
347
     init_stab();
348
  }
349
 
350
  if ( init_trans(infname,outfname) || d_capsule() || good_trans)
351
     exit ( EXIT_FAILURE ) ;
352
 
353
  exit_translator();
354
 
355
  /* check for output errors and close the .s file */
356
  if (ferror(outf) != 0 || fclose(outf) != 0)
357
  {
358
    fprintf(stderr, "hppatrans: error writing to output file %s\n", outfname);
359
    exit ( EXIT_FAILURE ) ;
360
  }
361
 
362
  exit ( EXIT_SUCCESS ) ;
363
}
364
 
365
/*
366
 * Open input and output files.
367
 */
368
static int init_trans 
369
    PROTO_N ( ( infname, outfname ) )
370
    PROTO_T ( char * infname X char * outfname )
371
{
372
 
373
  /*
374
   * Open files.
375
   */
376
 
377
  if (!initreader(infname))
378
  {
379
    fprintf(stderr, "hppatrans: cannot open input file %s\n", infname);
380
    return 3;
381
  }
382
 
383
  if (strcmp(outfname, "-") == 0)
384
  {
385
    /* "-" by convention means stdout */
386
    outf = stdout;
387
  }
388
  else
389
  {
390
    outf = fopen(outfname, "w+");
391
    if (outf == (FILE *) 0)
392
    {
393
      fprintf(stderr, "hppatrans: cannot open output file %s\n", outfname);
394
      return 3;
395
    }
396
  }
397
 
398
  return 0;			/* OK */
399
}
400
 
401
void out_rename 
402
    PROTO_N ( ( oldid, newid ) )
403
    PROTO_T ( char * oldid X char * newid )
404
{
405
    comment2 ( "renamed %s as %s", oldid, newid ) ;
406
    return ;
407
}