*
*/
+#include "common/align.hpp"
+#include "common/bytecode/bytecode.hpp"
+#include "common/compat/string.hpp"
+#include "common/macros.hpp"
+#include "common/string-utils/string-utils.hpp"
+#include "filter-ast.hpp"
+#include "filter-ir.hpp"
+
+#include <common/align.hpp>
+#include <common/compat/errno.hpp>
+#include <common/compat/string.hpp>
+
#include <stdlib.h>
#include <string.h>
-#include <common/align.h>
-#include <common/compat/errno.h>
-#include <common/compat/string.h>
-
-#include "common/align.h"
-#include "common/bytecode/bytecode.h"
-#include "common/compat/string.h"
-#include "common/macros.h"
-#include "common/string-utils/string-utils.h"
-#include "filter-ast.h"
-#include "filter-ir.h"
-
-#ifndef max_t
-#define max_t(type, a, b) ((type) ((a) > (b) ? (a) : (b)))
-#endif
-
-static
-int recursive_visit_gen_bytecode(struct filter_parser_ctx *ctx,
- struct ir_op *node);
-
-static
-int bytecode_patch(struct lttng_bytecode_alloc **fb,
- const void *data,
- uint16_t offset,
- uint32_t len)
+
+static int recursive_visit_gen_bytecode(struct filter_parser_ctx *ctx, struct ir_op *node);
+
+static int
+bytecode_patch(struct lttng_bytecode_alloc **fb, const void *data, uint16_t offset, uint32_t len)
{
if (offset >= (*fb)->b.len) {
return -EINVAL;
return 0;
}
-static
-int visit_node_root(struct filter_parser_ctx *ctx, struct ir_op *node)
+static int visit_node_root(struct filter_parser_ctx *ctx, struct ir_op *node)
{
int ret;
struct return_op insn;
* 0: no match
* < 0: error
*/
-static
-int load_expression_legacy_match(const struct ir_load_expression *exp,
- enum bytecode_op *op_type,
- char **symbol)
+static int load_expression_legacy_match(const struct ir_load_expression *exp,
+ enum bytecode_op *op_type,
+ char **symbol)
{
const struct ir_load_expression_op *op;
bool need_dot = false;
case IR_LOAD_EXPRESSION_GET_INDEX:
case IR_LOAD_EXPRESSION_LOAD_FIELD:
default:
- return 0; /* no match */
+ return 0; /* no match */
}
for (;;) {
op = op->next;
if (!op) {
- return 0; /* no match */
+ return 0; /* no match */
}
switch (op->type) {
case IR_LOAD_EXPRESSION_LOAD_FIELD:
}
break;
default:
- return 0; /* no match */
+ return 0; /* no match */
}
need_dot = true;
}
end:
- return 1; /* Legacy match */
+ return 1; /* Legacy match */
}
/*
* 0: no legacy match
* < 0: error
*/
-static
-int visit_node_load_expression_legacy(struct filter_parser_ctx *ctx,
- const struct ir_load_expression *exp,
- const struct ir_load_expression_op *op)
+static int visit_node_load_expression_legacy(struct filter_parser_ctx *ctx,
+ const struct ir_load_expression *exp,
+ const struct ir_load_expression_op *op)
{
struct load_op *insn = NULL;
- uint32_t insn_len = sizeof(struct load_op)
- + sizeof(struct field_ref);
+ uint32_t insn_len = sizeof(struct load_op) + sizeof(struct field_ref);
struct field_ref ref_offset;
uint32_t reloc_offset_u32;
uint16_t reloc_offset;
goto end;
}
/* append reloc */
- ret = bytecode_push(&ctx->bytecode_reloc, &reloc_offset,
- 1, sizeof(reloc_offset));
+ ret = bytecode_push(&ctx->bytecode_reloc, &reloc_offset, 1, sizeof(reloc_offset));
if (ret) {
goto end;
}
- ret = bytecode_push(&ctx->bytecode_reloc, symbol,
- 1, strlen(symbol) + 1);
+ ret = bytecode_push(&ctx->bytecode_reloc, symbol, 1, strlen(symbol) + 1);
if (ret) {
goto end;
}
- ret = 1; /* legacy */
+ ret = 1; /* legacy */
end:
free(insn);
free(symbol);
return ret;
}
-static
-int visit_node_load_expression(struct filter_parser_ctx *ctx,
- const struct ir_op *node)
+static int visit_node_load_expression(struct filter_parser_ctx *ctx, const struct ir_op *node)
{
struct ir_load_expression *exp;
struct ir_load_expression_op *op;
return ret;
}
if (ret > 0) {
- return 0; /* legacy */
+ return 0; /* legacy */
}
for (; op != NULL; op = op->next) {
}
case IR_LOAD_EXPRESSION_GET_APP_CONTEXT_ROOT:
{
- ret = bytecode_push_get_app_context_root(
- &ctx->bytecode);
+ ret = bytecode_push_get_app_context_root(&ctx->bytecode);
if (ret) {
return ret;
}
case IR_LOAD_EXPRESSION_GET_SYMBOL:
{
- ret = bytecode_push_get_symbol(&ctx->bytecode,
- &ctx->bytecode_reloc, op->u.symbol);
+ ret = bytecode_push_get_symbol(
+ &ctx->bytecode, &ctx->bytecode_reloc, op->u.symbol);
if (ret) {
return ret;
}
case IR_LOAD_EXPRESSION_GET_INDEX:
{
- ret = bytecode_push_get_index_u64(
- &ctx->bytecode, op->u.index);
+ ret = bytecode_push_get_index_u64(&ctx->bytecode, op->u.index);
if (ret) {
return ret;
return 0;
}
-static
-int visit_node_load(struct filter_parser_ctx *ctx, struct ir_op *node)
+static int visit_node_load(struct filter_parser_ctx *ctx, struct ir_op *node)
{
int ret;
switch (node->data_type) {
case IR_DATA_UNKNOWN:
default:
- fprintf(stderr, "[error] Unknown data type in %s\n",
- __func__);
+ fprintf(stderr, "[error] Unknown data type in %s\n", __func__);
return -EINVAL;
case IR_DATA_STRING:
{
struct load_op *insn;
- uint32_t insn_len = sizeof(struct load_op)
- + strlen(node->u.load.u.string.value) + 1;
+ uint32_t insn_len =
+ sizeof(struct load_op) + strlen(node->u.load.u.string.value) + 1;
insn = (load_op *) calloc(insn_len, 1);
if (!insn)
case IR_DATA_NUMERIC:
{
struct load_op *insn;
- uint32_t insn_len = sizeof(struct load_op)
- + sizeof(struct literal_numeric);
+ uint32_t insn_len = sizeof(struct load_op) + sizeof(struct literal_numeric);
insn = (load_op *) calloc(insn_len, 1);
if (!insn)
case IR_DATA_FLOAT:
{
struct load_op *insn;
- uint32_t insn_len = sizeof(struct load_op)
- + sizeof(struct literal_double);
+ uint32_t insn_len = sizeof(struct load_op) + sizeof(struct literal_double);
insn = (load_op *) calloc(insn_len, 1);
if (!insn)
}
}
-static
-int visit_node_unary(struct filter_parser_ctx *ctx, struct ir_op *node)
+static int visit_node_unary(struct filter_parser_ctx *ctx, struct ir_op *node)
{
int ret;
struct unary_op insn;
switch (node->u.unary.type) {
case AST_UNARY_UNKNOWN:
default:
- fprintf(stderr, "[error] Unknown unary node type in %s\n",
- __func__);
+ fprintf(stderr, "[error] Unknown unary node type in %s\n", __func__);
return -EINVAL;
case AST_UNARY_PLUS:
/* Nothing to do. */
* Binary comparator nesting is disallowed. This allows fitting into
* only 2 registers.
*/
-static
-int visit_node_binary(struct filter_parser_ctx *ctx, struct ir_op *node)
+static int visit_node_binary(struct filter_parser_ctx *ctx, struct ir_op *node)
{
int ret;
struct binary_op insn;
switch (node->u.binary.type) {
case AST_OP_UNKNOWN:
default:
- fprintf(stderr, "[error] Unknown unary node type in %s\n",
- __func__);
+ fprintf(stderr, "[error] Unknown unary node type in %s\n", __func__);
return -EINVAL;
case AST_OP_AND:
case AST_OP_OR:
- fprintf(stderr, "[error] Unexpected logical node type in %s\n",
- __func__);
+ fprintf(stderr, "[error] Unexpected logical node type in %s\n", __func__);
return -EINVAL;
case AST_OP_MUL:
/*
* A logical op always return a s64 (1 or 0).
*/
-static
-int visit_node_logical(struct filter_parser_ctx *ctx, struct ir_op *node)
+static int visit_node_logical(struct filter_parser_ctx *ctx, struct ir_op *node)
{
int ret;
struct logical_op insn;
if (ret)
return ret;
/* Cast to s64 if float or field ref */
- if ((node->u.binary.left->data_type == IR_DATA_FIELD_REF
- || node->u.binary.left->data_type == IR_DATA_GET_CONTEXT_REF
- || node->u.binary.left->data_type == IR_DATA_EXPRESSION)
- || node->u.binary.left->data_type == IR_DATA_FLOAT) {
+ if ((node->u.binary.left->data_type == IR_DATA_FIELD_REF ||
+ node->u.binary.left->data_type == IR_DATA_GET_CONTEXT_REF ||
+ node->u.binary.left->data_type == IR_DATA_EXPRESSION) ||
+ node->u.binary.left->data_type == IR_DATA_FLOAT) {
struct cast_op cast_insn;
- if (node->u.binary.left->data_type == IR_DATA_FIELD_REF
- || node->u.binary.left->data_type == IR_DATA_GET_CONTEXT_REF
- || node->u.binary.left->data_type == IR_DATA_EXPRESSION) {
+ if (node->u.binary.left->data_type == IR_DATA_FIELD_REF ||
+ node->u.binary.left->data_type == IR_DATA_GET_CONTEXT_REF ||
+ node->u.binary.left->data_type == IR_DATA_EXPRESSION) {
cast_insn.op = BYTECODE_OP_CAST_TO_S64;
} else {
cast_insn.op = BYTECODE_OP_CAST_DOUBLE_TO_S64;
}
- ret = bytecode_push(&ctx->bytecode, &cast_insn,
- 1, sizeof(cast_insn));
+ ret = bytecode_push(&ctx->bytecode, &cast_insn, 1, sizeof(cast_insn));
if (ret)
return ret;
}
switch (node->u.logical.type) {
default:
- fprintf(stderr, "[error] Unknown node type in %s\n",
- __func__);
+ fprintf(stderr, "[error] Unknown node type in %s\n", __func__);
return -EINVAL;
case AST_OP_AND:
insn.op = BYTECODE_OP_OR;
break;
}
- insn.skip_offset = (uint16_t) -1UL; /* Temporary */
- ret = bytecode_push_logical(&ctx->bytecode, &insn, 1, sizeof(insn),
- &skip_offset_loc);
+ insn.skip_offset = (uint16_t) -1UL; /* Temporary */
+ ret = bytecode_push_logical(&ctx->bytecode, &insn, 1, sizeof(insn), &skip_offset_loc);
if (ret)
return ret;
/* Visit right child */
if (ret)
return ret;
/* Cast to s64 if float or field ref */
- if ((node->u.binary.right->data_type == IR_DATA_FIELD_REF
- || node->u.binary.right->data_type == IR_DATA_GET_CONTEXT_REF
- || node->u.binary.right->data_type == IR_DATA_EXPRESSION)
- || node->u.binary.right->data_type == IR_DATA_FLOAT) {
+ if ((node->u.binary.right->data_type == IR_DATA_FIELD_REF ||
+ node->u.binary.right->data_type == IR_DATA_GET_CONTEXT_REF ||
+ node->u.binary.right->data_type == IR_DATA_EXPRESSION) ||
+ node->u.binary.right->data_type == IR_DATA_FLOAT) {
struct cast_op cast_insn;
- if (node->u.binary.right->data_type == IR_DATA_FIELD_REF
- || node->u.binary.right->data_type == IR_DATA_GET_CONTEXT_REF
- || node->u.binary.right->data_type == IR_DATA_EXPRESSION) {
+ if (node->u.binary.right->data_type == IR_DATA_FIELD_REF ||
+ node->u.binary.right->data_type == IR_DATA_GET_CONTEXT_REF ||
+ node->u.binary.right->data_type == IR_DATA_EXPRESSION) {
cast_insn.op = BYTECODE_OP_CAST_TO_S64;
} else {
cast_insn.op = BYTECODE_OP_CAST_DOUBLE_TO_S64;
}
- ret = bytecode_push(&ctx->bytecode, &cast_insn,
- 1, sizeof(cast_insn));
+ ret = bytecode_push(&ctx->bytecode, &cast_insn, 1, sizeof(cast_insn));
if (ret)
return ret;
}
/* We now know where the logical op can skip. */
target_loc = (uint16_t) bytecode_get_len(&ctx->bytecode->b);
ret = bytecode_patch(&ctx->bytecode,
- &target_loc, /* Offset to jump to */
- skip_offset_loc, /* Where to patch */
- sizeof(uint16_t));
+ &target_loc, /* Offset to jump to */
+ skip_offset_loc, /* Where to patch */
+ sizeof(uint16_t));
return ret;
}
* Postorder traversal of the tree. We need the children result before
* we can evaluate the parent.
*/
-static
-int recursive_visit_gen_bytecode(struct filter_parser_ctx *ctx,
- struct ir_op *node)
+static int recursive_visit_gen_bytecode(struct filter_parser_ctx *ctx, struct ir_op *node)
{
switch (node->op) {
case IR_OP_UNKNOWN:
default:
- fprintf(stderr, "[error] Unknown node type in %s\n",
- __func__);
+ fprintf(stderr, "[error] Unknown node type in %s\n", __func__);
return -EINVAL;
case IR_OP_ROOT:
/* Finally, append symbol table to bytecode */
ctx->bytecode->b.reloc_table_offset = bytecode_get_len(&ctx->bytecode->b);
- return bytecode_push(&ctx->bytecode, ctx->bytecode_reloc->b.data,
- 1, bytecode_get_len(&ctx->bytecode_reloc->b));
+ return bytecode_push(&ctx->bytecode,
+ ctx->bytecode_reloc->b.data,
+ 1,
+ bytecode_get_len(&ctx->bytecode_reloc->b));
error:
filter_bytecode_free(ctx);