Unverified Commit e45595ec authored by Dridi Boukelmoune's avatar Dridi Boukelmoune Committed by Nils Goroll

vcc: Parse the built-in VCL independently

This is a lookahead parsing to learn about built-in subroutines that are
not tied to a VCL state. Instead of maintaining a mapping of the other
subroutines the builtin.vcl file itself becomes authoritative.
parent 4646a5bd
...@@ -72,6 +72,8 @@ static const struct method method_tab[] = { ...@@ -72,6 +72,8 @@ static const struct method method_tab[] = {
{ NULL, 0U, 0} { NULL, 0U, 0}
}; };
struct vcc *vcc_builtin;
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static void static void
...@@ -782,11 +784,14 @@ vcc_CompileSource(struct vcc *tl, struct source *sp, const char *jfile) ...@@ -782,11 +784,14 @@ vcc_CompileSource(struct vcc *tl, struct source *sp, const char *jfile)
Fh(tl, 0, "\nextern const struct VCL_conf VCL_conf;\n"); Fh(tl, 0, "\nextern const struct VCL_conf VCL_conf;\n");
/* Register and lex the main source */ /* Register and lex the main source */
VTAILQ_INSERT_TAIL(&tl->sources, sp, list); if (sp != NULL) {
sp->idx = tl->nsources++; AN(vcc_builtin);
vcc_Lexer(tl, sp, 0); VTAILQ_INSERT_TAIL(&tl->sources, sp, list);
if (tl->err) sp->idx = tl->nsources++;
return (NULL); vcc_Lexer(tl, sp, 0);
if (tl->err)
return (NULL);
}
/* Register and lex the builtin VCL */ /* Register and lex the builtin VCL */
sp = vcc_new_source(tl->builtin_vcl, "Builtin"); sp = vcc_new_source(tl->builtin_vcl, "Builtin");
...@@ -808,15 +813,6 @@ vcc_CompileSource(struct vcc *tl, struct source *sp, const char *jfile) ...@@ -808,15 +813,6 @@ vcc_CompileSource(struct vcc *tl, struct source *sp, const char *jfile)
if (tl->err) if (tl->err)
return (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);
}
/* Check for orphans */ /* Check for orphans */
if (vcc_CheckReferences(tl)) if (vcc_CheckReferences(tl))
return (NULL); return (NULL);
...@@ -829,6 +825,18 @@ vcc_CompileSource(struct vcc *tl, struct source *sp, const char *jfile) ...@@ -829,6 +825,18 @@ vcc_CompileSource(struct vcc *tl, struct source *sp, const char *jfile)
if (vcc_CheckUses(tl) || tl->err) if (vcc_CheckUses(tl) || tl->err)
return (NULL); 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 */ /* Tie vcl_init/fini in */
ifp = New_IniFin(tl); ifp = New_IniFin(tl);
VSB_cat(ifp->ini, "\tVGC_function_vcl_init(ctx, VSUB_STATIC, NULL);\n"); VSB_cat(ifp->ini, "\tVGC_function_vcl_init(ctx, VSUB_STATIC, NULL);\n");
...@@ -881,6 +889,19 @@ vcc_CompileSource(struct vcc *tl, struct source *sp, const char *jfile) ...@@ -881,6 +889,19 @@ vcc_CompileSource(struct vcc *tl, struct source *sp, const char *jfile)
return (vsb); return (vsb);
} }
static struct vcc *
vcc_ParseBuiltin(struct vcc *tl)
{
struct vcc *tl_builtin;
CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
tl_builtin = VCC_New();
AN(tl_builtin);
VCC_Builtin_VCL(tl_builtin, tl->builtin_vcl);
AZ(vcc_CompileSource(tl_builtin, NULL, NULL));
return (tl_builtin);
}
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* Report the range of VCL language we support * Report the range of VCL language we support
*/ */
...@@ -913,6 +934,16 @@ VCC_Compile(struct vcc *tl, struct vsb **sb, ...@@ -913,6 +934,16 @@ VCC_Compile(struct vcc *tl, struct vsb **sb,
AN(vclsrcfile); AN(vclsrcfile);
AN(ofile); AN(ofile);
AN(jfile); AN(jfile);
AZ(vcc_builtin);
vcc_builtin = vcc_ParseBuiltin(tl);
AN(vcc_builtin);
if (vcc_builtin->err) {
AZ(VSB_finish(vcc_builtin->sb));
*sb = vcc_builtin->sb;
return (-1);
}
if (vclsrc != NULL) if (vclsrc != NULL)
sp = vcc_new_source(vclsrc, vclsrcfile); sp = vcc_new_source(vclsrc, vclsrcfile);
else else
......
...@@ -288,6 +288,8 @@ struct vcc { ...@@ -288,6 +288,8 @@ struct vcc {
unsigned vmod_count; unsigned vmod_count;
}; };
extern struct vcc *vcc_builtin;
struct method { struct method {
const char *name; const char *name;
unsigned ret_bitmap; unsigned ret_bitmap;
......
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