Implement dispatch-table based interpretor
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 13 Jul 2012 22:10:34 +0000 (18:10 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 13 Jul 2012 22:10:34 +0000 (18:10 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust/lttng-filter.c

index 7fe2a7b5d5642cb3ac92f0de76589448956ea2c6..60879e1fc73f437e134130b55adce25a3ab08cb2 100644 (file)
@@ -264,10 +264,12 @@ int lttng_filter_false(void *filter_data,
        return 0;
 }
 
-#define INTERPRETER_USE_SWITCH
-
 #ifdef INTERPRETER_USE_SWITCH
 
+/*
+ * Fallback for compilers that do not support taking address of labels.
+ */
+
 #define START_OP       \
        start_pc = &bytecode->data[0]; \
        for (pc = next_pc = start_pc; pc - start_pc < bytecode->len; \
@@ -286,7 +288,25 @@ int lttng_filter_false(void *filter_data,
 
 #else
 
-#define OP(name)       
+/*
+ * Dispatch-table based interpreter.
+ */
+
+#define START_OP                                       \
+       start_pc = &bytecode->data[0];                  \
+       pc = next_pc = start_pc;                        \
+       if (unlikely(pc - start_pc >= bytecode->len))   \
+               goto end;                               \
+       goto *dispatch[*(filter_opcode_t *) pc];
+
+#define OP(name)                                       \
+LABEL_##name
+
+#define PO                                             \
+               pc = next_pc;                           \
+               goto *dispatch[*(filter_opcode_t *) pc];
+
+#define END_OP
 
 #endif
 
@@ -301,7 +321,7 @@ int lttng_filter_interpret_bytecode(void *filter_data,
        struct reg reg[NR_REG];
 #ifndef INTERPRETER_USE_SWITCH
        static void *dispatch[NR_FILTER_OPS] = {
-               [ FILTER_OP_UNKNOWN ] = &&LABEL_FILTER_OP_UNKNOWN = 0,
+               [ FILTER_OP_UNKNOWN ] = &&LABEL_FILTER_OP_UNKNOWN,
 
                [ FILTER_OP_RETURN ] = &&LABEL_FILTER_OP_RETURN,
 
@@ -774,6 +794,11 @@ end:
        return retval;
 }
 
+#undef START_OP
+#undef OP
+#undef PO
+#undef END_OP
+
 static
 int bin_op_compare_check(struct vreg reg[NR_REG], const char *str)
 {
This page took 0.025882 seconds and 4 git commands to generate.