Filter bytecode: Implement stack-based interpreter
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 16 Jul 2012 21:56:59 +0000 (17:56 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 16 Jul 2012 21:56:59 +0000 (17:56 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/lib/lttng-ctl/filter-bytecode.h
src/lib/lttng-ctl/filter-visitor-generate-bytecode.c

index 1bb00dd4577afe0f095c92b375e53eab5c40f41d..df1b34c34eb55ad57c6b035cbfca5a855375cda6 100644 (file)
  * offsets are absolute from start of bytecode.
  */
 
-enum filter_register {
-       REG_R0 = 0,
-       REG_R1 = 1,
-       REG_ERROR,
-};
-
 struct field_ref {
        /* Initially, symbol offset. After link, field offset. */
        uint16_t offset;
@@ -139,7 +133,6 @@ typedef uint8_t filter_opcode_t;
 
 struct load_op {
        filter_opcode_t op;
-       uint8_t reg;            /* enum filter_register */
        char data[0];
        /* data to load. Size known by enum filter_opcode and null-term char. */
 } __attribute__((packed));
@@ -150,7 +143,6 @@ struct binary_op {
 
 struct unary_op {
        filter_opcode_t op;
-       uint8_t reg;            /* enum filter_register */
 } __attribute__((packed));
 
 /* skip_offset is absolute from start of bytecode */
@@ -161,7 +153,6 @@ struct logical_op {
 
 struct cast_op {
        filter_opcode_t op;
-       uint8_t reg;            /* enum filter_register */
 } __attribute__((packed));
 
 struct return_op {
index a9e741cd21ae2983dbb1ba28d949bbb6e01643e6..9877a86f9af7b1cf736527b4c91265d16d6cf3cd 100644 (file)
@@ -136,22 +136,6 @@ int visit_node_root(struct filter_parser_ctx *ctx, struct ir_op *node)
        return bytecode_push(&ctx->bytecode, &insn, 1, sizeof(insn));
 }
 
-static
-enum filter_register reg_sel(struct ir_op *node)
-{
-       switch (node->side) {
-       case IR_SIDE_UNKNOWN:
-       default:
-               fprintf(stderr, "[error] Unknown node side in %s\n",
-                       __func__);
-               return REG_ERROR;
-       case IR_LEFT:
-               return REG_R0;
-       case IR_RIGHT:
-               return REG_R1;
-       }
-}
-
 static
 int visit_node_load(struct filter_parser_ctx *ctx, struct ir_op *node)
 {
@@ -174,9 +158,6 @@ int visit_node_load(struct filter_parser_ctx *ctx, struct ir_op *node)
                if (!insn)
                        return -ENOMEM;
                insn->op = FILTER_OP_LOAD_STRING;
-               insn->reg = reg_sel(node);
-               if (insn->reg == REG_ERROR)
-                       return -EINVAL;
                strcpy(insn->data, node->u.load.u.string);
                ret = bytecode_push(&ctx->bytecode, insn, 1, insn_len);
                free(insn);
@@ -192,9 +173,6 @@ int visit_node_load(struct filter_parser_ctx *ctx, struct ir_op *node)
                if (!insn)
                        return -ENOMEM;
                insn->op = FILTER_OP_LOAD_S64;
-               insn->reg = reg_sel(node);
-               if (insn->reg == REG_ERROR)
-                       return -EINVAL;
                *(int64_t *) insn->data = node->u.load.u.num;
                ret = bytecode_push(&ctx->bytecode, insn, 1, insn_len);
                free(insn);
@@ -210,9 +188,6 @@ int visit_node_load(struct filter_parser_ctx *ctx, struct ir_op *node)
                if (!insn)
                        return -ENOMEM;
                insn->op = FILTER_OP_LOAD_DOUBLE;
-               insn->reg = reg_sel(node);
-               if (insn->reg == REG_ERROR)
-                       return -EINVAL;
                *(double *) insn->data = node->u.load.u.flt;
                ret = bytecode_push(&ctx->bytecode, insn, 1, insn_len);
                free(insn);
@@ -230,11 +205,8 @@ int visit_node_load(struct filter_parser_ctx *ctx, struct ir_op *node)
                if (!insn)
                        return -ENOMEM;
                insn->op = FILTER_OP_LOAD_FIELD_REF;
-               insn->reg = reg_sel(node);
                ref_offset.offset = (uint16_t) -1U;
                memcpy(insn->data, &ref_offset, sizeof(ref_offset));
-               if (insn->reg == REG_ERROR)
-                       return -EINVAL;
                /* reloc_offset points to struct load_op */
                reloc_offset = bytecode_get_len(&ctx->bytecode->b);
                ret = bytecode_push(&ctx->bytecode, insn, 1, insn_len);
@@ -280,15 +252,9 @@ int visit_node_unary(struct filter_parser_ctx *ctx, struct ir_op *node)
                return 0;
        case AST_UNARY_MINUS:
                insn.op = FILTER_OP_UNARY_MINUS;
-               insn.reg = reg_sel(node);
-               if (insn.reg == REG_ERROR)
-                       return -EINVAL;
                return bytecode_push(&ctx->bytecode, &insn, 1, sizeof(insn));
        case AST_UNARY_NOT:
                insn.op = FILTER_OP_UNARY_NOT;
-               insn.reg = reg_sel(node);
-               if (insn.reg == REG_ERROR)
-                       return -EINVAL;
                return bytecode_push(&ctx->bytecode, &insn, 1, sizeof(insn));
        }
 }
@@ -402,7 +368,6 @@ int visit_node_logical(struct filter_parser_ctx *ctx, struct ir_op *node)
                } else {
                        cast_insn.op = FILTER_OP_CAST_DOUBLE_TO_S64;
                }
-               cast_insn.reg = REG_R0;
                ret = bytecode_push(&ctx->bytecode, &cast_insn,
                                        1, sizeof(cast_insn));
                if (ret)
@@ -440,7 +405,6 @@ int visit_node_logical(struct filter_parser_ctx *ctx, struct ir_op *node)
                } else {
                        cast_insn.op = FILTER_OP_CAST_DOUBLE_TO_S64;
                }
-               cast_insn.reg = REG_R0;
                ret = bytecode_push(&ctx->bytecode, &cast_insn,
                                        1, sizeof(cast_insn));
                if (ret)
This page took 0.037184 seconds and 4 git commands to generate.