Commit 1447c4dd authored by Maria Matejka's avatar Maria Matejka
Browse files

Filter refactoring: Partial conversion to stack. Does not even compile. WIP.

parent 41195970
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@
      while (tt) {
	*vv = lp_alloc(fs->pool, sizeof(struct f_path_mask));
	if (tt->kind == PM_ASN_EXPR) {
	  INTERPRET((struct f_inst *) tt->val, 0);
	  fret = interpret(fs, (struct f_inst *) tt->val);
	  (*vv)->kind = PM_ASN;
	  if (res.type != T_INT) {
	    runtime( "Error resolving path mask template: value not an integer" );
@@ -672,11 +672,10 @@
      }
      /* It is actually possible to have t->data NULL */

      fret = interpret(fs, t->data);
      if (fret >= F_RETURN)
	return fret;
      what = t->data;
      jmp = what->fi_code;
      continue;
    }
    break;
  case FI_IP_MASK: /* IP.MASK(val) */
    ARG(1, T_IP);
    ARG(2, T_INT);
+28 −11
Original line number Diff line number Diff line
@@ -52,9 +52,15 @@

#define FILTER_STACK_DEPTH 16384

#define F_JMP_NEXT	(~0U)
#define F_JMP_INST(x)	((x) & 0xffffff)
#define F_JMP_ARG(x, n)	((x) | ((n) << 24))

/* Filter interpreter stack. Make this thread local after going parallel. */
struct filter_stack {
  struct f_val val;
  struct f_inst *what;
  uint jmp;
};

static struct filter_stack filter_stack[FILTER_STACK_DEPTH];
@@ -631,19 +637,25 @@ interpret(struct filter_state *fs, struct f_inst *what)
  unsigned u1, u2;
  enum filter_return fret;
  int i;
  uint fi;
  u32 as;

#define res fs->stack[fs->stack_ptr].val
#define stk(n) fs->stack[fs->stack_ptr + n]
#define res stk(0).val
#define v0 res
#define v1 fs->stack[fs->stack_ptr + 1].val
#define v2 fs->stack[fs->stack_ptr + 2].val
#define v3 fs->stack[fs->stack_ptr + 3].val
#define v1 stk(1).val
#define v2 stk(2).val
#define v3 stk(3).val

  res = (struct f_val) { .type = T_VOID };

  for ( ; what; what = what->next) {
    res = (struct f_val) { .type = T_VOID };
    switch (what->fi_code) {
    uint jmp = what->fi_code;
    while (jmp != F_JMP_NEXT) {
      uint jmpc = jmp;
      jmp = F_JMP_NEXT;
      switch (jmpc) {

#define runtime(fmt, ...) do { \
  if (!(fs->flags & FF_SILENT)) \
@@ -651,6 +663,8 @@ interpret(struct filter_state *fs, struct f_inst *what)
  return F_ERROR; \
} while(0)

#define INSTRUCTION(fi_) case fi_: fi = fi_;

#define ARG_ANY_T(n, tt) INTERPRET(what->a[n-1].p, tt)
#define ARG_ANY(n) ARG_ANY_T(n, n)

@@ -658,19 +672,21 @@ interpret(struct filter_state *fs, struct f_inst *what)
  ARG_ANY_T(n,tt); \
  if (v##tt.type != t) \
    runtime("Argument %d of instruction %s must be of type %02x, got %02x", \
	    n, f_instruction_name(what->fi_code), t, v##tt.type); \
	    n, f_instruction_name(fi), t, v##tt.type); \
} while (0)

#define ARG(n,t) ARG_T(n,n,t)

#define INTERPRET(what_, n) do { \
  stk(n).what = what; \
  stk(n).jmp = F_JMP_ARG(fi, n); \
  fs->stack_ptr += n; \
  fret = interpret(fs, what_); \
  what = what_; \
  jmp = what->fi_code; \
  continue; \
case F_JMP_ARG(fi, n): \
  fs->stack_ptr -= n; \
  if (fret == F_RETURN) \
    bug("This shall not happen"); \
  if (fret > F_RETURN) \
    return fret; \
  what = stk(n).what; \
} while (0)

#define ACCESS_RTE do { if (!fs->rte) runtime("No route to access"); } while (0)
@@ -690,6 +706,7 @@ interpret(struct filter_state *fs, struct f_inst *what)
#undef ACCESS_EATTRS
      }
    }
  }
  return F_NOP;
}