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