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
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
/**********************************************************************
32
$Author: release $
33
$Date: 1998/02/04 10:43:43 $
34
$Revision: 1.2 $
35
$Log: new_symbol.c,v $
36
 * Revision 1.2  1998/02/04  10:43:43  release
37
 * Changes during testing.
38
 *
39
 * Revision 1.1.1.1  1998/01/17  15:56:06  release
40
 * First version to be checked into rolling release.
41
 *
42
 * Revision 1.4  1995/10/25  13:48:26  currie
43
 * change to position of .glob
44
 *
45
 * Revision 1.3  1995/09/20  08:28:09  currie
46
 * Inits
47
 *
48
 * Revision 1.2  1995/08/16  16:07:02  currie
49
 * Shortened some .h names
50
 *
51
 * Revision 1.1  1995/04/13  09:08:06  currie
52
 * Initial revision
53
 *
54
***********************************************************************/
55
#include "config.h"
56
#include "cross_config.h"
57
 
58
#ifndef CROSS_INCLUDE
59
#include <symconst.h>
60
#else
61
#include CROSS_INCLUDE/symconst.h>
62
#endif
63
 
64
#include "common_types.h"
65
#include "symtab.h"
66
#include "bstack.h"
67
#include "type_to_aux.h"
68
#include "makesymtab.h"
69
#include "xalloc.h"
70
#include "diagtypes.h"
71
#include "flags.h"
72
#include "new_symbol.h"
73
 
74
extern char * init_NAME;
75
 
76
/* Procedures to accumulate symbol table records for MIPS translator
77
 
78
new_lsym
79
new_lsym_d
80
new_esym
81
new_esym_d
82
 
83
and to output the table
84
 
85
output_symtab(name)
86
 
87
by R.R.R.  25/1/91	*/
88
 
89
long numfiles;
90
long numprocs;	/* provided by mipstrans in call to init */
91
 
92
 
93
DENSETAB *dense_numbers, *densenos;
94
STRINGS* extstrings, *external_strings;
95
ESYMS* esymlist, *external_symbols;
96
 
97
pSYMFDR fdrlist, file_desc_table;
98
LSYMS* local_symbols;
99
STRINGS* local_strings;
100
AUXTAB* aux_symbols;
101
BSTACK* blockstack;
102
 
103
 
104
long* file_inds;
105
long* aux_inds;
106
long* str_inds;
107
long* sym_inds;
108
 
109
PROCSYM* proc_isym_inds;
110
 
111
long nosyms = 0;
112
long stringsize = 0;
113
long nostrings=0;
114
long noaux = 0;
115
long densind = 0;
116
long esymindex = 0;
117
long extind=0;
118
 
119
 
120
void init_table_space
121
    PROTO_N ( (noofiles, noprocs) )
122
    PROTO_T ( long noofiles X long noprocs )
