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