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) 1996
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
			    VERSION INFORMATION
61
			    ===================
62
 
63
--------------------------------------------------------------------------
64
$Header: /u/g/release/CVSROOT/Source/src/installers/680x0/sunos/main.c,v 1.2 1998/02/06 17:04:20 release Exp $
65
--------------------------------------------------------------------------
66
$Log: main.c,v $
67
 * Revision 1.2  1998/02/06  17:04:20  release
68
 * Last minute pre-release polishing.
69
 *
70
 * Revision 1.1.1.1  1998/01/17  15:55:51  release
71
 * First version to be checked into rolling release.
72
 *
73
Revision 1.1.1.1  1997/10/13 12:42:56  ma
74
First version.
75
 
76
Revision 1.5  1997/10/13 08:49:39  ma
77
Made all pl_tests for general proc & exception handling pass.
78
 
79
Revision 1.4  1997/09/25 06:45:19  ma
80
All general_proc tests passed
81
 
82
Revision 1.3  1997/06/18 10:09:40  ma
83
Checking in before merging with Input Baseline changes.
84
 
85
Revision 1.2  1997/04/20 11:30:33  ma
86
Introduced gcproc.c & general_proc.[ch].
87
Added cases for apply_general_proc next to apply_proc in all files.
88
 
89
Revision 1.1.1.1  1997/03/14 07:50:15  ma
90
Imported from DRA
91
 
92
 * Revision 1.1.1.1  1996/09/20  10:56:55  john
93
 *
94
 * Revision 1.3  1996/09/13  13:47:17  john
95
 * Removed my_check_routines
96
 *
97
 * Revision 1.2  1996/07/05  14:23:07  john
98
 * Changed version reporting
99
 *
100
 * Revision 1.1.1.1  1996/03/26  15:45:15  john
101
 *
102
 * Revision 1.9  94/06/30  11:52:52  11:52:52  ra (Robert Andrews)
103
 * Print version numbers from common section as well as machine dependent
104
 * version number.
105
 *
106
 * Revision 1.8  94/06/29  14:22:32  14:22:32  ra (Robert Andrews)
107
 * Changed version number.  Added support for common installer command-line
108
 * options.
109
 *
110
 * Revision 1.7  94/02/21  16:01:03  16:01:03  ra (Robert Andrews)
111
 * A number of flags which used to be bool are now int.
112
 *
113
 * Revision 1.6  93/11/19  16:22:12  16:22:12  ra (Robert Andrews)
114
 * Changed version number to 0.5.
115
 *
116
 * Revision 1.5  93/05/24  15:57:30  15:57:30  ra (Robert Andrews)
117
 * version has been renamed version_str.  New flags for reporting version
118
 * numbers of input capsules and hptrans version (on stderr).
119
 *
120
 * Revision 1.4  93/04/19  13:42:20  13:42:20  ra (Robert Andrews)
121
 * New version number for March93 spec.
122
 *
123
 * Revision 1.3  93/04/19  13:35:03  13:35:03  ra (Robert Andrews)
124
 * Representation of alignments has changed.
125
 *
126
 * Revision 1.2  93/02/26  17:01:08  17:01:08  ra (Robert Andrews)
127
 * Added version.h, an automatically generated file which contains
128
 * an overall RCS revision number and the date of this revision.
129
 *
130
 * Revision 1.1  93/02/26  16:21:57  16:21:57  ra (Robert Andrews)
131
 * Initial revision
132
 *
133
--------------------------------------------------------------------------
134
*/
135
 
