lib/libvcc/vcc_compile.c
static void
EmitCoordinates(const struct vcc *tl, struct vsb *vsb)
{
	struct token *t;
	unsigned lin, pos;
	const struct source *sp;
	const char *p;

	VSB_cat(vsb, "/* ---===### Source Code ###===---*/\n");

	VSB_printf(vsb, "\n#define VGC_NSRCS %u\n", tl->nsources);

	VSB_cat(vsb, "\nstatic const char *srcname[VGC_NSRCS] = {\n");
	VTAILQ_FOREACH(sp, &tl->sources, list) {
		VSB_cat(vsb, "\t");
		VSB_quote(vsb, sp->name, -1, VSB_QUOTE_CSTR);
		VSB_cat(vsb, ",\n");
	}
	VSB_cat(vsb, "};\n");

	VSB_printf(vsb, "\nstatic const char *srcbody[%u] = {\n", tl->nsources);
	VTAILQ_FOREACH(sp, &tl->sources, list) {
		VSB_cat(vsb, "    /* ");
		VSB_quote(vsb, sp->name, -1, VSB_QUOTE_CSTR);
		VSB_cat(vsb, " */\n");
		VSB_quote_pfx(vsb, "\t", sp->b, sp->e - sp->b, VSB_QUOTE_CSTR);
		VSB_cat(vsb, ",\n");
	}
	VSB_cat(vsb, "};\n\n");

	VSB_cat(vsb, "/* ---===### Location Counters ###===---*/\n");

	VSB_printf(vsb, "\n#define VGC_NREFS %u\n\n", tl->cnt + 1);

	VSB_cat(vsb, "static const struct vpi_ref VGC_ref[VGC_NREFS] = {\n");
	lin = 1;
	pos = 0;
	sp = 0;
	p = NULL;
	VTAILQ_FOREACH(t, &tl->tokens, list) {
		if (t->cnt == 0)
			continue;
		assert(t->src != NULL);
		if (t->src != sp) {
			lin = 1;
			pos = 0;
			sp = t->src;
			p = sp->b;
		}
		assert(sp != NULL);
		assert(p != NULL);
		for (;p < t->b; p++) {
			if (*p == '\n') {
				lin++;
				pos = 0;
			} else if (*p == '\t') {
				pos &= ~7;
				pos += 8;
			} else
				pos++;

		}
		VSB_printf(vsb, "  [%3u] = { %u, %8tu, %4u, %3u, ",
		    t->cnt, sp->idx, t->b - sp->b, lin, pos + 1);
		if (t->tok == CSRC)
			VSB_cat(vsb, " \"C{\"},\n");
		else
			VSB_printf(vsb, " \"%.*s\" },\n", PF(t));
	}
	VSB_cat(vsb, "};\n\n");
}
/*--------------------------------------------------------------------
 * Output the location/profiling table.  For each counted token, we
 * record source+line+charpos for the first character in the token.
 */
