Commit 8f5c1681 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Automate generation of tables and prototypes for the objects which

VCL programs can manipulate.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@545 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 90005c6b
/*
* $Id: vcl_compile.c 531 2006-07-20 22:08:43Z phk $
* $Id$
*/
/*
......@@ -791,7 +791,7 @@ Action(struct tokenlist *tl)
vp = FindVar(tl, tl->t, vcc_vars);
ERRCHK(tl);
assert(vp != NULL);
Fc(tl, 1, "%s ", vp->rname);
Fc(tl, 1, "%s", vp->lname);
vcc_NextToken(tl);
switch (vp->fmt) {
case INT:
......@@ -799,7 +799,8 @@ Action(struct tokenlist *tl)
case RATE:
case TIME:
case FLOAT:
Fc(tl, 0, "%T ", tl->t);
if (tl->t->tok != '=')
Fc(tl, 0, "%s %c ", vp->rname, *tl->t->b);
a = tl->t->tok;
vcc_NextToken(tl);
if (a == T_MUL || a == T_DIV)
......@@ -812,7 +813,7 @@ Action(struct tokenlist *tl)
RateVal(tl);
else
Fc(tl, 0, "%g", DoubleVal(tl));
Fc(tl, 0, ";\n");
Fc(tl, 0, ");\n");
break;
case IP:
if (tl->t->tok == '=') {
......@@ -1007,19 +1008,13 @@ Backend(struct tokenlist *tl)
case HOSTNAME:
ExpectErr(tl, CSTR);
t_host = tl->t;
Fc(tl, 1, "\tp = %T;\n", tl->t);
Fc(tl, 1, "\t");
Fc(tl, 0, vp->lname, "p");
Fc(tl, 0, ";\n");
Fc(tl, 1, "\t%s %T);\n", vp->lname, tl->t);
vcc_NextToken(tl);
break;
case PORTNAME:
ExpectErr(tl, CSTR);
t_port = tl->t;
Fc(tl, 1, "\tp = %T;\n", tl->t);
Fc(tl, 1, "\t");
Fc(tl, 0, vp->lname, "p");
Fc(tl, 0, ";\n");
Fc(tl, 1, "\t%s %T);\n", vp->lname, tl->t);
vcc_NextToken(tl);
break;
default:
......@@ -1381,6 +1376,7 @@ VCC_Compile(struct sbuf *sb, const char *b, const char *e)
FILE *fo;
char *of = NULL;
char buf[BUFSIZ];
int i;
memset(&tokens, 0, sizeof tokens);
TAILQ_INIT(&tokens.tokens);
......@@ -1434,6 +1430,7 @@ VCC_Compile(struct sbuf *sb, const char *b, const char *e)
assert(fo != NULL);
vcl_output_lang_h(fo);
fputs(vrt_obj_h, fo);
sbuf_finish(tokens.fh);
fputs(sbuf_data(tokens.fh), fo);
......@@ -1443,7 +1440,14 @@ VCC_Compile(struct sbuf *sb, const char *b, const char *e)
fputs(sbuf_data(tokens.fc), fo);
sbuf_delete(tokens.fc);
pclose(fo);
i = pclose(fo);
fprintf(stderr, "pclose=%d\n", i);
if (i) {
sbuf_printf(sb, "Internal error: GCC returned 0x%04x\n", i);
unlink(of);
free(of);
return (NULL);
}
done:
/* Free References */
......
......@@ -63,7 +63,7 @@ struct ref {
struct var {
const char *name;
enum var_type fmt;
int len;
unsigned len;
const char *rname;
const char *lname;
};
......@@ -107,6 +107,7 @@ extern const char *vcc_default_vcl_b, *vcc_default_vcl_e;
/* vcc_obj.c */
extern struct var vcc_be_vars[];
extern struct var vcc_vars[];
const char *vrt_obj_h;
/* vcc_token.c */
void vcc_ErrToken(struct tokenlist *tl, struct token *t);
......
#!/usr/local/bin/tclsh8.4
#
# Generate various .c and .h files for the VCL compiler and the interfaces
# for it.
# Objects which operate on backends
set beobj {
{ backend.host HOSTNAME }
{ backend.port PORTNAME }
}
# Objects which operate on sessions
set spobj {
{ req.request STRING }
{ req.url STRING }
{ obj.valid BOOL }
{ obj.cacheable BOOL }
{ obj.backend BACKEND }
{ obj.ttl TIME }
{ req.http. HEADER }
}
set tt(STRING) "char *"
set tt(BOOL) "double"
set tt(BACKEND) "struct backend *"
set tt(TIME) "double"
set tt(HEADER) "char *"
set tt(HOSTNAME) "char *"
set tt(PORTNAME) "char *"
#----------------------------------------------------------------------
# Boilerplate warning for all generated files.
proc warns {fd} {
puts $fd "/*"
puts $fd { * $Id$}
puts $fd " *"
puts $fd " * NB: This file is machine generated, DO NOT EDIT!"
puts $fd " *"
puts $fd " * Edit vcc_gen_obj.tcl instead"
puts $fd " */"
puts $fd ""
}
set fo [open vcc_obj.c w]
warns $fo
set fp [open ../../include/vrt_obj.h w]
warns $fp
proc vars {v ty pa} {
global tt fo fp
foreach v $v {
set n [lindex $v 0]
regsub -all {[.]} $n "_" m
set t [lindex $v 1]
puts $fo "\t\{ \"$n\", $t, [string length $n],"
puts $fo "\t \"VRT_r_${m}($pa)\","
puts $fo "\t \"VRT_l_${m}($pa, \","
puts $fo "\t\},"
puts $fp "$tt($t) VRT_r_${m}($ty);"
puts $fp "void VRT_l_${m}($ty, $tt($t));"
}
puts $fo "\t{ NULL }"
}
puts $fo "#include <stdio.h>"
puts $fo "#include \"vcc_compile.h\""
puts $fo ""
puts $fo "struct var vcc_be_vars\[\] = {"
vars $beobj "struct backend *" "backend"
puts $fo "};"
puts $fo ""
puts $fo "struct var vcc_vars\[\] = {"
vars $spobj "struct sess *" "sp"
puts $fo "};"
close $fp
set fp [open ../../include/vrt_obj.h]
puts $fo ""
puts $fo "const char *vrt_obj_h = "
while {[gets $fp a] >= 0} {
puts $fo "\t\"$a\\n\""
}
puts $fo ";"
close $fo
close $fp
This diff is collapsed.
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