136
#include "config.h"
137
#include "release.h"
138
#include "common_types.h"
139
#include "assembler.h"
140
#include "basicread.h"
141
#include "flpt.h"
142
#include "main_reads.h"
143
#include "weights.h"
144
#include "instrs.h"
145
#include "installglob.h"
146
#include "expmacs.h"
147
#include "exp.h"
148
#include "externs.h"
149
#include "flags.h"
150
#include "mach.h"
151
#include "mach_ins.h"
152
#include "mach_op.h"
153
#include "codex.h"
154
#include "output.h"
155
#include "peephole.h"
156
#include "szs_als.h"
157
#include "tests.h"
158
#include "utility.h"
159
#include "version.h"
160
#include "reader_v.h"
161
#include "construct_v.h"
162
#include "where.h"
163
#if have_diagnostics
164
#include "xdb_basics.h"
165
#include "xdb_output.h"
166
#endif
7 7u83 167
extern int errors;
168
extern int max_errors;
2 7u83 169
 
170
 
171
/*
172
    PROGRAM NAME AND VERSION NUMBER
173
*/
174
 
7 7u83 175
char *progname = "hptrans";
176
static char *version_str = "Version: 0.6";
177
static char *revision = REVISION_STRING;
178
static char *revdate = DATE_STRING;
179
int normal_version = 1;
2 7u83 180
 
181
 
182
/*
183
    EXTRA COMPILATION FLAGS
184
*/
185
 
7 7u83 186
int do_peephole = 1;
187
int do_pic = 0;
188
static int do_quit = 0;
189
static int do_sep_units = 0;
190
static int ignore_errors = 0;
2 7u83 191
#ifdef EBUG
7 7u83 192
int optimize = 0;
2 7u83 193
#else
7 7u83 194
static int optimize = 1;
2 7u83 195
#endif
7 7u83 196
static int report_version = 0;
197
static int report_tdf_versions = 0;
198
static int show_options = 0;
199
static int dummy_option = 0;
2 7u83 200
 
201
#ifdef EBUG
202
 
7 7u83 203
int do_test = 0;
204
int seek_label = 0;
205
int seek_extern = 0;
206
int seek_label_no;
207
char *seek_extern_id;
2 7u83 208
 
7 7u83 209
int seek_line = 0;
210
int seek_line_no;
211
static char *seek_line_id;
2 7u83 212
 
213
#endif
214
 
7 7u83 215
int diag_override;
216
static int diag_stab_override = 0;
217
static int diag_xdb_new_override = 0;
218
static int diag_xdb_old_override = 0;
2 7u83 219
 
220
 
221
 
222
/*
223
    VARIABLE SIZES AND ALIGNMENTS
224
*/
225
 
7 7u83 226
alignment MAX_BF_SIZE;
2 7u83 227
 
228
 
229
/*
230
    MAXIMUM EXPONENT FOR FLOATING-POINT NUMBERS
231
*/
232
 
7 7u83 233
int target_dbl_maxexp = 1024;
2 7u83 234
 
235
 
236
/*
237
    OPTIONS
238
 
239
    There are two types of options.  Firstly, for certain key words,
240
    key, the option "-key" enables, and the option "-no_key" disables,
241
    the corresponding action.  Some of these options take an additional
242
    argument in their positive form, i.e. "-key arg".  Secondly, single
243
    letter options are used as shorthand for some of the options of the
244
    first type.
245
 
246
    Each entry in this table gives a key word, key, followed by the
247
    single letter option for "-key" (or 0 is there isn't one) and
248
    the single letter option for "-no_key".  There is also a pointer
249
    to the boolean changed by this option and, if the option takes a
250
    qualifying string, a pointer to the string thus set.
251
*/
252
 
