diff options
Diffstat (limited to 'tools/llvm-c-test')
-rw-r--r-- | tools/llvm-c-test/CMakeLists.txt | 27 | ||||
-rw-r--r-- | tools/llvm-c-test/disassemble.c | 20 |
2 files changed, 40 insertions, 7 deletions
diff --git a/tools/llvm-c-test/CMakeLists.txt b/tools/llvm-c-test/CMakeLists.txt index 34fea3d69c16a..baf970a02781a 100644 --- a/tools/llvm-c-test/CMakeLists.txt +++ b/tools/llvm-c-test/CMakeLists.txt @@ -7,6 +7,29 @@ set(LLVM_LINK_COMPONENTS Target ) +# We should only have llvm-c-test use libLLVM if libLLVM is built with the +# default list of components. Using libLLVM with custom components can result in +# build failures. + +set (USE_LLVM_DYLIB FALSE) + +if (TARGET LLVM) + set (USE_LLVM_DYLIB TRUE) + if (DEFINED LLVM_DYLIB_COMPONENTS) + foreach(c in ${LLVM_LINK_COMPONENTS}) + list(FIND LLVM_DYLIB_COMPONENTS ${c} C_IDX) + if (C_IDX EQUAL -1) + set(USE_LLVM_DYLIB FALSE) + break() + endif() + endforeach() + endif() +endif() + +if(USE_LLVM_DYLIB) + set(LLVM_LINK_COMPONENTS) +endif() + if (LLVM_COMPILER_IS_GCC_COMPATIBLE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wstrict-prototypes") endif () @@ -21,3 +44,7 @@ add_llvm_tool(llvm-c-test object.c targets.c ) + +if(USE_LLVM_DYLIB) + target_link_libraries(llvm-c-test LLVM) +endif() diff --git a/tools/llvm-c-test/disassemble.c b/tools/llvm-c-test/disassemble.c index eb40bf3d4461d..05a9218d014a6 100644 --- a/tools/llvm-c-test/disassemble.c +++ b/tools/llvm-c-test/disassemble.c @@ -18,6 +18,7 @@ #include "llvm-c/Target.h" #include <stdio.h> #include <stdlib.h> +#include <string.h> static void pprint(int pos, unsigned char *buf, int len, const char *disasm) { int i; @@ -33,13 +34,15 @@ static void pprint(int pos, unsigned char *buf, int len, const char *disasm) { printf(" %s\n", disasm); } -static void do_disassemble(const char *triple, unsigned char *buf, int siz) { - LLVMDisasmContextRef D = LLVMCreateDisasm(triple, NULL, 0, NULL, NULL); +static void do_disassemble(const char *triple, const char *features, + unsigned char *buf, int siz) { + LLVMDisasmContextRef D = LLVMCreateDisasmCPUFeatures(triple, "", features, + NULL, 0, NULL, NULL); char outline[1024]; int pos; if (!D) { - printf("ERROR: Couldn't create disassebler for triple %s\n", triple); + printf("ERROR: Couldn't create disassembler for triple %s\n", triple); return; } @@ -62,19 +65,22 @@ static void do_disassemble(const char *triple, unsigned char *buf, int siz) { static void handle_line(char **tokens, int ntokens) { unsigned char disbuf[128]; size_t disbuflen = 0; - char *triple = tokens[0]; + const char *triple = tokens[0]; + const char *features = tokens[1]; int i; - printf("triple: %s\n", triple); + printf("triple: %s, features: %s\n", triple, features); + if (!strcmp(features, "NULL")) + features = ""; - for (i = 1; i < ntokens; i++) { + for (i = 2; i < ntokens; i++) { disbuf[disbuflen++] = strtol(tokens[i], NULL, 16); if (disbuflen >= sizeof(disbuf)) { fprintf(stderr, "Warning: Too long line, truncating\n"); break; } } - do_disassemble(triple, disbuf, disbuflen); + do_disassemble(triple, features, disbuf, disbuflen); } int disassemble(void) { |