Output the location/profiling table.  For each counted token, we
record source+line+charpos for the first character in the token.
Output the location / profiling table . For each counted token we record source + line + charpos for the first character in the token .
static void
EmitCoordinates(const struct vcc *tl, struct vsb *vsb)
{
	struct token *t;
	unsigned lin, pos;
	const struct source *sp;
	const char *p;
	VSB_cat(vsb, "/* ---===### Source Code ###===---*/\n");
	VSB_printf(vsb, "\n#define VGC_NSRCS %u\n", tl->nsources);
	VSB_cat(vsb, "\nstatic const char *srcname[VGC_NSRCS] = {\n");
	VTAILQ_FOREACH(sp, &tl->sources, list) {
		VSB_cat(vsb, "\t");
		VSB_quote(vsb, sp->name, -1, VSB_QUOTE_CSTR);
		VSB_cat(vsb, ",\n");
	}
	VSB_cat(vsb, "};\n");
	VSB_printf(vsb, "\nstatic const char *srcbody[%u] = {\n", tl->nsources);
	VTAILQ_FOREACH(sp, &tl->sources, list) {
		VSB_cat(vsb, "    /* ");
		VSB_quote(vsb, sp->name, -1, VSB_QUOTE_CSTR);
		VSB_cat(vsb, " */\n");
		VSB_quote_pfx(vsb, "\t", sp->b, sp->e - sp->b, VSB_QUOTE_CSTR);
		VSB_cat(vsb, ",\n");
	}
	VSB_cat(vsb, "};\n\n");
	VSB_cat(vsb, "/* ---===### Location Counters ###===---*/\n");
	VSB_printf(vsb, "\n#define VGC_NREFS %u\n\n", tl->cnt + 1);
	VSB_cat(vsb, "static const struct vpi_ref VGC_ref[VGC_NREFS] = {\n");
	lin = 1;
	pos = 0;
	sp = 0;
	p = NULL;
	VTAILQ_FOREACH(t, &tl->tokens, list) {
		if (t->cnt == 0)
			continue;
		assert(t->src != NULL);
		if (t->src != sp) {
			lin = 1;
			pos = 0;
			sp = t->src;
			p = sp->b;
		}
		assert(sp != NULL);
		assert(p != NULL);
		for (;p < t->b; p++) {
			if (*p == '\n') {
				lin++;
				pos = 0;
			} else if (*p == '\t') {
				pos &= ~7;
				pos += 8;
			} else
				pos++;
		}
		VSB_printf(vsb, "  [%3u] = { %u, %8tu, %4u, %3u, ",
		    t->cnt, sp->idx, t->b - sp->b, lin, pos + 1);
		if (t->tok == CSRC)
			VSB_cat(vsb, " \"C{\"},\n");
		else
			VSB_printf(vsb, " \"%.*s\" },\n", PF(t));
	}
	VSB_cat(vsb, "};\n\n");
}
static void EmitCoordinates ( const struct vcc * tl , struct vsb * vsb ) { struct token * t ; unsigned lin , pos ; const struct source * sp ; const char * p ; VSB_cat ( vsb , " \n " ) ; VSB_printf ( vsb , " \n \n " , tl -> nsources ) ; VSB_cat ( vsb , " \n \n " ) ; VTAILQ_FOREACH ( sp , & tl -> sources , list ) { VSB_cat ( vsb , " \t " ) ; VSB_quote ( vsb , sp -> name , -1 , VSB_QUOTE_CSTR ) ; VSB_cat ( vsb , " \n " ) ; } VSB_cat ( vsb , " \n " ) ; VSB_printf ( vsb , " \n \n " , tl -> nsources ) ; VTAILQ_FOREACH ( sp , & tl -> sources , list ) { VSB_cat ( vsb , " " ) ; VSB_quote ( vsb , sp -> name , -1 , VSB_QUOTE_CSTR ) ; VSB_cat ( vsb , " \n " ) ; VSB_quote_pfx ( vsb , " \t " , sp -> b , sp -> e - sp -> b , VSB_QUOTE_CSTR ) ; VSB_cat ( vsb , " \n " ) ; } VSB_cat ( vsb , " \n \n " ) ; VSB_cat ( vsb , " \n " ) ; VSB_printf ( vsb , " \n \n \n " , tl -> cnt + 1 ) ; VSB_cat ( vsb , " \n " ) ; lin = 1 ; pos = 0 ; sp = 0 ; p = NULL ; VTAILQ_FOREACH ( t , & tl -> tokens , list ) { if ( t -> cnt == 0 ) continue ; assert ( t -> src != NULL ) ; if ( t -> src != sp ) { lin = 1 ; pos = 0 ; sp = t -> src ; p = sp -> b ; } assert ( sp != NULL ) ; assert ( p != NULL ) ; for ( ; p < t -> b ; p ++ ) { if ( * p == ' \n ' ) { lin ++ ; pos = 0 ; } else if ( * p == ' \t ' ) { pos &= ~ 7 ; pos += 8 ; } else pos ++ ; } VSB_printf ( vsb , " " , t -> cnt , sp -> idx , t -> b - sp -> b , lin , pos + 1 ) ; if ( t -> tok == CSRC ) VSB_cat ( vsb , " \" \" \n " ) ; else VSB_printf ( vsb , " \" \" \n " , PF ( t ) ) ; } VSB_cat ( vsb , " \n \n " ) ; }
Output the location/profiling table.
Output the location / profiling table .