1 | /*===-- main.c - tool for testing libLLVM and llvm-c API ------------------===*\ |
2 | |* *| |
3 | |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| |
4 | |* Exceptions. *| |
5 | |* See https://llvm.org/LICENSE.txt for license information. *| |
6 | |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| |
7 | |* *| |
8 | |*===----------------------------------------------------------------------===*| |
9 | |* *| |
10 | |* Main file for llvm-c-tests. "Parses" arguments and dispatches. *| |
11 | |* *| |
12 | \*===----------------------------------------------------------------------===*/ |
13 | |
14 | #include "llvm-c-test.h" |
15 | #include <stdio.h> |
16 | #include <string.h> |
17 | |
18 | static void print_usage(void) { |
19 | fprintf(stderr, format: "llvm-c-test command\n\n" ); |
20 | fprintf(stderr, format: " Commands:\n" ); |
21 | fprintf(stderr, format: " * --module-dump\n" ); |
22 | fprintf(stderr, format: " Read bitcode from stdin - print disassembly\n\n" ); |
23 | fprintf(stderr, format: " * --lazy-module-dump\n" ); |
24 | fprintf(stderr, |
25 | format: " Lazily read bitcode from stdin - print disassembly\n\n" ); |
26 | fprintf(stderr, format: " * --new-module-dump\n" ); |
27 | fprintf(stderr, format: " Read bitcode from stdin - print disassembly\n\n" ); |
28 | fprintf(stderr, format: " * --lazy-new-module-dump\n" ); |
29 | fprintf(stderr, |
30 | format: " Lazily read bitcode from stdin - print disassembly\n\n" ); |
31 | fprintf(stderr, format: " * --module-list-functions\n" ); |
32 | fprintf(stderr, |
33 | format: " Read bitcode from stdin - list summary of functions\n\n" ); |
34 | fprintf(stderr, format: " * --module-list-globals\n" ); |
35 | fprintf(stderr, format: " Read bitcode from stdin - list summary of globals\n\n" ); |
36 | fprintf(stderr, format: " * --targets-list\n" ); |
37 | fprintf(stderr, format: " List available targets\n\n" ); |
38 | fprintf(stderr, format: " * --object-list-sections\n" ); |
39 | fprintf(stderr, format: " Read object file from stdin - list sections\n\n" ); |
40 | fprintf(stderr, format: " * --object-list-symbols\n" ); |
41 | fprintf(stderr, |
42 | format: " Read object file from stdin - list symbols (like nm)\n\n" ); |
43 | fprintf(stderr, format: " * --disassemble\n" ); |
44 | fprintf(stderr, format: " Read lines of triple, hex ascii machine code from stdin " |
45 | "- print disassembly\n\n" ); |
46 | fprintf(stderr, format: " * --calc\n" ); |
47 | fprintf( |
48 | stderr, |
49 | format: " Read lines of name, rpn from stdin - print generated module\n\n" ); |
50 | fprintf(stderr, format: " * --get-di-tag\n" ); |
51 | fprintf(stderr, format: " Run test for getting MDNode dwarf tag\n" ); |
52 | fprintf(stderr, format: " * --di-type-get-name\n" ); |
53 | fprintf(stderr, format: " Run test for getting MDNode type name\n" ); |
54 | fprintf(stderr, format: " * --replace-md-operand\n" ); |
55 | fprintf(stderr, format: " Run test for replacing MDNode operands\n" ); |
56 | fprintf(stderr, format: " * --is-a-value-as-metadata\n" ); |
57 | fprintf(stderr, |
58 | format: " Run test for checking if LLVMValueRef is a ValueAsMetadata\n" ); |
59 | fprintf(stderr, format: " * --echo\n" ); |
60 | fprintf(stderr, format: " Read bitcode file from stdin - print it back out\n\n" ); |
61 | fprintf(stderr, format: " * --test-diagnostic-handler\n" ); |
62 | fprintf(stderr, |
63 | format: " Read bitcode file from stdin with a diagnostic handler set\n\n" ); |
64 | fprintf(stderr, format: " * --test-dibuilder\n" ); |
65 | fprintf(stderr, |
66 | format: " Run tests for the DIBuilder C API - print generated module\n\n" ); |
67 | } |
68 | |
69 | int main(int argc, char **argv) { |
70 | if (argc == 2 && !strcmp(s1: argv[1], s2: "--lazy-new-module-dump" )) { |
71 | return llvm_module_dump(true, true); |
72 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--new-module-dump" )) { |
73 | return llvm_module_dump(false, true); |
74 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--lazy-module-dump" )) { |
75 | return llvm_module_dump(true, false); |
76 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--module-dump" )) { |
77 | return llvm_module_dump(false, false); |
78 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--module-list-functions" )) { |
79 | return llvm_module_list_functions(); |
80 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--module-list-globals" )) { |
81 | return llvm_module_list_globals(); |
82 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--targets-list" )) { |
83 | return llvm_targets_list(); |
84 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--object-list-sections" )) { |
85 | return llvm_object_list_sections(); |
86 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--object-list-symbols" )) { |
87 | return llvm_object_list_symbols(); |
88 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--disassemble" )) { |
89 | return llvm_disassemble(); |
90 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--calc" )) { |
91 | return llvm_calc(); |
92 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--add-named-metadata-operand" )) { |
93 | return llvm_add_named_metadata_operand(); |
94 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--set-metadata" )) { |
95 | return llvm_set_metadata(); |
96 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--get-di-tag" )) { |
97 | return llvm_get_di_tag(); |
98 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--di-type-get-name" )) { |
99 | return llvm_di_type_get_name(); |
100 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--replace-md-operand" )) { |
101 | return llvm_replace_md_operand(); |
102 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--is-a-value-as-metadata" )) { |
103 | return llvm_is_a_value_as_metadata(); |
104 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--test-function-attributes" )) { |
105 | return llvm_test_function_attributes(); |
106 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--test-callsite-attributes" )) { |
107 | return llvm_test_callsite_attributes(); |
108 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--echo" )) { |
109 | return llvm_echo(); |
110 | } else if (argc == 2 && !strcmp(s1: argv[1], s2: "--test-diagnostic-handler" )) { |
111 | return llvm_test_diagnostic_handler(); |
112 | } else if (argc == 2 && |
113 | !strcmp(s1: argv[1], s2: "--test-dibuilder-debuginfo-format" )) { |
114 | return llvm_test_dibuilder(); |
115 | } else { |
116 | print_usage(); |
117 | } |
118 | |
119 | return 1; |
120 | } |
121 | |