123
{
124
	int ind=0;
125
	AUXU nilaux;
126
	nilaux.isym=0;
127
	blockstack= (BSTACK*)xcalloc(noofiles,sizeof(BSTACK));
128
 
129
	densenos=(DENSETAB*)xcalloc(1,sizeof(DENSETAB));
130
	densenos->num = 0;
131
	densenos->densenolist = (pDNR)xcalloc(DENSETABSIZE,sizeof(DNR));
132
	densenos->moredensenos= (DENSETAB*)0;
133
	dense_numbers=densenos;
134
 
135
	extstrings=(STRINGS*)xcalloc(1,sizeof(STRINGS));
136
	extstrings->str=(char*)xcalloc(STRINGTABSIZE,sizeof(char));
137
	extstrings->usage=0;
138
	extstrings->overspill=(STRINGS*)0;
139
	external_strings=extstrings;
140
 
141
 
142
	esymlist=(ESYMS*)xcalloc(1,sizeof(ESYMS));
143
	esymlist->symlist=(pEXTR)xcalloc(SYMTABSIZE,sizeof(EXTR));
144
	esymlist->noofsyms=0;
145
	esymlist->nextsyms=(ESYMS*)0;
146
	external_symbols=esymlist;
147
 
148
	numfiles=noofiles;
149
	numprocs=noprocs;
150
	file_inds =(long*)xcalloc(noofiles,sizeof(long));
151
	aux_inds =(long*)xcalloc(noofiles,sizeof(long));
152
	str_inds =(long*)xcalloc(noofiles,sizeof(long));
153
	sym_inds =(long*)xcalloc(noofiles,sizeof(long));
154
	proc_isym_inds =(PROCSYM*)xcalloc(noprocs,sizeof(PROCSYM));
155
 
156
	fdrlist = (pSYMFDR)xcalloc(noofiles,sizeof(SYMFDR));
157
	file_desc_table = fdrlist;
158
 
159
	local_symbols = (LSYMS*)xcalloc(noofiles,sizeof(LSYMS));
160
	local_symbols->symlist = (pSYMR)xcalloc(noofiles*SYMTABSIZE,sizeof(SYMR));
161
 
162
	local_strings = (STRINGS*)xcalloc(noofiles,sizeof(STRINGS));
163
	local_strings->str = (char*)xcalloc(noofiles*STRINGTABSIZE,sizeof(char));
164
 
165
	aux_symbols=(AUXTAB*)xcalloc(noofiles,sizeof(AUXTAB));
166
	aux_symbols->auxinfo=(pAUXU)xcalloc(noofiles*AUXTABSIZE,sizeof(AUXU));
167
 
168
	for (ind=0; ind<noofiles;ind++,fdrlist++)
169
	   {	fdrlist->symbols=local_symbols+ind;
170
		fdrlist->filestr=local_strings+ind;
171
		fdrlist->auxtabs=aux_symbols+ind;
172
		fdrlist->proc_count=0;
173
	(local_symbols+ind)->symlist=local_symbols->symlist+ind*SYMTABSIZE;
174
	(local_strings+ind)->str=local_strings->str+ind*STRINGTABSIZE;
175
		add_to_loc_strings("",ind);
176
	(aux_symbols+ind)->auxinfo=aux_symbols->auxinfo+ind*AUXTABSIZE;
177
		add_aux(nilaux,ind);	/* for each file add nilaux so no 0 */
178
	    }
179
}
180
 
181
 
182
void add_proc
183
    PROTO_N ( (sympos, filenum) )
184
    PROTO_T ( long sympos X long filenum )
185
{
186
	static long symcount=0;
187
	pSYMFDR fdrlist=file_desc_table+filenum;
188
	fdrlist->proc_count+=1;
189
	(proc_isym_inds+symcount)->procsymindex=sympos;
190
	(proc_isym_inds+symcount)->fnum=filenum;
191
	symcount++;
192
}
193
 
194
 
195
 
196
 
197
/*********************  STRING procedures  ********************/
198
 
199
 
200
long add_string
201
    PROTO_N ( (str, list) )
202
    PROTO_T ( char* str X STRINGS* list )
203
{
204
	long stringind=list->usage;
205
	int length = strlen(str)+1;
206
	while (list->overspill!=0)
207
	   {  list=list->overspill;
208
	      stringind+=list->usage;
209
	   }
210
	if ((list->usage+length)>STRINGTABSIZE)
211
		{  list->overspill = (STRINGS*)xcalloc(1,sizeof(STRINGS));
212
		   list=list->overspill;
213
		   list->str=(char*)xcalloc(STRINGTABSIZE,sizeof(char));
214
		   list->usage=length;
215
		   strcpy(list->str,str);
216
		}
217
	else 	{  strcpy(list->str+list->usage,str);
218
		   list->usage+=length;
219
		}
220
	return (stringind);
221
}
222
 
223
 
224
long add_to_loc_strings
225
    PROTO_N ( (locstr,index) )
226
    PROTO_T ( char* locstr X int index )
227
{
228
	stringsize+=strlen(locstr)+1;
229
	nostrings++;
230
	return(add_string(locstr, local_strings+index));
231
}
232
 
233
 
234
 
235
long add_to_ext_strings
236
    PROTO_N ( (extstr) )
237
    PROTO_T ( char* extstr )
238
{
239
	long posind=extind;
240
	add_string(extstr, extstrings);
241
	extind+=strlen(extstr)+1;
242
	return(posind);
243
}
244
 
245
 
246
/******************  DENSE NUMBERS  ********************/
247
 
248
 
249
 
250
long add_dense_no
251
    PROTO_N ( (rfd, index) )
252
    PROTO_T ( long rfd X long index )
