1 /* symtab.c Routines to maintain and manipulate a symbol table
3 * These routines donated to the NASM effort by Graeme Defty.
5 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
6 * Julian Hall. All rights reserved. The software is
7 * redistributable under the licence given in the file "Licence"
8 * distributed in the NASM archive.
19 #define slotnum(x) (hash((x)) % SYMTABSIZE)
21 /* ------------------------------------- */
22 /* Private data types */
24 typedef struct tagSymtabNode
{
25 struct tagSymtabNode
* next
;
29 typedef symtabNode
*(symtabTab
[SYMTABSIZE
]);
31 typedef symtabTab
*symtab
;
33 /* ------------------------------------- */
39 mytab
= (symtabTab
*) calloc(SYMTABSIZE
,sizeof(symtabNode
*));
41 fprintf(stderr
,"symtab: out of memory\n");
48 /* ------------------------------------- */
50 symtabDone(void *stab
)
52 symtab mytab
= (symtab
)stab
;
54 symtabNode
*this, *next
;
56 for (i
=0; i
< SYMTABSIZE
; ++i
) {
58 for (this = (*mytab
)[i
]; this; this=next
)
59 { next
= this->next
; free (this); }
65 /* ------------------------------------- */
67 symtabInsert(void *stab
, symtabEnt
*ent
)
69 symtab mytab
= (symtab
) stab
;
73 node
= malloc(sizeof(symtabNode
));
75 fprintf(stderr
,"symtab: out of memory\n");
79 slot
= slotnum(ent
->name
);
82 node
->next
= (*mytab
)[slot
];
83 (*mytab
)[slot
] = node
;
86 /* ------------------------------------- */
88 symtabFind(void *stab
, const char *name
)
90 symtab mytab
= (symtab
) stab
;
91 int slot
= slotnum(name
);
92 symtabNode
*node
= (*mytab
)[slot
];
95 if (!strcmp(node
->ent
.name
,name
)) {
104 /* ------------------------------------- */
106 symtabDump(void *stab
, FILE* of
)
108 symtab mytab
= (symtab
)stab
;
110 char *SegNames
[3]={"code","data","bss"};
112 fprintf(of
, "Symbol table is ...\n");
113 for (i
=0; i
< SYMTABSIZE
; ++i
) {
114 symtabNode
*l
= (symtabNode
*)(*mytab
)[i
];
117 fprintf(of
, " ... slot %d ...\n", i
);
120 if ((l
->ent
.segment
) == -1) {
121 fprintf(of
,"%-32s Unresolved reference\n",l
->ent
.name
);
123 fprintf(of
, "%-32s %s:%08lx (%ld)\n",l
->ent
.name
,
124 SegNames
[l
->ent
.segment
],
125 l
->ent
.offset
, l
->ent
.flags
);
130 fprintf(of
, "........... end of Symbol table.\n");