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-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
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
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
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 89... Line 119...
89
 * some superflous code removed ( includingincluding the SunOS "-G" option).
119
 * some superflous code removed ( includingincluding the SunOS "-G" option).
90
 * minor alterations for diagnostics stuff.
120
 * minor alterations for diagnostics stuff.
91
 *
121
 *
92
 * Revision 3.1  95/04/10  16:26:49  16:26:49  wfs (William Simmonds)
122
 * Revision 3.1  95/04/10  16:26:49  16:26:49  wfs (William Simmonds)
93
 * Apr95 tape version.
123
 * Apr95 tape version.
94
 * 
124
 *
95
 * Revision 3.0  95/03/30  11:17:27  11:17:27  wfs (William Simmonds)
125
 * Revision 3.0  95/03/30  11:17:27  11:17:27  wfs (William Simmonds)
96
 * Mar95 tape version with CRCR95_178 bug fix.
126
 * Mar95 tape version with CRCR95_178 bug fix.
97
 * 
127
 *
98
 * Revision 2.0  95/03/15  15:27:34  15:27:34  wfs (William Simmonds)
128
 * Revision 2.0  95/03/15  15:27:34  15:27:34  wfs (William Simmonds)
99
 * spec 3.1 changes implemented, tests outstanding.
129
 * spec 3.1 changes implemented, tests outstanding.
100
 * 
130
 *
101
 * Revision 1.1  95/01/17  13:58:43  13:58:43  wfs (William Simmonds)
131
 * Revision 1.1  95/01/17  13:58:43  13:58:43  wfs (William Simmonds)
102
 * Initial revision
132
 * Initial revision
103
 * 
133
 *
104
*/
134
*/
105
 
135
 
106
 
136
 
107
 
137
 
108
#define HPPATRANS_CODE
138
#define HPPATRANS_CODE
Line 136... Line 166...
136
 
166
 
137
extern int good_trans;
167
extern int good_trans;
138
int OPTIM=1;
168
int OPTIM=1;
139
int gdb,xdb,gcc_assembler;
169
int gdb,xdb,gcc_assembler;
140
 
170
 
141
#define GET_0_1 ( (arg[2]=='0') ? 0 : 1 )
171
#define GET_0_1((arg[2] =='0')? 0 : 1)
142
 
172
 
143
char *local_prefix, *name_prefix;
173
char *local_prefix, *name_prefix;
144
 
174
 
145
bool do_tlrecursion = 0;	/* eventually to be moved to flagsdescs.h */
175
bool do_tlrecursion = 0;	/* eventually to be moved to flagsdescs.h */
146
 
176
 
147
 
177
 
148
 
178
 
149
/* only advertise options in manual page, other debugging options available as well */
179
/* 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";
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";
151
 
181
 
152
static int init_trans PROTO_S ( ( char *, char * ) ) ; /* forward reference */
182
static int init_trans PROTO_S ( ( char *, char * ) ) ; /* forward reference */
153
 
183
 
154
int main 
184
int main
155
    PROTO_N ( ( argc, argv ) )
-
 
156
    PROTO_T ( int argc X char ** argv )
