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
Line 115... Line 145...
115
 
145
 
116
extern long aritherr_lab;
146
extern long aritherr_lab;
117
extern long stackerr_lab;
147
extern long stackerr_lab;
118
 
148
 
119
 
149
 
120
extern exp find_named_tg PROTO_S ((char*, shape));
150
extern exp find_named_tg(char*, shape);
121
extern shape f_top;
151
extern shape f_top;
122
extern shape f_proc;
152
extern shape f_proc;
123
 
153
 
124
procrec * procrecs;
154
procrec * procrecs;
125
dec ** main_globals;
155
dec ** main_globals;
Line 127... Line 157...
127
 
157
 
128
extern long fscopefile;
158
extern long fscopefile;
129
extern bool do_extern_adds;
159
extern bool do_extern_adds;
130
 
160
 
131
ash ashof
161
ash ashof
132
    PROTO_N ( (s) )
-
 
133
    PROTO_T ( shape s )
162
(shape s)
134
{
163
{
135
	ash a;
164
	ash a;
136
	a.ashsize = shape_size(s);
165
	a.ashsize = shape_size(s);
137
	a.ashalign = shape_align(s);
166
	a.ashalign = shape_align(s);
138
	return a;
167
	return a;
139
}
168
}
140
 
169
 
141
 
170
 
142
bool not_reserved
171
bool not_reserved
143
    PROTO_N ( (id) )
-
 
144
    PROTO_T ( char *id )
172
(char *id)
145
{
173
{
146
  /* various identifier reserved by MIPS */
174
  /* various identifier reserved by MIPS */
147
  if (!strcmp (id, "edata"))
175
  if (!strcmp(id, "edata"))
148
    return (0);
176
    return(0);
149
  if (!strcmp (id, "etext"))
177
  if (!strcmp(id, "etext"))
150
    return (0);
178
    return(0);
151
  if (!strcmp (id, "end"))
179
  if (!strcmp(id, "end"))
152
    return (0);
180
    return(0);
153
  if (!strcmp (id, "_ftext"))
181
  if (!strcmp(id, "_ftext"))
154
    return (0);
182
    return(0);
155
  if (!strcmp (id, "_fdata"))
183
  if (!strcmp(id, "_fdata"))
156
    return (0);
184
    return(0);
157
  if (!strcmp (id, "_fbss"))
185
  if (!strcmp(id, "_fbss"))
158
    return (0);
186
    return(0);
159
  if (!strcmp (id, "_gp"))
187
  if (!strcmp(id, "_gp"))
160
    return (0);
188
    return(0);
161
  if (!strcmp (id, "_procedure_table"))
189
  if (!strcmp(id, "_procedure_table"))
162
    return (0);
190
    return(0);
163
  if (!strcmp (id, "_procedure_string_table"))
191
  if (!strcmp(id, "_procedure_string_table"))
164
    return (0);
192
    return(0);
165
  return (1);
193
  return(1);
166
}
194
}
167
 
195
 
168
 
196
 
169
 
197
 
170
 
198
 
171
 
199
 
172
char varsize
200
char varsize
173
    PROTO_N ( (sha) )
-
 
174
    PROTO_T ( shape sha )
201
(shape sha)
175
{
202
{
176
  return (name(sha)==nofhd);
203
  return(name(sha) ==nofhd);
177
}
204
}
178
 
205
 
179
int current_symno;
206
int current_symno;
180
 
207
 
181
void globalise_name
208
void globalise_name
182
    PROTO_N ( (my_def) )
-
 
183
    PROTO_T ( dec * my_def )
209
(dec * my_def)
184
{
210
{
185
	char *id = my_def -> dec_u.dec_val.dec_id;
211
	char *id = my_def -> dec_u.dec_val.dec_id;
186
        if (!my_def -> dec_u.dec_val.extnamed) return;
212
        if (!my_def -> dec_u.dec_val.extnamed) return;
187
	if (as_file)
213
	if (as_file)
188
	  fprintf (as_file, "\t.globl\t%s\n", id);
214
	  fprintf(as_file, "\t.globl\t%s\n", id);
189
	out_common (symnos[my_def->dec_u.dec_val.sym_number], iglobal);
215
	out_common(symnos[my_def->dec_u.dec_val.sym_number], iglobal);
190
 
216
 
191
}
217
}
192
 
218
 
193
void code_it
219
void code_it
194
    PROTO_N ( (my_def) )
-
 
195
    PROTO_T ( dec * my_def )
