summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2019-02-11 16:44:14 +0100
committerMaria Matejka <mq@ucw.cz>2019-02-20 22:30:54 +0100
commit87bd7cd7b03f24c9d7c37a2a060ef553f26ead29 (patch)
tree39963e57b8658da46bfc678e3c004701b7b86005
parent75206f266f8534367b88401be463953b7d5dc770 (diff)
Filter: split the constructors to a separate file
-rw-r--r--filter/Makefile13
-rw-r--r--filter/decl.m421
-rw-r--r--filter/f-inst.h2
3 files changed, 27 insertions, 9 deletions
diff --git a/filter/Makefile b/filter/Makefile
index 18fd8137..78d39638 100644
--- a/filter/Makefile
+++ b/filter/Makefile
@@ -1,9 +1,9 @@
-src := filter.c f-util.c tree.c trie.c
+src := filter.c f-util.c tree.c trie.c inst-gen.c
obj := $(src-o-files)
$(all-daemon)
$(cf-local)
-$(conf-y-targets) $(conf-lex-targets): $(o)f-inst-decl.h
+$(conf-y-targets) $(conf-lex-targets) $(src-o-files): $(o)inst-gen.h
M4FLAGS_FILTERS=$(filter-out -s,$(M4FLAGS))
@@ -16,13 +16,16 @@ $(o)f-inst-interpret.c: $(s)interpret.m4 $(s)f-inst.c $(objdir)/.dir-stamp
$(o)f-inst-same.c: $(s)same.m4 $(s)f-inst.c $(objdir)/.dir-stamp
$(M4) $(M4FLAGS_FILTERS) -P $^ >$@
-$(o)f-inst-decl.h: $(s)decl.m4 $(s)f-inst.c $(objdir)/.dir-stamp
- $(M4) $(M4FLAGS_FILTERS) -P $^ >$@
+$(o)inst-gen.h: $(s)decl.m4 $(s)f-inst.c $(objdir)/.dir-stamp
+ $(M4) $(M4FLAGS_FILTERS) -DTARGET=H -P $^ >$@
+
+$(o)inst-gen.c: $(s)decl.m4 $(s)f-inst.c $(objdir)/.dir-stamp
+ $(M4) $(M4FLAGS_FILTERS) -DTARGET=C -P $^ >$@
$(o)f-inst-dump.c: $(s)dump.m4 $(s)f-inst.c $(objdir)/.dir-stamp
$(M4) $(M4FLAGS_FILTERS) -P $^ >$@
-$(o)filter.o: $(o)f-inst-interpret.c $(o)f-inst-postfixify.c $(o)f-inst-same.c $(o)f-inst-dump.c $(o)f-inst-decl.h
+$(o)filter.o: $(o)f-inst-interpret.c $(o)f-inst-postfixify.c $(o)f-inst-same.c $(o)f-inst-dump.c $(o)inst-gen.h
tests_src := tree_test.c filter_test.c trie_test.c
tests_targets := $(tests_targets) $(tests-target-files)
diff --git a/filter/decl.m4 b/filter/decl.m4
index bdbb3e27..7ff22c2e 100644
--- a/filter/decl.m4
+++ b/filter/decl.m4
@@ -19,9 +19,10 @@ m4_divert(-1)m4_dnl
# 13 constructor body
# Flush the completed instruction
-
m4_define(FID_END, `m4_divert(-1)')
+m4_dnl m4_debugmode(aceflqtx)
+
m4_define(FID_ZONE, `m4_divert($1) /* $2 for INST_NAME() */')
m4_define(FID_STRUCT, `FID_ZONE(1, Per-instruction structure)')
m4_define(FID_UNION, `FID_ZONE(2, Union member)')
@@ -32,6 +33,11 @@ m4_define(FID_STRUCT_IN, `m4_divert(101)')
m4_define(FID_NEW_ARGS, `m4_divert(102)')
m4_define(FID_NEW_BODY, `m4_divert(103)')
+m4_define(FID_ALL, `/* fidall */m4_ifdef([[FID_CURDIV]], [[m4_divert(FID_CURDIV)m4_undefine([[FID_CURDIV]])]])')
+m4_define(FID_C, `m4_ifelse(TARGET, [[C]], FID_ALL, [[m4_define(FID_CURDIV, m4_divnum)m4_divert(-1)]])')
+m4_define(FID_H, `m4_ifelse(TARGET, [[H]], FID_ALL, [[m4_define(FID_CURDIV, m4_divnum)m4_divert(-1)]])')
+
+
m4_define(INST_FLUSH, `m4_ifdef([[INST_NAME]], [[
FID_ENUM
INST_NAME(),
@@ -42,9 +48,11 @@ m4_undivert(101)
FID_UNION
struct f_inst_[[]]INST_NAME() i_[[]]INST_NAME();
FID_NEW
-static inline struct f_inst *f_new_inst_]]INST_NAME()[[(enum f_instruction_code fi_code
+struct f_inst *f_new_inst_]]INST_NAME()[[(enum f_instruction_code fi_code
m4_undivert(102)
-) {
+)
+FID_H ; FID_C
+{
struct f_inst *what_ = cfg_allocz(sizeof(struct f_inst));
what_->fi_code = fi_code;
what_->lineno = ifs->lino;
@@ -53,6 +61,7 @@ m4_undivert(102)
m4_undivert(103)
return what_;
}
+FID_ALL
FID_END
]])')
@@ -103,6 +112,11 @@ m4_define(STRING, `FID_MEMBER(const char *, s)')
m4_m4wrap(`
INST_FLUSH()
m4_divert(0)
+FID_C
+#include "nest/bird.h"
+#include "filter/filter.h"
+#include "filter/f-inst.h"
+FID_H
/* Filter instruction codes */
enum f_instruction_code {
m4_undivert(4)
@@ -121,6 +135,7 @@ struct f_inst {
};
};
+FID_ALL
/* Instruction constructors */
m4_undivert(3)
')
diff --git a/filter/f-inst.h b/filter/f-inst.h
index 1423e685..ad994857 100644
--- a/filter/f-inst.h
+++ b/filter/f-inst.h
@@ -16,7 +16,7 @@
#include "filter/data.h"
/* Include generated filter instruction declarations */
-#include "filter/f-inst-decl.h"
+#include "filter/inst-gen.h"
#define f_new_inst(...) MACRO_CONCAT_AFTER(f_new_inst_, MACRO_FIRST(__VA_ARGS__))(__VA_ARGS__)