Clean-up: consumer: consumer_metadata_cache_write is not const-correct
[lttng-tools.git] / src / lib / lttng-ctl / filter / filter-visitor-generate-ir.c
index cd7930ad5476cb36e62f949d7a9ae818b4cf3723..11c6b610c1276893ea4986dd18fc9a090f02fdc4 100644 (file)
@@ -3,20 +3,10 @@
  *
  * LTTng filter generate intermediate representation
  *
- * Copyright 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License, version 2.1 only,
- * as published by the Free Software Foundation.
+ * SPDX-License-Identifier: LGPL-2.1-only
  *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <stdio.h>
@@ -87,7 +77,7 @@ enum ir_load_string_type get_literal_string_type(const char *string)
 }
 
 static
-struct ir_op *make_op_load_string(char *string, enum ir_side side)
+struct ir_op *make_op_load_string(const char *string, enum ir_side side)
 {
        struct ir_op *op;
 
@@ -197,7 +187,7 @@ struct ir_load_expression *create_load_expression(struct filter_node *node)
 {
        struct ir_load_expression *load_exp;
        struct ir_load_expression_op *load_exp_op, *prev_op;
-       char *str;
+       const char *str;
 
        /* Get forward chain. */
        node = load_expression_get_forward_chain(node);
@@ -358,6 +348,13 @@ struct ir_op *make_op_unary_not(struct ir_op *child, enum ir_side side)
                        child, side);
 }
 
+static
+struct ir_op *make_op_unary_bit_not(struct ir_op *child, enum ir_side side)
+{
+       return make_op_unary(AST_UNARY_BIT_NOT, "~", child->signedness,
+                       child, side);
+}
+
 static
 struct ir_op *make_op_binary_compare(enum op_type bin_op_type,
                const char *op_str, struct ir_op *left, struct ir_op *right,
@@ -538,6 +535,20 @@ struct ir_op *make_op_binary_logical_or(struct ir_op *left, struct ir_op *right,
        return make_op_binary_logical(AST_OP_OR, "||", left, right, side);
 }
 
+static
+struct ir_op *make_op_binary_bitwise_rshift(struct ir_op *left, struct ir_op *right,
+               enum ir_side side)
+{
+       return make_op_binary_bitwise(AST_OP_BIT_RSHIFT, ">>", left, right, side);
+}
+
+static
+struct ir_op *make_op_binary_bitwise_lshift(struct ir_op *left, struct ir_op *right,
+               enum ir_side side)
+{
+       return make_op_binary_bitwise(AST_OP_BIT_LSHIFT, "<<", left, right, side);
+}
+
 static
 struct ir_op *make_op_binary_bitwise_and(struct ir_op *left, struct ir_op *right,
                enum ir_side side)
@@ -662,13 +673,9 @@ struct ir_op *make_op(struct filter_parser_ctx *ctx,
        case AST_OP_MINUS:
                op_str = "-";
                goto error_not_supported;
-       case AST_OP_RSHIFT:
-               op_str = ">>";
-               goto error_not_supported;
-       case AST_OP_LSHIFT:
-               op_str = "<<";
-               goto error_not_supported;
 
+       case AST_OP_BIT_RSHIFT:
+       case AST_OP_BIT_LSHIFT:
        case AST_OP_BIT_AND:
        case AST_OP_BIT_OR:
        case AST_OP_BIT_XOR:
@@ -740,6 +747,12 @@ struct ir_op *make_op(struct filter_parser_ctx *ctx,
        case AST_OP_LE:
                op = make_op_binary_le(lchild, rchild, side);
                break;
+       case AST_OP_BIT_RSHIFT:
+               op = make_op_binary_bitwise_rshift(lchild, rchild, side);
+               break;
+       case AST_OP_BIT_LSHIFT:
+               op = make_op_binary_bitwise_lshift(lchild, rchild, side);
+               break;
        case AST_OP_BIT_AND:
                op = make_op_binary_bitwise_and(lchild, rchild, side);
                break;
@@ -769,8 +782,6 @@ static
 struct ir_op *make_unary_op(struct filter_parser_ctx *ctx,
                struct filter_node *node, enum ir_side side)
 {
-       const char *op_str = "?";
-
        switch (node->u.unary_op.type) {
        case AST_UNARY_UNKNOWN:
        default:
@@ -824,14 +835,21 @@ struct ir_op *make_unary_op(struct filter_parser_ctx *ctx,
        }
        case AST_UNARY_BIT_NOT:
        {
-               op_str = "~";
-               goto error_not_supported;
+               struct ir_op *op, *child;
+
+               child = generate_ir_recursive(ctx, node->u.unary_op.child,
+                                       side);
+               if (!child)
+                       return NULL;
+               op = make_op_unary_bit_not(child, side);
+               if (!op) {
+                       filter_free_ir_recursive(child);
+                       return NULL;
+               }
+               return op;
        }
        }
 
-error_not_supported:
-       fprintf(stderr, "[error] %s: unary operation '%s' not supported\n",
-               __func__, op_str);
        return NULL;
 }
 
This page took 0.025474 seconds and 4 git commands to generate.