[master] ac517cb Emit a rudimentary symbol table at the end of the emitted C-code

Poul-Henning Kamp phk at FreeBSD.org
Thu Dec 8 11:01:06 CET 2016


commit ac517cb9560f7cf87633adb67f843f1656067888
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Dec 8 09:25:31 2016 +0000

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

diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index b2b6cab..e350c95 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -669,6 +669,8 @@ vcc_CompileSource(struct vcc *tl, struct source *sp)
 
 	EmitStruct(tl);
 
+	VCC_XrefTable(tl);
+
 	/* Combine it all */
 
 	vsb = VSB_new_auto();
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 65e7de7..008c9bb 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -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);
diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c
index 03b069f..14831b8 100644
--- a/lib/libvcc/vcc_symb.c
+++ b/lib/libvcc/vcc_symb.c
@@ -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
diff --git a/lib/libvcc/vcc_xref.c b/lib/libvcc/vcc_xref.c
index 8a75c25..d492cc6 100644
--- a/lib/libvcc/vcc_xref.c
+++ b/lib/libvcc/vcc_xref.c
@@ -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");
+}



More information about the varnish-commit mailing list