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
12 #include <common/bytecode/bytecode.hpp>
13 #include <common/compat/errno.hpp>
14 #include <common/filter/filter-ast.hpp>
15 #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, print_bytecode
= 0;
35 for (argidx
= 1; argidx
< argc
; argidx
++) {
36 if (strcmp(argv
[argidx
], "-p") == 0)
38 else if (strcmp(argv
[argidx
], "-i") == 0)
40 else if (strcmp(argv
[argidx
], "-b") == 0)
41 generate_bytecode
= 1;
42 else if (strcmp(argv
[argidx
], "-d") == 0)
43 filter_parser_debug
= 1;
44 else if (strcmp(argv
[argidx
], "-B") == 0)
49 * Force generate the bytecode if the user asks to print the bytecode
50 * (can't print it without generating it first).
53 generate_bytecode
= 1;
57 * Force generate the IR if the user asks to generate the bytecode
58 * (the bytecode is generated by visiting the IR).
60 if (generate_bytecode
) {
64 ctx
= filter_parser_ctx_alloc(stdin
);
66 fprintf(stderr
, "Error allocating parser\n");
69 ret
= filter_parser_ctx_append_ast(ctx
);
71 fprintf(stderr
, "Parse error\n");
75 ret
= filter_visitor_print_xml(ctx
, stdout
, 0);
78 fprintf(stderr
, "XML print error\n");
83 printf("Generating IR... ");
85 ret
= filter_visitor_ir_generate(ctx
);
87 fprintf(stderr
, "Generate IR error\n");
92 printf("Validating IR... ");
94 ret
= filter_visitor_ir_check_binary_op_nesting(ctx
);
100 if (generate_bytecode
) {
101 printf("Generating bytecode... ");
103 ret
= filter_visitor_bytecode_generate(ctx
);
105 fprintf(stderr
, "Generate bytecode error\n");
109 printf("Size of bytecode generated: %u bytes.\n",
110 bytecode_get_len(&ctx
->bytecode
->b
));
113 if (print_bytecode
) {
114 unsigned int bytecode_len
, len
, i
;
116 len
= bytecode_get_len(&ctx
->bytecode
->b
);
117 bytecode_len
= ctx
->bytecode
->b
.reloc_table_offset
;
118 printf("Bytecode:\n");
119 for (i
= 0; i
< bytecode_len
; i
++) {
120 printf("0x%X ", ((uint8_t *) ctx
->bytecode
->b
.data
)[i
]);
123 printf("Reloc table:\n");
124 for (i
= bytecode_len
; i
< len
;) {
125 printf("{ 0x%X, ", *(uint16_t *) &ctx
->bytecode
->b
.data
[i
]);
126 i
+= sizeof(uint16_t);
127 printf("%s } ", &((char *) ctx
->bytecode
->b
.data
)[i
]);
128 i
+= strlen(&((char *) ctx
->bytecode
->b
.data
)[i
]) + 1;
133 filter_bytecode_free(ctx
);
135 filter_parser_ctx_free(ctx
);
139 filter_bytecode_free(ctx
);
141 filter_parser_ctx_free(ctx
);
This page took 0.039335 seconds and 4 git commands to generate.