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.
18 #define slotnum(x) (hash((x)) % SYMTABSIZE)
20 /* ------------------------------------- */
21 /* Private data types */
23 typedef struct tagSymtabNode
{
24 struct tagSymtabNode
*next
;
28 typedef symtabNode
*(symtabTab
[SYMTABSIZE
]);
30 typedef symtabTab
*symtab
;
32 /* ------------------------------------- */
37 mytab
= (symtabTab
*) calloc(SYMTABSIZE
, sizeof(symtabNode
*));
39 fprintf(stderr
, "symtab: out of memory\n");
46 /* ------------------------------------- */
47 void symtabDone(void *stab
)
49 symtab mytab
= (symtab
) stab
;
51 symtabNode
*this, *next
;
53 for (i
= 0; i
< SYMTABSIZE
; ++i
) {
55 for (this = (*mytab
)[i
]; this; this = next
) {
64 /* ------------------------------------- */
65 void symtabInsert(void *stab
, symtabEnt
* ent
)
67 symtab mytab
= (symtab
) stab
;
71 node
= malloc(sizeof(symtabNode
));
73 fprintf(stderr
, "symtab: out of memory\n");
77 slot
= slotnum(ent
->name
);
80 node
->next
= (*mytab
)[slot
];
81 (*mytab
)[slot
] = node
;
84 /* ------------------------------------- */
85 symtabEnt
*symtabFind(void *stab
, const char *name
)
87 symtab mytab
= (symtab
) stab
;
88 int slot
= slotnum(name
);
89 symtabNode
*node
= (*mytab
)[slot
];
92 if (!strcmp(node
->ent
.name
, name
)) {
101 /* ------------------------------------- */
102 void symtabDump(void *stab
, FILE * of
)
104 symtab mytab
= (symtab
) stab
;
106 char *SegNames
[3] = { "code", "data", "bss" };
108 fprintf(of
, "Symbol table is ...\n");
109 for (i
= 0; i
< SYMTABSIZE
; ++i
) {
110 symtabNode
*l
= (symtabNode
*) (*mytab
)[i
];
113 fprintf(of
, " ... slot %d ...\n", i
);
116 if ((l
->ent
.segment
) == -1) {
117 fprintf(of
, "%-32s Unresolved reference\n", l
->ent
.name
);
119 fprintf(of
, "%-32s %s:%08lx (%ld)\n", l
->ent
.name
,
120 SegNames
[l
->ent
.segment
],
121 l
->ent
.offset
, l
->ent
.flags
);
126 fprintf(of
, "........... end of Symbol table.\n");