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