X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Flib%2Flttng-ctl%2Ffilter-grammar-test.c;fp=src%2Flib%2Flttng-ctl%2Ffilter-grammar-test.c;h=b47b1e9500c5b3a1d7f44112955a877f4fd972c3;hb=953192ba6eb2118c22bcfcb4bcd813f141b407e7;hp=0000000000000000000000000000000000000000;hpb=e74ecf5ad921a3edccacad4d79deb484cd19b1d5;p=lttng-tools.git diff --git a/src/lib/lttng-ctl/filter-grammar-test.c b/src/lib/lttng-ctl/filter-grammar-test.c new file mode 100644 index 000000000..b47b1e950 --- /dev/null +++ b/src/lib/lttng-ctl/filter-grammar-test.c @@ -0,0 +1,133 @@ +/* + * filter-grammar-test.c + * + * LTTng filter grammar test + * + * Copyright 2012 - Mathieu Desnoyers + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License, version 2.1 only, + * as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include "filter-parser.h" +#include "filter-ast.h" +#include "filter-bytecode.h" + +int main(int argc, char **argv) +{ + struct filter_parser_ctx *ctx; + int ret; + int print_xml = 0, generate_ir = 0, generate_bytecode = 0; + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-p") == 0) + print_xml = 1; + else if (strcmp(argv[i], "-i") == 0) + generate_ir = 1; + else if (strcmp(argv[i], "-b") == 0) + generate_bytecode = 1; + else if (strcmp(argv[i], "-d") == 0) + filter_parser_debug = 1; + } + + ctx = filter_parser_ctx_alloc(stdin); + if (!ctx) { + fprintf(stderr, "Error allocating parser\n"); + goto alloc_error; + } + ret = filter_parser_ctx_append_ast(ctx); + if (ret) { + fprintf(stderr, "Parse error\n"); + goto parse_error; + } + ret = filter_visitor_set_parent(ctx); + if (ret) { + fprintf(stderr, "Set parent error\n"); + goto parse_error; + } + if (print_xml) { + ret = filter_visitor_print_xml(ctx, stdout, 0); + if (ret) { + fflush(stdout); + fprintf(stderr, "XML print error\n"); + goto parse_error; + } + } + if (generate_ir) { + printf("Generating IR... "); + fflush(stdout); + ret = filter_visitor_ir_generate(ctx); + if (ret) { + fprintf(stderr, "Generate IR error\n"); + goto parse_error; + } + printf("done\n"); + + printf("Validating IR... "); + fflush(stdout); + ret = filter_visitor_ir_check_binary_op_nesting(ctx); + if (ret) { + goto parse_error; + } + printf("done\n"); + } + if (generate_bytecode) { + printf("Generating bytecode... "); + fflush(stdout); + ret = filter_visitor_bytecode_generate(ctx); + if (ret) { + fprintf(stderr, "Generate bytecode error\n"); + goto parse_error; + } + printf("done\n"); + printf("Size of bytecode generated: %u bytes.\n", + bytecode_get_len(&ctx->bytecode->b)); + } +#if 0 + if (run_bytecode) { + int64_t retval; + + printf("Interpreting bytecode... "); + fflush(stdout); + ret = bytecode_interpret(&ctx->bytecode->b, &retval, NULL); + if (ret) { + fprintf(stderr, "Error interpreting bytecode\n"); + goto parse_error; + } else { + printf("Bytecode interpret result: %" PRIi64 "\n", + retval); + } + printf("done\n"); + } +#endif //0 + + filter_bytecode_free(ctx); + filter_ir_free(ctx); + filter_parser_ctx_free(ctx); + return 0; + +parse_error: + filter_bytecode_free(ctx); + filter_ir_free(ctx); + filter_parser_ctx_free(ctx); +alloc_error: + exit(EXIT_FAILURE); +}