Subversion Repositories tendra.SVN

Rev

Rev 5 | Details | Compare with Previous | Last modification | View Log | RSS feed

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