185
(int argc, char ** argv)
157
{
186
{
158
  int a=1;
187
  int a=1;
159
  char *arg;
188
  char *arg;
160
  bool errflg = 0;
189
  bool errflg = 0;
161
  bool versionflg = 0;
190
  bool versionflg = 0;
162
  char *infname=(char*)0;
191
  char *infname= (char*)0;
163
  char *outfname=(char*)0;
192
  char *outfname= (char*)0;
164
 
193
 
165
 
194
 
166
  /* initialise output file */
195
  /* initialise output file */
167
  outf = stdout ;
196
  outf = stdout;
168
 
197
 
169
  /* errors messages are output on stdout, ensure they get out */
198
  /* errors messages are output on stdout, ensure they get out */
170
  setbuf(stdout, NULL);
199
  setbuf(stdout, NULL);
171
 
200
 
172
   /* set defaults for options */
201
   /* set defaults for options */
173
 
202
 
174
   do_unroll = 1;                   /* do unroll loops */		
203
   do_unroll = 1;                   /* do unroll loops */
175
   do_inlining = 1;                /* do inline */		
204
   do_inlining = 1;                /* do inline */
176
   do_special_fns = 1;            /* do special functions */
205
   do_special_fns = 1;            /* do special functions */
177
   do_loopconsts = 1;	         /* remove constants from loops */
206
   do_loopconsts = 1;	         /* remove constants from loops */
178
   do_foralls = 1;	        /* do foralls optimisation */
207
   do_foralls = 1;	        /* do foralls optimisation */
179
   gcc_assembler = 0; 
208
   gcc_assembler = 0;
180
   xdb = 0;
209
   xdb = 0;
181
   gdb = 0;
210
   gdb = 0;
182
   OPTIM = 1;
211
   OPTIM = 1;
183
 
212
 
184
  redo_structfns = 0;	  /* procs delivering structs recast to extra param */
213
  redo_structfns = 0;	  /* procs delivering structs recast to extra param */
Line 197... Line 226...
197
  /* from translat.c */
226
  /* from translat.c */
198
  optim_level = 2;		/* default equiv to -O2 */
227
  optim_level = 2;		/* default equiv to -O2 */
199
 
228
 
200
 
229
 
201
   /* process program args */
230
   /* process program args */
202
   while ( a < argc && ( arg = argv[a], arg[0] == '-' ) )
231
   while (a < argc && (arg = argv[a], arg[0] == '-'))
203
     {
232
     {
204
       switch ( arg[1] )
233
       switch (arg[1])
205
	 {
234
	 {
206
	 case 'A' : do_alloca = GET_0_1; break;
235
	 case 'A': do_alloca = GET_0_1; break;
207
	 case 'B' : flpt_const_overflow_fail = GET_0_1; break;
236
	 case 'B': flpt_const_overflow_fail = GET_0_1; break;
208
	 case 'C' : do_loopconsts = GET_0_1; break;
237
	 case 'C': do_loopconsts = GET_0_1; break;
209
	 case 'D' :
238
	 case 'D':
210
           {
239
           {
211
             /* -D emulates cc's +Z flag */
240
             /* -D emulates cc's +Z flag */
212
             PIC_code = GET_0_1;
241
             PIC_code = GET_0_1;
213
             plusZ = 1;
242
             plusZ = 1;
214
             break;
243
             break;
215
	   }
244
	   }
216
	 case 'd' :
245
	 case 'd':
217
           {
246
           {
218
             /* -d emulates cc's +z flag */
247
             /* -d emulates cc's +z flag */
219
             PIC_code = GET_0_1;
248
             PIC_code = GET_0_1;
220
             plusZ = 0;
249
             plusZ = 0;
221
             break;
250
             break;
222
	   }
251
	   }
223
	 case 'E' : extra_checks = 0; break;
252
	 case 'E': extra_checks = 0; break;
224
	 case 'F' : do_foralls = GET_0_1; break;
253
	 case 'F': do_foralls = GET_0_1; break;
225
	 case 'G' : gcc_assembler = GET_0_1; break;
254
	 case 'G': gcc_assembler = GET_0_1; break;
226
	 case 'H' :
255
	 case 'H':
227
	   {
256
	   {
228
#ifdef _SYMTAB_INCLUDED
257
#ifdef _SYMTAB_INCLUDED
229
	        diagnose = 1;
258
	        diagnose = 1;
230
                xdb = 1;  
259
                xdb = 1;
231
#else
260
#else
232
	        fprintf(stderr,"trans warning: XDB diagnostics not supported on this version of hppatrans, -H option ignored\n");
261
	        fprintf(stderr,"trans warning: XDB diagnostics not supported on this version of hppatrans, -H option ignored\n");
233
                xdb = 0;
262
                xdb = 0;
234
                diagnose = 0;
263
                diagnose = 0;
235
#endif
264
#endif
236
	     break;
265
	     break;
237
	   }
266
	   }
238
         case 'h':
267
         case 'h':
239
	   {
268
	   {
240
              diagnose = 1;
269
              diagnose = 1;
241
              gdb = 1;
270
              gdb = 1;
242
              gcc_assembler = 1;
271
              gcc_assembler = 1;
243
	   }
272
	   }
244
	 case 'I': do_inlining = GET_0_1; break;
273
	 case 'I': do_inlining = GET_0_1; break;
245
	 case 'K' : break;
274
	 case 'K': break;
246
	 case 'M' : strict_fl_div = GET_0_1; break;
275
	 case 'M': strict_fl_div = GET_0_1; break;
247
	 case 'O' : /* optim_level not applicable to hp_pa */ break;
276
	 case 'O' : /* optim_level not applicable to hp_pa */ break;
248
	 case 'P' :
277
	 case 'P':
249
           {
278
           {
250
	     do_profile = 1;
279
	     do_profile = 1;
251
	     break;
280
	     break;
252
           }
281
           }
253
	 case 'Q' : exit( EXIT_SUCCESS ); break;
282
	 case 'Q': exit(EXIT_SUCCESS); break;
254
	 case 'R' : round_after_flop = GET_0_1; break;
283
	 case 'R': round_after_flop = GET_0_1; break;
255
	 case 'T' : /* tempdecopt = 0, not applicable to hp_pa */ break;
284
	 case 'T' : /* tempdecopt = 0, not applicable to hp_pa */ break;
256
	 case 'U' : do_unroll = GET_0_1; break;
285
	 case 'U': do_unroll = GET_0_1; break;
257
	 case 'V' :
286
	 case 'V':
258
	   {
287
	   {
259
	     /* print version number */
288
	     /* 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 ",
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 ",
261
		    MAJOR,MINOR,MAJOR_VERSION,MINOR_VERSION,
290
		    MAJOR,MINOR,MAJOR_VERSION,MINOR_VERSION,
262
		    reader_version,reader_revision,construct_version,
291
		    reader_version,reader_revision,construct_version,
263
		    construct_revision,compile_date);
292
		    construct_revision,compile_date);
264
	     versionflg = 1;
293
	     versionflg = 1;
265
	     break;
294
	     break;
266
	   }
295
	   }
267
	 case 'W' : break;
296
	 case 'W': break;
268
	 case 'X' :
297
	 case 'X':
269
	   {
298
	   {
270
	     /* disable all optimisations */
299
	     /* disable all optimisations */
271
	     tempdecopt = 0;
300
	     tempdecopt = 0;
272
	     do_inlining = 0;
301
	     do_inlining = 0;
273
	     do_loopconsts = 0;
302
	     do_loopconsts = 0;
274
	     do_foralls = 0;
303
	     do_foralls = 0;
275
	     do_tlrecursion = 0;
304
	     do_tlrecursion = 0;
276
	     do_unroll = 0;
305
	     do_unroll = 0;
277
	     break;
306
	     break;
278
	   }
307
	   }
279
	 case 'Z' : report_versions = 1; break;
308
	 case 'Z': report_versions = 1; break;
280
	 case '?' : default:
309
	 case '?': default:
281
           {
310
           {
282
    	     fprintf ( stderr, "%s : unknown option, \"%s\"\n", "trans", arg );
311
    	     fprintf(stderr, "%s : unknown option, \"%s\"\n", "trans", arg);
283
             errflg = 1; break;
312
             errflg = 1; break;
284
           }
313
           }
285
	 }  /* switch */
314
	 }  /* switch */
286
       a++;
315
       a++;
287
     }
316
     }
288
   
317
 
289
   /* we expect two further filename arguments */
318
   /* we expect two further filename arguments */
290
   if ( argc == a+2 )
319
   if (argc == a+2)
291
     {
320
     {
292
       infname = argv[a] ;
321
       infname = argv[a];
293
       outfname = argv[a+1] ;
322
       outfname = argv[a+1];
294
     }
323
     }
295
   else if ( argc == a+1 )
324
   else if (argc == a+1)
296
     {
325
     {
297
       infname = argv [a] ;
326
       infname = argv[a];
298
       outfname = "-" ;
327
       outfname = "-";
299
     }
328
     }
300
   else { errflg = 1; } ;
329
   else { errflg = 1; };
301
   
330
 
302
   if (errflg)
331
   if (errflg)
303
     {
332
     {
304
       if (!versionflg)		/* no complaints for -v */
333
       if (!versionflg)		/* no complaints for -v */
305
	 fprintf(stderr, usage_mess);
334
	 fprintf(stderr, usage_mess);
306
       exit ( EXIT_FAILURE ) ;
335
       exit(EXIT_FAILURE);
307
     }
336
     }
308
   
337
 
309
   if (do_profile && PIC_code)
338
   if (do_profile && PIC_code)
310
   {
339
   {
311
      fprintf(stderr,"hppatrans warning: \"-P\" and \"-D\" are mutually exclusive. \"-P\" ignored.\n");
340
      fprintf(stderr,"hppatrans warning: \"-P\" and \"-D\" are mutually exclusive. \"-P\" ignored.\n");
312
      do_profile = 0;
341
      do_profile = 0;
313
   }
342
   }
314
 
343
 
315
   /* Switch off certain optimisations when in diagnostics mode. */
344
   /* Switch off certain optimisations when in diagnostics mode. */
316
   if (diagnose)
345
   if (diagnose)
317
   {
346
   {
318
      optim_level = 0;
347
      optim_level = 0;
Line 324... Line 353...
324
      do_unroll = 0;
353
      do_unroll = 0;
325
      OPTIM = 0;
354
      OPTIM = 0;
326
      if (gdb)
355
      if (gdb)
327
         gcc_assembler = 1;
356
         gcc_assembler = 1;
328
   }
357
   }
329
   
358
 
330
   /* init nowhere */
359
   /* init nowhere */
331
  setregalt(nowhere.answhere, 0);
360
  setregalt(nowhere.answhere, 0);
332
  nowhere.ashwhere.ashsize = 0;
361
  nowhere.ashwhere.ashsize = 0;
333
  nowhere.ashwhere.ashsize = 0;
362
  nowhere.ashwhere.ashsize = 0;
334
 
363
 
Line 338... Line 367...
338
 
367
 
339
   name_prefix = "";
368
   name_prefix = "";
340
 
369
 
341
  init_flpt();			/* initialise the floating point array */
370
  init_flpt();			/* initialise the floating point array */
342
#include "inits.h"		/* initialise common parts of translator */
371
#include "inits.h"		/* initialise common parts of translator */
343
  top_def = (dec *) 0;
372
  top_def = (dec *)0;
344
 
373
 
345
  if ( diagnose )
374
  if (diagnose)
346
  {
375
  {
347
     init_stab();
376
     init_stab();
348
  }
377
  }
349
 
378
 
350
  if ( init_trans(infname,outfname) || d_capsule() || good_trans)
379
  if (init_trans(infname,outfname) || d_capsule() || good_trans)
351
     exit ( EXIT_FAILURE ) ;
380
     exit(EXIT_FAILURE);
352
 
381
 
353
  exit_translator();
382
  exit_translator();
354
 
383
 
355
  /* check for output errors and close the .s file */
384
  /* check for output errors and close the .s file */
356
  if (ferror(outf) != 0 || fclose(outf) != 0)
385
  if (ferror(outf)!= 0 || fclose(outf)!= 0)
357
  {
386
  {
358
    fprintf(stderr, "hppatrans: error writing to output file %s\n", outfname);
387
    fprintf(stderr, "hppatrans: error writing to output file %s\n", outfname);
359
    exit ( EXIT_FAILURE ) ;
388
    exit(EXIT_FAILURE);
360
  }
389
  }
361
 
390
 
362
  exit ( EXIT_SUCCESS ) ;
391
  exit(EXIT_SUCCESS);
363
}
392
}
364
 
