Implement support for brackets in filter expressions
[lttng-tools.git] / src / lib / lttng-ctl / filter / filter-bytecode.h
1 #ifndef _FILTER_BYTECODE_H
2 #define _FILTER_BYTECODE_H
3
4 /*
5 * filter-bytecode.h
6 *
7 * LTTng filter bytecode
8 *
9 * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * This library is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License, version 2.1 only,
13 * as published by the Free Software Foundation.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #include <common/sessiond-comm/sessiond-comm.h>
26
27 #include "filter-ast.h"
28
29 /*
30 * offsets are absolute from start of bytecode.
31 */
32
33 struct field_ref {
34 /* Initially, symbol offset. After link, field offset. */
35 uint16_t offset;
36 } LTTNG_PACKED;
37
38 struct field_ref_index {
39 /* Initially, symbol offset. After link, field offset. */
40 uint16_t offset;
41 uint64_t index; /* array index */
42 } LTTNG_PACKED;
43
44 struct literal_numeric {
45 int64_t v;
46 } LTTNG_PACKED;
47
48 struct literal_double {
49 double v;
50 } LTTNG_PACKED;
51
52 struct literal_string {
53 char string[0];
54 } LTTNG_PACKED;
55
56 enum filter_op {
57 FILTER_OP_UNKNOWN = 0,
58
59 FILTER_OP_RETURN = 1,
60
61 /* binary */
62 FILTER_OP_MUL = 2,
63 FILTER_OP_DIV = 3,
64 FILTER_OP_MOD = 4,
65 FILTER_OP_PLUS = 5,
66 FILTER_OP_MINUS = 6,
67 FILTER_OP_RSHIFT = 7,
68 FILTER_OP_LSHIFT = 8,
69 FILTER_OP_BIN_AND = 9,
70 FILTER_OP_BIN_OR = 10,
71 FILTER_OP_BIN_XOR = 11,
72
73 /* binary comparators */
74 FILTER_OP_EQ = 12,
75 FILTER_OP_NE = 13,
76 FILTER_OP_GT = 14,
77 FILTER_OP_LT = 15,
78 FILTER_OP_GE = 16,
79 FILTER_OP_LE = 17,
80
81 /* string binary comparator: apply to */
82 FILTER_OP_EQ_STRING = 18,
83 FILTER_OP_NE_STRING = 19,
84 FILTER_OP_GT_STRING = 20,
85 FILTER_OP_LT_STRING = 21,
86 FILTER_OP_GE_STRING = 22,
87 FILTER_OP_LE_STRING = 23,
88
89 /* s64 binary comparator */
90 FILTER_OP_EQ_S64 = 24,
91 FILTER_OP_NE_S64 = 25,
92 FILTER_OP_GT_S64 = 26,
93 FILTER_OP_LT_S64 = 27,
94 FILTER_OP_GE_S64 = 28,
95 FILTER_OP_LE_S64 = 29,
96
97 /* double binary comparator */
98 FILTER_OP_EQ_DOUBLE = 30,
99 FILTER_OP_NE_DOUBLE = 31,
100 FILTER_OP_GT_DOUBLE = 32,
101 FILTER_OP_LT_DOUBLE = 33,
102 FILTER_OP_GE_DOUBLE = 34,
103 FILTER_OP_LE_DOUBLE = 35,
104
105 /* Mixed S64-double binary comparators */
106 FILTER_OP_EQ_DOUBLE_S64 = 36,
107 FILTER_OP_NE_DOUBLE_S64 = 37,
108 FILTER_OP_GT_DOUBLE_S64 = 38,
109 FILTER_OP_LT_DOUBLE_S64 = 39,
110 FILTER_OP_GE_DOUBLE_S64 = 40,
111 FILTER_OP_LE_DOUBLE_S64 = 41,
112
113 FILTER_OP_EQ_S64_DOUBLE = 42,
114 FILTER_OP_NE_S64_DOUBLE = 43,
115 FILTER_OP_GT_S64_DOUBLE = 44,
116 FILTER_OP_LT_S64_DOUBLE = 45,
117 FILTER_OP_GE_S64_DOUBLE = 46,
118 FILTER_OP_LE_S64_DOUBLE = 47,
119
120 /* unary */
121 FILTER_OP_UNARY_PLUS = 48,
122 FILTER_OP_UNARY_MINUS = 49,
123 FILTER_OP_UNARY_NOT = 50,
124 FILTER_OP_UNARY_PLUS_S64 = 51,
125 FILTER_OP_UNARY_MINUS_S64 = 52,
126 FILTER_OP_UNARY_NOT_S64 = 53,
127 FILTER_OP_UNARY_PLUS_DOUBLE = 54,
128 FILTER_OP_UNARY_MINUS_DOUBLE = 55,
129 FILTER_OP_UNARY_NOT_DOUBLE = 56,
130
131 /* logical */
132 FILTER_OP_AND = 57,
133 FILTER_OP_OR = 58,
134
135 /* load field ref */
136 FILTER_OP_LOAD_FIELD_REF = 59,
137 FILTER_OP_LOAD_FIELD_REF_STRING = 60,
138 FILTER_OP_LOAD_FIELD_REF_SEQUENCE = 61,
139 FILTER_OP_LOAD_FIELD_REF_S64 = 62,
140 FILTER_OP_LOAD_FIELD_REF_DOUBLE = 63,
141
142 /* load immediate from operand */
143 FILTER_OP_LOAD_STRING = 64,
144 FILTER_OP_LOAD_S64 = 65,
145 FILTER_OP_LOAD_DOUBLE = 66,
146
147 /* cast */
148 FILTER_OP_CAST_TO_S64 = 67,
149 FILTER_OP_CAST_DOUBLE_TO_S64 = 68,
150 FILTER_OP_CAST_NOP = 69,
151
152 /* get context ref */
153 FILTER_OP_GET_CONTEXT_REF = 70,
154 FILTER_OP_GET_CONTEXT_REF_STRING = 71,
155 FILTER_OP_GET_CONTEXT_REF_S64 = 72,
156 FILTER_OP_GET_CONTEXT_REF_DOUBLE = 73,
157
158 /* load userspace field ref */
159 FILTER_OP_LOAD_FIELD_REF_USER_STRING = 74,
160 FILTER_OP_LOAD_FIELD_REF_USER_SEQUENCE = 75,
161
162 /*
163 * load immediate star globbing pattern (literal string)
164 * from immediate
165 */
166 FILTER_OP_LOAD_STAR_GLOB_STRING = 76,
167
168 /* globbing pattern binary operator: apply to */
169 FILTER_OP_EQ_STAR_GLOB_STRING = 77,
170 FILTER_OP_NE_STAR_GLOB_STRING = 78,
171
172 /* load field ref with index */
173 FILTER_OP_LOAD_FIELD_REF_INDEX = 79,
174 FILTER_OP_LOAD_FIELD_REF_INDEX_S64 = 80,
175
176 /* get context ref with index */
177 FILTER_OP_GET_CONTEXT_REF_INDEX = 81,
178 FILTER_OP_GET_CONTEXT_REF_INDEX_S64 = 82,
179
180 NR_FILTER_OPS,
181 };
182
183 typedef uint8_t filter_opcode_t;
184
185 struct load_op {
186 filter_opcode_t op;
187 char data[0];
188 /* data to load. Size known by enum filter_opcode and null-term char. */
189 } LTTNG_PACKED;
190
191 struct binary_op {
192 filter_opcode_t op;
193 } LTTNG_PACKED;
194
195 struct unary_op {
196 filter_opcode_t op;
197 } LTTNG_PACKED;
198
199 /* skip_offset is absolute from start of bytecode */
200 struct logical_op {
201 filter_opcode_t op;
202 uint16_t skip_offset; /* bytecode insn, if skip second test */
203 } LTTNG_PACKED;
204
205 struct cast_op {
206 filter_opcode_t op;
207 } LTTNG_PACKED;
208
209 struct return_op {
210 filter_opcode_t op;
211 } LTTNG_PACKED;
212
213 struct lttng_filter_bytecode_alloc {
214 uint32_t alloc_len;
215 struct lttng_filter_bytecode b;
216 };
217
218 static inline
219 unsigned int bytecode_get_len(struct lttng_filter_bytecode *bytecode)
220 {
221 return bytecode->len;
222 }
223
224 #endif /* _FILTER_BYTECODE_H */
This page took 0.054391 seconds and 5 git commands to generate.