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
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
/**********************************************************************
62
$Author: release $
63
$Date: 1998/01/17 15:56:04 $
64
$Revision: 1.1.1.1 $
65
$Log: main.c,v $
66
 * Revision 1.1.1.1  1998/01/17  15:56:04  release
67
 * First version to be checked into rolling release.
68
 *
69
 * Revision 1.2  1995/09/12  11:00:34  currie
70
 * gcc pedanttry
71
 *
72
 * Revision 1.1  1995/04/13  09:33:41  currie
73
 * Initial revision
74
 *
75
***********************************************************************/
76
 
77
/*********************************************************************
78
                     main.c
79
 
80
   This is the main routine.
81
    It constructs .G (binasm) and .T (symbol table) files from the input .t
82
    files. If -S is given it will also construct a .s (assembler) file in as_file.
83
 
84
 *********************************************************************/
85
 
86
 
87
 
88
 
89
#include "config.h"
90
#include "version.h"
91
#include "common_types.h"
92
#include "basicread.h"
93
#include "flags.h"
94
#include "main_reads.h"
95
#include "flpt.h"
96
#include "externs.h"
97
#include "installglob.h"
98
#include "machine.h"
99
#include "exp.h"
100
#include "dump_distr.h"
101
#include "construct_v.h"
102
#include "reader_v.h"
6 7u83 103
extern void output_symtab(char*);
2 7u83 104
 
105
 
106
/* extern int bytes_allocated; */
107
 
108
void out_rename
6 7u83 109
(char * oldid, char * newid)
2 7u83 110
{
111
	/* ??? this may be wrong with diagnostics */
112
	return;
113
}
114
 
115
extern int good_trans;
116
bool do_extern_adds;
117
FILE * as_file;
118
 
119
FILE * ba_file;
120
 
121
int   majorno = 3;
122
int   minorno = 0;
123
 
124
long  currentfile = -1;		/* our source fileno 0.. */
125
long  mainfile = 0;		/* would be best if it  actually contained
126
				   main ! */
127
bool BIGEND = (little_end == 0);
128
 
129
bool do_tlrecursion = 1;
130
 
131
bool opt
6 7u83 132
(char c)
2 7u83 133
{ if (c == '0' || c == 0) return 0;
134
  else return 1;
135
}
136
 
