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
, " * --echo\n");
51 fprintf(stderr
, " Read bitcode file from stdin - print it back out\n\n");
52 fprintf(stderr
, " * --test-diagnostic-handler\n");
54 " Read bitcode file from stdin with a diagnostic handler set\n\n");
55 fprintf(stderr
, " * --test-dibuilder\n");
57 " Run tests for the DIBuilder C API - print generated module\n\n");
60 int main(int argc
, char **argv
) {
61 LLVMPassRegistryRef pr
= LLVMGetGlobalPassRegistry();
63 LLVMInitializeCore(pr
);
65 if (argc
== 2 && !strcmp(argv
[1], "--lazy-new-module-dump")) {
66 return llvm_module_dump(true, true);
67 } else if (argc
== 2 && !strcmp(argv
[1], "--new-module-dump")) {
68 return llvm_module_dump(false, true);
69 } else if (argc
== 2 && !strcmp(argv
[1], "--lazy-module-dump")) {
70 return llvm_module_dump(true, false);
71 } else if (argc
== 2 && !strcmp(argv
[1], "--module-dump")) {
72 return llvm_module_dump(false, false);
73 } else if (argc
== 2 && !strcmp(argv
[1], "--module-list-functions")) {
74 return llvm_module_list_functions();
75 } else if (argc
== 2 && !strcmp(argv
[1], "--module-list-globals")) {
76 return llvm_module_list_globals();
77 } else if (argc
== 2 && !strcmp(argv
[1], "--targets-list")) {
78 return llvm_targets_list();
79 } else if (argc
== 2 && !strcmp(argv
[1], "--object-list-sections")) {
80 return llvm_object_list_sections();
81 } else if (argc
== 2 && !strcmp(argv
[1], "--object-list-symbols")) {
82 return llvm_object_list_symbols();
83 } else if (argc
== 2 && !strcmp(argv
[1], "--disassemble")) {
84 return llvm_disassemble();
85 } else if (argc
== 2 && !strcmp(argv
[1], "--calc")) {
87 } else if (argc
== 2 && !strcmp(argv
[1], "--add-named-metadata-operand")) {
88 return llvm_add_named_metadata_operand();
89 } else if (argc
== 2 && !strcmp(argv
[1], "--set-metadata")) {
90 return llvm_set_metadata();
91 } else if (argc
== 2 && !strcmp(argv
[1], "--test-function-attributes")) {
92 return llvm_test_function_attributes();
93 } else if (argc
== 2 && !strcmp(argv
[1], "--test-callsite-attributes")) {
94 return llvm_test_callsite_attributes();
95 } else if (argc
== 2 && !strcmp(argv
[1], "--echo")) {
97 } else if (argc
== 2 && !strcmp(argv
[1], "--test-diagnostic-handler")) {
98 return llvm_test_diagnostic_handler();
99 } else if (argc
== 2 && !strcmp(argv
[1], "--test-dibuilder")) {
100 return llvm_test_dibuilder();