commit 2a872329eddbee463a4150cfb6082feacb0761c0
parent 0f7ab686171677c9d8e7e6d6c5c518038c8e25cb
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 26 May 2015 08:21:35 +0200
Add dumpstab()
This function dumps the content of the symbol table hash and it is useful
for debugging.
Diffstat:
2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/cc1/cc1.h b/cc1/cc1.h
@@ -251,6 +251,7 @@ extern Type *ctype(unsigned type, unsigned sign, unsigned size);
extern Type *mktype(Type *tp, unsigned op, short nelem, void *data);
/* symbol.c */
+extern void dumpstab(char *msg);
extern Symbol *lookup(unsigned ns);
extern Symbol *install(unsigned ns);
extern Symbol *newsym(unsigned ns);
diff --git a/cc1/symbol.c b/cc1/symbol.c
@@ -16,6 +16,26 @@ static short globalcnt;
static Symbol *head;
static Symbol *htab[NR_SYM_HASH];
+#ifndef NDEBUG
+#include <stdio.h>
+void
+dumpstab(char *msg)
+{
+ Symbol **bp, *sym;
+
+ fputs(msg, stderr);
+ putc('\n', stderr);
+ for (bp = htab; bp < &htab[NR_SYM_HASH]; ++bp) {
+ if (*bp == NULL)
+ continue;
+ fprintf(stderr, "%d", bp - htab);
+ for (sym = *bp; sym; sym = sym->hash)
+ fprintf(stderr, "->%d:%s", sym->ns, sym->name);
+ putc('\n', stderr);
+ }
+}
+#endif
+
static inline unsigned
hash(const char *s)
{