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-parser.h"
30 #include "filter-ast.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;
40 for (i
= 1; i
< argc
; i
++) {
41 if (strcmp(argv
[i
], "-p") == 0)
43 else if (strcmp(argv
[i
], "-i") == 0)
45 else if (strcmp(argv
[i
], "-b") == 0)
46 generate_bytecode
= 1;
47 else if (strcmp(argv
[i
], "-d") == 0)
48 filter_parser_debug
= 1;
51 ctx
= filter_parser_ctx_alloc(stdin
);
53 fprintf(stderr
, "Error allocating parser\n");
56 ret
= filter_parser_ctx_append_ast(ctx
);
58 fprintf(stderr
, "Parse error\n");
61 ret
= filter_visitor_set_parent(ctx
);
63 fprintf(stderr
, "Set parent error\n");
67 ret
= filter_visitor_print_xml(ctx
, stdout
, 0);
70 fprintf(stderr
, "XML print error\n");
75 printf("Generating IR... ");
77 ret
= filter_visitor_ir_generate(ctx
);
79 fprintf(stderr
, "Generate IR error\n");
84 printf("Validating IR... ");
86 ret
= filter_visitor_ir_check_binary_op_nesting(ctx
);
92 if (generate_bytecode
) {
93 printf("Generating bytecode... ");
95 ret
= filter_visitor_bytecode_generate(ctx
);
97 fprintf(stderr
, "Generate bytecode error\n");
101 printf("Size of bytecode generated: %u bytes.\n",
102 bytecode_get_len(&ctx
->bytecode
->b
));
108 printf("Interpreting bytecode... ");
110 ret
= bytecode_interpret(&ctx
->bytecode
->b
, &retval
, NULL
);
112 fprintf(stderr
, "Error interpreting bytecode\n");
115 printf("Bytecode interpret result: %" PRIi64
"\n",
122 filter_bytecode_free(ctx
);
124 filter_parser_ctx_free(ctx
);
128 filter_bytecode_free(ctx
);
130 filter_parser_ctx_free(ctx
);
This page took 0.034456 seconds and 4 git commands to generate.