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");
65 ret
= filter_visitor_print_xml(ctx
, stdout
, 0);
68 fprintf(stderr
, "XML print error\n");
73 printf("Generating IR... ");
75 ret
= filter_visitor_ir_generate(ctx
);
77 fprintf(stderr
, "Generate IR error\n");
82 printf("Validating IR... ");
84 ret
= filter_visitor_ir_check_binary_op_nesting(ctx
);
90 if (generate_bytecode
) {
91 printf("Generating bytecode... ");
93 ret
= filter_visitor_bytecode_generate(ctx
);
95 fprintf(stderr
, "Generate bytecode error\n");
99 printf("Size of bytecode generated: %u bytes.\n",
100 bytecode_get_len(&ctx
->bytecode
->b
));
103 if (print_bytecode
) {
104 unsigned int bytecode_len
, len
, i
;
106 len
= bytecode_get_len(&ctx
->bytecode
->b
);
107 bytecode_len
= ctx
->bytecode
->b
.reloc_table_offset
;
108 printf("Bytecode:\n");
109 for (i
= 0; i
< bytecode_len
; i
++) {
111 ((uint8_t *) ctx
->bytecode
->b
.data
)[i
]);
114 printf("Reloc table:\n");
115 for (i
= bytecode_len
; i
< len
;) {
117 *(uint16_t *) &ctx
->bytecode
->b
.data
[i
]);
118 i
+= sizeof(uint16_t);
119 printf("%s } ", &((char *) ctx
->bytecode
->b
.data
)[i
]);
120 i
+= strlen(&((char *) ctx
->bytecode
->b
.data
)[i
]) + 1;
125 filter_bytecode_free(ctx
);
127 filter_parser_ctx_free(ctx
);
131 filter_bytecode_free(ctx
);
133 filter_parser_ctx_free(ctx
);
This page took 0.032768 seconds and 5 git commands to generate.