lib/libvcc/vcc_compile.c
static struct vsb *
vcc_CompileSource(struct vcc *tl, struct source *sp, const char *jfile)
{
	struct proc *p;
	struct vsb *vsb;
	struct inifin *ifp;

	Fh(tl, 0, "/* ---===### VCC generated .h code ###===---*/\n");
	Fc(tl, 0, "\n/* ---===### VCC generated .c code ###===---*/\n");

	Fc(tl, 0, "\n#define END_ if (*ctx->handling) return\n");

	vcc_Parse_Init(tl);

	vcc_Expr_Init(tl);

	vcc_Action_Init(tl);

	vcc_Backend_Init(tl);

	vcc_Var_Init(tl);

	vcc_Type_Init(tl);

	Fh(tl, 0, "\nextern const struct VCL_conf VCL_conf;\n");

	/* Register and lex the main source */
	if (sp != NULL) {
		AN(vcc_builtin);
		vcc_lex_source(tl, sp, 0);
		if (tl->err)
			return (NULL);
	}

	/* Register and lex the builtin VCL */
	sp = vcc_new_source(tl->builtin_vcl, "builtin", "<builtin>");
	assert(sp != NULL);
	vcc_lex_source(tl, sp, 1);
	if (tl->err)
		return (NULL);

	/* Expand and lex any includes in the token string */
	if (tl->err)
		return (NULL);

	/* Parse the token string */
	tl->t = VTAILQ_FIRST(&tl->tokens);
	vcc_Parse(tl);
	if (tl->err)
		return (NULL);

	/* Check for orphans */
	if (vcc_CheckReferences(tl))
		return (NULL);

	/* Check that all action returns are legal */
	if (vcc_CheckAction(tl) || tl->err)
		return (NULL);

	/* Check that all variable uses are legal */
	if (vcc_CheckUses(tl) || tl->err)
		return (NULL);

	if (vcc_builtin == NULL)
		return (NULL);

	/* Check if we have any backends at all */
	if (tl->default_director == NULL) {
		VSB_cat(tl->sb,
		    "No backends or directors found in VCL program, "
		    "at least one is necessary.\n");
		tl->err = 1;
		return (NULL);
	}

	/* Tie vcl_init/fini in */
	ifp = New_IniFin(tl);
	VSB_cat(ifp->ini, "\tVGC_function_vcl_init(ctx, VSUB_STATIC, NULL);\n");
	/*
	 * Because the failure could be half way into vcl_init{} so vcl_fini{}
	 * must always be called, also on failure.
	 */
	ifp->ignore_errors = 1;
	VSB_cat(ifp->fin, "\t\tVGC_function_vcl_fini(ctx, VSUB_STATIC, NULL);\n");
	VSB_cat(ifp->fin, "\t\t\tVPI_vcl_fini(ctx);");

	/* Emit method functions */
	Fh(tl, 1, "\n");
	VTAILQ_FOREACH(p, &tl->procs, list)
		if (p->method == NULL)
			vcc_EmitProc(tl, p);
	VTAILQ_FOREACH(p, &tl->procs, list)
		if (p->method != NULL)
			vcc_EmitProc(tl, p);

	EmitInitFini(tl);

	VCC_InstanceInfo(tl);

	EmitStruct(tl);

	VCC_XrefTable(tl);

	VSB_cat(tl->symtab, "\n]\n");
	AZ(VSB_finish(tl->symtab));
	if (TLWriteVSB(tl, jfile, tl->symtab, "Symbol table"))
		return (NULL);

	/* Combine it all */

	vsb = VSB_new_auto();
	AN(vsb);

	vcl_output_lang_h(vsb);

	EmitCoordinates(tl, vsb);

	AZ(VSB_finish(tl->fh));
	VSB_cat(vsb, VSB_data(tl->fh));

	AZ(VSB_finish(tl->fc));
	VSB_cat(vsb, VSB_data(tl->fc));

	AZ(VSB_finish(vsb));
	return (vsb);
}
/*--------------------------------------------------------------------
 * Compile the VCL code from the given source and return the C-source
 */
