NASM 0.91
[nasm/avx512.git] / rdoff / symtab.c
blobc0ff3e562a12fbe93cb1b367b12522f101e60d99
1 /* symtab.c Routines to maintain and manipulate a symbol table
3 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
4 * Julian Hall. All rights reserved. The software is
5 * redistributable under the licence given in the file "Licence"
6 * distributed in the NASM archive.
7 */
8 #include <stdio.h>
9 #include <stdlib.h>
11 #include "symtab.h"
13 /* TODO: Implement a hash table, not this stupid implementation which
14 is too slow to be of practical use */
16 /* Private data types */
18 typedef struct tagSymtab {
19 symtabEnt ent;
20 struct tagSymtab * next;
21 } symtabList;
23 typedef symtabList * _symtab;
25 void *symtabNew(void)
27 void *p = malloc(sizeof(_symtab));
28 if (p == NULL) {
29 fprintf(stderr,"symtab: out of memory\n");
30 exit(3);
32 *(_symtab *)p = NULL;
34 return p;
37 void symtabDone(void *symtab)
39 /* DO SOMETHING HERE! */
42 void symtabInsert(void *symtab,symtabEnt *ent)
44 symtabList *l = malloc(sizeof(symtabList));
46 if (l == NULL) {
47 fprintf(stderr,"symtab: out of memory\n");
48 exit(3);
51 l->ent = *ent;
52 l->next = *(_symtab *)symtab;
53 *(_symtab *)symtab = l;
56 symtabEnt *symtabFind(void *symtab,char *name)
58 symtabList *l = *(_symtab *)symtab;
60 while (l) {
61 if (!strcmp(l->ent.name,name)) {
62 return &(l->ent);
64 l = l->next;
66 return NULL;
69 void symtabDump(void *symtab,FILE *of)
71 symtabList *l = *(_symtab *)symtab;
73 while(l) {
74 fprintf(of,"%32s %s:%08lx (%ld)\n",l->ent.name,
75 l->ent.segment ? "data" : "code" ,
76 l->ent.offset, l->ent.flags);
77 l = l->next;