220
(dec * my_def)
196
{
221
{
197
  exp tg = my_def -> dec_u.dec_val.dec_exp;
222
  exp tg = my_def -> dec_u.dec_val.dec_exp;
198
  char *id = my_def -> dec_u.dec_val.dec_id;
223
  char *id = my_def -> dec_u.dec_val.dec_id;
199
  long symdef = my_def ->dec_u.dec_val.sym_number;
224
  long symdef = my_def ->dec_u.dec_val.sym_number;
200
  bool extnamed =  my_def -> dec_u.dec_val.extnamed;
225
  bool extnamed =  my_def -> dec_u.dec_val.extnamed;
Line 202... Line 227...
202
  static  space tempspace = {
227
  static  space tempspace = {
203
      0, 0
228
      0, 0
204
    };
229
    };
205
  if (symnos[symdef] <0) goto end; /* ? unused symbols */
230
  if (symnos[symdef] <0) goto end; /* ? unused symbols */
206
 
231
 
207
  if (son (tg) != nilexp && (!extnamed || !is_comm(son(tg)))) {
232
  if (son(tg)!= nilexp && (!extnamed || !is_comm(son(tg)))) {
208
    if (name (son (tg)) == proc_tag
233
    if (name(son(tg)) == proc_tag
209
		|| name(son(tg)) == general_proc_tag) {
234
		|| name(son(tg)) == general_proc_tag) {
210
        diag_descriptor * dd =  my_def -> dec_u.dec_val.diag_info;
235
        diag_descriptor * dd =  my_def -> dec_u.dec_val.diag_info;
211
	/* compile code for proc */
236
	/* compile code for proc */
212
	if (as_file) {
237
	if (as_file) {
213
	  fprintf (as_file,"\t.text\n\t.align 3\n");
238
	  fprintf(as_file,"\t.text\n\t.align 3\n");
214
	}
239
	}
215
 
240
 
216
 
241
 
217
	out_common (0, itext);
242
	out_common(0, itext);
218
	out_value (0, ialign, 3, 0);
243
	out_value(0, ialign, 3, 0);
219
	if (diagnose) {
244
	if (diagnose) {
220
	 if ( dd != (diag_descriptor*)0) {
245
	 if (dd != (diag_descriptor*)0) {
221
	    sourcemark *sm = &dd -> data.id.whence;
246
	    sourcemark *sm = &dd -> data.id.whence;
222
	    stabd(fscopefile = find_file(sm->file->file.ints.chars),
247
	    stabd(fscopefile = find_file(sm->file->file.ints.chars),
223
	               sm->line_no.nat_val.small_nat);
248
	               sm->line_no.nat_val.small_nat);
224
	 }
249
	 }
225
	 else { stabd(0,1); /*no diagnostics for this proc */ }
250
	 else { stabd(0,1); /*no diagnostics for this proc */ }
226
	}
251
	}
227
 
252
 
228
	globalise_name(my_def);
253
	globalise_name(my_def);
229
 
254
 
230
	if (as_file) fprintf(as_file, "\t.ent\t%s\n%s:\n", id, id);
255
	if (as_file)fprintf(as_file, "\t.ent\t%s\n%s:\n", id, id);
231
 
256
 
232
	out_ent (current_symno = symnos[symdef], ient, 2);/* why 2? */
257
	out_ent (current_symno = symnos[symdef], ient, 2);/* why 2? */
233
	out_common (symnos[symdef], ilabel);
258
	out_common(symnos[symdef], ilabel);
234
	if (as_file) {
259
	if (as_file) {
235
		fprintf (as_file,
260
		fprintf(as_file,
236
			(diagnose) ? "\t.option O1\n" : "\t.option O2\n");
261
			(diagnose)? "\t.option O1\n" : "\t.option O2\n");
237
	}
262
	}
238
 
263
 
239
	out_option (1, (diagnose) ? 1 : 2);
264
	out_option(1,(diagnose)? 1 : 2);
240
 
265
 
241
	symnoforstart (symdef, currentfile);
266
	symnoforstart(symdef, currentfile);
242
	settempregs (son(tg));
267
	settempregs(son(tg));
243
	code_here (son (tg), tempspace, nowhere);
268
	code_here(son(tg), tempspace, nowhere);
244
	if (diagnose && dd != (diag_descriptor*)0) {
269
	if (diagnose && dd != (diag_descriptor*)0) {
245
		stabd(fscopefile, currentlno+1);
270
		stabd(fscopefile, currentlno+1);
246
	}
271
	}
247
	if (as_file)
272
	if (as_file)
248
	  fprintf (as_file, "\t.end\t%s\n", id);
273
	  fprintf(as_file, "\t.end\t%s\n", id);
249
	out_common (symnoforend (my_def, currentfile), iend);
274
	out_common(symnoforend(my_def, currentfile), iend);
250
    }
275
    }
251
    else {			/* global values */
276
    else {			/* global values */
252
 
277
 
253
	exp c = son (tg);
278
	exp c = son(tg);
254
	IGNORE evaluated (c, (isvar (tg)) ? (-symdef - 1) : symdef + 1, my_def);
279
	IGNORE evaluated(c,(isvar(tg))?(-symdef - 1): symdef + 1, my_def);
255
 
280
 
256
 
281
 
257
    };
282
    };
258
  }
283
  }
259
  else {	/* global declarations but no definitions or is_comm */
284
  else {	/* global declarations but no definitions or is_comm */
260
      long  size;
285
      long  size;
261
      shape s = (son(tg)==nilexp)?my_def -> dec_u.dec_val.dec_shape :
286
      shape s = (son(tg) ==nilexp)?my_def -> dec_u.dec_val.dec_shape :
262
				sh(son(tg));
287
				sh(son(tg));
263
      size = (shape_size(s) + 7) >> 3;
288
      size = (shape_size(s) + 7) >> 3;
264
 
289
 
265
      if ((isvar(tg) || name(s) != prokhd) && not_reserved (id)) {
290
      if ((isvar(tg) || name(s)!= prokhd) && not_reserved(id)) {
266
	if ((son(tg) != nilexp && is_comm(son(tg)))
291
	if ((son(tg)!= nilexp && is_comm(son(tg)))
267
		|| (son(tg)==nilexp && varsize(sh(tg))) ) {
292
		|| (son(tg) ==nilexp && varsize(sh(tg)))) {
268
	  if (size !=0) { /* ? ? ! ? */
293
	  if (size !=0) { /* ? ? ! ? */
269
	     globalise_name(my_def);
294
	     globalise_name(my_def);
270
	     if (as_file)
295
	     if (as_file)
271
	        fprintf (as_file, "\t.comm\t%s %ld\n", id, size);
296
	        fprintf(as_file, "\t.comm\t%s %ld\n", id, size);
272
	      out_value (symnos[symdef], icomm, size, 1);
297
	      out_value(symnos[symdef], icomm, size, 1);
273
	  }
298
	  }
274
	}
299
	}
275
	else {
300
	else {
276
	  if (as_file)
301
	  if (as_file)
277
	    fprintf (as_file, "\t.extern\t%s %ld\n", id,
302
	    fprintf(as_file, "\t.extern\t%s %ld\n", id,
278
		size);
303
		size);
279
	  out_value (symnos[symdef], iextern, size, 1);
304
	  out_value(symnos[symdef], iextern, size, 1);
280
	}
305
	}
281
      }
306
      }
282
      else
307
      else
283
	if (son (tg) == nilexp && !extnamed) {
308
	if (son(tg) == nilexp && !extnamed) {
284
	  if (size !=0) { /* ? ? ! ? */
309
	  if (size !=0) { /* ? ? ! ? */
285
	      if (as_file)
310
	      if (as_file)
286
	        fprintf (as_file, "\t.lcomm\t%s %ld\n", id, size);
311
	        fprintf(as_file, "\t.lcomm\t%s %ld\n", id, size);
287
	      out_value (symnos[symdef], ilcomm, size, 1);
312
	      out_value(symnos[symdef], ilcomm, size, 1);
288
	  }
313
	  }
289
	}
314
	}
290
 
315
 
291
  }
316
  }
292
 
317
 
Line 295... Line 320...
295
  my_def -> dec_u.dec_val.processed = 1;
320
  my_def -> dec_u.dec_val.processed = 1;
296
  return;
321
  return;
297
}
322
}
298
 
