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 "llvm-c/Core.h"
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20
print_usage(void)21 static void print_usage(void) {
22 fprintf(stderr, "llvm-c-test command\n\n");
23 fprintf(stderr, " Commands:\n");
24 fprintf(stderr, " * --module-dump\n");
25 fprintf(stderr, " Read bytecode from stdin - print disassembly\n\n");
26 fprintf(stderr, " * --module-list-functions\n");
27 fprintf(stderr,
28 " Read bytecode from stdin - list summary of functions\n\n");
29 fprintf(stderr, " * --module-list-globals\n");
30 fprintf(stderr, " Read bytecode from stdin - list summary of globals\n\n");
31 fprintf(stderr, " * --targets-list\n");
32 fprintf(stderr, " List available targets\n\n");
33 fprintf(stderr, " * --object-list-sections\n");
34 fprintf(stderr, " Read object file form stdin - list sections\n\n");
35 fprintf(stderr, " * --object-list-symbols\n");
36 fprintf(stderr,
37 " Read object file form stdin - list symbols (like nm)\n\n");
38 fprintf(stderr, " * --disassemble\n");
39 fprintf(stderr, " Read lines of triple, hex ascii machine code from stdin "
40 "- print disassembly\n\n");
41 fprintf(stderr, " * --calc\n");
42 fprintf(
43 stderr,
44 " Read lines of name, rpn from stdin - print generated module\n\n");
45 }
46
main(int argc,char ** argv)47 int main(int argc, char **argv) {
48 LLVMPassRegistryRef pr = LLVMGetGlobalPassRegistry();
49
50 LLVMInitializeCore(pr);
51
52 if (argc == 2 && !strcmp(argv[1], "--module-dump")) {
53 return module_dump();
54 } else if (argc == 2 && !strcmp(argv[1], "--module-list-functions")) {
55 return module_list_functions();
56 } else if (argc == 2 && !strcmp(argv[1], "--module-list-globals")) {
57 return module_list_globals();
58 } else if (argc == 2 && !strcmp(argv[1], "--targets-list")) {
59 return targets_list();
60 } else if (argc == 2 && !strcmp(argv[1], "--object-list-sections")) {
61 return object_list_sections();
62 } else if (argc == 2 && !strcmp(argv[1], "--object-list-symbols")) {
63 return object_list_symbols();
64 } else if (argc == 2 && !strcmp(argv[1], "--disassemble")) {
65 return disassemble();
66 } else if (argc == 2 && !strcmp(argv[1], "--calc")) {
67 return calc();
68 } else {
69 print_usage();
70 }
71
72 return 1;
73 }
74