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.
21 #define slotnum(x) (hash((x)) % SYMTABSIZE)
23 /* ------------------------------------- */
24 /* Private data types */
26 typedef struct tagSymtabNode
{
27 struct tagSymtabNode
*next
;
31 typedef symtabNode
*(symtabTab
[SYMTABSIZE
]);
33 typedef symtabTab
*symtab
;
35 /* ------------------------------------- */
40 mytab
= (symtabTab
*) calloc(SYMTABSIZE
, sizeof(symtabNode
*));
42 fprintf(stderr
, "symtab: out of memory\n");
49 /* ------------------------------------- */
50 void 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
) {
67 /* ------------------------------------- */
68 void symtabInsert(void *stab
, symtabEnt
* ent
)
70 symtab mytab
= (symtab
) stab
;
74 node
= malloc(sizeof(symtabNode
));
76 fprintf(stderr
, "symtab: out of memory\n");
80 slot
= slotnum(ent
->name
);
83 node
->next
= (*mytab
)[slot
];
84 (*mytab
)[slot
] = node
;
87 /* ------------------------------------- */
88 symtabEnt
*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 /* ------------------------------------- */
105 void symtabDump(void *stab
, FILE * of
)
107 symtab mytab
= (symtab
) stab
;
109 char *SegNames
[3] = { "code", "data", "bss" };
111 fprintf(of
, "Symbol table is ...\n");
112 for (i
= 0; i
< SYMTABSIZE
; ++i
) {
113 symtabNode
*l
= (symtabNode
*) (*mytab
)[i
];
116 fprintf(of
, " ... slot %d ...\n", i
);
119 if ((l
->ent
.segment
) == -1) {
120 fprintf(of
, "%-32s Unresolved reference\n", l
->ent
.name
);
122 fprintf(of
, "%-32s %s:%08"PRIx32
" (%"PRId32
")\n", l
->ent
.name
,
123 SegNames
[l
->ent
.segment
],
124 l
->ent
.offset
, l
->ent
.flags
);
129 fprintf(of
, "........... end of Symbol table.\n");