Commit ac517cb9 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Emit a rudimentary symbol table at the end of the emitted C-code

parent 7fb87518
......@@ -669,6 +669,8 @@ vcc_CompileSource(struct vcc *tl, struct source *sp)
EmitStruct(tl);
VCC_XrefTable(tl);
/* Combine it all */
vsb = VSB_new_auto();
......
......@@ -121,6 +121,7 @@ struct symbol {
VTAILQ_ENTRY(symbol) list;
VTAILQ_HEAD(,symbol) children;
struct symbol *parent;
const char *vmod;
char *name;
......@@ -346,6 +347,7 @@ void vcc_ParseNew(struct vcc *tl);
int vcc_AddDef(struct vcc *tl, const struct token *t, enum symkind type);
void vcc_AddRef(struct vcc *tl, const struct token *t, enum symkind type);
int vcc_CheckReferences(struct vcc *tl);
void VCC_XrefTable(struct vcc *);
void vcc_AddCall(struct vcc *tl, struct token *t);
struct proc *vcc_AddProc(struct vcc *tl, struct token *t);
......
......@@ -144,6 +144,7 @@ VCC_Symbol(struct vcc *tl, struct symbol *parent,
return (sym);
if (sym == NULL) {
sym = vcc_new_symbol(tl, b, q);
sym->parent = parent;
if (sym2 != NULL)
VTAILQ_INSERT_BEFORE(sym2, sym, list);
else
......
......@@ -392,3 +392,37 @@ vcc_CheckUses(struct vcc *tl)
VCC_WalkSymbols(tl, vcc_checkuses, SYM_SUB);
return (tl->err);
}
/*---------------------------------------------------------------------*/
static void
vcc_pnam(struct vcc *tl, const struct symbol *sym)
{
if (sym->parent != tl->symbols) {
vcc_pnam(tl, sym->parent);
Fc(tl, 0, ".");
}
Fc(tl, 0, "%s", sym->name);
}
static void __match_proto__(symwalk_f)
vcc_xreftable(struct vcc *tl, const struct symbol *sym)
{
Fc(tl, 0, " * %-7s ", VCC_SymKind(tl, sym));
Fc(tl, 0, " %-9s ", sym->fmt != NULL ? sym->fmt->name : "");
vcc_pnam(tl, sym);
if (sym->wildcard != NULL)
Fc(tl, 0, "*");
Fc(tl, 0, "\n");
}
void
VCC_XrefTable(struct vcc *tl)
{
Fc(tl, 0, "\n/*\n * Symbol Table\n *\n");
VCC_WalkSymbols(tl, vcc_xreftable, SYM_NONE);
Fc(tl, 0, "*/\n\n");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment