Subversion Repositories tendra.SVN

Rev

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