323
 
299
void mark_unaliased
324
void mark_unaliased
300
    PROTO_N ( (e) )
-
 
301
    PROTO_T ( exp e )
325
(exp e)
302
{
326
{
303
  exp p = pt (e);
327
  exp p = pt(e);
304
  bool ca = 1;
328
  bool ca = 1;
305
  while (p != nilexp && ca) {
329
  while (p != nilexp && ca) {
306
    if (bro(p)==nilexp ||
330
    if (bro(p) ==nilexp ||
307
       (!(last (p) && name (bro (p)) == cont_tag) &&
331
      (!(last(p) && name(bro(p)) == cont_tag) &&
308
	!(!last (p) && last (bro (p)) && name (bro (bro (p))) == ass_tag)))
332
	!(!last(p) && last(bro(p)) && name(bro(bro(p))) == ass_tag)))
309
      ca = 0;
333
      ca = 0;
310
    p = pt (p);
334
    p = pt(p);
311
  };
335
  };
312
  if (ca)
336
  if (ca)
313
    setcaonly (e);
337
    setcaonly(e);
314
  return;
338
  return;
315
}
339
}
316
 
340
 
317
void remove_unused
341
void remove_unused
318
    PROTO_Z ()
342
(void)
319
{ dec ** sdef = &top_def;
343
{ dec ** sdef = &top_def;
320
  while (*sdef != (dec *) 0) {
344
  while (*sdef != (dec *)0) {
321
    exp crt_exp = (*sdef) -> dec_u.dec_val.dec_exp;
345
    exp crt_exp = (*sdef) -> dec_u.dec_val.dec_exp;
322
    bool extnamed = (*sdef) -> dec_u.dec_val.extnamed;
346
    bool extnamed = (*sdef) -> dec_u.dec_val.extnamed;
323
    if (no(crt_exp) == 0 && !extnamed) {
347
    if (no(crt_exp) == 0 && !extnamed) {
324
	*sdef = (*sdef)->def_next;
348
	*sdef = (*sdef) ->def_next;
325
    }
349
    }
326
    else sdef = &((*sdef)->def_next);
350
    else sdef = & ((*sdef) ->def_next);
327
  }
351
  }
328
}
352
}
329
 