393
 
365
/*
394
/*
366
 * Open input and output files.
395
 * Open input and output files.
367
 */
396
 */
368
static int init_trans 
397
static int init_trans
369
    PROTO_N ( ( infname, outfname ) )
-
 
370
    PROTO_T ( char * infname X char * outfname )
398
(char * infname, char * outfname)
371
{
399
{
372
 
400
 
373
  /*
401
  /*
374
   * Open files.
402
   * Open files.
375
   */
403
   */
Line 386... Line 414...
386
    outf = stdout;
414
    outf = stdout;
387
  }
415
  }
388
  else
416
  else
389
  {
417
  {
390
    outf = fopen(outfname, "w+");
418
    outf = fopen(outfname, "w+");
391
    if (outf == (FILE *) 0)
419
    if (outf == (FILE *)0)
392
    {
420
    {
393
      fprintf(stderr, "hppatrans: cannot open output file %s\n", outfname);
421
      fprintf(stderr, "hppatrans: cannot open output file %s\n", outfname);
394
      return 3;
422
      return 3;
395
    }
423
    }
396
  }
424
  }
397
 
425
 
398
  return 0;			/* OK */
426
  return 0;			/* OK */
399
}
427
}
400
 
428
 
401
void out_rename 
429
void out_rename
402
    PROTO_N ( ( oldid, newid ) )
-
 
403
    PROTO_T ( char * oldid X char * newid )
430
(char * oldid, char * newid)
404
{
431
{
405
    comment2 ( "renamed %s as %s", oldid, newid ) ;
432
    comment2("renamed %s as %s", oldid, newid);
406
    return ;
433
    return;
407
}
434
}