2 * filter-grammar-test.c
4 * LTTng filter grammar test
6 * Copyright 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * SPDX-License-Identifier: LGPL-2.1-only
18 #include <common/compat/errno.h>
19 #include <common/bytecode/bytecode.h>
20 #include <common/filter/filter-ast.h>
21 #include <common/filter/filter-parser.hpp>
24 int lttng_opt_quiet
= 1;
25 int lttng_opt_verbose
;
28 int main(int argc
, char **argv
)
30 struct filter_parser_ctx
*ctx
;
32 int print_xml
= 0, generate_ir
= 0, generate_bytecode
= 0,
36 for (argidx
= 1; argidx
< argc
; argidx
++) {
37 if (strcmp(argv
[argidx
], "-p") == 0)
39 else if (strcmp(argv
[argidx
], "-i") == 0)
41 else if (strcmp(argv
[argidx
], "-b") == 0)
42 generate_bytecode
= 1;
43 else if (strcmp(argv
[argidx
], "-d") == 0)
44 filter_parser_debug
= 1;
45 else if (strcmp(argv
[argidx
], "-B") == 0)
50 * Force generate the bytecode if the user asks to print the bytecode
51 * (can't print it without generating it first).
54 generate_bytecode
= 1;
58 * Force generate the IR if the user asks to generate the bytecode
59 * (the bytecode is generated by visiting the IR).
61 if (generate_bytecode
) {
65 ctx
= filter_parser_ctx_alloc(stdin
);
67 fprintf(stderr
, "Error allocating parser\n");
70 ret
= filter_parser_ctx_append_ast(ctx
);
72 fprintf(stderr
, "Parse error\n");
76 ret
= filter_visitor_print_xml(ctx
, stdout
, 0);
79 fprintf(stderr
, "XML print error\n");
84 printf("Generating IR... ");
86 ret
= filter_visitor_ir_generate(ctx
);
88 fprintf(stderr
, "Generate IR error\n");
93 printf("Validating IR... ");
95 ret
= filter_visitor_ir_check_binary_op_nesting(ctx
);
101 if (generate_bytecode
) {
102 printf("Generating bytecode... ");
104 ret
= filter_visitor_bytecode_generate(ctx
);
106 fprintf(stderr
, "Generate bytecode error\n");
110 printf("Size of bytecode generated: %u bytes.\n",
111 bytecode_get_len(&ctx
->bytecode
->b
));
114 if (print_bytecode
) {
115 unsigned int bytecode_len
, len
, i
;
117 len
= bytecode_get_len(&ctx
->bytecode
->b
);
118 bytecode_len
= ctx
->bytecode
->b
.reloc_table_offset
;
119 printf("Bytecode:\n");
120 for (i
= 0; i
< bytecode_len
; i
++) {
122 ((uint8_t *) ctx
->bytecode
->b
.data
)[i
]);
125 printf("Reloc table:\n");
126 for (i
= bytecode_len
; i
< len
;) {
128 *(uint16_t *) &ctx
->bytecode
->b
.data
[i
]);
129 i
+= sizeof(uint16_t);
130 printf("%s } ", &((char *) ctx
->bytecode
->b
.data
)[i
]);
131 i
+= strlen(&((char *) ctx
->bytecode
->b
.data
)[i
]) + 1;
136 filter_bytecode_free(ctx
);
138 filter_parser_ctx_free(ctx
);
142 filter_bytecode_free(ctx
);
144 filter_parser_ctx_free(ctx
);
This page took 0.033237 seconds and 4 git commands to generate.