353
 
330
 
354
 
331
 
355
 
332
void translate_capsule
356
void translate_capsule
333
    PROTO_Z ()
357
(void)
334
{
358
{
335
  dec * my_def;
359
  dec * my_def;
336
  int noprocs;
360
  int noprocs;
337
  int i;
361
  int i;
338
 
362
 
339
  opt_all_exps ();
363
  opt_all_exps();
340
  remove_unused();
364
  remove_unused();
341
 
365
 
342
#ifdef INCLUDE_INITS
366
#ifdef INCLUDE_INITS
343
  my_def = top_def;
367
  my_def = top_def;
344
  while (my_def != (dec *) 0) {
368
  while (my_def != (dec *)0) {
345
        exp crt_exp = my_def -> dec_u.dec_val.dec_exp;
369
        exp crt_exp = my_def -> dec_u.dec_val.dec_exp;
346
	char * id = my_def -> dec_u.dec_val.dec_id;
370
	char * id = my_def -> dec_u.dec_val.dec_id;
347
	if (strcmp(id, "main")==0 && son(crt_exp)!= nilexp &&
371
	if (strcmp(id, "main") ==0 && son(crt_exp)!= nilexp &&
348
		name(son(crt_exp)) == proc_tag) {
372
		name(son(crt_exp)) == proc_tag) {
349
	   exp fn = me_obtain(find_named_tg("__DO_I_TDF", f_proc));
373
	   exp fn = me_obtain(find_named_tg("__DO_I_TDF", f_proc));
350
	   exp cll = getexp(f_top, nilexp, 0, fn, nilexp, 0, 0, apply_tag);
374
	   exp cll = getexp(f_top, nilexp, 0, fn, nilexp, 0, 0, apply_tag);
351
	   exp * dm = &son(son(crt_exp));
375
	   exp * dm = &son(son(crt_exp));
352
	   exp hld, seq;
376
	   exp hld, seq;
353
	   bro(fn) = cll; setlast(fn);
377
	   bro(fn) = cll; setlast(fn);
354
	   while (name(*dm)==ident_tag && isparam(*dm)) dm = &bro(son(*dm));
378
	   while (name(*dm) ==ident_tag && isparam(*dm))dm = &bro(son(*dm));
355
	   /* dm is body of main after params */
379
	   /* dm is body of main after params */
356
	   hld = getexp(f_top, *dm, 0, cll, nilexp, 0, 1, 0);
380
	   hld = getexp(f_top, *dm, 0, cll, nilexp, 0, 1, 0);
357
	   seq = getexp(sh(*dm), bro(*dm), last(*dm), hld, nilexp, 0, 0, seq_tag);
381
	   seq = getexp(sh(*dm), bro(*dm), last(*dm), hld, nilexp, 0, 0, seq_tag);
358
	   bro(*dm) = seq; setlast(*dm);
382
	   bro(*dm) = seq; setlast(*dm);
359
	   bro(cll) = hld; setlast(cll);
383
	   bro(cll) = hld; setlast(cll);
Line 364... Line 388...
364
   }
388
   }
365
#endif
389
#endif
366
 
390
 
367
    /* mark static unaliased */
391
    /* mark static unaliased */
368
  my_def = top_def;
392
  my_def = top_def;
369
  while (my_def != (dec *) 0) {
393
  while (my_def != (dec *)0) {
370
    exp crt_exp = my_def -> dec_u.dec_val.dec_exp;
394
    exp crt_exp = my_def -> dec_u.dec_val.dec_exp;
371
    if (son (crt_exp) != nilexp &&
395
    if (son(crt_exp)!= nilexp &&
372
	!my_def -> dec_u.dec_val.extnamed &&
396
	!my_def -> dec_u.dec_val.extnamed &&
373
	isvar (crt_exp))
397
	isvar(crt_exp))
374
      mark_unaliased (crt_exp);
398
      mark_unaliased(crt_exp);
375
    my_def = my_def -> def_next;
399
    my_def = my_def -> def_next;
376
  };
400
  };
377
 
401
 
378
  noprocs = 0;
402
  noprocs = 0;
379
  my_def = top_def;
403
  my_def = top_def;
380
  while (my_def != (dec *) 0) {
404
  while (my_def != (dec *)0) {
381
    exp crt_exp = my_def -> dec_u.dec_val.dec_exp;
405
    exp crt_exp = my_def -> dec_u.dec_val.dec_exp;
382
    if (son (crt_exp) != nilexp
406
    if (son(crt_exp)!= nilexp
383
        && (name (son (crt_exp)) == proc_tag ||
407
        && (name(son(crt_exp)) == proc_tag ||
384
		name(son(crt_exp)) == general_proc_tag)) {
408
		name(son(crt_exp)) == general_proc_tag)) {
385
      noprocs++;
409
      noprocs++;
386
    }
410
    }
387
    my_def = my_def -> def_next;
411
    my_def = my_def -> def_next;
388
  }
412
  }
389
  /* count procs */
413
  /* count procs */
390
 
414
 
391
  procrecs = (procrec *) xcalloc (noprocs, sizeof (procrec));
415
  procrecs = (procrec *)xcalloc(noprocs, sizeof(procrec));
392
  noprocs = 0;
416
  noprocs = 0;
393
 
417
 
394
  my_def = top_def;
418
  my_def = top_def;
395
  while (my_def != (dec *) 0) {
419
  while (my_def != (dec *)0) {
396
    exp crt_exp = my_def -> dec_u.dec_val.dec_exp;
420
    exp crt_exp = my_def -> dec_u.dec_val.dec_exp;
397
    if (son (crt_exp) != nilexp &&
421
    if (son(crt_exp)!= nilexp &&
398
	(name (son (crt_exp)) == proc_tag || name(son(crt_exp)) == general_proc_tag)) {
422
	(name(son(crt_exp)) == proc_tag || name(son(crt_exp)) == general_proc_tag)) {
399
      no (son (crt_exp)) = noprocs++;
423
      no(son(crt_exp)) = noprocs++;
400
      /* put index into procrecs in no(proc) */
424
      /* put index into procrecs in no(proc) */
401
    }
425
    }
402
    my_def = my_def -> def_next;
426
    my_def = my_def -> def_next;
403
  }
427
  }
404
 
428
 
405
  if (do_extern_adds) {
429
  if (do_extern_adds) {
406
	usages = (exp*)xcalloc(noprocs, sizeof(exp));
430
	usages = (exp*)xcalloc(noprocs, sizeof(exp));
407
	my_def = top_def;
431
	my_def = top_def;
408
  	while (my_def != (dec *) 0) {
432
  	while (my_def != (dec *)0) {
409
		exp crt_exp = my_def -> dec_u.dec_val.dec_exp;
433
		exp crt_exp = my_def -> dec_u.dec_val.dec_exp;
410
		if (son(crt_exp) == nilexp && isvar(crt_exp) ) {
434
		if (son(crt_exp) == nilexp && isvar(crt_exp)) {
411
			global_usages(crt_exp, noprocs);
435
			global_usages(crt_exp, noprocs);
412
			/* try to identify globals ptrs in procs */
436
			/* try to identify globals ptrs in procs */
413
		}
437
		}
414
		my_def = my_def -> def_next;
438
		my_def = my_def -> def_next;
415
	}
439
	}
416
  }
440
  }
417
 
441
 
418
  if (diagnose && nofds !=0) {
442
  if (diagnose && nofds !=0) {
419
      init_table_space (nofds, noprocs);
443
      init_table_space(nofds, noprocs);
420
      add_dense_no (0, 0);
444
      add_dense_no(0, 0);
421
      add_dense_no (0, 0);	/* dont know why!! */
445
      add_dense_no (0, 0);	/* dont know why!! */
422
      symnosforfiles ();
446
      symnosforfiles();
423
      stab_types();
447
      stab_types();
424
  }
448
  }
425
  else {
449
  else {
426
    init_table_space (1,noprocs);
450
    init_table_space(1,noprocs);
427
    add_dense_no (0, 0);
451
    add_dense_no(0, 0);
428
    add_dense_no (0, 0);	/* dont know why!! */
452
    add_dense_no (0, 0);	/* dont know why!! */
429
    IGNORE new_lsym_d ("NOFILE.c", 0, stFile, scText, 0, 0);
453
    IGNORE new_lsym_d("NOFILE.c", 0, stFile, scText, 0, 0);
430
  };
454
  };
431
 
455
 
432
  /* scan to put everything in MIPS form */
456
  /* scan to put everything in MIPS form */
433
 
457
 
434
  my_def = top_def;
458
  my_def = top_def;
435
  while (my_def != (dec *) 0) {
459
  while (my_def != (dec *)0) {
436
    exp crt_exp = my_def -> dec_u.dec_val.dec_exp;
460
    exp crt_exp = my_def -> dec_u.dec_val.dec_exp;
437
    if (son (crt_exp) != nilexp
461
    if (son(crt_exp)!= nilexp
438
	&& (name (son (crt_exp)) == proc_tag ||
462
	&& (name(son(crt_exp)) == proc_tag ||
439
		name(son(crt_exp))== general_proc_tag)) {
463
		name(son(crt_exp)) == general_proc_tag)) {
440
      procrec * pr = &procrecs[no (son (crt_exp))];
464
      procrec * pr = &procrecs[no(son(crt_exp))];
441
      exp * st = &son(crt_exp);
465
      exp * st = &son(crt_exp);
442
      pr -> needsproc = scan (st, &st);
466
      pr -> needsproc = scan(st, &st);
443
      pr->callee_size = (callee_size+63)&~63;
467
      pr->callee_size = (callee_size+63) &~63;
444
    }
468
    }
445
    my_def = my_def -> def_next;
469
    my_def = my_def -> def_next;
446
  }
470
  }
447
 
471
 
448
 
472
 
449
  /* calculate the break points for register allocation and do it */
473
  /* calculate the break points for register allocation and do it */
450
  my_def = top_def;
474
  my_def = top_def;
451
  while (my_def != (dec *) 0) {
475
  while (my_def != (dec *)0) {
452
    exp crt_exp = my_def -> dec_u.dec_val.dec_exp;
476
    exp crt_exp = my_def -> dec_u.dec_val.dec_exp;
453
    if (son (crt_exp) != nilexp
477
    if (son(crt_exp)!= nilexp
454
        && ( name (son (crt_exp)) == proc_tag ||
478
        && (name(son(crt_exp)) == proc_tag ||
455
		name(son(crt_exp))== general_proc_tag)) {
479
		name(son(crt_exp)) == general_proc_tag)) {
456
      procrec * pr = &procrecs[no (son (crt_exp))];
480
      procrec * pr = &procrecs[no(son(crt_exp))];
457
      needs * ndpr = & pr->needsproc;
481
      needs * ndpr = & pr->needsproc;
458
      long pprops = (ndpr->propsneeds);
482
      long pprops = (ndpr->propsneeds);
459
      bool leaf = (pprops & anyproccall) == 0;
483
      bool leaf = (pprops & anyproccall) == 0;
460
      spacereq forrest;
484
      spacereq forrest;
461
      int   freefixed = 8;	/* NO OF S_REGISTERS */
485
      int   freefixed = 8;	/* NO OF S_REGISTERS */
Line 464... Line 488...
464
      setframe_flags(son(crt_exp), leaf);
488
      setframe_flags(son(crt_exp), leaf);
465
      if (!Has_fp) freefixed++; /* can use $30 as normal caller save */
489
      if (!Has_fp) freefixed++; /* can use $30 as normal caller save */
466
 
490
 
467
      if (Has_vcallees) { freefixed--; }
491
      if (Has_vcallees) { freefixed--; }
468
 
492
 
469
      if (!No_S) IGNORE weightsv (1.0, bro (son (son (crt_exp))));
493
      if (!No_S)IGNORE weightsv(1.0, bro(son(son(crt_exp))));
470
      /* estimate usage of tags in body of proc */
494
      /* estimate usage of tags in body of proc */
471
 
495
 
472
      forrest = regalloc (bro (son (son (crt_exp))), freefixed, freefloat,
496
      forrest = regalloc(bro(son(son(crt_exp))), freefixed, freefloat,
473
				(PIC_code && !leaf)?32:0);
497
				(PIC_code && !leaf)?32:0);
474
      /* reg and stack allocation for tags */
498
      /* reg and stack allocation for tags */
475
 
499
 
476
      pr -> spacereqproc = forrest;
500
      pr -> spacereqproc = forrest;
477
 
501
 
Line 481... Line 505...
481
  }
505
  }
482
 
506
 
483
  /* put defs in main globals and set up symnos*/
507
  /* put defs in main globals and set up symnos*/
484
  my_def = top_def;
508
  my_def = top_def;
485
  main_globals_index = 0;
509
  main_globals_index = 0;
486
  while (my_def != (dec*) 0) {
510
  while (my_def != (dec*)0) {
487
  	main_globals_index++;
511
  	main_globals_index++;
488
  	my_def = my_def -> def_next;
512
  	my_def = my_def -> def_next;
489
  }
513
  }
490
 
514
 
491
  data_lab = (main_globals_index > 33)?main_globals_index:33;
515
  data_lab = (main_globals_index > 33)?main_globals_index:33;
492
  main_globals = (dec**)xcalloc(main_globals_index, sizeof(dec*));
516
  main_globals = (dec**)xcalloc(main_globals_index, sizeof(dec*));
493
  symnos = (int *) xcalloc (main_globals_index, sizeof (int));
517
  symnos = (int *)xcalloc(main_globals_index, sizeof(int));
494
 
518
 
495
  my_def = top_def;
519
  my_def = top_def;
496
  for (i=0; i < main_globals_index; i++) {
520
  for (i=0; i < main_globals_index; i++) {
497
  	main_globals[i] = my_def;
521
  	main_globals[i] = my_def;
498
  	my_def = my_def -> def_next;
522
  	my_def = my_def -> def_next;
Line 504... Line 528...
504
    exp tg = main_globals[i] -> dec_u.dec_val.dec_exp;
528
    exp tg = main_globals[i] -> dec_u.dec_val.dec_exp;
505
    char *id = main_globals[i] -> dec_u.dec_val.dec_id;
529
    char *id = main_globals[i] -> dec_u.dec_val.dec_id;
506
    bool extnamed = main_globals[i] -> dec_u.dec_val.extnamed;
530
    bool extnamed = main_globals[i] -> dec_u.dec_val.extnamed;
507
    diag_descriptor * dinf = main_globals[i] -> dec_u.dec_val.diag_info;
531
    diag_descriptor * dinf = main_globals[i] -> dec_u.dec_val.diag_info;
508
    main_globals[i] ->dec_u.dec_val.sym_number = i;
532
    main_globals[i] ->dec_u.dec_val.sym_number = i;
509
    if ( no (tg) != 0 || (extnamed && son(tg) != nilexp)
533
    if (no(tg)!= 0 || (extnamed && son(tg)!= nilexp)
510
		|| strcmp(id,"__TDFhandler") == 0
534
		|| strcmp(id,"__TDFhandler") == 0
511
		|| strcmp(id,"__TDFstacklim")==0
535
		|| strcmp(id,"__TDFstacklim") ==0
512
	) {
536
	) {
513
     	if(no(tg)==1 && son(tg)==nilexp && dinf != (diag_descriptor *)0
537
     	if (no(tg) ==1 && son(tg) ==nilexp && dinf != (diag_descriptor *)0
514
 		 /* diagnostics only! */ ) {
538
 		 /* diagnostics only! */ ) {
515
    		symnos[i]= -1;
539
    		symnos[i] = -1;
516
    	}
540
    	}
517
    	else {
541
    	else {
518
          no (tg) = (i + 1) * 64 + 32;
542
          no(tg) = (i + 1)* 64 + 32;
519
          symnos[i] = symnoforext (main_globals[i], mainfile);
543
          symnos[i] = symnoforext(main_globals[i], mainfile);
520
        }
544
        }
521
    }
545
    }
522
    else
546
    else
523
      symnos[i] = -1;
547
      symnos[i] = -1;
524
  };
548
  };
525
 
549
 
526
 
550
 
527
 
551
 
528
  setregalt (nowhere.answhere, 0);
552
  setregalt(nowhere.answhere, 0);
529
  nowhere.ashwhere.ashsize = 0;
553
  nowhere.ashwhere.ashsize = 0;
530
  nowhere.ashwhere.ashsize = 0;
554
  nowhere.ashwhere.ashsize = 0;
531
 
555
 
532
  if (as_file) {
556
  if (as_file) {
533
    fprintf (as_file, "\t.verstamp %d %d\n", majorno, minorno);
557
    fprintf(as_file, "\t.verstamp %d %d\n", majorno, minorno);
534
 
558
 
535
    if (PIC_code) {
559
    if (PIC_code) {
536
	fprintf (as_file, "\t.option pic2\n");
560
	fprintf(as_file, "\t.option pic2\n");
537
    }
561
    }
538
    else {
562
    else {
539
        fprintf (as_file, (diagnose) ? "\t.option O1\n" : "\t.option O2\n");
563
        fprintf(as_file,(diagnose)? "\t.option O1\n" : "\t.option O2\n");
540
    }
564
    }
541
  }
565
  }
542
 
566
 
543
  out_verstamp (majorno, minorno);
567
  out_verstamp(majorno, minorno);
544
				/* this is the only? use of these nos, to
568
				/* this is the only? use of these nos, to
545
				   satisfy as1 */
569
				   satisfy as1 */
546
  if (PIC_code) {
570
  if (PIC_code) {
547
	out_option(2, 2);
571
	out_option(2, 2);
548
  }
572
  }
549
  else
573
  else
550
  { out_option (1, (diagnose) ? 1 : 2); }
574
  { out_option(1,(diagnose)? 1 : 2); }
551
 
575
 
552
  if (diagnose && nofds!=0) {
576
  if (diagnose && nofds!=0) {
553
    stab_file (0);
577
    stab_file(0);
554
  }
578
  }
555
  else
579
  else
556
  {
580
  {
557
    currentfile = 0;
581
    currentfile = 0;
558
  }
582
  }
Line 578... Line 602...
578
    my_def = my_def -> def_next;
602
    my_def = my_def -> def_next;
579
  }
603
  }
580
*/
604
*/
581
  my_def = top_def;
605
  my_def = top_def;
582
 
606
 
583
  while (my_def != (dec *) 0) {
607
  while (my_def != (dec *)0) {
584
    if (!my_def -> dec_u.dec_val.processed)
608
    if (!my_def -> dec_u.dec_val.processed)
585
       code_it (my_def);
609
       code_it(my_def);
586
    my_def = my_def -> def_next;
610
    my_def = my_def -> def_next;
587
  };
611
  };
588
 
612
 
589
 
613
 
590
  return;		/* return 1 for error, 0 for good */
614
  return;		/* return 1 for error, 0 for good */
591
 
615
 
592
 
616
 
593
}
617
}
594
void translate_unit
618
void translate_unit
595
    PROTO_Z ()
619
(void)
596
{
620
{
597
  if (separate_units)
621
  if (separate_units)
598
   {
622
   {
599
     dec * my_def;
623
     dec * my_def;
600
     translate_capsule();
624
     translate_capsule();
601
     my_def = top_def;
625
     my_def = top_def;
602
     while (my_def != (dec *) 0) {
626
     while (my_def != (dec *)0) {
603
       exp crt_exp = my_def -> dec_u.dec_val.dec_exp;
627
       exp crt_exp = my_def -> dec_u.dec_val.dec_exp;
604
       no(crt_exp) = 0;
628
       no(crt_exp) = 0;
605
       pt(crt_exp) = nilexp;
629
       pt(crt_exp) = nilexp;
606
       my_def = my_def -> def_next;
630
       my_def = my_def -> def_next;
607
     };
631
     };
Line 611... Line 635...
611
  return;
635
  return;
612
}
636
}
613
 
637
 
614
 
638
 
615
void translate_tagdef
639
void translate_tagdef
616
    PROTO_Z ()
640
(void)
617
{
641
{
618
  return;
642
  return;
619
}
643
}