137
int   main
6 7u83 138
(int argc, char **argv)
2 7u83 139
{
140
  long  i;
141
  char *nm;
142
  char *aname;
143
  char *dname;
144
  bool withs = 0;
145
  bool no_opts = 0;
146
  bool override_diags = 0;
147
/*  bool show_size = 0; */
148
 
6 7u83 149
  as_file = (FILE *)0;
2 7u83 150
  do_inlining = 1;
151
  redo_structfns = 1;
152
  do_unroll = 1;
153
  do_extern_adds = 0;
154
 
155
 
156
  flpt_const_overflow_fail = 1; /* HUGEVAL requires 0 for Ysystem */
157
 
158
  do_foralls = 1;
159
  do_alloca = 1;
160
  for (i = 1; argv[i][0] == '-'; ++i) {/* read flags */
161
    char *s = argv[i];
162
    switch (s[1]) {
163
/*      case '?':
164
	show_size = 1;
165
	break;
166
*/
167
      case 'A':
168
	do_alloca = opt(s[2]);
169
	break;
170
      case 'B':
171
	flpt_const_overflow_fail = opt(s[2]);
172
	break;
173
      case 'C':
174
	do_loopconsts = opt(s[2]);
175
	break;
176
      case 'D':
177
	failer("No PIC code available");
178
	exit(EXIT_FAILURE);
179
      case 'E':
180
        extra_checks = 0;
181
        break;
182
      case 'e':
183
	do_extern_adds = opt(s[2]);
184
	break;
185
      case 'F':
186
        do_foralls = opt(s[2]);
187
        break;
188
      case '-':
189
      	override_diags = 1;
190
      	break;
191
      case 'H':
192
	diagnose = 1;
193
	do_alloca = 0; /* dbx does not understand variable frame sizes */
194
	break;
195
      case 'I':
196
	do_inlining = opt(s[2]);
197
        break;
198
      case 'K':
199
	/* only MIPS ultrix */
200
	break;
201
      case 'M':
202
	strict_fl_div = (opt(s[2]) == 0);
203
	break;
204
      case 'P':
205
	do_profile = 1;
206
	break;
207
      case 'Q':
208
	exit(EXIT_FAILURE);
209
      case 'R':
210
	round_after_flop = opt(s[2]);
211
	break;
212
      case 'S':
213
	withs =1;
214
	break;
215
      case 'U':
216
        do_unroll = opt(s[2]);
217
        break;
218
      case 'V': {
219
		int   ind = 2;
220
		int maj = 0;
221
		minorno = 0;
222
		for (;; ind++) {
223
		  char  si = s[ind];
224
		  if (si != ' ') {
225
		    if (si >= '0' && si <= '9') {
226
		      maj = maj * 10 + si - '0';
227
		    }
228
		    else
229
		      break;
230
		  }
231
		}
232
 
6 7u83 233
		if (s[ind]!= '.') {
2 7u83 234
		  fprintf(stderr,
235
                "DRA TDF Mips Ultrix (as:3.x) translator %d.%d: (TDF version %d.%d)\n",
236
                 mipstrans_version,mipstrans_revision, MAJOR_VERSION, MINOR_VERSION);
237
                 fprintf(stderr, "reader %d.%d: \n", reader_version,
238
		 reader_revision);
239
	         fprintf(stderr, "construct %d.%d: \n", construct_version,
240
		 construct_revision);
241
        	 break;
242
		}
243
		majorno = maj;
244
		minorno = 0;
245
 
246
		for (ind++;; ind++) {
247
		  char  si = s[ind];
248
		  if (si >= '0' && si <= '9') {
249
		    minorno = minorno * 10 + si - '0';
250
		  }
251
		  else
252
		    break;
253
		}
254
 
255
	      }
256
      case 'W':
257
        writable_strings = opt(s[2]);
258
        break;
259
      case 'X':
260
        no_opts = 1;
261
        break;
262
      case 'd':
263
        do_dump_opt = 0;
264
        break;
265
      case 'l':
266
        do_tlrecursion = opt(s[2]);
267
        break;
268
      case 'Z': /* prints on stderr the versions of all the capsules
269
                   from which this capsule was made */
270
        report_versions = 1;
271
        break;
272
      default:
6 7u83 273
	failer("Illegal flag");
2 7u83 274
	break;
275
    };
276
  };
277
 
278
#ifdef V210
279
	if (majorno != 2) {
280
		printf("This translator is only for ULTRIX versions 2.x\n");
281
		exit(EXIT_FAILURE);
282
	}
283
#else
284
	if (majorno == 2) {
285
		printf("This translator is not for ULTRIX versions 2.x\n");
286
		exit(EXIT_FAILURE);
287
	}
288
#endif
289
 
6 7u83 290
  if (override_diags)diagnose = 0;
2 7u83 291
  if (diagnose || no_opts) {		/* line numbering goes to hell with
292
				   optimisations */
293
 
294
        do_inlining = 0;
295
        do_loopconsts = 0;
296
        do_foralls = 0;
297
        do_dump_opt = 0;
298
        do_unroll = 0;
299
	do_tlrecursion = 0;
300
  };
301
 
302
 
303
  if (withs) {			/* requires assembler text */
304
    aname = argv[argc - 1];
6 7u83 305
    as_file = fopen(aname, "w");
306
    if (as_file == (FILE *)0) {
307
      failer("can't find .s file");
2 7u83 308
      return 1;
309
    }
310
    argc--;
311
  }
312
 
313
 
314
  dname = argv[argc - 1];	/* the .T file */
315
  nm = argv[argc - 2];		/* the .G file */
6 7u83 316
  ba_file = fopen(nm, "w");
317
  if (ba_file == (FILE *)0) {
318
    printf("install: can't open output file %s\n", nm);
319
    return(1);
2 7u83 320
  }
321
 
322
 
6 7u83 323
  if (!initreader(argv[argc - 3])) {
324
    failer("cant read .t file");
325
    return(1);
2 7u83 326
  };
327
 
328
  init_flpt();
329
#include "inits.h"
330
  top_def = (dec*)0;
331
 
332
 
333
 
334
 
335
 
336
  local_prefix = "$$";
337
  name_prefix = "";
338
 
339
 
340
  d_capsule();
341
/*
342
  if (show_size) {
343
	printf("bytes allocated = %d\n", bytes_allocated);
344
  }
345
*/
346
 
347
 
348
 
349
  if (as_file)
350
    fclose (as_file);		/* close the .s file */
351
  fclose (ba_file);		/* close the .G file */
352
  output_symtab (dname);	/* construct the .T file */
353
  return (good_trans);		/* return 1 for error, 0 for good */
354
}
355