253
{
254
	DNR* curr_dense;
255
	DENSETAB* denseptr= densenos;
256
	while (denseptr->moredensenos)
257
		{  denseptr=denseptr->moredensenos;
258
		}
259
	if(denseptr->num==DENSETABSIZE)
260
		{
261
		denseptr->moredensenos = (DENSETAB*)xcalloc(1,sizeof(DENSETAB));
262
		denseptr=denseptr->moredensenos;
263
		denseptr->num = 0;
264
		denseptr->densenolist = (pDNR)xcalloc(DENSETABSIZE,sizeof(DNR));
265
		denseptr->moredensenos = (DENSETAB*)0;
266
		}
267
	curr_dense=(denseptr->densenolist)+denseptr->num;
268
	curr_dense->rfd = rfd;
269
	curr_dense->index = index;
270
	denseptr->num+=1;
271
	densind++;
272
	return (densind-1);
273
}
274
 
275
DNR* get_dense_ptr
276
    PROTO_N ( (densind) )
277
    PROTO_T ( long densind )
278
{
279
	DENSETAB* denseptr = densenos;
280
	long densecount=denseptr->num;
281
	while (densecount<=densind)
282
	   {denseptr=denseptr->moredensenos;
283
	    densecount+=denseptr->num;
284
	    }
285
	return(denseptr->densenolist+(denseptr->num-(densecount-densind)));
286
}
287
 
288
 
289
/********************  SYMBOL PROCEDURES  ********************/
290
 
291
long get_sym_index
292
    PROTO_N ( (ind) )
293
    PROTO_T ( long ind )
294
{
295
	LSYMS* lsymlist=local_symbols+ind;
296
	long lsymindex = lsymlist->noofsyms;
297
	while (lsymlist->nextsyms!=0)
298
		   {  lsymlist=lsymlist->nextsyms;
299
		      lsymindex+=lsymlist->noofsyms;
300
		   }
301
	return (lsymindex);
302
}
303
 
304
 
305
SYMR* get_sym_ptr
306
    PROTO_N ( (ind, symind) )
307
    PROTO_T ( long ind X long symind )
308
{
309
	LSYMS* lsymlist=local_symbols+ind;
310
	long symcount=lsymlist->noofsyms;
311
	while (symcount<=symind)
312
	   {	lsymlist=lsymlist->nextsyms;
313
		symcount+=lsymlist->noofsyms;
314
	   }
315
	return(lsymlist->symlist+(lsymlist->noofsyms-(symcount-symind)));
316
}
317
 
318
 
319
 
320
 
321
long add_lsym
322
    PROTO_N ( (ind, newsym) )
323
    PROTO_T ( long ind X SYMR* newsym )
324
{
325
	LSYMS* lsymlist=local_symbols+ind;
326
	long lsymindex = lsymlist->noofsyms;
327
	nosyms++;
328
	while (lsymlist->nextsyms!=0)
329
		   {  lsymlist=lsymlist->nextsyms;
330
		      lsymindex+=lsymlist->noofsyms;
331
		   }
332
	if (lsymlist->noofsyms==SYMTABSIZE)
333
	   {	lsymlist->nextsyms=(LSYMS*)xcalloc(1,sizeof(LSYMS));
334
		lsymlist=lsymlist->nextsyms;
335
		lsymlist->symlist=(pSYMR)xcalloc(SYMTABSIZE,sizeof(SYMR));
336
		lsymlist->noofsyms=0;
337
		lsymlist->nextsyms=(LSYMS*)0;
338
	   }
339
	*(lsymlist->symlist+lsymlist->noofsyms)=(*newsym);
340
	lsymlist->noofsyms += 1;
341
	return (lsymindex);
342
}
343
 
344
 
345
 
346
long add_esym
347
    PROTO_N ( (ind, newsym) )
348
    PROTO_T ( long ind X SYMR* newsym )
349
{
350
	if (esymlist->noofsyms==SYMTABSIZE)
351
	     {   esymlist->nextsyms=(ESYMS*)xcalloc(1,sizeof(ESYMS));
352
		 esymlist=esymlist->nextsyms;
353
		 esymlist->symlist=(pEXTR)xcalloc(SYMTABSIZE,sizeof(EXTR));
354
		 esymlist->noofsyms=0;
355
		 esymlist->nextsyms=(ESYMS*)0;
356
	    }
357
 
358
	    (esymlist->symlist+esymlist->noofsyms)->ifd = ind;
359
	    (esymlist->symlist+esymlist->noofsyms)->asym=(*newsym);
360
	    esymlist->noofsyms += 1;
361
	    esymindex++;
362
	    return(esymindex-1);
363
 
364
}
365
 
366
long new_lsym
367
    PROTO_N ( (str, value, symtype,symclass, s, filenum) )
368
    PROTO_T ( char* str X long value X short symtype X short symclass X diag_type s X long filenum )
