Filter fix: support bison 2.6
[lttng-tools.git] / src / lib / lttng-ctl / filter-grammar-test.c
CommitLineData
953192ba
MD
1/*
2 * filter-grammar-test.c
3 *
4 * LTTng filter grammar test
5 *
6 * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
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.
11 *
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.
16 *
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
20 */
21
22#include <stdio.h>
23#include <unistd.h>
24#include <string.h>
25#include <stdlib.h>
26#include <assert.h>
27#include <errno.h>
28#include <inttypes.h>
953192ba 29#include "filter-ast.h"
95b9bd90 30#include "filter-parser.h"
953192ba
MD
31#include "filter-bytecode.h"
32
33int main(int argc, char **argv)
34{
35 struct filter_parser_ctx *ctx;
36 int ret;
37 int print_xml = 0, generate_ir = 0, generate_bytecode = 0;
38 int i;
39
40 for (i = 1; i < argc; i++) {
41 if (strcmp(argv[i], "-p") == 0)
42 print_xml = 1;
43 else if (strcmp(argv[i], "-i") == 0)
44 generate_ir = 1;
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;
49 }
50
51 ctx = filter_parser_ctx_alloc(stdin);
52 if (!ctx) {
53 fprintf(stderr, "Error allocating parser\n");
54 goto alloc_error;
55 }
56 ret = filter_parser_ctx_append_ast(ctx);
57 if (ret) {
58 fprintf(stderr, "Parse error\n");
59 goto parse_error;
60 }
61 ret = filter_visitor_set_parent(ctx);
62 if (ret) {
63 fprintf(stderr, "Set parent error\n");
64 goto parse_error;
65 }
66 if (print_xml) {
67 ret = filter_visitor_print_xml(ctx, stdout, 0);
68 if (ret) {
69 fflush(stdout);
70 fprintf(stderr, "XML print error\n");
71 goto parse_error;
72 }
73 }
74 if (generate_ir) {
75 printf("Generating IR... ");
76 fflush(stdout);
77 ret = filter_visitor_ir_generate(ctx);
78 if (ret) {
79 fprintf(stderr, "Generate IR error\n");
80 goto parse_error;
81 }
82 printf("done\n");
83
84 printf("Validating IR... ");
85 fflush(stdout);
86 ret = filter_visitor_ir_check_binary_op_nesting(ctx);
87 if (ret) {
88 goto parse_error;
89 }
90 printf("done\n");
91 }
92 if (generate_bytecode) {
93 printf("Generating bytecode... ");
94 fflush(stdout);
95 ret = filter_visitor_bytecode_generate(ctx);
96 if (ret) {
97 fprintf(stderr, "Generate bytecode error\n");
98 goto parse_error;
99 }
100 printf("done\n");
101 printf("Size of bytecode generated: %u bytes.\n",
102 bytecode_get_len(&ctx->bytecode->b));
103 }
104#if 0
105 if (run_bytecode) {
106 int64_t retval;
107
108 printf("Interpreting bytecode... ");
109 fflush(stdout);
110 ret = bytecode_interpret(&ctx->bytecode->b, &retval, NULL);
111 if (ret) {
112 fprintf(stderr, "Error interpreting bytecode\n");
113 goto parse_error;
114 } else {
115 printf("Bytecode interpret result: %" PRIi64 "\n",
116 retval);
117 }
118 printf("done\n");
119 }
120#endif //0
121
122 filter_bytecode_free(ctx);
123 filter_ir_free(ctx);
124 filter_parser_ctx_free(ctx);
125 return 0;
126
127parse_error:
128 filter_bytecode_free(ctx);
129 filter_ir_free(ctx);
130 filter_parser_ctx_free(ctx);
131alloc_error:
132 exit(EXIT_FAILURE);
133}
This page took 0.027185 seconds and 4 git commands to generate.