Subversion Repositories tendra.SVN

Rev

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

Rev Author Line No. Line
2 7u83 1
/*
7 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
33
 
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:-
42
 
43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
45
 
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;
49
 
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;
53
 
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
/* 80x86/trans.c */
62
 
63
/**********************************************************************
64
$Author: pwe $
65
$Date: 1998/03/11 11:03:06 $
66
$Revision: 1.4 $
67
$Log: trans.c,v $
68
 * Revision 1.4  1998/03/11  11:03:06  pwe
69
 * DWARF optimisation info
70
 *
71
 * Revision 1.3  1998/02/06  17:04:21  release
72
 * Last minute pre-release polishing.
73
 *
74
 * Revision 1.2  1998/01/21  10:30:01  pwe
75
 * labdiff change
76
 *
77
 * Revision 1.1.1.1  1998/01/17  15:55:52  release
78
 * First version to be checked into rolling release.
79
 *
80
 * Revision 1.14  1997/12/05  10:32:38  pwe
81
 * system identification
82
 *
83
 * Revision 1.13  1997/10/23  09:37:15  pwe
84
 * extra_diags
85
 *
86
 * Revision 1.12  1997/10/10  18:25:33  pwe
87
 * prep ANDF-DE revision
88
 *
89
 * Revision 1.11  1997/08/23  13:45:46  pwe
90
 * initial ANDF-DE
91
 *
92
 * Revision 1.10  1997/06/02  08:36:00  pwe
93
 * diags visibility
94
 *
95
 * Revision 1.9  1997/03/24  11:15:36  pwe
96
 * dwarf2 option/default
97
 *
98
 * Revision 1.8  1997/03/20  16:24:10  pwe
99
 * dwarf2
100
 *
101
 * Revision 1.7  1996/12/13  14:39:36  pwe
102
 * prep NEWDIAGS
103
 *
104
 * Revision 1.6  1996/02/16  10:10:44  pwe
105
 * Linux/ELF struct result and PIC jump table
106
 *
107
 * Revision 1.5  1996/02/08  13:45:15  pwe
108
 * Linux elf v aout option
109
 *
110
 * Revision 1.4  1995/03/16  09:13:35  pwe
111
 * sco_gas now install time option
112
 *
113
 * Revision 1.3  1995/02/17  13:21:17  pwe
114
 * rationalise compilation info
115
 *
116
 * Revision 1.2  1995/01/30  12:56:56  pwe
117
 * Ownership -> PWE, tidy banners
118
 *
119
 * Revision 1.1  1994/10/27  14:15:22  jmf
120
 * Initial revision
121
 *
122
 * Revision 1.2  1994/07/13  07:39:57  jmf
123
 * Remove prefix initialising, do it in machine.c
124
 *
125
 * Revision 1.1  1994/07/12  14:42:47  jmf
126
 * Initial revision
127
 *
128
**********************************************************************/
129
 
130
 
131
#include "config.h"
132
#include "release.h"
133
#include "common_types.h"
134
#include "basicread.h"
135
#include "flags.h"
136
#include "out.h"
137
#include "main_reads.h"
138
#include "flpt.h"
139
#include "externs.h"
140
#include "weights.h"
141
#include "installglob.h"
142
#include "instr.h"
143
#include "machine.h"
144
#include "exp.h"
145
#include "expmacs.h"
146
#include "instr386.h"
147
#include "localflags.h"
148
#include "messages_8.h"
149
#include "diag_fns.h"
150
#include "readglob.h"
151
#include "assembler.h"
152
#include "target_v.h"
153
#include "system_v.h"
154
#include "reader_v.h"
155
#include "construct_v.h"
156
#include "operand.h"
157
#ifdef NEWDIAGS
158
#include "diag_v.h"
159
#include "dg_version.h"
160
#endif
161
#ifdef NEWDWARF
162
#include "dw2_iface.h"
163
#include "dw2_vsn.h"
164
#include "dw2_abbrev.h"
165
#include "dw2_common.h"
7 7u83 166
static bool dump_abbrev = 0;
2 7u83 167
#endif
168
 