369
{
370
	SYMR newsym;
371
	AUXU nilaux;
372
	long strind, symindex;
373
	nilaux.isym=0;
374
	symindex = get_sym_index(filenum);
375
 	newsym.value = value;
376
  	newsym.st = symtype;
377
  	newsym.sc = symclass;
378
/* do the following as a switch statment */
379
 
380
   if (symtype == stEnd)
381
 
382
	{  SYMSTR symstrind;
383
	   long isymstart;
384
	   symstrind = pop(blockstack+filenum);
385
	   isymstart = symstrind.sym;
386
	   if (symstrind.str>0)
387
	   	{newsym.iss = symstrind.str;}
388
	   else {newsym.iss = 0;}
389
	   if (isymstart<0)
390
		{
391
		newsym.index=(-isymstart);
392
		get_aux_ptr(filenum,get_sym_ptr(filenum, -isymstart)->index)->isym=symindex+1;
393
		}
394
	else
395
		{get_sym_ptr(filenum, isymstart)->index=symindex+1;
396
		newsym.index=isymstart;
397
		}
398
 
399
	 /* (((local_symbols + filenum)->symlist)+newsym.index)->index = symindex+1; */
400
	}
401
 
402
   else if (symtype == stFile)
403
	{add_aux(nilaux,filenum);
404
	strind=add_to_loc_strings(str,filenum);
405
 	newsym.iss = strind;
406
	push(symindex, strind, blockstack+filenum);
407
	/* newsym.index filled in later by stEnd  */
408
	}
409
 
410
   else if (symtype == stBlock)
411
	{if (str){strind=add_to_loc_strings(str,filenum);}
412
	else {strind = 0;}
413
	push(symindex, strind, blockstack+filenum);
414
 	newsym.iss = strind;
415
	/* newsym.index filled in later by stEnd  */
416
	}
417
 
418
   else if (symtype == stLabel /*|| symtype == stMember and enum???*/ )
419
	{  newsym.index = 0;
420
 	newsym.iss = add_to_loc_strings(str,filenum);
421
	}
422
 
423
   else	if (symtype==stProc)
424
		{DNR* procdense=get_dense_ptr(value);
425
		strind=add_to_loc_strings(str,filenum);
426
		newsym.value=0;	/* not needed now */
427
/* add esym but with lsymindex as index not aux or isymMac */
428
		newsym.iss = add_to_ext_strings(str);
429
		newsym.index=symindex;
430
		procdense->rfd=0x7fffffff;
431
		procdense->index=add_esym(filenum, &newsym);
432
		newsym.iss=strind;
433
		newsym.index=add_aux(nilaux,filenum);
434
		push(-symindex, strind, blockstack+filenum);
435
		/*AUX to be filled in at stEnd */
436
		add_proc(symindex,filenum);	/* all are scText */
437
		add_aux(nilaux,filenum);	/* add nil type !! */
438
		}
439
 
440
   else if (symtype==stStaticProc)
441
		{DNR* procdense=get_dense_ptr(value);
442
 		strind=add_to_loc_strings(str,filenum);
443
		newsym.iss=strind;
444
		newsym.value = 0;	/* not needed now */
445
/* add esym but with lsymindex as index not aux or isymMac */
446
		procdense->rfd=filenum;
447
		procdense->index=symindex;
448
		newsym.index=add_aux(nilaux,filenum);
449
		push(-symindex, strind, blockstack+filenum);
450
		add_proc(symindex, filenum);
451
		add_aux(nilaux,filenum);	/* add nil type !! */
452
		}
453
 
454
   else if (!diagnose )
455
	{newsym.index = 1048575;
456
 	newsym.iss = add_to_loc_strings(str,filenum);
457
	}
458
 
459
   else	{newsym.iss = add_to_loc_strings(str,filenum);
460
	newsym.index = add_type_to_aux(s, filenum);
461
	}
462
 
463
 
464
   return(add_lsym (filenum, &newsym));
465
}
466
 
467
 
468
long new_lsym_d
469
    PROTO_N ( (str, value, symtype, symclass, s, filenum) )
470
    PROTO_T ( char* str X long value X short symtype X short symclass X diag_type s X long filenum )
471
{
472
	return(add_dense_no(filenum,new_lsym (str, value, symtype, symclass,s, filenum)));
473
}
474
 
475
 
476
 
477
long new_esym
478
    PROTO_N ( (str,value, symtype, symclass, s, filenum) )