253
struct {
7 7u83 254
    char *opt;
255
    char on;
256
    char off;
257
    char sw;
258
    int *flag;
259
    char **value;
260
} options[] = {
261
    {"alloca", 0, 0, 'A', &do_alloca, null},
262
    {"cc", 'c', 'g', 0, &cc_conventions, null},
263
    {"diag", 'H', 0, 0, &diagnose, null},
264
    {"extra_checks", 0, 'E', 0, &extra_checks, null},
265
    {"float_div", 0, 0, 'M', &strict_fl_div, null},
266
    {"float_inf", 0, 0, 'B', &flpt_const_overflow_fail, null},
267
    {"foralls", 0, 0, 'F', &do_foralls, null},
268
    {"ignore", 0, 0, 0, &ignore_errors, null},
269
    {"immediate", 'i', 0, 0, &output_immediately, null},
270
    {"inlining", 0, 0, 'I', &do_inlining, null},
271
    {"loopconsts", 0, 0, 'C', &do_loopconsts, null},
2 7u83 272
#if have_diagnostics
7 7u83 273
    {"stab", 0, 0, 0, &diag_stab_override, null},
274
    {"new_diag", 0, 0, 0, &diag_xdb_new_override, null},
275
    {"old_diag", 0, 0, 0, &diag_xdb_old_override, null},
2 7u83 276
#endif
7 7u83 277
    {"opt", 'O', 'X', 0, &optimize, null},
278
    {"options", 'o', 0, 0, &show_options, null},
279
    {"peephole", 0, 0, 0, &do_peephole, null},
280
    {"pic", 0, 0, 'D', &do_pic, null},
281
    {"profile", 'P', 0, 0, &do_profile, null},
282
    {"quit", 'Q', 0, 0, &do_quit, null},
283
    {"report_version", 'Z', 0, 0, &report_tdf_versions, null},
284
    {"round", 'r', 0, 'R', &round_after_flop, null},
285
    {"separate_units", 'U', 0, 0, &do_sep_units, null},
286
    {"special_fns", 0, 0, 0, &do_special_fns, null},
287
    {"sub_params", 0, 0, 0, &do_sub_params, null},
2 7u83 288
#ifdef EBUG
7 7u83 289
    {"label", 'L', 0, 0, &seek_extern, &seek_extern_id},
290
    {"line", 'l', 0, 0, &seek_line, &seek_line_id},
291
    {"test", 'l', 0, 0, &do_test, null},
2 7u83 292
#endif
7 7u83 293
    {"unroll", 0, 0, 'U', &do_unroll, null},
294
    {"version", 'V', 0, 0, &report_version, null},
295
    {"write_strings", 0, 0, 'W', &dummy_option, null}
296
};
2 7u83 297
 
298
 
299
/*
300
    MAIN ROUTINE
301
 
302
    This routine processes the command-line arguments, calls the
303
    initialization routines, and then calls the main processing
304
    routines.
305
*/
306
 
