blob: 10d7d75f4ffcb42deefd9a35dd96c255d6615397 [file] [log] [blame]
Anders Waldenborgb932c662013-10-23 08:10:20 +00001/*===-- 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"
Anders Waldenborgb932c662013-10-23 08:10:20 +000016#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 bytecode from stdin - print disassembly\n\n");
Rafael Espindola125592d2015-12-18 03:57:26 +000025 fprintf(stderr, " * --lazy-module-dump\n");
26 fprintf(stderr,
27 " Lazily read bytecode from stdin - print disassembly\n\n");
Rafael Espindola2339ffe2015-12-18 23:46:42 +000028 fprintf(stderr, " * --new-module-dump\n");
29 fprintf(stderr, " Read bytecode from stdin - print disassembly\n\n");
30 fprintf(stderr, " * --lazy-new-module-dump\n");
31 fprintf(stderr,
32 " Lazily read bytecode from stdin - print disassembly\n\n");
Anders Waldenborgb932c662013-10-23 08:10:20 +000033 fprintf(stderr, " * --module-list-functions\n");
34 fprintf(stderr,
35 " Read bytecode from stdin - list summary of functions\n\n");
36 fprintf(stderr, " * --module-list-globals\n");
37 fprintf(stderr, " Read bytecode 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");
Amaury Sechete8ea7d82016-02-04 23:26:19 +000049 fprintf(stderr, " * --echo\n");
50 fprintf(stderr,
51 " Read object file form stdin - and print it back out\n\n");
Anders Waldenborgb932c662013-10-23 08:10:20 +000052 fprintf(
53 stderr,
54 " Read lines of name, rpn from stdin - print generated module\n\n");
55}
56
57int main(int argc, char **argv) {
58 LLVMPassRegistryRef pr = LLVMGetGlobalPassRegistry();
59
60 LLVMInitializeCore(pr);
61
Rafael Espindola2339ffe2015-12-18 23:46:42 +000062 if (argc == 2 && !strcmp(argv[1], "--lazy-new-module-dump")) {
63 return module_dump(true, true);
64 } else if (argc == 2 && !strcmp(argv[1], "--new-module-dump")) {
65 return module_dump(false, true);
66 } else if (argc == 2 && !strcmp(argv[1], "--lazy-module-dump")) {
67 return module_dump(true, false);
Rafael Espindola125592d2015-12-18 03:57:26 +000068 } else if (argc == 2 && !strcmp(argv[1], "--module-dump")) {
Rafael Espindola2339ffe2015-12-18 23:46:42 +000069 return module_dump(false, false);
Anders Waldenborgb932c662013-10-23 08:10:20 +000070 } else if (argc == 2 && !strcmp(argv[1], "--module-list-functions")) {
71 return module_list_functions();
72 } else if (argc == 2 && !strcmp(argv[1], "--module-list-globals")) {
73 return module_list_globals();
74 } else if (argc == 2 && !strcmp(argv[1], "--targets-list")) {
75 return targets_list();
76 } else if (argc == 2 && !strcmp(argv[1], "--object-list-sections")) {
77 return object_list_sections();
78 } else if (argc == 2 && !strcmp(argv[1], "--object-list-symbols")) {
79 return object_list_symbols();
80 } else if (argc == 2 && !strcmp(argv[1], "--disassemble")) {
81 return disassemble();
82 } else if (argc == 2 && !strcmp(argv[1], "--calc")) {
83 return calc();
Bjorn Steinbrinka09ac002015-01-28 16:35:59 +000084 } else if (argc == 2 && !strcmp(argv[1], "--add-named-metadata-operand")) {
85 return add_named_metadata_operand();
86 } else if (argc == 2 && !strcmp(argv[1], "--set-metadata")) {
87 return set_metadata();
Amaury Sechete8ea7d82016-02-04 23:26:19 +000088 } else if (argc == 2 && !strcmp(argv[1], "--echo")) {
89 return echo();
Anders Waldenborgb932c662013-10-23 08:10:20 +000090 } else {
91 print_usage();
92 }
93
94 return 1;
95}