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 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, " * --lazy-module-dump\n"); 27 fprintf(stderr, 28 " Lazily read bytecode from stdin - print disassembly\n\n"); 29 fprintf(stderr, " * --new-module-dump\n"); 30 fprintf(stderr, " Read bytecode from stdin - print disassembly\n\n"); 31 fprintf(stderr, " * --lazy-new-module-dump\n"); 32 fprintf(stderr, 33 " Lazily read bytecode from stdin - print disassembly\n\n"); 34 fprintf(stderr, " * --module-list-functions\n"); 35 fprintf(stderr, 36 " Read bytecode from stdin - list summary of functions\n\n"); 37 fprintf(stderr, " * --module-list-globals\n"); 38 fprintf(stderr, " Read bytecode from stdin - list summary of globals\n\n"); 39 fprintf(stderr, " * --targets-list\n"); 40 fprintf(stderr, " List available targets\n\n"); 41 fprintf(stderr, " * --object-list-sections\n"); 42 fprintf(stderr, " Read object file form stdin - list sections\n\n"); 43 fprintf(stderr, " * --object-list-symbols\n"); 44 fprintf(stderr, 45 " Read object file form stdin - list symbols (like nm)\n\n"); 46 fprintf(stderr, " * --disassemble\n"); 47 fprintf(stderr, " Read lines of triple, hex ascii machine code from stdin " 48 "- print disassembly\n\n"); 49 fprintf(stderr, " * --calc\n"); 50 fprintf( 51 stderr, 52 " Read lines of name, rpn from stdin - print generated module\n\n"); 53 } 54 55 int main(int argc, char **argv) { 56 LLVMPassRegistryRef pr = LLVMGetGlobalPassRegistry(); 57 58 LLVMInitializeCore(pr); 59 60 if (argc == 2 && !strcmp(argv[1], "--lazy-new-module-dump")) { 61 return module_dump(true, true); 62 } else if (argc == 2 && !strcmp(argv[1], "--new-module-dump")) { 63 return module_dump(false, true); 64 } else if (argc == 2 && !strcmp(argv[1], "--lazy-module-dump")) { 65 return module_dump(true, false); 66 } else if (argc == 2 && !strcmp(argv[1], "--module-dump")) { 67 return module_dump(false, false); 68 } else if (argc == 2 && !strcmp(argv[1], "--module-list-functions")) { 69 return module_list_functions(); 70 } else if (argc == 2 && !strcmp(argv[1], "--module-list-globals")) { 71 return module_list_globals(); 72 } else if (argc == 2 && !strcmp(argv[1], "--targets-list")) { 73 return targets_list(); 74 } else if (argc == 2 && !strcmp(argv[1], "--object-list-sections")) { 75 return object_list_sections(); 76 } else if (argc == 2 && !strcmp(argv[1], "--object-list-symbols")) { 77 return object_list_symbols(); 78 } else if (argc == 2 && !strcmp(argv[1], "--disassemble")) { 79 return disassemble(); 80 } else if (argc == 2 && !strcmp(argv[1], "--calc")) { 81 return calc(); 82 } else if (argc == 2 && !strcmp(argv[1], "--add-named-metadata-operand")) { 83 return add_named_metadata_operand(); 84 } else if (argc == 2 && !strcmp(argv[1], "--set-metadata")) { 85 return set_metadata(); 86 } else { 87 print_usage(); 88 } 89 90 return 1; 91 } 92