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
19 #include <common/compat/errno.h>
20 #include <common/bytecode/bytecode.h>
21 #include <common/filter/filter-ast.h>
22 #include <common/filter/filter-parser.h>
25 int lttng_opt_quiet
= 1;
26 int lttng_opt_verbose
;
29 int main(int argc
, char **argv
)
31 struct filter_parser_ctx
*ctx
;
33 int print_xml
= 0, generate_ir
= 0, generate_bytecode
= 0,
37 for (argidx
= 1; argidx
< argc
; argidx
++) {
38 if (strcmp(argv
[argidx
], "-p") == 0)
40 else if (strcmp(argv
[argidx
], "-i") == 0)
42 else if (strcmp(argv
[argidx
], "-b") == 0)
43 generate_bytecode
= 1;
44 else if (strcmp(argv
[argidx
], "-d") == 0)
45 filter_parser_debug
= 1;
46 else if (strcmp(argv
[argidx
], "-B") == 0)
51 * Force generate the bytecode if the user asks to print the bytecode
52 * (can't print it without generating it first).
55 generate_bytecode
= 1;
59 * Force generate the IR if the user asks to generate the bytecode
60 * (the bytecode is generated by visiting the IR).
62 if (generate_bytecode
) {
66 ctx
= filter_parser_ctx_alloc(stdin
);
68 fprintf(stderr
, "Error allocating parser\n");
71 ret
= filter_parser_ctx_append_ast(ctx
);
73 fprintf(stderr
, "Parse error\n");
77 ret
= filter_visitor_print_xml(ctx
, stdout
, 0);
80 fprintf(stderr
, "XML print error\n");
85 printf("Generating IR... ");
87 ret
= filter_visitor_ir_generate(ctx
);
89 fprintf(stderr
, "Generate IR error\n");
94 printf("Validating IR... ");
96 ret
= filter_visitor_ir_check_binary_op_nesting(ctx
);
102 if (generate_bytecode
) {
103 printf("Generating bytecode... ");
105 ret
= filter_visitor_bytecode_generate(ctx
);
107 fprintf(stderr
, "Generate bytecode error\n");
111 printf("Size of bytecode generated: %u bytes.\n",
112 bytecode_get_len(&ctx
->bytecode
->b
));
115 if (print_bytecode
) {
116 unsigned int bytecode_len
, len
, i
;
118 len
= bytecode_get_len(&ctx
->bytecode
->b
);
119 bytecode_len
= ctx
->bytecode
->b
.reloc_table_offset
;
120 printf("Bytecode:\n");
121 for (i
= 0; i
< bytecode_len
; i
++) {
123 ((uint8_t *) ctx
->bytecode
->b
.data
)[i
]);
126 printf("Reloc table:\n");
127 for (i
= bytecode_len
; i
< len
;) {
129 *(uint16_t *) &ctx
->bytecode
->b
.data
[i
]);
130 i
+= sizeof(uint16_t);
131 printf("%s } ", &((char *) ctx
->bytecode
->b
.data
)[i
]);
132 i
+= strlen(&((char *) ctx
->bytecode
->b
.data
)[i
]) + 1;
137 filter_bytecode_free(ctx
);
139 filter_parser_ctx_free(ctx
);
143 filter_bytecode_free(ctx
);
145 filter_parser_ctx_free(ctx
);
This page took 0.033843 seconds and 4 git commands to generate.