307
int main
7 7u83 308
(int argc, char **argv)
2 7u83 309
{
7 7u83 310
    int a;
311
    char **p = null;
312
    char *input = null;
313
    char *output = null;
2 7u83 314
 
315
    /* Set up program name */
7 7u83 316
    progname = basename(argv[0]);
2 7u83 317
 
318
    /* Set default options */
7 7u83 319
    diagnose = 0;
320
    do_alloca = 1;
321
    do_foralls = 1;
322
    do_inlining = 1;
323
    do_loopconsts = 1;
324
    do_profile = 0;
325
    do_special_fns = 1;
326
    do_unroll = 1;
327
    extra_checks = 1;
328
    redo_structfns = 0;
2 7u83 329
 
330
    /* Process arguments */
7 7u83 331
    for (a = 1; a < argc; a++) {
332
	if (p) {
2 7u83 333
	    /* Set extra part of two part options */
7 7u83 334
	    *p = argv[a];
335
	    p = null;
336
	} else if (argv[a][0] == '-' && argv[a][1]) {
2 7u83 337
	    /* Search option table */
7 7u83 338
	    bool found = 0;
339
	    char *s = argv[a] + 1;
340
	    int i, n = array_size(options);
341
	    if ((s[1] == '0' || s[1] == '1') && s[2] == 0) {
342
		for (i = 0; !found && i < n; i++) {
343
		    if (*s == options[i].sw) {
344
			*(options[i].flag) = (s[1] - '0');
345
			p = options[i].value;
346
			found = 1;
2 7u83 347
		    }
348
		}
7 7u83 349
	    } else if (s[1]) {
350
		bool b = 1;
351
		if (strncmp(s, "no_", 3) == 0) {
352
		    s + = 3;
353
		    b = 0;
2 7u83 354
		}
7 7u83 355
		for (i = 0; !found && i < n; i++) {
356
		    if (eq(s, options[i].opt)) {
357
			*(options[i].flag) = b;
358
			if (b)p = options[i].value;
359
			found = 1;
2 7u83 360
		    }
361
		}
362
	    } else {
7 7u83 363
		for (i = 0; !found && i < n; i++) {
364
		    if (*s == options[i].on) {
365
			*(options[i].flag) = 1;
366
			p = options[i].value;
367
			found = 1;
368
		    } else if (*s == options[i].off) {
369
			*(options[i].flag) = 0;
370
			found = 1;
2 7u83 371
		    }
372
		}
373
	    }
7 7u83 374
	    if (!found) {
375
		    warning("Unknown option, %s", argv[a]);
376
	    }
2 7u83 377
	} else {
378
	    /* Set up input and output files */
7 7u83 379
	    if (input == null) {
380
		input = argv[a];
381
	    } else if (output == null) {
382
		output = argv[a];
2 7u83 383
	    } else {
7 7u83 384
		error("Too many arguments");
385
		exit(EXIT_FAILURE);
2 7u83 386
	    }
387
	}
388
    }
389
 
390
#ifdef EBUG
391
    /* Deal with debugging options */
7 7u83 392
    if (seek_extern) {
393
	if (is_local(seek_extern_id)) {
394
	    seek_label = 1;
395
	    seek_label_no = atoi(seek_extern_id + 1);
2 7u83 396
	}
397
    }
7 7u83 398
    if (seek_line)seek_line_no = atoi(seek_line_id);
2 7u83 399
#endif
400
 
401
    /* Report version if required */
7 7u83 402
    if (report_version) {
2 7u83 403
#ifdef NEXT
7 7u83 404
	char *machine = "NeXT";
2 7u83 405
#else
406
#ifdef SUN
7 7u83 407
	char *machine = "Sun / 3";
2 7u83 408
#else
7 7u83 409
	char *machine = "HP";
2 7u83 410
#endif
411
#endif
412
	fprintf(stderr, "DRA TDF translator (TDF version %d.%d)\n",
413
		MAJOR_VERSION, MINOR_VERSION);
414
	fprintf(stderr, "reader %d.%d: ", reader_version,
415
		reader_revision);
416
	fprintf(stderr, "construct %d.%d: ", construct_version,
417
		construct_revision);
418
	fprintf(stderr, "target %d.%d.%d: \n", target_version,
419
		target_revision,target_patchlevel);
420
	fprintf(stderr, "system %s",machine);
421
#ifdef __DATE__
422
	fprintf(stderr," : installer compilation %s\n", __DATE__);
423
#endif
424
	fprintf(stderr,"release: %s\n",RELEASE);
7 7u83 425
	fprintf(stderr, ".\n");
2 7u83 426
#ifdef EBUG
7 7u83 427
	fprintf(stderr, "Last revised %s.\n", revdate);
2 7u83 428
#endif
429
    }
7 7u83 430
    if (report_tdf_versions) {
431
	    report_versions = 1;
432
    }
2 7u83 433
 
434
    /* Check on diagnostics */
7 7u83 435
    if (!have_diagnostics && diagnose) {
436
	error("Diagnostics not supported");
437
	diagnose = 0;
2 7u83 438
    }
439
 
440
#if have_diagnostics
7 7u83 441
    diag_override = DIAG_UNKNOWN;
442
    if (diag_stab_override) {
443
	    diag_override = DIAG_STAB;
444
    }
445
    if (diag_xdb_new_override) {
446
	    diag_override = DIAG_XDB_NEW;
447
    }
448
    if (diag_xdb_old_override) {
449
	    diag_override = DIAG_XDB_OLD;
450
    }
2 7u83 451
#endif
452
 
453
    /* Switch off optimizations if required */
7 7u83 454
    if (diagnose || !optimize) {
455
	do_inlining = 0;
456
	do_loopconsts = 0;
457
	do_foralls = 0;
458
	do_peephole = 0;
459
	do_unroll = 0;
2 7u83 460
    }
461
 
462
    /* Show options if necessary */
7 7u83 463
    if (show_options) {
464
	int i, n = array_size(options);
465
	for (i = 0; i < n; i++) {
466
	    bool b = *(options[i].flag);
467
	    char **pv = options[i].value;
468
	    printf("%s = %s", options[i].opt,(b ? "True" : "False"));
469
	    if (pv && b) {
470
		    printf(" (%s)", *pv);
471
	    }
472
	    printf("\n");
2 7u83 473
	}
474
    }
475
 
476
    /* Check on separate units */
7 7u83 477
    if (do_sep_units) {
478
	separate_units = 1;
2 7u83 479
#if 0
7 7u83 480
	current_alloc_size = first_alloc_size;
2 7u83 481
#endif
482
    }
483
 
484
    do_pic = 0 ; /* TODO */
485
 
486
    /* Other options */
7 7u83 487
    if (do_pic) {
488
	    PIC_code = 1;
489
    }
490
 
491
    if (!extra_checks) {
492
	    target_dbl_maxexp = 16384;
493
    }
2 7u83 494
 
7 7u83 495
    if (do_quit) {
496
	    exit(EXIT_SUCCESS);
497
    }
498
 
2 7u83 499
    /* Open input file */
7 7u83 500
    if (input == null) {
501
	error("Not enough arguments");
502
	exit(EXIT_FAILURE);
2 7u83 503
    }
7 7u83 504
    if (!initreader(input)) {
505
	exit(EXIT_FAILURE);
2 7u83 506
    }
7 7u83 507
    /* open_input(input);*/
2 7u83 508
 
509
    /* Set up alignment rules */
7 7u83 510
    double_align = DBL_ALIGN;
511
    param_align = PARAM_ALIGN;
512
    stack_align = STACK_ALIGN;
2 7u83 513
 
7 7u83 514
    MAX_BF_SIZE = (cc_conventions ? MAX_BF_SIZE_CC : MAX_BF_SIZE_GCC);
2 7u83 515
 
516
    /* Call initialization routines */
7 7u83 517
    top_def = null;
518
    init_flpt();
519
    init_instructions();
2 7u83 520
#include "inits.h"
7 7u83 521
    init_weights();
522
    init_wheres();
2 7u83 523
 
524
    /* Decode, optimize and process the input TDF */
7 7u83 525
    open_output(output);
526
    asm_comment;
527
    outs(" TDF to 680x0, ");
528
    outs(version_str);
529
    outs(", ");
530
    outs(revision);
531
    outnl();
532
    init_output();
533
    area(ptext);
2 7u83 534
#if have_diagnostics
7 7u83 535
    if (diagnose) {
536
	    diag_prologue();
537
    }
2 7u83 538
#endif
7 7u83 539
    d_capsule();
2 7u83 540
#if have_diagnostics
7 7u83 541
    if (diagnose) {
542
	    diag_epilogue();
543
    }
2 7u83 544
#endif
545
#ifdef asm_version
7 7u83 546
    if (normal_version) {
547
	asm_version;
2 7u83 548
    } else {
7 7u83 549
	asm_version_aux;
2 7u83 550
    }
7 7u83 551
    outnl();
2 7u83 552
#endif
7 7u83 553
    if (errors && !ignore_errors) {
554
	    exit(EXIT_FAILURE);
555
    }
556
    return(0);
2 7u83 557
}