*
* 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>
}
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;
{
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);
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,
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)
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:
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;
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:
}
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;
}