2 * filter-grammar-test.c
4 * LTTng filter grammar test
6 * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License, version 2.1 only,
10 * as published by the Free Software Foundation.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "filter-ast.h"
30 #include "filter-parser.h"
31 #include "filter-bytecode.h"
33 int main(int argc
, char **argv
)
35 struct filter_parser_ctx
*ctx
;
37 int print_xml
= 0, generate_ir
= 0, generate_bytecode
= 0,
41 for (i
= 1; i
< argc
; i
++) {
42 if (strcmp(argv
[i
], "-p") == 0)
44 else if (strcmp(argv
[i
], "-i") == 0)
46 else if (strcmp(argv
[i
], "-b") == 0)
47 generate_bytecode
= 1;
48 else if (strcmp(argv
[i
], "-d") == 0)
49 filter_parser_debug
= 1;
50 else if (strcmp(argv
[i
], "-B") == 0)
54 ctx
= filter_parser_ctx_alloc(stdin
);
56 fprintf(stderr
, "Error allocating parser\n");
59 ret
= filter_parser_ctx_append_ast(ctx
);
61 fprintf(stderr
, "Parse error\n");
64 ret
= filter_visitor_set_parent(ctx
);
66 fprintf(stderr
, "Set parent error\n");
70 ret
= filter_visitor_print_xml(ctx
, stdout
, 0);
73 fprintf(stderr
, "XML print error\n");
78 printf("Generating IR... ");
80 ret
= filter_visitor_ir_generate(ctx
);
82 fprintf(stderr
, "Generate IR error\n");
87 printf("Validating IR... ");
89 ret
= filter_visitor_ir_check_binary_op_nesting(ctx
);
95 if (generate_bytecode
) {
96 printf("Generating bytecode... ");
98 ret
= filter_visitor_bytecode_generate(ctx
);
100 fprintf(stderr
, "Generate bytecode error\n");
104 printf("Size of bytecode generated: %u bytes.\n",
105 bytecode_get_len(&ctx
->bytecode
->b
));
108 if (print_bytecode
) {
109 unsigned int bytecode_len
, len
, i
;
111 len
= bytecode_get_len(&ctx
->bytecode
->b
);
112 bytecode_len
= ctx
->bytecode
->b
.reloc_table_offset
;
113 printf("Bytecode:\n");
114 for (i
= 0; i
< bytecode_len
; i
++) {
116 ((uint8_t *) ctx
->bytecode
->b
.data
)[i
]);
119 printf("Reloc table:\n");
120 for (i
= bytecode_len
; i
< len
;) {
122 *(uint16_t *) &ctx
->bytecode
->b
.data
[i
]);
123 i
+= sizeof(uint16_t);
124 printf("%s } ", &((char *) ctx
->bytecode
->b
.data
)[i
]);
125 i
+= strlen(&((char *) ctx
->bytecode
->b
.data
)[i
]) + 1;
130 filter_bytecode_free(ctx
);
132 filter_parser_ctx_free(ctx
);
136 filter_bytecode_free(ctx
);
138 filter_parser_ctx_free(ctx
);
This page took 0.03163 seconds and 4 git commands to generate.