169
#if DWARF
170
#include "dwarf_mc.h"
171
#endif
172
 
173
extern int print_inlines;
174
 
175
/* PROCEDURES */
176
 
177
static void init_all
7 7u83 178
(void)
2 7u83 179
{
180
  init_flpt();
181
#include "inits.h"
182
  good_trans = 0;
183
  capsule_freelist = (capsule_frees*)0;
184
  old_proc_props = (proc_props *)0;
185
 
186
/* 80x86 specific */
187
  extra_stack = 0;
188
  top_def = (dec*)0;
189
  init_weights();
7 7u83 190
  initzeros();
2 7u83 191
  const_list = nilexp;
192
  return;
193
}
194
 
195
int   main
7 7u83 196
(int argc, char **argv)
2 7u83 197
{
198
  int i;
199
  char *outfname;
200
 
201
		/* defaults */
202
  do_inlining = 1;		/* inline */
203
  redo_structfns = 1;		/* replace fns delivering structs */
204
  redo_structparams = 0;	/* no change to struct params */
205
  is80486 = 1;			/* (at least) 80486 */
206
  is80586 = 1;			/* Pentium */
207
  separate_units = 0;		/* combine units */
208
  do_foralls = 1;		/* do forall optimisations */
209
  extra_checks = 1;		/* perform the extra checks */
210
  always_use_frame = 0;		/* avoid using frame pointer */
211
  do_loopconsts = 1;		/* extract constants from loops */
212
  diagnose = 0;			/* diagnostics off */
213
#ifdef NEWDIAGS
214
  diag_visible = 0;
215
  extra_diags = 0;
216
#endif
217
#ifdef NEWDWARF
218
  dwarf2 = 0;
219
#endif
220
  do_profile = 0;		/* no profiling code */
221
  writable_strings = 0;		/* strings are read only */
222
  PIC_code = 0;			/* do not produce PIC code */
223
  all_variables_visible = 0;	/* use registers */
224
  do_alloca = 1;		/* inline calls of alloca */
225
  round_after_flop = 0;		/* do not round after each floating point
226
				   operation */
227
  strict_fl_div = 1;		/* do not replace divisions by
228
				   multiplication by the inverse */
229
  flpt_const_overflow_fail = 1;	/* constant floating point arithmetic
230
				   fails installation, if overflow */
231
  flpt_always_comparable = 0;	/* this is the default for SVR4.2 */
232
  report_versions = 0;		/* do not print version numbers */
233
  permit_8byte_align = 1;	/* allow 8byte alignment for local doubles
234
				*/
235
  do_unroll = 1;		/* perform loop unrolling */
236
  replace_arith_type = 1;	/* use the C definitions of promote etc.
237
				*/
238
  indirect_jumps = 1;		/* follow gotos and tests to final dest */
239
  no_bss = 0;			/* use .comm */
240
 
241
 
242
  ptr_null = 0;			/* null value for pointer */
243
  proc_null = 0;		/* null value for proc */
244
  lv_null = 0;			/* null value for label_value*/
245
 
246
 
247
  for (i = 1; i != argc && argv[i][0] == '-'; ++i) {/* read flags */
248
    char *s = argv[i];
249
 
250
    switch (s[1]) {
251
      case 'A':
252
        do_alloca = (s[2] == '1');
253
        break;
254
      case 'B':
255
	flpt_const_overflow_fail = (s[2] == '1');
256
	break;
257
      case 'C':
258
	do_loopconsts = (s[2] == '1');
259
	break;
260
      case 'D':
261
        PIC_code = (s[2] == '1');
262
        break;
263
      case 'E':
264
        extra_checks = 0;
265
        break;
266
      case 'F':
267
	do_foralls = (s[2] == '1');
268
	break;
269
      case 'G':
270
	gcc_compatible = (s[2] == '1');
271
	break;
272
      case 'H':
273
	diagnose = 1;
274
#ifdef NEWDIAGS
7 7u83 275
	if (s[2]!= 'O')
2 7u83 276
#endif
277
	{
278
#ifdef NEWDIAGS
279
	  diag_visible = 1;
280
#endif
281
	  always_use_frame = 1;
282
          do_inlining = 0;
283
          do_loopconsts = 0;
284
          do_foralls = 0;
285
          all_variables_visible = 1;
286
	}
287
	break;
288
      case 'I':
289
	do_inlining = (s[2] == '1');
290
	break;
291
#ifdef NEWDWARF
292
      case 'J':
293
	diagnose = 1;
294
	extra_diags = 1;
295
	dwarf2 = 1;
296
	break;
297
#endif
298
      case 'K':
299
        if (s[2] == '3')
300
         {
301
           is80486 = 0;
302
           is80586 = 0;
303
         };
304
        if (s[2] == '4')
305
         {
306
           is80486 = 1;
307
           is80586 = 0;
308
         };
309
        if (s[2] == '5')
310
         {
311
           is80486 = 1;
312
           is80586 = 1;
313
         };
314
        break;
315
      case 'M':
316
	strict_fl_div = (s[2] == '1');
317
	break;
318
      case 'N':
319
	do_prom = 1;
320
	break;
321
      case 'P':
322
	do_profile = 1;
323
	break;
324
      case 'Q':
325
	return 0;
326
      case 'R':
327
        round_after_flop = (s[2] == '1');
328
        break;
329
#ifdef NEWDWARF
330
      case 'T':
331
	dump_abbrev = 1;
332
	diagnose = 1;
333
	extra_diags = 1;
334
	dwarf2 = 1;
335
	break;
336
#endif
337
      case 'U':
338
	do_unroll = (s[2] == '1');
339
	break;
340
      case 'V':
341
	IGNORE fprintf(stderr, "DERA ANDF 80x86/Pentium translator (TDF version %d.%d)\n",
342
		 MAJOR_VERSION, MINOR_VERSION);
343
	IGNORE fprintf(stderr, "reader %d.%d: ", reader_version,
344
		 reader_revision);
345
	IGNORE fprintf(stderr, "construct %d.%d: ", construct_version,
346
		 construct_revision);
347
	IGNORE fprintf(stderr, "target %d.%d: ", target_version,
348
		 target_revision);
349
#if DWARF
350
	IGNORE fprintf(stderr, "dwarf1 %d.%d: ", DWARF_MAJOR,
351
		 DWARF_MINOR);
352
#endif
353
#ifdef NEWDIAGS
354
	IGNORE fprintf(stderr, "diag_info %d.%d:\n%s   ", diag_version,
355
		 diag_revision, DG_VERSION);
356
#endif
357
#ifdef NEWDWARF
358
	IGNORE fprintf(stderr, "dwarf2 %d.%d: ", DWARF2_MAJOR,
359
		 DWARF2_MINOR);
360
#endif
361
	IGNORE fprintf(stderr, "\n");
362
	IGNORE fprintf(stderr, "system %s: ", target_system);
363
#ifdef __DATE__
364
	IGNORE fprintf(stderr, "installer compilation %s", __DATE__);
365
#endif
366
	IGNORE fprintf(stderr, "\n");
367
#ifdef RELEASE
368
	IGNORE fprintf(stderr, "release: %s\n",RELEASE);
369
#endif
370
        break;
371
      case 'W':
372
        writable_strings = (s[2] == '1');
373
        break;
374
      case 'X':
375
	do_unroll = 0;
376
	do_inlining = 0;
377
	do_loopconsts = 0;
378
	do_special_fns = 0;
379
	do_foralls = 0;
380
	indirect_jumps = 0;
381
        all_variables_visible = 1;
382
        break;
383
      case 'Z':
384
	report_versions = 1;
385
	break;
386
 
387
      case 'a':
388
        always_use_frame = 1;
389
        break;
390
      case 'b':
391
        all_variables_visible = 1;
392
        break;
393
      case 'c':
394
	replace_arith_type = 0;
395
	break;
396
      case 'd':
397
        redo_structfns = 0;
398
        break;
399
      case 'e':
400
	indirect_jumps = 0;
401
	break;
402
      case 'f':
403
	ptr_null = 0x55555555;		/* null value for pointer */
404
	break;
405
      case 'g':
406
        flpt_always_comparable = 1;
407
        break;
408
      case 'h':
409
	no_bss = 1;
410
	break;
411
      case 'i':
412
	print_inlines = 1;
413
	break;
7 7u83 414
#if isdragonfly
415
      case 'k':
416
        set_dragonfly_format(s[2] == '1');
417
        break;
418
#endif
419
#if isfreebsd
420
      case 'k':
421
        set_freebsd_format(s[2] == '1');
422
        break;
423
#endif
2 7u83 424
#if islinux
425
      case 'k':
7 7u83 426
	set_linux_format(s[2] == '1');
2 7u83 427
	break;
428
#endif
429
#if issco
430
      case 's':
431
	sco_gas = 1;
432
	break;
433
#endif
434
 
435
      default:
7 7u83 436
	failer(BAD_FLAG);
2 7u83 437
	break;
438
    };
439
  };
440
 
7 7u83 441
#if isdragonfly
442
  if (gcc_compatible < 0)
443
    gcc_compatible = !dragonfly_elf;
444
#endif
445
#if isfreebsd
446
  if (gcc_compatible < 0)
447
    gcc_compatible = !freebsd_elf;
448
#endif
2 7u83 449
#if islinux
450
  if (gcc_compatible < 0)
451
    gcc_compatible = ! linux_elf;
452
#endif
453
 
454
  if (i == argc)
455
    i--;	/* BAD_COMMAND1 */
456
 
7 7u83 457
  for (; i < argc; i += 2) {
2 7u83 458
    if (i == (argc-1))
459
      {
7 7u83 460
        failer(BAD_COMMAND1);
461
        return(1);
2 7u83 462
      };
463
 
464
 
465
    outfname = argv[i+1];
466
 
467
    /* initiate the output file */
7 7u83 468
    if (!outinit(outfname)) {
469
      failer(CANT_OPEN);
470
      return(1);
2 7u83 471
    };
472
 
7 7u83 473
    if (!initreader(argv[i])) {
474
      failer(CANT_READ);
475
      return(1);
2 7u83 476
    };
477
 
478
    init_all();
479
 
480
#ifdef NEWDWARF
481
    if (dwarf2) {
7 7u83 482
      init_dwarf2();
2 7u83 483
    } else
484
#endif
7 7u83 485
    if (diagnose)out_diagnose_prelude();
2 7u83 486
 
487
#ifdef NEWDWARF
488
    if (dump_abbrev) {
7 7u83 489
      outs(".text\n");
490
      do_abbreviations();
491
      dwarf2_prelude();
492
      make_dwarf_common();
493
      dwarf2_postlude();
2 7u83 494
    } else
495
#endif
496
 
497
    IGNORE d_capsule();
498
 
499
    while (weak_list)
500
     {
501
       outs(".set ");
502
       outs(weak_list -> weak_id);
503
       outs(",");
504
       outs(weak_list -> val_id);
505
       outnl();
506
       weak_list = weak_list -> next;
507
     };
508
 
509
#ifdef NEWDWARF
510
    if (dwarf2) {
7 7u83 511
      end_dwarf2();
2 7u83 512
    } else
513
#endif
7 7u83 514
    if (diagnose)out_diagnose_postlude();
2 7u83 515
 
516
    outend ();			/* close the .s file */
517
    endreader();
518
 
519
    if (good_trans)
520
      exit(EXIT_FAILURE);
521
  }
522
  return 0;
523
}