diff options
-rw-r--r-- | filter/dump.m4 | 36 | ||||
-rw-r--r-- | filter/filter.c | 6 | ||||
-rw-r--r-- | filter/interpret.m4 | 19 | ||||
-rw-r--r-- | filter/line-size.m4 | 29 | ||||
-rw-r--r-- | filter/new.m4 | 36 | ||||
-rw-r--r-- | filter/postfixify.m4 | 60 | ||||
-rw-r--r-- | filter/same.m4 | 35 | ||||
-rw-r--r-- | filter/struct.m4 | 52 |
8 files changed, 150 insertions, 123 deletions
diff --git a/filter/dump.m4 b/filter/dump.m4 index cb8e5c5f..4ea3e3be 100644 --- a/filter/dump.m4 +++ b/filter/dump.m4 @@ -10,34 +10,42 @@ m4_divert(-1)m4_dnl # Common aliases m4_define(DNL, `m4_dnl') -m4_define(INST, `m4_divert(1)break; case $1: -m4_divert(-1)')) -m4_define(LINE, `m4_divert(1)f_dump_line(item->lines[$2], indent + 1); +m4_define(INST_FLUSH, `m4_ifdef([[INST_NAME]], [[ +m4_divert(1) +case INST_NAME(): +m4_undivert(2) +break; +m4_divert(-1) +]])') +m4_define(INST, `INST_FLUSH()m4_define([[INST_NAME]], [[$1]])') + +m4_define(LINE, `m4_divert(2)f_dump_line(item->lines[$2], indent + 1); m4_divert(-1)') m4_define(LINEP, `LINE($@)') -m4_define(SYMBOL, `m4_divert(1)debug("%ssymbol %s\n", INDENT, item->sym->name); +m4_define(SYMBOL, `m4_divert(2)debug("%ssymbol %s\n", INDENT, item->sym->name); m4_divert(-1)') -m4_define(VALI, `m4_divert(1)debug("%svalue %s\n", INDENT, val_dump(&item->val)); +m4_define(VALI, `m4_divert(2)debug("%svalue %s\n", INDENT, val_dump(&item->val)); m4_divert(-1)') -m4_define(VAR, `m4_divert(1)debug("%svar %s: value %s\n", INDENT, item->sym->name, val_dump(item->vp)); +m4_define(VAR, `m4_divert(2)debug("%svar %s: value %s\n", INDENT, item->sym->name, val_dump(item->vp)); m4_divert(-1)') -m4_define(FRET, `m4_divert(1)debug("%sfilter return value %d\n", INDENT, item->fret); +m4_define(FRET, `m4_divert(2)debug("%sfilter return value %d\n", INDENT, item->fret); m4_divert(-1)') -m4_define(ECS, `m4_divert(1)debug("%sec subtype %d\n", INDENT, item->ecs); +m4_define(ECS, `m4_divert(2)debug("%sec subtype %d\n", INDENT, item->ecs); m4_divert(-1)') -m4_define(RTC, `m4_divert(1)debug("%sroute table %s\n", INDENT, item->rtc->name); +m4_define(RTC, `m4_divert(2)debug("%sroute table %s\n", INDENT, item->rtc->name); m4_divert(-1)') -m4_define(STATIC_ATTR, `m4_divert(1)debug("%sstatic attribute %u/%u/%u\n", INDENT, item->sa.f_type, item->sa.sa_code, item->sa.readonly); +m4_define(STATIC_ATTR, `m4_divert(2)debug("%sstatic attribute %u/%u/%u\n", INDENT, item->sa.f_type, item->sa.sa_code, item->sa.readonly); m4_divert(-1)') -m4_define(DYNAMIC_ATTR, `m4_divert(1)debug("%sdynamic attribute %u/%u/%u/%u\n", INDENT, item->da.type, item->da.bit, item->da.f_type, item->da.ea_code); +m4_define(DYNAMIC_ATTR, `m4_divert(2)debug("%sdynamic attribute %u/%u/%u/%u\n", INDENT, item->da.type, item->da.bit, item->da.f_type, item->da.ea_code); m4_divert(-1)') -m4_define(DUMP, `m4_divert(1)$1m4_divert(-1)') +m4_define(DUMP, `m4_divert(2)$1m4_divert(-1)') m4_m4wrap(` +INST_FLUSH() m4_divert(0)DNL -case FI_NOP: bug("This shall not happen"); m4_undivert(1) -break; default: bug( "Unknown instruction %d (%c)", item->fi_code, item->fi_code & 0xff); + +default: bug( "Unknown instruction %d (%c)", item->fi_code, item->fi_code & 0xff); ') m4_changequote([[,]]) diff --git a/filter/filter.c b/filter/filter.c index a69d1b3d..bb5e4235 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -626,7 +626,6 @@ inst_line_size(const struct f_inst *what_) return cnt; } -#if DEBUGGING #define INDENT (((const char *) f_dump_line_indent_str) + sizeof(f_dump_line_indent_str) - (indent) - 1) static const char f_dump_line_indent_str[] = " "; @@ -667,9 +666,6 @@ f_dump_line(const struct f_line *dest, int indent) debug("%sFilter line %p dump done\n", INDENT, dest); #undef INDENT } -#else -#define f_dump_line(...) -#endif static uint postfixify(struct f_line *dest, const struct f_inst *what_, uint pos) @@ -695,7 +691,9 @@ f_postfixify_concat(const struct f_inst * const inst[], uint count) for (uint i=0; i<count; i++) out->len = postfixify(out, inst[i], out->len); +#if DEBUGGING f_dump_line(out, 0); +#endif return out; } diff --git a/filter/interpret.m4 b/filter/interpret.m4 index f449d580..dfd5c6a7 100644 --- a/filter/interpret.m4 +++ b/filter/interpret.m4 @@ -10,10 +10,16 @@ m4_divert(-1)m4_dnl # Common aliases m4_define(DNL, `m4_dnl') -m4_define(INST, `break; case $1: -m4_ifelse(eval($2 > 0), `if (vstk.cnt < $2) runtime("Stack underflow");', `') -vstk.cnt -= $2; -') +m4_define(INST_FLUSH, `m4_ifdef([[INST_NAME]], [[ +m4_divert(1) +case INST_NAME(): +m4_ifelse(m4_eval(INST_INVAL() > 0), 1, [[if (vstk.cnt < INST_INVAL()) runtime("Stack underflow"); vstk.cnt -= INST_INVAL(); ]]) +m4_undivert(2) +break; +m4_divert(-1) +]])') + +m4_define(INST, `INST_FLUSH()m4_define([[INST_NAME]], [[$1]])m4_define([[INST_INVAL]], [[$2]])m4_divert(2)') m4_define(ARG, `if (v$1.type != $2) runtime("Argument $1 of instruction %s must be of type $2, got 0x%02x", f_instruction_name(what->fi_code), v$1.type)') @@ -63,12 +69,11 @@ m4_define(STRUCT, `') m4_define(NEW, `') m4_m4wrap(` +INST_FLUSH() m4_divert(0)DNL -case FI_NOP: bug("This shall not happen"); m4_undivert(1) -break; default: bug( "Unknown instruction %d (%c)", what->fi_code, what->fi_code & 0xff); +default: bug( "Unknown instruction %d (%c)", what->fi_code, what->fi_code & 0xff); ') -m4_divert(1) m4_changequote([[,]]) diff --git a/filter/line-size.m4 b/filter/line-size.m4 index 2c6b500b..051d3b90 100644 --- a/filter/line-size.m4 +++ b/filter/line-size.m4 @@ -10,25 +10,32 @@ m4_divert(-1)m4_dnl # Common aliases m4_define(DNL, `m4_dnl') -m4_define(INST, `m4_divert(1) +m4_define(INST_FLUSH, `m4_ifdef([[INST_NAME]], [[ +m4_divert(1) +case INST_NAME(): +cnt += 1; +#define what ((const struct f_inst_]]INST_NAME()[[ *) &(what_->i_]]INST_NAME()[[)) +m4_undivert(2) #undef what -break; case $1: cnt += 1; -#define what ((const struct f_inst_$1 *) &(what_->i_$1)) -m4_divert(-1)') -m4_define(ARG, `m4_divert(1)cnt += inst_line_size(what->f$1); +break; +m4_divert(-1) +]])') +m4_define(INST, `INST_FLUSH()m4_define([[INST_NAME]], [[$1]])') + +m4_define(ARG, `m4_divert(2)cnt += inst_line_size(what->f$1); m4_divert(-1)') -m4_define(ARG_T, `m4_divert(1)cnt += inst_line_size(what->f$1); +m4_define(ARG_T, `m4_divert(2)cnt += inst_line_size(what->f$1); m4_divert(-1)') -m4_define(ARG_ANY, `m4_divert(1)cnt += inst_line_size(what->f$1); +m4_define(ARG_ANY, `m4_divert(2)cnt += inst_line_size(what->f$1); m4_divert(-1)') -m4_define(LINE_SIZE, `m4_divert(1)$1m4_divert(-1)') +m4_define(LINE_SIZE, `m4_divert(2)$1m4_divert(-1)') m4_m4wrap(` +INST_FLUSH() m4_divert(0)DNL -case FI_NOP: bug("This shall not happen"); m4_undivert(1) -#undef what -break; default: bug( "Unknown instruction %d (%c)", what_->fi_code, what_->fi_code & 0xff); + +default: bug( "Unknown instruction %d (%c)", what_->fi_code, what_->fi_code & 0xff); ') m4_changequote([[,]]) diff --git a/filter/new.m4 b/filter/new.m4 index ebb367d0..d499c94b 100644 --- a/filter/new.m4 +++ b/filter/new.m4 @@ -20,23 +20,27 @@ m4_define(FNOUT, `m4_divert(1)') m4_define(FNARG, `m4_divert(2)') m4_define(FNBODY, `m4_divert(3)') -m4_define(INST, `m4_define([[INST_NAME]], [[$1]])FNOUT()DNL -m4_undivert(2)DNL -m4_undivert(3)DNL - return what; -} - -struct f_inst *f_new_inst_$1(enum f_instruction_code fi_code -FNBODY()) { +m4_define(INST_FLUSH, `m4_ifdef([[INST_NAME]], [[ +FNOUT()DNL +struct f_inst *f_new_inst_]]INST_NAME()[[(enum f_instruction_code fi_code +m4_undivert(2) +) { struct f_inst *what = cfg_allocz(sizeof(struct f_inst)); what->fi_code = fi_code; what->lineno = ifs->lino; -FNSTOP()') +m4_undivert(3) + return what; +} +FNSTOP() +]]DNL +)') + +m4_define(INST, `INST_FLUSH()m4_define([[INST_NAME]], [[$1]])') m4_define(WHAT, `what->i_[[]]INST_NAME()') m4_define(FNMETAARG, `FNARG(), $1 $2 -FNBODY() WHAT().$2 = $2; +FNBODY() WHAT().$2 = $2; FNSTOP()') m4_define(ARG, `FNMETAARG(const struct f_inst *, f$1)') m4_define(ARG_ANY, `FNMETAARG(const struct f_inst *, f$1)') @@ -60,25 +64,15 @@ FNBODY()$2 FNSTOP()') m4_m4wrap(` -FNOUT() -m4_undivert(2) -m4_undivert(3) - +INST_FLUSH() m4_divert(0) #include "nest/bird.h" #include "conf/conf.h" #include "filter/filter.h" #include "filter/f-inst-struct.h" -struct f_inst *f_new_inst_FI_NOP(enum f_instruction_code fi_code) { - struct f_inst *what = cfg_allocz(sizeof(struct f_inst)); - what->fi_code = fi_code; - what->lineno = ifs->lino; - m4_undivert(1) - return what; -} ') m4_changequote([[,]]) diff --git a/filter/postfixify.m4 b/filter/postfixify.m4 index 36cadfba..853c9a51 100644 --- a/filter/postfixify.m4 +++ b/filter/postfixify.m4 @@ -10,55 +10,59 @@ m4_divert(-1)m4_dnl # Common aliases m4_define(DNL, `m4_dnl') -m4_define(POSTFIXIFY_TRAILER, `dest->items[pos].fi_code = what_->fi_code; -dest->items[pos].lineno = what_->lineno;') - -m4_define(INST, `m4_divert(1)POSTFIXIFY_TRAILER +m4_define(INST_FLUSH, `m4_ifdef([[INST_NAME]], [[ +m4_divert(1) +case INST_NAME(): +#define what ((const struct f_inst_]]INST_NAME()[[ *) &(what_->i_]]INST_NAME()[[)) +m4_undivert(2) #undef what -break; case $1: -#define what ((const struct f_inst_$1 *) &(what_->i_$1)) -m4_divert(-1)')) -m4_define(ARG, `m4_divert(1)pos = postfixify(dest, what->f$1, pos); +dest->items[pos].fi_code = what_->fi_code; +dest->items[pos].lineno = what_->lineno; +break; +m4_divert(-1) +]])') +m4_define(INST, `INST_FLUSH()m4_define([[INST_NAME]], [[$1]])') + +m4_define(ARG, `m4_divert(2)pos = postfixify(dest, what->f$1, pos); m4_divert(-1)') -m4_define(ARG_ANY, `m4_divert(1)pos = postfixify(dest, what->f$1, pos); +m4_define(ARG_ANY, `m4_divert(2)pos = postfixify(dest, what->f$1, pos); m4_divert(-1)') -m4_define(LINE, `m4_divert(1)dest->items[pos].lines[$2] = f_postfixify(what->f$1); +m4_define(LINE, `m4_divert(2)dest->items[pos].lines[$2] = f_postfixify(what->f$1); m4_divert(-1)') -m4_define(LINEP, `m4_divert(1)dest->items[pos].lines[$2] = what->fl$1; +m4_define(LINEP, `m4_divert(2)dest->items[pos].lines[$2] = what->fl$1; m4_divert(-1)') -m4_define(SYMBOL, `m4_divert(1)dest->items[pos].sym = what->sym; +m4_define(SYMBOL, `m4_divert(2)dest->items[pos].sym = what->sym; m4_divert(-1)') -m4_define(VALI, `m4_divert(1)dest->items[pos].val = what->vali; +m4_define(VALI, `m4_divert(2)dest->items[pos].val = what->vali; m4_divert(-1)') -m4_define(VALP, `m4_divert(1)dest->items[pos].val = *(what->valp); +m4_define(VALP, `m4_divert(2)dest->items[pos].val = *(what->valp); m4_divert(-1)') -m4_define(VAR, `m4_divert(1)dest->items[pos].vp = (dest->items[pos].sym = what->sym)->def; +m4_define(VAR, `m4_divert(2)dest->items[pos].vp = (dest->items[pos].sym = what->sym)->def; m4_divert(-1)') -m4_define(FRET, `m4_divert(1)dest->items[pos].fret = what->fret; +m4_define(FRET, `m4_divert(2)dest->items[pos].fret = what->fret; m4_divert(-1)') -m4_define(ECS, `m4_divert(1)dest->items[pos].ecs = what->ecs; +m4_define(ECS, `m4_divert(2)dest->items[pos].ecs = what->ecs; m4_divert(-1)') -m4_define(RTC, `m4_divert(1)dest->items[pos].rtc = what->rtc; +m4_define(RTC, `m4_divert(2)dest->items[pos].rtc = what->rtc; m4_divert(-1)') -m4_define(STATIC_ATTR, `m4_divert(1)dest->items[pos].sa = what->sa; +m4_define(STATIC_ATTR, `m4_divert(2)dest->items[pos].sa = what->sa; m4_divert(-1)') -m4_define(DYNAMIC_ATTR, `m4_divert(1)dest->items[pos].da = what->da; +m4_define(DYNAMIC_ATTR, `m4_divert(2)dest->items[pos].da = what->da; m4_divert(-1)') -m4_define(COUNT, `m4_divert(1)dest->items[pos].count = what->count; +m4_define(COUNT, `m4_divert(2)dest->items[pos].count = what->count; m4_divert(-1)') -m4_define(TREE, `m4_divert(1)dest->items[pos].tree = what->tree; +m4_define(TREE, `m4_divert(2)dest->items[pos].tree = what->tree; m4_divert(-1)') -m4_define(STRING, `m4_divert(1)dest->items[pos].s = what->s; +m4_define(STRING, `m4_divert(2)dest->items[pos].s = what->s; m4_divert(-1)') -m4_define(POSTFIXIFY, `m4_divert(1)$1m4_divert(-1)') +m4_define(POSTFIXIFY, `m4_divert(2)$1m4_divert(-1)') m4_m4wrap(` +INST_FLUSH() m4_divert(0)DNL -case FI_NOP: bug("This shall not happen"); m4_undivert(1) -POSTFIXIFY_TRAILER -#undef what -break; default: bug( "Unknown instruction %d (%c)", what_->fi_code, what_->fi_code & 0xff); + +default: bug( "Unknown instruction %d (%c)", what_->fi_code, what_->fi_code & 0xff); ') m4_changequote([[,]]) diff --git a/filter/same.m4 b/filter/same.m4 index 10979449..cf739af4 100644 --- a/filter/same.m4 +++ b/filter/same.m4 @@ -10,49 +10,54 @@ m4_divert(-1)m4_dnl # Common aliases m4_define(DNL, `m4_dnl') -m4_define(INST, `m4_divert(1)break; case $1: -m4_divert(-1)') +m4_define(INST_FLUSH, `m4_ifdef([[INST_NAME]], [[ +m4_divert(1) +case INST_NAME(): +m4_undivert(2) +break; +m4_divert(-1) +]])') +m4_define(INST, `INST_FLUSH()m4_define([[INST_NAME]], [[$1]])') m4_define(ARG, `') m4_define(ARG_ANY, `') -m4_define(LINE, `m4_divert(1)if (!f_same(f1->lines[$2], f2->lines[$2])) return 0; +m4_define(LINE, `m4_divert(2)if (!f_same(f1->lines[$2], f2->lines[$2])) return 0; m4_divert(-1)') m4_define(LINEP, LINE) -m4_define(SYMBOL, `m4_divert(1){ +m4_define(SYMBOL, `m4_divert(2){ const struct symbol *s1 = f1->sym, *s2 = f2->sym; if (strcmp(s1->name, s2->name)) return 0; if (s1->class != s2->class) return 0; } m4_divert(-1)') -m4_define(VALI, `m4_divert(1)if (!val_same(f1->vp, f2->vp)) return 0; +m4_define(VALI, `m4_divert(2)if (!val_same(f1->vp, f2->vp)) return 0; m4_divert(-1)') -m4_define(VALP, `m4_divert(1)if (!val_same(f1->vp, f2->vp)) return 0; +m4_define(VALP, `m4_divert(2)if (!val_same(f1->vp, f2->vp)) return 0; m4_divert(-1)') m4_define(VAR, `SYMBOL()VALP()') -m4_define(FRET, `m4_divert(1)if (f1->fret != f2->fret) return 0; +m4_define(FRET, `m4_divert(2)if (f1->fret != f2->fret) return 0; m4_divert(-1)') -m4_define(ECS, `m4_divert(1)if (f1->ecs != f2->ecs) return 0; +m4_define(ECS, `m4_divert(2)if (f1->ecs != f2->ecs) return 0; m4_divert(-1)') -m4_define(RTC, `m4_divert(1)if (strcmp(f1->rtc->name, f2->rtc->name)) return 0; +m4_define(RTC, `m4_divert(2)if (strcmp(f1->rtc->name, f2->rtc->name)) return 0; m4_divert(-1)') -m4_define(STATIC_ATTR, `m4_divert(1)if (f1->sa.sa_code != f2->sa.sa_code) return 0; +m4_define(STATIC_ATTR, `m4_divert(2)if (f1->sa.sa_code != f2->sa.sa_code) return 0; m4_divert(-1)') -m4_define(DYNAMIC_ATTR, `m4_divert(1)if (f1->da.ea_code != f2->da.ea_code) return 0; +m4_define(DYNAMIC_ATTR, `m4_divert(2)if (f1->da.ea_code != f2->da.ea_code) return 0; m4_divert(-1)') -m4_define(SAME, `m4_divert(1)$1m4_divert(-1)') +m4_define(SAME, `m4_divert(2)$1m4_divert(-1)') m4_m4wrap(` +INST_FLUSH() m4_divert(0)DNL -case FI_NOP: bug("This shall not happen"); m4_undivert(1) -break; default: bug( "Unknown instruction %d (%c)", f1->fi_code, f1->fi_code & 0xff); +default: bug( "Unknown instruction %d (%c)", f1->fi_code, f1->fi_code & 0xff); ') -m4_divert(1) m4_changequote([[,]]) diff --git a/filter/struct.m4 b/filter/struct.m4 index 66205bfd..7af28cfd 100644 --- a/filter/struct.m4 +++ b/filter/struct.m4 @@ -10,56 +10,62 @@ m4_divert(-1)m4_dnl # Common aliases m4_define(DNL, `m4_dnl') -m4_define(INST, `m4_divert(2)struct f_inst_$1 i_$1; -m4_divert(1)}; -struct f_inst_$1 { -m4_divert(-1)')) -m4_define(ARG, `m4_divert(1)const struct f_inst *f$1; +m4_define(INST_FLUSH, `m4_ifdef([[INST_NAME]], [[ +m4_divert(1) +struct f_inst_[[]]INST_NAME() { +m4_undivert(2) +}; +m4_divert(3) +struct f_inst_[[]]INST_NAME() i_[[]]INST_NAME(); +m4_divert(-1) +]])') +m4_define(INST, `INST_FLUSH()m4_define([[INST_NAME]], [[$1]])') + +m4_define(ARG, `m4_divert(2)const struct f_inst *f$1; m4_divert(-1)') -m4_define(ARG_ANY, `m4_divert(1)const struct f_inst *f$1; +m4_define(ARG_ANY, `m4_divert(2)const struct f_inst *f$1; m4_divert(-1)') -m4_define(LINE, `m4_divert(1)const struct f_inst *f$1; +m4_define(LINE, `m4_divert(2)const struct f_inst *f$1; m4_divert(-1)') -m4_define(LINEP, `m4_divert(1)const struct f_line *fl$1; +m4_define(LINEP, `m4_divert(2)const struct f_line *fl$1; m4_divert(-1)') -m4_define(SYMBOL, `m4_divert(1)const struct symbol *sym; +m4_define(SYMBOL, `m4_divert(2)const struct symbol *sym; m4_divert(-1)') -m4_define(VALI, `m4_divert(1)struct f_val vali; +m4_define(VALI, `m4_divert(2)struct f_val vali; m4_divert(-1)') -m4_define(VALP, `m4_divert(1)const struct f_val *valp; +m4_define(VALP, `m4_divert(2)const struct f_val *valp; m4_divert(-1)') m4_define(VAR, `VALP()SYMBOL()') -m4_define(FRET, `m4_divert(1)enum filter_return fret; +m4_define(FRET, `m4_divert(2)enum filter_return fret; m4_divert(-1)') -m4_define(ECS, `m4_divert(1)enum ec_subtype ecs; +m4_define(ECS, `m4_divert(2)enum ec_subtype ecs; m4_divert(-1)') -m4_define(RTC, `m4_divert(1)const struct rtable_config *rtc; +m4_define(RTC, `m4_divert(2)const struct rtable_config *rtc; m4_divert(-1)') -m4_define(STATIC_ATTR, `m4_divert(1)struct f_static_attr sa; +m4_define(STATIC_ATTR, `m4_divert(2)struct f_static_attr sa; m4_divert(-1)') -m4_define(DYNAMIC_ATTR, `m4_divert(1)struct f_dynamic_attr da; +m4_define(DYNAMIC_ATTR, `m4_divert(2)struct f_dynamic_attr da; m4_divert(-1)') -m4_define(COUNT, `m4_divert(1)uint count; +m4_define(COUNT, `m4_divert(2)uint count; m4_divert(-1)') -m4_define(TREE, `m4_divert(1)const struct f_tree *tree; +m4_define(TREE, `m4_divert(2)const struct f_tree *tree; m4_divert(-1)') -m4_define(STRING, `m4_divert(1)const char *s; +m4_define(STRING, `m4_divert(2)const char *s; m4_divert(-1)') -m4_define(STRUCT, `m4_divert(1)$1 +m4_define(STRUCT, `m4_divert(2)$1 m4_divert(-1)') m4_m4wrap(` +INST_FLUSH() m4_divert(0)DNL -struct f_inst_FI_NOP { m4_undivert(1) -}; struct f_inst { const struct f_inst *next; /* Next instruction */ enum f_instruction_code fi_code; /* Instruction code */ int lineno; /* Line number */ union { - m4_undivert(2) + m4_undivert(3) }; }; ') |