Move all sources to 'src/'
[lttng-ust.git] / src / liblttng-ust / bytecode.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2012-2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 */
6
7 #ifndef _BYTECODE_H
8 #define _BYTECODE_H
9
10 #include <stdint.h>
11 #include <lttng/ust-abi.h>
12
13 /*
14 * offsets are absolute from start of bytecode.
15 */
16
17 struct field_ref {
18 /* Initially, symbol offset. After link, field offset. */
19 uint16_t offset;
20 } __attribute__((packed));
21
22 struct get_symbol {
23 /* Symbol offset. */
24 uint16_t offset;
25 } __attribute__((packed));
26
27 struct get_index_u16 {
28 uint16_t index;
29 } __attribute__((packed));
30
31 struct get_index_u64 {
32 uint64_t index;
33 } __attribute__((packed));
34
35 struct literal_numeric {
36 int64_t v;
37 } __attribute__((packed));
38
39 struct literal_double {
40 double v;
41 } __attribute__((packed));
42
43 struct literal_string {
44 char string[0];
45 } __attribute__((packed));
46
47 enum bytecode_op {
48 BYTECODE_OP_UNKNOWN = 0,
49
50 BYTECODE_OP_RETURN = 1,
51
52 /* binary */
53 BYTECODE_OP_MUL = 2,
54 BYTECODE_OP_DIV = 3,
55 BYTECODE_OP_MOD = 4,
56 BYTECODE_OP_PLUS = 5,
57 BYTECODE_OP_MINUS = 6,
58 BYTECODE_OP_BIT_RSHIFT = 7,
59 BYTECODE_OP_BIT_LSHIFT = 8,
60 BYTECODE_OP_BIT_AND = 9,
61 BYTECODE_OP_BIT_OR = 10,
62 BYTECODE_OP_BIT_XOR = 11,
63
64 /* binary comparators */
65 BYTECODE_OP_EQ = 12,
66 BYTECODE_OP_NE = 13,
67 BYTECODE_OP_GT = 14,
68 BYTECODE_OP_LT = 15,
69 BYTECODE_OP_GE = 16,
70 BYTECODE_OP_LE = 17,
71
72 /* string binary comparator: apply to */
73 BYTECODE_OP_EQ_STRING = 18,
74 BYTECODE_OP_NE_STRING = 19,
75 BYTECODE_OP_GT_STRING = 20,
76 BYTECODE_OP_LT_STRING = 21,
77 BYTECODE_OP_GE_STRING = 22,
78 BYTECODE_OP_LE_STRING = 23,
79
80 /* s64 binary comparator */
81 BYTECODE_OP_EQ_S64 = 24,
82 BYTECODE_OP_NE_S64 = 25,
83 BYTECODE_OP_GT_S64 = 26,
84 BYTECODE_OP_LT_S64 = 27,
85 BYTECODE_OP_GE_S64 = 28,
86 BYTECODE_OP_LE_S64 = 29,
87
88 /* double binary comparator */
89 BYTECODE_OP_EQ_DOUBLE = 30,
90 BYTECODE_OP_NE_DOUBLE = 31,
91 BYTECODE_OP_GT_DOUBLE = 32,
92 BYTECODE_OP_LT_DOUBLE = 33,
93 BYTECODE_OP_GE_DOUBLE = 34,
94 BYTECODE_OP_LE_DOUBLE = 35,
95
96 /* Mixed S64-double binary comparators */
97 BYTECODE_OP_EQ_DOUBLE_S64 = 36,
98 BYTECODE_OP_NE_DOUBLE_S64 = 37,
99 BYTECODE_OP_GT_DOUBLE_S64 = 38,
100 BYTECODE_OP_LT_DOUBLE_S64 = 39,
101 BYTECODE_OP_GE_DOUBLE_S64 = 40,
102 BYTECODE_OP_LE_DOUBLE_S64 = 41,
103
104 BYTECODE_OP_EQ_S64_DOUBLE = 42,
105 BYTECODE_OP_NE_S64_DOUBLE = 43,
106 BYTECODE_OP_GT_S64_DOUBLE = 44,
107 BYTECODE_OP_LT_S64_DOUBLE = 45,
108 BYTECODE_OP_GE_S64_DOUBLE = 46,
109 BYTECODE_OP_LE_S64_DOUBLE = 47,
110
111 /* unary */
112 BYTECODE_OP_UNARY_PLUS = 48,
113 BYTECODE_OP_UNARY_MINUS = 49,
114 BYTECODE_OP_UNARY_NOT = 50,
115 BYTECODE_OP_UNARY_PLUS_S64 = 51,
116 BYTECODE_OP_UNARY_MINUS_S64 = 52,
117 BYTECODE_OP_UNARY_NOT_S64 = 53,
118 BYTECODE_OP_UNARY_PLUS_DOUBLE = 54,
119 BYTECODE_OP_UNARY_MINUS_DOUBLE = 55,
120 BYTECODE_OP_UNARY_NOT_DOUBLE = 56,
121
122 /* logical */
123 BYTECODE_OP_AND = 57,
124 BYTECODE_OP_OR = 58,
125
126 /* load field ref */
127 BYTECODE_OP_LOAD_FIELD_REF = 59,
128 BYTECODE_OP_LOAD_FIELD_REF_STRING = 60,
129 BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE = 61,
130 BYTECODE_OP_LOAD_FIELD_REF_S64 = 62,
131 BYTECODE_OP_LOAD_FIELD_REF_DOUBLE = 63,
132
133 /* load immediate from operand */
134 BYTECODE_OP_LOAD_STRING = 64,
135 BYTECODE_OP_LOAD_S64 = 65,
136 BYTECODE_OP_LOAD_DOUBLE = 66,
137
138 /* cast */
139 BYTECODE_OP_CAST_TO_S64 = 67,
140 BYTECODE_OP_CAST_DOUBLE_TO_S64 = 68,
141 BYTECODE_OP_CAST_NOP = 69,
142
143 /* get context ref */
144 BYTECODE_OP_GET_CONTEXT_REF = 70,
145 BYTECODE_OP_GET_CONTEXT_REF_STRING = 71,
146 BYTECODE_OP_GET_CONTEXT_REF_S64 = 72,
147 BYTECODE_OP_GET_CONTEXT_REF_DOUBLE = 73,
148
149 /* load userspace field ref */
150 BYTECODE_OP_LOAD_FIELD_REF_USER_STRING = 74,
151 BYTECODE_OP_LOAD_FIELD_REF_USER_SEQUENCE = 75,
152
153 /*
154 * load immediate star globbing pattern (literal string)
155 * from immediate
156 */
157 BYTECODE_OP_LOAD_STAR_GLOB_STRING = 76,
158
159 /* globbing pattern binary operator: apply to */
160 BYTECODE_OP_EQ_STAR_GLOB_STRING = 77,
161 BYTECODE_OP_NE_STAR_GLOB_STRING = 78,
162
163 /*
164 * Instructions for recursive traversal through composed types.
165 */
166 BYTECODE_OP_GET_CONTEXT_ROOT = 79,
167 BYTECODE_OP_GET_APP_CONTEXT_ROOT = 80,
168 BYTECODE_OP_GET_PAYLOAD_ROOT = 81,
169
170 BYTECODE_OP_GET_SYMBOL = 82,
171 BYTECODE_OP_GET_SYMBOL_FIELD = 83,
172 BYTECODE_OP_GET_INDEX_U16 = 84,
173 BYTECODE_OP_GET_INDEX_U64 = 85,
174
175 BYTECODE_OP_LOAD_FIELD = 86,
176 BYTECODE_OP_LOAD_FIELD_S8 = 87,
177 BYTECODE_OP_LOAD_FIELD_S16 = 88,
178 BYTECODE_OP_LOAD_FIELD_S32 = 89,
179 BYTECODE_OP_LOAD_FIELD_S64 = 90,
180 BYTECODE_OP_LOAD_FIELD_U8 = 91,
181 BYTECODE_OP_LOAD_FIELD_U16 = 92,
182 BYTECODE_OP_LOAD_FIELD_U32 = 93,
183 BYTECODE_OP_LOAD_FIELD_U64 = 94,
184 BYTECODE_OP_LOAD_FIELD_STRING = 95,
185 BYTECODE_OP_LOAD_FIELD_SEQUENCE = 96,
186 BYTECODE_OP_LOAD_FIELD_DOUBLE = 97,
187
188 BYTECODE_OP_UNARY_BIT_NOT = 98,
189
190 BYTECODE_OP_RETURN_S64 = 99,
191
192 NR_BYTECODE_OPS,
193 };
194
195 typedef uint8_t bytecode_opcode_t;
196
197 struct load_op {
198 bytecode_opcode_t op;
199 /*
200 * data to load. Size known by enum bytecode_opcode and null-term char.
201 */
202 char data[0];
203 } __attribute__((packed));
204
205 struct binary_op {
206 bytecode_opcode_t op;
207 } __attribute__((packed));
208
209 struct unary_op {
210 bytecode_opcode_t op;
211 } __attribute__((packed));
212
213 /* skip_offset is absolute from start of bytecode */
214 struct logical_op {
215 bytecode_opcode_t op;
216 uint16_t skip_offset; /* bytecode insn, if skip second test */
217 } __attribute__((packed));
218
219 struct cast_op {
220 bytecode_opcode_t op;
221 } __attribute__((packed));
222
223 struct return_op {
224 bytecode_opcode_t op;
225 } __attribute__((packed));
226
227 #endif /* _BYTECODE_H */
This page took 0.034027 seconds and 4 git commands to generate.