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 /* ------------------------------------- */
38 mytab
= (symtabTab
*) calloc(SYMTABSIZE
,sizeof(symtabNode
*));
40 fprintf(stderr
,"symtab: out of memory\n");
47 /* ------------------------------------- */
49 symtabDone(void *stab
)
51 symtab mytab
= (symtab
)stab
;
53 symtabNode
*this, *next
;
55 for (i
=0; i
< SYMTABSIZE
; ++i
) {
57 for (this = (*mytab
)[i
]; this; this=next
)
58 { next
= this->next
; free (this); }
64 /* ------------------------------------- */
66 symtabInsert(void *stab
, symtabEnt
*ent
)
68 symtab mytab
= (symtab
) stab
;
72 node
= malloc(sizeof(symtabNode
));
74 fprintf(stderr
,"symtab: out of memory\n");
78 slot
= slotnum(ent
->name
);
81 node
->next
= (*mytab
)[slot
];
82 (*mytab
)[slot
] = node
;
85 /* ------------------------------------- */
87 symtabFind(void *stab
, const char *name
)
89 symtab mytab
= (symtab
) stab
;
90 int slot
= slotnum(name
);
91 symtabNode
*node
= (*mytab
)[slot
];
94 if (!strcmp(node
->ent
.name
,name
)) {
103 /* ------------------------------------- */
105 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:%08lx (%ld)\n",l
->ent
.name
,
123 SegNames
[l
->ent
.segment
],
124 l
->ent
.offset
, l
->ent
.flags
);
129 fprintf(of
, "........... end of Symbol table.\n");