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
));
111 printf("Interpreting bytecode... ");
113 ret
= bytecode_interpret(&ctx
->bytecode
->b
, &retval
, NULL
);
115 fprintf(stderr
, "Error interpreting bytecode\n");
118 printf("Bytecode interpret result: %" PRIi64
"\n",
125 if (print_bytecode
) {
126 unsigned int bytecode_len
, len
, i
;
128 len
= bytecode_get_len(&ctx
->bytecode
->b
);
129 bytecode_len
= ctx
->bytecode
->b
.reloc_table_offset
;
130 printf("Bytecode:\n");
131 for (i
= 0; i
< bytecode_len
; i
++) {
133 ((uint8_t *) ctx
->bytecode
->b
.data
)[i
]);
136 printf("Reloc table:\n");
137 for (i
= bytecode_len
; i
< len
;) {
139 *(uint16_t *) &ctx
->bytecode
->b
.data
[i
]);
140 i
+= sizeof(uint16_t);
141 printf("%s } ", &((char *) ctx
->bytecode
->b
.data
)[i
]);
142 i
+= strlen(&((char *) ctx
->bytecode
->b
.data
)[i
]) + 1;
147 filter_bytecode_free(ctx
);
149 filter_parser_ctx_free(ctx
);
153 filter_bytecode_free(ctx
);
155 filter_parser_ctx_free(ctx
);
This page took 0.03322 seconds and 5 git commands to generate.