479
    PROTO_T ( char* str X long value X short symtype X short symclass X diag_type s X long filenum )
480
{
481
   SYMR newsym;
482
   long strind=add_to_ext_strings(str);
483
   newsym.iss = strind;
484
   newsym.value = value;
485
   newsym.st = symtype;
486
   newsym.reserved = 0;
487
   newsym.sc = symclass;
488
 
489
	if (((symtype==stProc) && (symclass==scNil ||symclass==scUndefined)) || (!diagnose))
490
		/* no diagnostics  */
491
		{newsym.index=1048575;newsym.value=0;}
492
	else {newsym.index=add_type_to_aux(s,filenum);
493
		}
494
 
495
   return add_esym (filenum, &newsym);
496
}
497
 
498
 
499
long new_esym_d
500
    PROTO_N ( (str, value, symtype, symclass, s, filenum) )
501
    PROTO_T ( char* str X long value X short symtype X short symclass X diag_type s X long filenum )
502
{
503
	return(add_dense_no(0x7fffffff,new_esym(str, value, symtype, symclass, s, filenum)));
504
}
505
 
506
 
507
/********************* Auxillary information  ********************/
508
 
509
AUXU* get_aux_ptr
510
    PROTO_N ( (index, auxind) )
511
    PROTO_T ( long index X long auxind )
512
{
513
	AUXTAB* auxdata;
514
	long auxcount;
515
	auxdata=aux_symbols+index;
516
	auxcount=auxdata->num;
517
	while (auxcount <= auxind)
518
	   {	auxdata=auxdata->moreaux;
519
		auxcount+=auxdata->num;
520
	   }
521
	return(auxdata->auxinfo+(auxdata->num-(auxcount-auxind)));
522
}
523
 
524
 
525
long add_aux
526
    PROTO_N ( (auxent, index) )
527
    PROTO_T ( AUXU auxent X long index )
528
{
529
	AUXTAB* auxdata;
530
	long auxind;
531
	noaux++;
532
	auxdata=aux_symbols+index;
533
	auxind=auxdata->num;
534
	while (auxdata->moreaux!=0)
535
	   {	auxdata=auxdata->moreaux;
536
		auxind+=auxdata->num;
537
	   }
538
	if (auxdata->num==AUXTABSIZE)
539
	   {	auxdata->moreaux=(AUXTAB*)xcalloc(1,sizeof(AUXTAB));
540
		auxdata=auxdata->moreaux;
541
		auxdata->auxinfo=(pAUXU)xcalloc(AUXTABSIZE,sizeof(AUXU));
542
		auxdata->moreaux=(AUXTAB*)0;
543
		auxdata->num=0;
544
	   }
545
 
546
	*((auxdata->auxinfo)+auxdata->num) = auxent;
547
	auxdata->num+=1;
548
	return (auxind);
549
}
550
 
551
 
552
long add_st_aux
553
    PROTO_N ( (ind) )
554
    PROTO_T ( long ind )
555
{
556
   AUXU straux;
557
   AUXU maxaux;
558
   long indaux;
559
	maxaux.count=0xffffffff;
560
	straux.ti.bt=btStruct;
561
	indaux=add_aux(straux, ind);
562
	add_aux(maxaux, ind);
563
	add_aux(maxaux, ind);
564
   return indaux;
565
}
566
 
567
 
568
long add_un_aux
569
    PROTO_N ( (ind) )
570
    PROTO_T ( long ind )
571
{
572
   AUXU uniaux;
573
   AUXU maxaux;
574
   long indaux;
575
	maxaux.count=0xffffffff;
576
	uniaux.ti.bt=btUnion;
577
	indaux=add_aux(uniaux, ind);
578
	add_aux(maxaux, ind);
579
	add_aux(maxaux, ind);
580
   return indaux;
581
}
582
 
583
 
584
void output_symtab
585
    PROTO_N ( (symfilename) )
586
    PROTO_T ( char* symfilename )
587
{
588
   /* end all the files */
589
   int i;
590
   for (i=0;i<numfiles;i++)	/* might need the iss */
591
	{new_lsym("",0,stEnd,scText,(diag_type)0,i);
592
	 add_to_loc_strings("", i);
593
	}
594
   add_to_ext_strings("");
595
   makesymtab(external_strings, external_symbols, dense_numbers,
596
	file_desc_table, numfiles, symfilename, esymindex, nosyms,
597
	extind, stringsize, noaux, densind, proc_isym_inds, numprocs);
598
}