Compile the VCL code from the given source and return the C-source
Compile the VCL code from the given source and return the C - source
static struct vsb *
vcc_CompileSource(struct vcc *tl, struct source *sp, const char *jfile)
{
	struct proc *p;
	struct vsb *vsb;
	struct inifin *ifp;
	Fh(tl, 0, "/* ---===### VCC generated .h code ###===---*/\n");
	Fc(tl, 0, "\n/* ---===### VCC generated .c code ###===---*/\n");
	Fc(tl, 0, "\n#define END_ if (*ctx->handling) return\n");
	vcc_Parse_Init(tl);
	vcc_Expr_Init(tl);
	vcc_Action_Init(tl);
	vcc_Backend_Init(tl);
	vcc_Var_Init(tl);
	vcc_Type_Init(tl);
	Fh(tl, 0, "\nextern const struct VCL_conf VCL_conf;\n");
	if (sp != NULL) {
		AN(vcc_builtin);
		vcc_lex_source(tl, sp, 0);
		if (tl->err)
			return (NULL);
	}
	sp = vcc_new_source(tl->builtin_vcl, "builtin", "<builtin>");
	assert(sp != NULL);
	vcc_lex_source(tl, sp, 1);
	if (tl->err)
		return (NULL);
	if (tl->err)
		return (NULL);
	tl->t = VTAILQ_FIRST(&tl->tokens);
	vcc_Parse(tl);
	if (tl->err)
		return (NULL);
	if (vcc_CheckReferences(tl))
		return (NULL);
	if (vcc_CheckAction(tl) || tl->err)
		return (NULL);
	if (vcc_CheckUses(tl) || tl->err)
		return (NULL);
	if (vcc_builtin == NULL)
		return (NULL);
	if (tl->default_director == NULL) {
		VSB_cat(tl->sb,
		    "No backends or directors found in VCL program, "
		    "at least one is necessary.\n");
		tl->err = 1;
		return (NULL);
	}
	ifp = New_IniFin(tl);
	VSB_cat(ifp->ini, "\tVGC_function_vcl_init(ctx, VSUB_STATIC, NULL);\n");
	ifp->ignore_errors = 1;
	VSB_cat(ifp->fin, "\t\tVGC_function_vcl_fini(ctx, VSUB_STATIC, NULL);\n");
	VSB_cat(ifp->fin, "\t\t\tVPI_vcl_fini(ctx);");
	Fh(tl, 1, "\n");
	VTAILQ_FOREACH(p, &tl->procs, list)
		if (p->method == NULL)
			vcc_EmitProc(tl, p);
	VTAILQ_FOREACH(p, &tl->procs, list)
		if (p->method != NULL)
			vcc_EmitProc(tl, p);
	EmitInitFini(tl);
	VCC_InstanceInfo(tl);
	EmitStruct(tl);
	VCC_XrefTable(tl);
	VSB_cat(tl->symtab, "\n]\n");
	AZ(VSB_finish(tl->symtab));
	if (TLWriteVSB(tl, jfile, tl->symtab, "Symbol table"))
		return (NULL);
	vsb = VSB_new_auto();
	AN(vsb);
	vcl_output_lang_h(vsb);
	EmitCoordinates(tl, vsb);
	AZ(VSB_finish(tl->fh));
	VSB_cat(vsb, VSB_data(tl->fh));
	AZ(VSB_finish(tl->fc));
	VSB_cat(vsb, VSB_data(tl->fc));
	AZ(VSB_finish(vsb));
	return (vsb);
}
static struct vsb * vcc_CompileSource ( struct vcc * tl , struct source * sp , const char * jfile ) { struct proc * p ; struct vsb * vsb ; struct inifin * ifp ; Fh ( tl , 0 , " \n " ) ; Fc ( tl , 0 , " \n \n " ) ; Fc ( tl , 0 , " \n \n " ) ; vcc_Parse_Init ( tl ) ; vcc_Expr_Init ( tl ) ; vcc_Action_Init ( tl ) ; vcc_Backend_Init ( tl ) ; vcc_Var_Init ( tl ) ; vcc_Type_Init ( tl ) ; Fh ( tl , 0 , " \n \n " ) ; if ( sp != NULL ) { AN ( vcc_builtin ) ; vcc_lex_source ( tl , sp , 0 ) ; if ( tl -> err ) return ( NULL ) ; } sp = vcc_new_source ( tl -> builtin_vcl , " " , " " ) ; assert ( sp != NULL ) ; vcc_lex_source ( tl , sp , 1 ) ; if ( tl -> err ) return ( NULL ) ; if ( tl -> err ) return ( NULL ) ; tl -> t = VTAILQ_FIRST ( & tl -> tokens ) ; vcc_Parse ( tl ) ; if ( tl -> err ) return ( NULL ) ; if ( vcc_CheckReferences ( tl ) ) return ( NULL ) ; if ( vcc_CheckAction ( tl ) || tl -> err ) return ( NULL ) ; if ( vcc_CheckUses ( tl ) || tl -> err ) return ( NULL ) ; if ( vcc_builtin == NULL ) return ( NULL ) ; if ( tl -> default_director == NULL ) { VSB_cat ( tl -> sb , " " " \n " ) ; tl -> err = 1 ; return ( NULL ) ; } ifp = New_IniFin ( tl ) ; VSB_cat ( ifp -> ini , " \t \n " ) ; ifp -> ignore_errors = 1 ; VSB_cat ( ifp -> fin , " \t \t \n " ) ; VSB_cat ( ifp -> fin , " \t \t \t " ) ; Fh ( tl , 1 , " \n " ) ; VTAILQ_FOREACH ( p , & tl -> procs , list ) if ( p -> method == NULL ) vcc_EmitProc ( tl , p ) ; VTAILQ_FOREACH ( p , & tl -> procs , list ) if ( p -> method != NULL ) vcc_EmitProc ( tl , p ) ; EmitInitFini ( tl ) ; VCC_InstanceInfo ( tl ) ; EmitStruct ( tl ) ; VCC_XrefTable ( tl ) ; VSB_cat ( tl -> symtab , " \n \n " ) ; AZ ( VSB_finish ( tl -> symtab ) ) ; if ( TLWriteVSB ( tl , jfile , tl -> symtab , " " ) ) return ( NULL ) ; vsb = VSB_new_auto ( ) ; AN ( vsb ) ; vcl_output_lang_h ( vsb ) ; EmitCoordinates ( tl , vsb ) ; AZ ( VSB_finish ( tl -> fh ) ) ; VSB_cat ( vsb , VSB_data ( tl -> fh ) ) ; AZ ( VSB_finish ( tl -> fc ) ) ; VSB_cat ( vsb , VSB_data ( tl -> fc ) ) ; AZ ( VSB_finish ( vsb ) ) ; return ( vsb ) ; }
Compile the VCL code from the given source and return the C-source
Compile the VCL code from the given source and return the C - source
/* Register and lex the main source */ /* Register and lex the builtin VCL */ /* Expand and lex any includes in the token string */ /* Parse the token string */ /* Check for orphans */ /* Check that all action returns are legal */ /* Check that all variable uses are legal */ /* Check if we have any backends at all */ /* Tie vcl_init/fini in */ /*
	 * Because the failure could be half way into vcl_init{} so vcl_fini{}
	 * must always be called, also on failure.
	 */ /* Emit method functions */ /* Combine it all */