1/*===-- main.c - tool for testing libLLVM and llvm-c API ------------------===*\
2|*                                                                            *|
3|*                     The LLVM Compiler Infrastructure                       *|
4|*                                                                            *|
5|* This file is distributed under the University of Illinois Open Source      *|
6|* License. See LICENSE.TXT for details.                                      *|
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 "llvm-c/BitReader.h"
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19
20static void print_usage(void) {
21  fprintf(stderr, "llvm-c-test command\n\n");
22  fprintf(stderr, " Commands:\n");
23  fprintf(stderr, "  * --module-dump\n");
24  fprintf(stderr, "    Read bitcode from stdin - print disassembly\n\n");
25  fprintf(stderr, "  * --lazy-module-dump\n");
26  fprintf(stderr,
27          "    Lazily read bitcode from stdin - print disassembly\n\n");
28  fprintf(stderr, "  * --new-module-dump\n");
29  fprintf(stderr, "    Read bitcode from stdin - print disassembly\n\n");
30  fprintf(stderr, "  * --lazy-new-module-dump\n");
31  fprintf(stderr,
32          "    Lazily read bitcode from stdin - print disassembly\n\n");
33  fprintf(stderr, "  * --module-list-functions\n");
34  fprintf(stderr,
35          "    Read bitcode from stdin - list summary of functions\n\n");
36  fprintf(stderr, "  * --module-list-globals\n");
37  fprintf(stderr, "    Read bitcode from stdin - list summary of globals\n\n");
38  fprintf(stderr, "  * --targets-list\n");
39  fprintf(stderr, "    List available targets\n\n");
40  fprintf(stderr, "  * --object-list-sections\n");
41  fprintf(stderr, "    Read object file form stdin - list sections\n\n");
42  fprintf(stderr, "  * --object-list-symbols\n");
43  fprintf(stderr,
44          "    Read object file form stdin - list symbols (like nm)\n\n");
45  fprintf(stderr, "  * --disassemble\n");
46  fprintf(stderr, "    Read lines of triple, hex ascii machine code from stdin "
47                  "- print disassembly\n\n");
48  fprintf(stderr, "  * --calc\n");
49  fprintf(
50      stderr,
51      "    Read lines of name, rpn from stdin - print generated module\n\n");
52  fprintf(stderr, "  * --echo\n");
53  fprintf(stderr,
54          "    Read bitcode file form stdin - print it back out\n\n");
55  fprintf(stderr, "  * --test-diagnostic-handler\n");
56  fprintf(stderr,
57          "    Read bitcode file form stdin with a diagnostic handler set\n\n");
58}
59
60int main(int argc, char **argv) {
61  LLVMPassRegistryRef pr = LLVMGetGlobalPassRegistry();
62
63  LLVMInitializeCore(pr);
64
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")) {
86    return llvm_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], "--echo")) {
92    return llvm_echo();
93  } else if (argc == 2 && !strcmp(argv[1], "--test-diagnostic-handler")) {
94    return llvm_test_diagnostic_handler();
95  } else {
96    print_usage();
97  }
98
99  return 1;
100}
101