#include <sys/queue.h>
#include "vcl_priv.h"
+#include "libvcl.h"
+
#define ERRCHK(tl) do { if ((tl)->err) return; } while (0)
#define INDENT 2
struct token *t;
int indent;
unsigned cnt;
- FILE *fc, *fh;
+ struct sbuf *fc, *fh;
TAILQ_HEAD(, ref) refs;
struct sbuf *sb;
int err;
{
if (tl->t->tok == tok)
return;
- sbuf_printf(tl->sb, "Expected %s got ", tnames[tok]);
+ sbuf_printf(tl->sb, "Expected %s got ", vcl_tnames[tok]);
ErrToken(tl, tl->t);
sbuf_printf(tl->sb, "\n(program line %u), at\n", line);
ErrWhere(tl, tl->t);
#define ExpectErr(a, b) do { _Expect(a, b, __LINE__); ERRCHK(a);} while (0)
#define I(tl) do { \
- fprintf(tl->fc, "/* %-11s */ ", __func__); \
- fprintf(tl->fc, "%*.*s", tl->indent, tl->indent, ""); \
+ sbuf_printf(tl->fc, "/* %-11s */ ", __func__); \
+ sbuf_printf(tl->fc, "%*.*s", tl->indent, tl->indent, ""); \
} while (0)
#define L(tl, foo) do { \
#define C(tl, sep) do { \
I(tl); \
- fprintf(tl->fc, "VCL_count(%u)%s\n", ++tl->cnt, sep); \
+ sbuf_printf(tl->fc, "VCL_count(%u)%s\n", ++tl->cnt, sep); \
tl->t->cnt = tl->cnt; \
} while (0)
v = DoubleVal(tl);
ExpectErr(tl, ID);
sc = TimeUnit(tl);
- fprintf(tl->fc, "(%g * %g)", v, sc);
+ sbuf_printf(tl->fc, "(%g * %g)", v, sc);
}
static void
v = DoubleVal(tl);
ExpectErr(tl, ID);
sc = SizeUnit(tl);
- fprintf(tl->fc, "(%g * %g)", v, sc);
+ sbuf_printf(tl->fc, "(%g * %g)", v, sc);
}
static void
v = DoubleVal(tl);
ExpectErr(tl, ID);
sc = RateUnit(tl);
- fprintf(tl->fc, "(%g * %g)", v, sc);
+ sbuf_printf(tl->fc, "(%g * %g)", v, sc);
}
/*--------------------------------------------------------------------*/
ExpectErr(tl, ID);
I(tl);
AddRef(tl, tl->t, R_ACL);
- fprintf(tl->fc, "ip_match(%s, acl_%*.*s)\n",
+ sbuf_printf(tl->fc, "ip_match(%s, acl_%*.*s)\n",
vp->cname,
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
case T_EQ:
case T_NEQ:
I(tl);
- fprintf(tl->fc, "%s %*.*s ",
+ sbuf_printf(tl->fc, "%s %*.*s ",
vp->cname,
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
NextToken(tl);
u = IpVal(tl);
- fprintf(tl->fc, "%uU /* %u.%u.%u.%u */\n", u,
+ sbuf_printf(tl->fc, "%uU /* %u.%u.%u.%u */\n", u,
(u >> 24) & 0xff, (u >> 16) & 0xff,
(u >> 8) & 0xff, (u) & 0xff);
break;
switch (tl->t->tok) {
case '~':
- I(tl); fprintf(tl->fc, "string_match(%s, ", vp->cname);
+ I(tl); sbuf_printf(tl->fc, "string_match(%s, ", vp->cname);
NextToken(tl);
ExpectErr(tl, CSTR);
- fprintf(tl->fc, "%*.*s)\n",
+ sbuf_printf(tl->fc, "%*.*s)\n",
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
NextToken(tl);
{
I(tl);
- fprintf(tl->fc, "%s ", vp->cname);
+ sbuf_printf(tl->fc, "%s ", vp->cname);
switch (tl->t->tok) {
case T_EQ:
case T_NEQ:
case T_GEQ:
case '>':
case '<':
- fprintf(tl->fc, "%*.*s ",
+ sbuf_printf(tl->fc, "%*.*s ",
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
NextToken(tl);
break;
case INT:
ExpectErr(tl, CNUM);
- fprintf(tl->fc, "%*.*s ",
+ sbuf_printf(tl->fc, "%*.*s ",
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
NextToken(tl);
ErrWhere(tl, tl->t);
return;
}
- fprintf(tl->fc, "\n");
+ sbuf_printf(tl->fc, "\n");
break;
default:
sbuf_printf(tl->sb, "Illegal condition ");
{
I(tl);
- fprintf(tl->fc, "%s\n", vp->cname);
+ sbuf_printf(tl->fc, "%s\n", vp->cname);
}
static void
C(tl, ",");
I(tl);
if (tl->t->tok == '!') {
- fprintf(tl->fc, "!");
+ sbuf_printf(tl->fc, "!");
NextToken(tl);
}
- fprintf(tl->fc, "(\n");
+ sbuf_printf(tl->fc, "(\n");
if (tl->t->tok == '(') {
NextToken(tl);
Cond_0(tl);
return;
}
I(tl);
- fprintf(tl->fc, ")\n");
+ sbuf_printf(tl->fc, ")\n");
}
static void
Cond_1(struct tokenlist *tl)
{
- I(tl); fprintf(tl->fc, "(\n");
+ I(tl); sbuf_printf(tl->fc, "(\n");
L(tl, Cond_2(tl));
while (tl->t->tok == T_CAND) {
NextToken(tl);
- I(tl); fprintf(tl->fc, ") && (\n");
+ I(tl); sbuf_printf(tl->fc, ") && (\n");
L(tl, Cond_2(tl));
}
- I(tl); fprintf(tl->fc, ")\n");
+ I(tl); sbuf_printf(tl->fc, ")\n");
}
static void
Cond_0(struct tokenlist *tl)
{
- I(tl); fprintf(tl->fc, "(\n");
+ I(tl); sbuf_printf(tl->fc, "(\n");
L(tl, Cond_1(tl));
while (tl->t->tok == T_COR) {
NextToken(tl);
- I(tl); fprintf(tl->fc, ") || (\n");
+ I(tl); sbuf_printf(tl->fc, ") || (\n");
L(tl, Cond_1(tl));
}
- I(tl); fprintf(tl->fc, ")\n");
+ I(tl); sbuf_printf(tl->fc, ")\n");
}
static void
ExpectErr(tl, '(');
NextToken(tl);
- I(tl); fprintf(tl->fc, "(\n");
+ I(tl); sbuf_printf(tl->fc, "(\n");
L(tl, Cond_0(tl));
ERRCHK(tl);
- I(tl); fprintf(tl->fc, ")\n");
+ I(tl); sbuf_printf(tl->fc, ")\n");
ExpectErr(tl, ')');
NextToken(tl);
}
{
ExpectErr(tl, T_IF);
- I(tl); fprintf(tl->fc, "if \n");
+ I(tl); sbuf_printf(tl->fc, "if \n");
NextToken(tl);
L(tl, Conditional(tl));
ERRCHK(tl);
case T_ELSE:
NextToken(tl);
if (tl->t->tok != T_IF) {
- I(tl); fprintf(tl->fc, "else \n");
+ I(tl); sbuf_printf(tl->fc, "else \n");
L(tl, Compound(tl));
ERRCHK(tl);
return;
/* FALLTHROUGH */
case T_ELSEIF:
case T_ELSIF:
- I(tl); fprintf(tl->fc, "else if \n");
+ I(tl); sbuf_printf(tl->fc, "else if \n");
NextToken(tl);
L(tl, Conditional(tl));
ERRCHK(tl);
switch (at->tok) {
case T_NO_NEW_CACHE:
I(tl);
- fprintf(tl->fc, "VCL_no_new_cache();\n");
+ sbuf_printf(tl->fc, "VCL_no_new_cache();\n");
return;
case T_NO_CACHE:
I(tl);
- fprintf(tl->fc, "VCL_no_cache();\n");
+ sbuf_printf(tl->fc, "VCL_no_cache();\n");
return;
case T_FINISH:
I(tl);
- fprintf(tl->fc, "return;\n");
+ sbuf_printf(tl->fc, "return;\n");
return;
case T_FETCH:
I(tl);
- fprintf(tl->fc, "VCL_fetch();\n");
+ sbuf_printf(tl->fc, "VCL_fetch();\n");
return;
case T_ERROR:
a = UintVal(tl);
I(tl);
- fprintf(tl->fc, "VCL_error(%u, ", a);
+ sbuf_printf(tl->fc, "VCL_error(%u, ", a);
if (tl->t->tok == CSTR) {
- fprintf(tl->fc, "%*.*s);\n",
+ sbuf_printf(tl->fc, "%*.*s);\n",
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
NextToken(tl);
} else
- fprintf(tl->fc, "(const char *)0);\n");
+ sbuf_printf(tl->fc, "(const char *)0);\n");
return;
case T_SWITCH_CONFIG:
ExpectErr(tl, ID);
I(tl);
- fprintf(tl->fc, "VCL_switch_config(\"%*.*s\");\n",
+ sbuf_printf(tl->fc, "VCL_switch_config(\"%*.*s\");\n",
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
NextToken(tl);
ExpectErr(tl, ID);
AddRef(tl, tl->t, R_FUNC);
I(tl);
- fprintf(tl->fc, "VCL_function_%*.*s(VCL_PASS_ARGS);\n",
+ sbuf_printf(tl->fc, "VCL_function_%*.*s(VCL_PASS_ARGS);\n",
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
/* XXX: check if function finished request */
case T_REWRITE:
ExpectErr(tl, CSTR);
I(tl);
- fprintf(tl->fc, "VCL_rewrite(%*.*s",
+ sbuf_printf(tl->fc, "VCL_rewrite(%*.*s",
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
NextToken(tl);
ExpectErr(tl, CSTR);
- fprintf(tl->fc, ", %*.*s);\n",
+ sbuf_printf(tl->fc, ", %*.*s);\n",
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
NextToken(tl);
ERRCHK(tl);
assert(vp != NULL);
I(tl);
- fprintf(tl->fc, "%s ", vp->cname);
+ sbuf_printf(tl->fc, "%s ", vp->cname);
NextToken(tl);
switch (vp->fmt) {
case INT:
case RATE:
case TIME:
case FLOAT:
- fprintf(tl->fc, "%*.*s ",
+ sbuf_printf(tl->fc, "%*.*s ",
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
a = tl->t->tok;
NextToken(tl);
if (a == T_MUL || a == T_DIV)
- fprintf(tl->fc, "%g", DoubleVal(tl));
+ sbuf_printf(tl->fc, "%g", DoubleVal(tl));
else if (vp->fmt == TIME)
TimeVal(tl);
else if (vp->fmt == SIZE)
else if (vp->fmt == RATE)
RateVal(tl);
else
- fprintf(tl->fc, "%g", DoubleVal(tl));
- fprintf(tl->fc, ";\n");
+ sbuf_printf(tl->fc, "%g", DoubleVal(tl));
+ sbuf_printf(tl->fc, ";\n");
break;
case IP:
if (tl->t->tok == '=') {
NextToken(tl);
u = IpVal(tl);
- fprintf(tl->fc, "= %uU; /* %u.%u.%u.%u */\n",
+ sbuf_printf(tl->fc, "= %uU; /* %u.%u.%u.%u */\n",
u,
(u >> 24) & 0xff,
(u >> 16) & 0xff,
case BACKEND:
if (tl->t->tok == '=') {
NextToken(tl);
- fprintf(tl->fc, "= &VCL_backend_%*.*s;\n",
+ sbuf_printf(tl->fc, "= &VCL_backend_%*.*s;\n",
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
NextToken(tl);
ExpectErr(tl, ID);
AddDef(tl, tl->t, R_ACL);
- fprintf(tl->fh, "static struct vcl_acl acl_%*.*s[];\n",
+ sbuf_printf(tl->fh, "static struct vcl_acl acl_%*.*s[];\n",
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
I(tl);
- fprintf(tl->fc, "static struct vcl_acl acl_%*.*s[] = {\n",
+ sbuf_printf(tl->fc, "static struct vcl_acl acl_%*.*s[] = {\n",
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
NextToken(tl);
ExpectErr(tl, ';');
NextToken(tl);
I(tl);
- fprintf(tl->fc, "{ %11uU, %3uU }, /* %u.%u.%u.%u/%u */\n",
+ sbuf_printf(tl->fc, "{ %11uU, %3uU }, /* %u.%u.%u.%u/%u */\n",
u, m,
(u >> 24) & 0xff, (u >> 16) & 0xff,
(u >> 8) & 0xff, (u) & 0xff, m);
}
ExpectErr(tl, '}');
I(tl);
- fprintf(tl->fc, "{ %11uU, %3uU }\n", 0, 0);
+ sbuf_printf(tl->fc, "{ %11uU, %3uU }\n", 0, 0);
tl->indent -= INDENT;
I(tl);
- fprintf(tl->fc, "};\n\n");
+ sbuf_printf(tl->fc, "};\n\n");
NextToken(tl);
}
{
ExpectErr(tl, '{');
- I(tl); fprintf(tl->fc, "{\n");
+ I(tl); sbuf_printf(tl->fc, "{\n");
tl->indent += INDENT;
C(tl, ";");
NextToken(tl);
case '}':
NextToken(tl);
tl->indent -= INDENT;
- I(tl); fprintf(tl->fc, "}\n");
+ I(tl); sbuf_printf(tl->fc, "}\n");
return;
case EOI:
sbuf_printf(tl->sb,
ExpectErr(tl, ID);
AddDef(tl, tl->t, R_BACKEND);
I(tl);
- fprintf(tl->fh, "static struct backend VCL_backend_%*.*s;\n",
+ sbuf_printf(tl->fh, "static struct backend VCL_backend_%*.*s;\n",
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
- fprintf(tl->fc, "static struct backend VCL_backend_%*.*s;\n",
+ sbuf_printf(tl->fc, "static struct backend VCL_backend_%*.*s;\n",
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
- fprintf(tl->fc, "static void\n");
+ sbuf_printf(tl->fc, "static void\n");
I(tl);
- fprintf(tl->fc, "VCL_init_backend_%*.*s (struct backend *backend)\n",
+ sbuf_printf(tl->fc,
+ "VCL_init_backend_%*.*s (struct backend *backend)\n",
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
NextToken(tl);
L(tl, Compound(tl));
- fprintf(tl->fc, "\n");
+ sbuf_printf(tl->fc, "\n");
}
/*--------------------------------------------------------------------*/
NextToken(tl);
ExpectErr(tl, ID);
AddDef(tl, tl->t, R_FUNC);
- fprintf(tl->fh, "static void VCL_function_%*.*s (VCL_FARGS);\n",
+ sbuf_printf(tl->fh, "static void VCL_function_%*.*s (VCL_FARGS);\n",
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
I(tl);
- fprintf(tl->fc, "static void\n");
+ sbuf_printf(tl->fc, "static void\n");
I(tl);
- fprintf(tl->fc, "VCL_function_%*.*s (VCL_FARGS)\n",
+ sbuf_printf(tl->fc, "VCL_function_%*.*s (VCL_FARGS)\n",
tl->t->e - tl->t->b,
tl->t->e - tl->t->b, tl->t->b);
NextToken(tl);
L(tl, Compound(tl));
- fprintf(tl->fc, "\n");
+ sbuf_printf(tl->fc, "\n");
}
/*--------------------------------------------------------------------
t->e = e;
TAILQ_INSERT_TAIL(&tl->tokens, t, list);
tl->t = t;
+ if (0)
+ fprintf(stderr, "+ %s\n", vcl_tnames[tok]);
}
/*--------------------------------------------------------------------
}
/* Match for the fixed tokens (see token.tcl) */
- u = fixed_token(p, &q);
+ u = vcl_fixed_token(p, &q);
if (u != 0) {
AddToken(tl, u, p, q);
p = q;
unsigned lin, pos;
const char *p;
- fprintf(tl->fh, "static struct vcl_ref VCL_ref[%u];\n", tl->cnt + 1);
- fprintf(tl->fc, "static struct vcl_ref VCL_ref[%u] = {\n", tl->cnt + 1);
+ sbuf_printf(tl->fh,
+ "#define VCL_NREFS %u\n", tl->cnt + 1);
+ sbuf_printf(tl->fh,
+ "static struct vcl_ref VCL_ref[VCL_NREFS];\n");
+ sbuf_printf(tl->fc,
+ "static struct vcl_ref VCL_ref[VCL_NREFS] = {\n");
lin = 1;
pos = 0;
p = tl->b;
pos++;
}
- fprintf(tl->fc,
+ sbuf_printf(tl->fc,
"%*.*s[%3u] = { %4u, %3u, 0, \"%*.*s\" },\n",
INDENT, INDENT, "",
t->cnt, lin, pos + 1,
t->e - t->b,
t->e - t->b, t->b);
}
- fprintf(tl->fc, "};\n");
+ sbuf_printf(tl->fc, "};\n");
}
/*--------------------------------------------------------------------*/
static void
-Compile(struct sbuf *sb, const char *b, const char *e)
+EmitInitFunc(struct tokenlist *tl)
+{
+ struct ref *r;
+
+ sbuf_printf(tl->fc,
+ "\nstatic void\n"
+ "VCL_Init(void)\n"
+ "{\n\n");
+
+ TAILQ_FOREACH(r, &tl->refs, list) {
+ switch(r->type) {
+ case R_FUNC:
+ break;
+ case R_ACL:
+ break;
+ case R_BACKEND:
+ sbuf_printf(tl->fc,
+ "\tVCL_init_backend_%*.*s(&VCL_backend_%*.*s);\n",
+ r->name->e - r->name->b,
+ r->name->e - r->name->b, r->name->b,
+ r->name->e - r->name->b,
+ r->name->e - r->name->b, r->name->b);
+ break;
+ }
+ }
+ sbuf_printf(tl->fc, "}\n");
+}
+
+/*--------------------------------------------------------------------*/
+
+static void
+EmitStruct(struct tokenlist *tl)
+{
+
+ sbuf_printf(tl->fc, "\nstruct VCL_conf VCL_conf = {\n");
+ sbuf_printf(tl->fc,
+ "\t.magic = VCL_CONF_MAGIC,\n");
+ sbuf_printf(tl->fc,
+ "\t.init_func = VCL_Init,\n");
+ sbuf_printf(tl->fc,
+ "\t.default_backend = &VCL_backend_default,\n");
+ sbuf_printf(tl->fc,
+ "\t.ref = VCL_ref,\n");
+ sbuf_printf(tl->fc,
+ "\t.nref = VCL_NREFS,\n");
+ sbuf_printf(tl->fc, "};\n");
+}
+
+/*--------------------------------------------------------------------*/
+
+void
+VCL_Compile(struct sbuf *sb, const char *b, const char *e)
{
struct tokenlist tokens;
+ FILE *fo;
memset(&tokens, 0, sizeof tokens);
TAILQ_INIT(&tokens.tokens);
TAILQ_INIT(&tokens.refs);
tokens.sb = sb;
- tokens.fc = fopen("_.c", "w");
+ tokens.fc = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
assert(tokens.fc != NULL);
- tokens.fh = fopen("_.h", "w");
+ tokens.fh = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
assert(tokens.fh != NULL);
- fprintf(tokens.fc, "#include \"vcl_lang.h\"\n");
- fprintf(tokens.fc, "#include \"_.h\"\n");
tokens.b = b;
+ if (e == NULL)
+ e = strchr(b, '\0');
+ assert(e != NULL);
tokens.e = e;
Lexer(&tokens, b, e);
ERRCHK(&tokens);
tokens.t = TAILQ_FIRST(&tokens.tokens);
Parse(&tokens);
ERRCHK(&tokens);
+if (0)
CheckRefs(&tokens);
ERRCHK(&tokens);
LocTable(&tokens);
+
+ EmitInitFunc(&tokens);
+
+ EmitStruct(&tokens);
+
+ fo = popen(
+ "tee /tmp/_.c |"
+ "cc -fpic -shared -Wl,-x -o /tmp/_.so.1 -x c - ", "w");
+
+ vcl_output_lang_h(fo);
+
+ fprintf(fo, "/* FH */\n");
+ sbuf_finish(tokens.fh);
+ fputs(sbuf_data(tokens.fh), fo);
+
+ fprintf(fo, "/* FC */\n");
+ sbuf_finish(tokens.fc);
+ fputs(sbuf_data(tokens.fc), fo);
+ pclose(fo);
+}
+
+/*--------------------------------------------------------------------*/
+
+void
+VCL_InitCompile(void)
+{
+ struct var *v;
+
+ vcl_init_tnames();
+ for (v = vars; v->name != NULL; v++)
+ v->len = strlen(v->name);
}
+#if 0
/*--------------------------------------------------------------------*/
#include <err.h>
printf("<%s>\n", sbuf_data(sb));
return (0);
}
+#endif
* instead, edit the Tcl script vcl_gen_fixed_token.tcl and run it by hand
*/
+#include <stdio.h>
+#include <ctype.h>
#include "vcl_priv.h"
unsigned
-fixed_token(const char *p, const char **q)
+vcl_fixed_token(const char *p, const char **q)
{
switch (p[0]) {
}
}
-const char *tnames[256];
+const char *vcl_tnames[256];
void
-init_tnames(void)
+vcl_init_tnames(void)
{
- tnames['!'] = "'!'";
- tnames['%'] = "'%'";
- tnames['&'] = "'&'";
- tnames['('] = "'('";
- tnames[')'] = "')'";
- tnames['*'] = "'*'";
- tnames['+'] = "'+'";
- tnames[','] = "','";
- tnames['-'] = "'-'";
- tnames['.'] = "'.'";
- tnames['/'] = "'/'";
- tnames['<'] = "'<'";
- tnames['='] = "'='";
- tnames['>'] = "'>'";
- tnames['{'] = "'{'";
- tnames['}'] = "'}'";
- tnames['|'] = "'|'";
- tnames['~'] = "'~'";
- tnames[';'] = "';'";
- tnames[CNUM] = "CNUM";
- tnames[CSTR] = "CSTR";
- tnames[EOI] = "EOI";
- tnames[ID] = "ID";
- tnames[T_ACL] = "acl";
- tnames[T_BACKEND] = "backend";
- tnames[T_CALL] = "call";
- tnames[T_CAND] = "&&";
- tnames[T_COR] = "||";
- tnames[T_DEC] = "--";
- tnames[T_DECR] = "/=";
- tnames[T_DIV] = "/=";
- tnames[T_ELSE] = "else";
- tnames[T_ELSEIF] = "elseif";
- tnames[T_ELSIF] = "elsif";
- tnames[T_EQ] = "==";
- tnames[T_ERROR] = "error";
- tnames[T_FETCH] = "fetch";
- tnames[T_FINISH] = "finish";
- tnames[T_FUNC] = "func";
- tnames[T_GEQ] = ">=";
- tnames[T_IF] = "if";
- tnames[T_INC] = "++";
- tnames[T_INCR] = "+=";
- tnames[T_LEQ] = "<=";
- tnames[T_MUL] = "*=";
- tnames[T_NEQ] = "!=";
- tnames[T_NO_CACHE] = "no_cache";
- tnames[T_NO_NEW_CACHE] = "no_new_cache";
- tnames[T_PROC] = "proc";
- tnames[T_REWRITE] = "rewrite";
- tnames[T_SET] = "set";
- tnames[T_SHL] = "<<";
- tnames[T_SHR] = ">>";
- tnames[T_SUB] = "sub";
- tnames[T_SWITCH_CONFIG] = "switch_config";
- tnames[VAR] = "VAR";
+ vcl_tnames['!'] = "'!'";
+ vcl_tnames['%'] = "'%'";
+ vcl_tnames['&'] = "'&'";
+ vcl_tnames['('] = "'('";
+ vcl_tnames[')'] = "')'";
+ vcl_tnames['*'] = "'*'";
+ vcl_tnames['+'] = "'+'";
+ vcl_tnames[','] = "','";
+ vcl_tnames['-'] = "'-'";
+ vcl_tnames['.'] = "'.'";
+ vcl_tnames['/'] = "'/'";
+ vcl_tnames['<'] = "'<'";
+ vcl_tnames['='] = "'='";
+ vcl_tnames['>'] = "'>'";
+ vcl_tnames['{'] = "'{'";
+ vcl_tnames['}'] = "'}'";
+ vcl_tnames['|'] = "'|'";
+ vcl_tnames['~'] = "'~'";
+ vcl_tnames[';'] = "';'";
+ vcl_tnames[CNUM] = "CNUM";
+ vcl_tnames[CSTR] = "CSTR";
+ vcl_tnames[EOI] = "EOI";
+ vcl_tnames[ID] = "ID";
+ vcl_tnames[T_ACL] = "acl";
+ vcl_tnames[T_BACKEND] = "backend";
+ vcl_tnames[T_CALL] = "call";
+ vcl_tnames[T_CAND] = "&&";
+ vcl_tnames[T_COR] = "||";
+ vcl_tnames[T_DEC] = "--";
+ vcl_tnames[T_DECR] = "/=";
+ vcl_tnames[T_DIV] = "/=";
+ vcl_tnames[T_ELSE] = "else";
+ vcl_tnames[T_ELSEIF] = "elseif";
+ vcl_tnames[T_ELSIF] = "elsif";
+ vcl_tnames[T_EQ] = "==";
+ vcl_tnames[T_ERROR] = "error";
+ vcl_tnames[T_FETCH] = "fetch";
+ vcl_tnames[T_FINISH] = "finish";
+ vcl_tnames[T_FUNC] = "func";
+ vcl_tnames[T_GEQ] = ">=";
+ vcl_tnames[T_IF] = "if";
+ vcl_tnames[T_INC] = "++";
+ vcl_tnames[T_INCR] = "+=";
+ vcl_tnames[T_LEQ] = "<=";
+ vcl_tnames[T_MUL] = "*=";
+ vcl_tnames[T_NEQ] = "!=";
+ vcl_tnames[T_NO_CACHE] = "no_cache";
+ vcl_tnames[T_NO_NEW_CACHE] = "no_new_cache";
+ vcl_tnames[T_PROC] = "proc";
+ vcl_tnames[T_REWRITE] = "rewrite";
+ vcl_tnames[T_SET] = "set";
+ vcl_tnames[T_SHL] = "<<";
+ vcl_tnames[T_SHR] = ">>";
+ vcl_tnames[T_SUB] = "sub";
+ vcl_tnames[T_SWITCH_CONFIG] = "switch_config";
+ vcl_tnames[VAR] = "VAR";
+}
+
+void
+vcl_output_lang_h(FILE *f)
+{
+ fputs("/*\n", f);
+ fputs(" * Stuff necessary to compile a VCL programs C code\n", f);
+ fputs(" *\n", f);
+ fputs(" * XXX: When this file is changed, lib/libvcl/vcl_gen_fixed_token.tcl\n", f);
+ fputs(" * XXX: *MUST* be rerun.\n", f);
+ fputs(" */\n", f);
+ fputs("\n", f);
+ fputs("\n", f);
+ fputs("struct vcl_ref {\n", f);
+ fputs(" unsigned line;\n", f);
+ fputs(" unsigned pos;\n", f);
+ fputs(" unsigned count;\n", f);
+ fputs(" const char *token;\n", f);
+ fputs("};\n", f);
+ fputs("\n", f);
+ fputs("struct vcl_acl {\n", f);
+ fputs(" unsigned ip;\n", f);
+ fputs(" unsigned mask;\n", f);
+ fputs("};\n", f);
+ fputs("\n", f);
+ fputs("struct client {\n", f);
+ fputs(" unsigned ip;\n", f);
+ fputs("};\n", f);
+ fputs("\n", f);
+ fputs("struct req {\n", f);
+ fputs(" char *req;\n", f);
+ fputs(" char *useragent;\n", f);
+ fputs(" struct {\n", f);
+ fputs(" char *path;\n", f);
+ fputs(" char *host;\n", f);
+ fputs(" } url;\n", f);
+ fputs(" double ttlfactor;\n", f);
+ fputs(" struct backend *backend;\n", f);
+ fputs("};\n", f);
+ fputs("\n", f);
+ fputs("struct backend {\n", f);
+ fputs(" unsigned ip;\n", f);
+ fputs(" double responsetime;\n", f);
+ fputs(" double timeout;\n", f);
+ fputs(" double bandwidth;\n", f);
+ fputs(" int down;\n", f);
+ fputs("};\n", f);
+ fputs("\n", f);
+ fputs("struct obj {\n", f);
+ fputs(" int exists;\n", f);
+ fputs(" double ttl;\n", f);
+ fputs(" unsigned result;\n", f);
+ fputs(" unsigned size;\n", f);
+ fputs(" unsigned usage;\n", f);
+ fputs("};\n", f);
+ fputs("\n", f);
+ fputs("#define VCL_FARGS struct client *client, struct obj *obj, struct req *req, struct backend *backend\n", f);
+ fputs("#define VCL_PASS_ARGS client, obj, req, backend\n", f);
+ fputs("\n", f);
+ fputs("void VCL_count(unsigned);\n", f);
+ fputs("void VCL_no_cache();\n", f);
+ fputs("void VCL_no_new_cache();\n", f);
+ fputs("int ip_match(unsigned, struct vcl_acl *);\n", f);
+ fputs("int string_match(const char *, const char *);\n", f);
+ fputs("int VCL_rewrite(const char *, const char *);\n", f);
+ fputs("int VCL_error(unsigned, const char *);\n", f);
+ fputs("int VCL_fetch(void);\n", f);
+ fputs("int VCL_switch_config(const char *);\n", f);
+ fputs("\n", f);
+ fputs("typedef void vcl_init_f(void);\n", f);
+ fputs("\n", f);
+ fputs("struct VCL_conf {\n", f);
+ fputs(" unsigned magic;\n", f);
+ fputs("#define VCL_CONF_MAGIC 0x7406c509 /* from /dev/random */\n", f);
+ fputs(" vcl_init_f *init_func;\n", f);
+ fputs(" struct backend *default_backend;\n", f);
+ fputs(" struct vcl_ref *ref;\n", f);
+ fputs(" unsigned nref;\n", f);
+ fputs("};\n", f);
}