You've already forked linux-packaging-mono
Imported Upstream version 5.18.0.167
Former-commit-id: 289509151e0fee68a1b591a20c9f109c3c789d3a
This commit is contained in:
parent
e19d552987
commit
b084638f15
56
external/llvm/tools/llvm-c-test/CMakeLists.txt
vendored
56
external/llvm/tools/llvm-c-test/CMakeLists.txt
vendored
@ -1,56 +0,0 @@
|
||||
set(LLVM_LINK_COMPONENTS
|
||||
${LLVM_TARGETS_TO_BUILD}
|
||||
BitReader
|
||||
Core
|
||||
MCDisassembler
|
||||
Object
|
||||
Support
|
||||
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 ()
|
||||
|
||||
add_llvm_tool(llvm-c-test
|
||||
attributes.c
|
||||
calc.c
|
||||
debuginfo.c
|
||||
diagnostic.c
|
||||
disassemble.c
|
||||
echo.cpp
|
||||
helpers.c
|
||||
include-all.c
|
||||
main.c
|
||||
module.c
|
||||
metadata.c
|
||||
object.c
|
||||
targets.c
|
||||
)
|
||||
|
||||
if(USE_LLVM_DYLIB)
|
||||
target_link_libraries(llvm-c-test LLVM)
|
||||
endif()
|
77
external/llvm/tools/llvm-c-test/attributes.c
vendored
77
external/llvm/tools/llvm-c-test/attributes.c
vendored
@ -1,77 +0,0 @@
|
||||
/*===-- attributes.c - tool for testing libLLVM and llvm-c API ------------===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file implements the --test-attributes and --test-callsite-attributes *|
|
||||
|* commands in llvm-c-test. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c-test.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int llvm_test_function_attributes(void) {
|
||||
LLVMEnablePrettyStackTrace();
|
||||
|
||||
LLVMModuleRef M = llvm_load_module(false, true);
|
||||
|
||||
LLVMValueRef F = LLVMGetFirstFunction(M);
|
||||
while (F) {
|
||||
// Read attributes
|
||||
int Idx, ParamCount;
|
||||
for (Idx = LLVMAttributeFunctionIndex, ParamCount = LLVMCountParams(F);
|
||||
Idx <= ParamCount; ++Idx) {
|
||||
int AttrCount = LLVMGetAttributeCountAtIndex(F, Idx);
|
||||
LLVMAttributeRef *Attrs =
|
||||
(LLVMAttributeRef *)malloc(AttrCount * sizeof(LLVMAttributeRef));
|
||||
LLVMGetAttributesAtIndex(F, Idx, Attrs);
|
||||
free(Attrs);
|
||||
}
|
||||
F = LLVMGetNextFunction(F);
|
||||
}
|
||||
|
||||
LLVMDisposeModule(M);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int llvm_test_callsite_attributes(void) {
|
||||
LLVMEnablePrettyStackTrace();
|
||||
|
||||
LLVMModuleRef M = llvm_load_module(false, true);
|
||||
|
||||
LLVMValueRef F = LLVMGetFirstFunction(M);
|
||||
while (F) {
|
||||
LLVMBasicBlockRef BB;
|
||||
for (BB = LLVMGetFirstBasicBlock(F); BB; BB = LLVMGetNextBasicBlock(BB)) {
|
||||
LLVMValueRef I;
|
||||
for (I = LLVMGetFirstInstruction(BB); I; I = LLVMGetNextInstruction(I)) {
|
||||
if (LLVMIsACallInst(I)) {
|
||||
// Read attributes
|
||||
int Idx, ParamCount;
|
||||
for (Idx = LLVMAttributeFunctionIndex,
|
||||
ParamCount = LLVMCountParams(F);
|
||||
Idx <= ParamCount; ++Idx) {
|
||||
int AttrCount = LLVMGetCallSiteAttributeCount(I, Idx);
|
||||
LLVMAttributeRef *Attrs = (LLVMAttributeRef *)malloc(
|
||||
AttrCount * sizeof(LLVMAttributeRef));
|
||||
LLVMGetCallSiteAttributes(I, Idx, Attrs);
|
||||
free(Attrs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
F = LLVMGetNextFunction(F);
|
||||
}
|
||||
|
||||
LLVMDisposeModule(M);
|
||||
|
||||
return 0;
|
||||
}
|
147
external/llvm/tools/llvm-c-test/calc.c
vendored
147
external/llvm/tools/llvm-c-test/calc.c
vendored
@ -1,147 +0,0 @@
|
||||
/*===-- calc.c - tool for testing libLLVM and llvm-c API ------------------===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file implements the --calc command in llvm-c-test. --calc reads lines *|
|
||||
|* from stdin, parses them as a name and an expression in reverse polish *|
|
||||
|* notation and prints a module with a function with the expression. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c-test.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
typedef LLVMValueRef (*binop_func_t)(LLVMBuilderRef, LLVMValueRef LHS,
|
||||
LLVMValueRef RHS, const char *Name);
|
||||
|
||||
static LLVMOpcode op_to_opcode(char op) {
|
||||
switch (op) {
|
||||
case '+': return LLVMAdd;
|
||||
case '-': return LLVMSub;
|
||||
case '*': return LLVMMul;
|
||||
case '/': return LLVMSDiv;
|
||||
case '&': return LLVMAnd;
|
||||
case '|': return LLVMOr;
|
||||
case '^': return LLVMXor;
|
||||
}
|
||||
assert(0 && "unknown operation");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define MAX_DEPTH 32
|
||||
|
||||
static LLVMValueRef build_from_tokens(char **tokens, int ntokens,
|
||||
LLVMBuilderRef builder,
|
||||
LLVMValueRef param) {
|
||||
LLVMValueRef stack[MAX_DEPTH];
|
||||
int depth = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ntokens; i++) {
|
||||
char tok = tokens[i][0];
|
||||
switch (tok) {
|
||||
case '+':
|
||||
case '-':
|
||||
case '*':
|
||||
case '/':
|
||||
case '&':
|
||||
case '|':
|
||||
case '^':
|
||||
if (depth < 2) {
|
||||
printf("stack underflow\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
stack[depth - 2] = LLVMBuildBinOp(builder, op_to_opcode(tok),
|
||||
stack[depth - 1], stack[depth - 2], "");
|
||||
depth--;
|
||||
|
||||
break;
|
||||
|
||||
case '@': {
|
||||
LLVMValueRef off;
|
||||
|
||||
if (depth < 1) {
|
||||
printf("stack underflow\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
off = LLVMBuildGEP(builder, param, &stack[depth - 1], 1, "");
|
||||
stack[depth - 1] = LLVMBuildLoad(builder, off, "");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
char *end;
|
||||
long val = strtol(tokens[i], &end, 0);
|
||||
if (end[0] != '\0') {
|
||||
printf("error parsing number\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (depth >= MAX_DEPTH) {
|
||||
printf("stack overflow\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
stack[depth++] = LLVMConstInt(LLVMInt64Type(), val, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (depth < 1) {
|
||||
printf("stack underflow at return\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LLVMBuildRet(builder, stack[depth - 1]);
|
||||
|
||||
return stack[depth - 1];
|
||||
}
|
||||
|
||||
static void handle_line(char **tokens, int ntokens) {
|
||||
char *name = tokens[0];
|
||||
LLVMValueRef param;
|
||||
LLVMValueRef res;
|
||||
|
||||
LLVMModuleRef M = LLVMModuleCreateWithName(name);
|
||||
|
||||
LLVMTypeRef I64ty = LLVMInt64Type();
|
||||
LLVMTypeRef I64Ptrty = LLVMPointerType(I64ty, 0);
|
||||
LLVMTypeRef Fty = LLVMFunctionType(I64ty, &I64Ptrty, 1, 0);
|
||||
|
||||
LLVMValueRef F = LLVMAddFunction(M, name, Fty);
|
||||
LLVMBuilderRef builder = LLVMCreateBuilder();
|
||||
LLVMPositionBuilderAtEnd(builder, LLVMAppendBasicBlock(F, "entry"));
|
||||
|
||||
LLVMGetParams(F, ¶m);
|
||||
LLVMSetValueName(param, "in");
|
||||
|
||||
res = build_from_tokens(tokens + 1, ntokens - 1, builder, param);
|
||||
if (res) {
|
||||
char *irstr = LLVMPrintModuleToString(M);
|
||||
puts(irstr);
|
||||
LLVMDisposeMessage(irstr);
|
||||
}
|
||||
|
||||
LLVMDisposeBuilder(builder);
|
||||
|
||||
LLVMDisposeModule(M);
|
||||
}
|
||||
|
||||
int llvm_calc(void) {
|
||||
|
||||
llvm_tokenize_stdin(handle_line);
|
||||
|
||||
return 0;
|
||||
}
|
36
external/llvm/tools/llvm-c-test/debuginfo.c
vendored
36
external/llvm/tools/llvm-c-test/debuginfo.c
vendored
@ -1,36 +0,0 @@
|
||||
/*===-- debuginfo.c - tool for testing libLLVM and llvm-c API -------------===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* Tests for the LLVM C DebugInfo API *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c/DebugInfo.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int llvm_test_dibuilder(void) {
|
||||
LLVMModuleRef M = LLVMModuleCreateWithName("debuginfo.c");
|
||||
LLVMDIBuilderRef DIB = LLVMCreateDIBuilder(M);
|
||||
|
||||
LLVMMetadataRef File = LLVMDIBuilderCreateFile(DIB, "debuginfo.c", 12,
|
||||
".", 1);
|
||||
|
||||
LLVMDIBuilderCreateCompileUnit(DIB,
|
||||
LLVMDWARFSourceLanguageC, File,"llvm-c-test", 11, 0, NULL, 0, 0,
|
||||
NULL, 0, LLVMDWARFEmissionFull, 0, 0, 0);
|
||||
|
||||
char *MStr = LLVMPrintModuleToString(M);
|
||||
puts(MStr);
|
||||
LLVMDisposeMessage(MStr);
|
||||
|
||||
LLVMDisposeDIBuilder(DIB);
|
||||
LLVMDisposeModule(M);
|
||||
|
||||
return 0;
|
||||
}
|
89
external/llvm/tools/llvm-c-test/diagnostic.c
vendored
89
external/llvm/tools/llvm-c-test/diagnostic.c
vendored
@ -1,89 +0,0 @@
|
||||
//===-- diagnostic.cpp - tool for testing libLLVM and llvm-c API ----------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements the --test-diagnostic-handler command in llvm-c-test.
|
||||
//
|
||||
// This command uses the C API to read a module with a custom diagnostic
|
||||
// handler set to test the diagnostic handler functionality.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm-c-test.h"
|
||||
#include "llvm-c/BitReader.h"
|
||||
#include "llvm-c/Core.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static void diagnosticHandler(LLVMDiagnosticInfoRef DI, void *C) {
|
||||
fprintf(stderr, "Executing diagnostic handler\n");
|
||||
|
||||
fprintf(stderr, "Diagnostic severity is of type ");
|
||||
switch (LLVMGetDiagInfoSeverity(DI)) {
|
||||
case LLVMDSError:
|
||||
fprintf(stderr, "error");
|
||||
break;
|
||||
case LLVMDSWarning:
|
||||
fprintf(stderr, "warning");
|
||||
break;
|
||||
case LLVMDSRemark:
|
||||
fprintf(stderr, "remark");
|
||||
break;
|
||||
case LLVMDSNote:
|
||||
fprintf(stderr, "note");
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
(*(int *)C) = 1;
|
||||
}
|
||||
|
||||
static int handlerCalled = 0;
|
||||
|
||||
int llvm_test_diagnostic_handler(void) {
|
||||
LLVMContextRef C = LLVMGetGlobalContext();
|
||||
LLVMContextSetDiagnosticHandler(C, diagnosticHandler, &handlerCalled);
|
||||
|
||||
if (LLVMContextGetDiagnosticHandler(C) != diagnosticHandler) {
|
||||
fprintf(stderr, "LLVMContext{Set,Get}DiagnosticHandler failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int *DC = (int *)LLVMContextGetDiagnosticContext(C);
|
||||
if (DC != &handlerCalled || *DC) {
|
||||
fprintf(stderr, "LLVMContextGetDiagnosticContext failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
LLVMMemoryBufferRef MB;
|
||||
char *msg = NULL;
|
||||
if (LLVMCreateMemoryBufferWithSTDIN(&MB, &msg)) {
|
||||
fprintf(stderr, "Error reading file: %s\n", msg);
|
||||
LLVMDisposeMessage(msg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
LLVMModuleRef M;
|
||||
int Ret = LLVMGetBitcodeModule2(MB, &M);
|
||||
if (Ret) {
|
||||
// We do not return if the bitcode was invalid, as we want to test whether
|
||||
// the diagnostic handler was executed.
|
||||
fprintf(stderr, "Error parsing bitcode: %s\n", msg);
|
||||
}
|
||||
|
||||
LLVMDisposeMemoryBuffer(MB);
|
||||
|
||||
if (handlerCalled) {
|
||||
fprintf(stderr, "Diagnostic handler was called while loading module\n");
|
||||
} else {
|
||||
fprintf(stderr, "Diagnostic handler was not called while loading module\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
94
external/llvm/tools/llvm-c-test/disassemble.c
vendored
94
external/llvm/tools/llvm-c-test/disassemble.c
vendored
@ -1,94 +0,0 @@
|
||||
/*===-- disassemble.c - tool for testing libLLVM and llvm-c API -----------===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file implements the --disassemble command in llvm-c-test. *|
|
||||
|* --disassemble reads lines from stdin, parses them as a triple and hex *|
|
||||
|* machine code, and prints disassembly of the machine code. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c-test.h"
|
||||
#include "llvm-c/Disassembler.h"
|
||||
#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;
|
||||
printf("%04x: ", pos);
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (i < len) {
|
||||
printf("%02x ", buf[i]);
|
||||
} else {
|
||||
printf(" ");
|
||||
}
|
||||
}
|
||||
|
||||
printf(" %s\n", disasm);
|
||||
}
|
||||
|
||||
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 disassembler for triple %s\n", triple);
|
||||
return;
|
||||
}
|
||||
|
||||
pos = 0;
|
||||
while (pos < siz) {
|
||||
size_t l = LLVMDisasmInstruction(D, buf + pos, siz - pos, 0, outline,
|
||||
sizeof(outline));
|
||||
if (!l) {
|
||||
pprint(pos, buf + pos, 1, "\t???");
|
||||
pos++;
|
||||
} else {
|
||||
pprint(pos, buf + pos, l, outline);
|
||||
pos += l;
|
||||
}
|
||||
}
|
||||
|
||||
LLVMDisasmDispose(D);
|
||||
}
|
||||
|
||||
static void handle_line(char **tokens, int ntokens) {
|
||||
unsigned char disbuf[128];
|
||||
size_t disbuflen = 0;
|
||||
const char *triple = tokens[0];
|
||||
const char *features = tokens[1];
|
||||
int i;
|
||||
|
||||
printf("triple: %s, features: %s\n", triple, features);
|
||||
if (!strcmp(features, "NULL"))
|
||||
features = "";
|
||||
|
||||
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, features, disbuf, disbuflen);
|
||||
}
|
||||
|
||||
int llvm_disassemble(void) {
|
||||
LLVMInitializeAllTargetInfos();
|
||||
LLVMInitializeAllTargetMCs();
|
||||
LLVMInitializeAllDisassemblers();
|
||||
|
||||
llvm_tokenize_stdin(handle_line);
|
||||
|
||||
return 0;
|
||||
}
|
958
external/llvm/tools/llvm-c-test/echo.cpp
vendored
958
external/llvm/tools/llvm-c-test/echo.cpp
vendored
File diff suppressed because it is too large
Load Diff
39
external/llvm/tools/llvm-c-test/helpers.c
vendored
39
external/llvm/tools/llvm-c-test/helpers.c
vendored
@ -1,39 +0,0 @@
|
||||
/*===-- helpers.c - tool for testing libLLVM and llvm-c API ---------------===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* Helper functions *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MAX_TOKENS 512
|
||||
#define MAX_LINE_LEN 1024
|
||||
|
||||
void llvm_tokenize_stdin(void (*cb)(char **tokens, int ntokens)) {
|
||||
char line[MAX_LINE_LEN];
|
||||
char *tokbuf[MAX_TOKENS];
|
||||
|
||||
while (fgets(line, sizeof(line), stdin)) {
|
||||
int c = 0;
|
||||
|
||||
if (line[0] == ';' || line[0] == '\n')
|
||||
continue;
|
||||
|
||||
while (c < MAX_TOKENS) {
|
||||
tokbuf[c] = strtok(c ? NULL : line, " \n");
|
||||
if (!tokbuf[c])
|
||||
break;
|
||||
c++;
|
||||
}
|
||||
if (c)
|
||||
cb(tokbuf, c);
|
||||
}
|
||||
}
|
33
external/llvm/tools/llvm-c-test/include-all.c
vendored
33
external/llvm/tools/llvm-c-test/include-all.c
vendored
@ -1,33 +0,0 @@
|
||||
/*===-- include-all.c - tool for testing libLLVM and llvm-c API -----------===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file doesn't have any actual code. It just make sure that all *|
|
||||
|* the llvm-c include files are good and doesn't generate any warnings *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
// FIXME: Autogenerate this list
|
||||
|
||||
#include "llvm-c/Analysis.h"
|
||||
#include "llvm-c/BitReader.h"
|
||||
#include "llvm-c/BitWriter.h"
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm-c/Disassembler.h"
|
||||
#include "llvm-c/ExecutionEngine.h"
|
||||
#include "llvm-c/Initialization.h"
|
||||
#include "llvm-c/LinkTimeOptimizer.h"
|
||||
#include "llvm-c/Linker.h"
|
||||
#include "llvm-c/Object.h"
|
||||
#include "llvm-c/Target.h"
|
||||
#include "llvm-c/TargetMachine.h"
|
||||
#include "llvm-c/Transforms/IPO.h"
|
||||
#include "llvm-c/Transforms/PassManagerBuilder.h"
|
||||
#include "llvm-c/Transforms/Scalar.h"
|
||||
#include "llvm-c/Transforms/Vectorize.h"
|
||||
#include "llvm-c/lto.h"
|
66
external/llvm/tools/llvm-c-test/llvm-c-test.h
vendored
66
external/llvm/tools/llvm-c-test/llvm-c-test.h
vendored
@ -1,66 +0,0 @@
|
||||
/*===-- llvm-c-test.h - tool for testing libLLVM and llvm-c API -----------===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* Header file for llvm-c-test *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
#ifndef LLVM_C_TEST_H
|
||||
#define LLVM_C_TEST_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "llvm-c/Core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// helpers.c
|
||||
void llvm_tokenize_stdin(void (*cb)(char **tokens, int ntokens));
|
||||
|
||||
// module.c
|
||||
LLVMModuleRef llvm_load_module(bool Lazy, bool New);
|
||||
int llvm_module_dump(bool Lazy, bool New);
|
||||
int llvm_module_list_functions(void);
|
||||
int llvm_module_list_globals(void);
|
||||
|
||||
// calc.c
|
||||
int llvm_calc(void);
|
||||
|
||||
// disassemble.c
|
||||
int llvm_disassemble(void);
|
||||
|
||||
// debuginfo.c
|
||||
int llvm_test_dibuilder(void);
|
||||
|
||||
// metadata.c
|
||||
int llvm_add_named_metadata_operand(void);
|
||||
int llvm_set_metadata(void);
|
||||
|
||||
// object.c
|
||||
int llvm_object_list_sections(void);
|
||||
int llvm_object_list_symbols(void);
|
||||
|
||||
// targets.c
|
||||
int llvm_targets_list(void);
|
||||
|
||||
// echo.c
|
||||
int llvm_echo(void);
|
||||
|
||||
// diagnostic.c
|
||||
int llvm_test_diagnostic_handler(void);
|
||||
|
||||
// attributes.c
|
||||
int llvm_test_function_attributes(void);
|
||||
int llvm_test_callsite_attributes(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* !defined(__cplusplus) */
|
||||
|
||||
#endif
|
107
external/llvm/tools/llvm-c-test/main.c
vendored
107
external/llvm/tools/llvm-c-test/main.c
vendored
@ -1,107 +0,0 @@
|
||||
/*===-- main.c - tool for testing libLLVM and llvm-c API ------------------===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* Main file for llvm-c-tests. "Parses" arguments and dispatches. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c-test.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static void print_usage(void) {
|
||||
fprintf(stderr, "llvm-c-test command\n\n");
|
||||
fprintf(stderr, " Commands:\n");
|
||||
fprintf(stderr, " * --module-dump\n");
|
||||
fprintf(stderr, " Read bitcode from stdin - print disassembly\n\n");
|
||||
fprintf(stderr, " * --lazy-module-dump\n");
|
||||
fprintf(stderr,
|
||||
" Lazily read bitcode from stdin - print disassembly\n\n");
|
||||
fprintf(stderr, " * --new-module-dump\n");
|
||||
fprintf(stderr, " Read bitcode from stdin - print disassembly\n\n");
|
||||
fprintf(stderr, " * --lazy-new-module-dump\n");
|
||||
fprintf(stderr,
|
||||
" Lazily read bitcode from stdin - print disassembly\n\n");
|
||||
fprintf(stderr, " * --module-list-functions\n");
|
||||
fprintf(stderr,
|
||||
" Read bitcode from stdin - list summary of functions\n\n");
|
||||
fprintf(stderr, " * --module-list-globals\n");
|
||||
fprintf(stderr, " Read bitcode from stdin - list summary of globals\n\n");
|
||||
fprintf(stderr, " * --targets-list\n");
|
||||
fprintf(stderr, " List available targets\n\n");
|
||||
fprintf(stderr, " * --object-list-sections\n");
|
||||
fprintf(stderr, " Read object file form stdin - list sections\n\n");
|
||||
fprintf(stderr, " * --object-list-symbols\n");
|
||||
fprintf(stderr,
|
||||
" Read object file form stdin - list symbols (like nm)\n\n");
|
||||
fprintf(stderr, " * --disassemble\n");
|
||||
fprintf(stderr, " Read lines of triple, hex ascii machine code from stdin "
|
||||
"- print disassembly\n\n");
|
||||
fprintf(stderr, " * --calc\n");
|
||||
fprintf(
|
||||
stderr,
|
||||
" Read lines of name, rpn from stdin - print generated module\n\n");
|
||||
fprintf(stderr, " * --echo\n");
|
||||
fprintf(stderr,
|
||||
" Read bitcode file form stdin - print it back out\n\n");
|
||||
fprintf(stderr, " * --test-diagnostic-handler\n");
|
||||
fprintf(stderr,
|
||||
" Read bitcode file form stdin with a diagnostic handler set\n\n");
|
||||
fprintf(stderr, " * --test-dibuilder\n");
|
||||
fprintf(stderr,
|
||||
" Run tests for the DIBuilder C API - print generated module\n\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
LLVMPassRegistryRef pr = LLVMGetGlobalPassRegistry();
|
||||
|
||||
LLVMInitializeCore(pr);
|
||||
|
||||
if (argc == 2 && !strcmp(argv[1], "--lazy-new-module-dump")) {
|
||||
return llvm_module_dump(true, true);
|
||||
} else if (argc == 2 && !strcmp(argv[1], "--new-module-dump")) {
|
||||
return llvm_module_dump(false, true);
|
||||
} else if (argc == 2 && !strcmp(argv[1], "--lazy-module-dump")) {
|
||||
return llvm_module_dump(true, false);
|
||||
} else if (argc == 2 && !strcmp(argv[1], "--module-dump")) {
|
||||
return llvm_module_dump(false, false);
|
||||
} else if (argc == 2 && !strcmp(argv[1], "--module-list-functions")) {
|
||||
return llvm_module_list_functions();
|
||||
} else if (argc == 2 && !strcmp(argv[1], "--module-list-globals")) {
|
||||
return llvm_module_list_globals();
|
||||
} else if (argc == 2 && !strcmp(argv[1], "--targets-list")) {
|
||||
return llvm_targets_list();
|
||||
} else if (argc == 2 && !strcmp(argv[1], "--object-list-sections")) {
|
||||
return llvm_object_list_sections();
|
||||
} else if (argc == 2 && !strcmp(argv[1], "--object-list-symbols")) {
|
||||
return llvm_object_list_symbols();
|
||||
} else if (argc == 2 && !strcmp(argv[1], "--disassemble")) {
|
||||
return llvm_disassemble();
|
||||
} else if (argc == 2 && !strcmp(argv[1], "--calc")) {
|
||||
return llvm_calc();
|
||||
} else if (argc == 2 && !strcmp(argv[1], "--add-named-metadata-operand")) {
|
||||
return llvm_add_named_metadata_operand();
|
||||
} else if (argc == 2 && !strcmp(argv[1], "--set-metadata")) {
|
||||
return llvm_set_metadata();
|
||||
} else if (argc == 2 && !strcmp(argv[1], "--test-function-attributes")) {
|
||||
return llvm_test_function_attributes();
|
||||
} else if (argc == 2 && !strcmp(argv[1], "--test-callsite-attributes")) {
|
||||
return llvm_test_callsite_attributes();
|
||||
} else if (argc == 2 && !strcmp(argv[1], "--echo")) {
|
||||
return llvm_echo();
|
||||
} else if (argc == 2 && !strcmp(argv[1], "--test-diagnostic-handler")) {
|
||||
return llvm_test_diagnostic_handler();
|
||||
} else if (argc == 2 && !strcmp(argv[1], "--test-dibuilder")) {
|
||||
return llvm_test_dibuilder();
|
||||
} else {
|
||||
print_usage();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
42
external/llvm/tools/llvm-c-test/metadata.c
vendored
42
external/llvm/tools/llvm-c-test/metadata.c
vendored
@ -1,42 +0,0 @@
|
||||
/*===-- object.c - tool for testing libLLVM and llvm-c API ----------------===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file implements the --add-named-metadata-operand and --set-metadata *|
|
||||
|* commands in llvm-c-test. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c-test.h"
|
||||
|
||||
int llvm_add_named_metadata_operand(void) {
|
||||
LLVMModuleRef m = LLVMModuleCreateWithName("Mod");
|
||||
LLVMValueRef values[] = { LLVMConstInt(LLVMInt32Type(), 0, 0) };
|
||||
|
||||
// This used to trigger an assertion
|
||||
LLVMAddNamedMetadataOperand(m, "name", LLVMMDNode(values, 1));
|
||||
|
||||
LLVMDisposeModule(m);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int llvm_set_metadata(void) {
|
||||
LLVMBuilderRef b = LLVMCreateBuilder();
|
||||
LLVMValueRef values[] = { LLVMConstInt(LLVMInt32Type(), 0, 0) };
|
||||
|
||||
// This used to trigger an assertion
|
||||
LLVMSetMetadata(
|
||||
LLVMBuildRetVoid(b),
|
||||
LLVMGetMDKindID("kind", 4),
|
||||
LLVMMDNode(values, 1));
|
||||
|
||||
LLVMDisposeBuilder(b);
|
||||
|
||||
return 0;
|
||||
}
|
138
external/llvm/tools/llvm-c-test/module.c
vendored
138
external/llvm/tools/llvm-c-test/module.c
vendored
@ -1,138 +0,0 @@
|
||||
/*===-- module.c - tool for testing libLLVM and llvm-c API ----------------===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file implements the --module-dump, --module-list-functions and *|
|
||||
|* --module-list-globals commands in llvm-c-test. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c-test.h"
|
||||
#include "llvm-c/BitReader.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void diagnosticHandler(LLVMDiagnosticInfoRef DI, void *C) {
|
||||
char *CErr = LLVMGetDiagInfoDescription(DI);
|
||||
fprintf(stderr, "Error with new bitcode parser: %s\n", CErr);
|
||||
LLVMDisposeMessage(CErr);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
LLVMModuleRef llvm_load_module(bool Lazy, bool New) {
|
||||
LLVMMemoryBufferRef MB;
|
||||
LLVMModuleRef M;
|
||||
char *msg = NULL;
|
||||
|
||||
if (LLVMCreateMemoryBufferWithSTDIN(&MB, &msg)) {
|
||||
fprintf(stderr, "Error reading file: %s\n", msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
LLVMBool Ret;
|
||||
if (New) {
|
||||
LLVMContextRef C = LLVMGetGlobalContext();
|
||||
LLVMContextSetDiagnosticHandler(C, diagnosticHandler, NULL);
|
||||
if (Lazy)
|
||||
Ret = LLVMGetBitcodeModule2(MB, &M);
|
||||
else
|
||||
Ret = LLVMParseBitcode2(MB, &M);
|
||||
} else {
|
||||
if (Lazy)
|
||||
Ret = LLVMGetBitcodeModule(MB, &M, &msg);
|
||||
else
|
||||
Ret = LLVMParseBitcode(MB, &M, &msg);
|
||||
}
|
||||
|
||||
if (Ret) {
|
||||
fprintf(stderr, "Error parsing bitcode: %s\n", msg);
|
||||
LLVMDisposeMemoryBuffer(MB);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!Lazy)
|
||||
LLVMDisposeMemoryBuffer(MB);
|
||||
|
||||
return M;
|
||||
}
|
||||
|
||||
int llvm_module_dump(bool Lazy, bool New) {
|
||||
LLVMModuleRef M = llvm_load_module(Lazy, New);
|
||||
|
||||
char *irstr = LLVMPrintModuleToString(M);
|
||||
puts(irstr);
|
||||
LLVMDisposeMessage(irstr);
|
||||
|
||||
LLVMDisposeModule(M);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int llvm_module_list_functions(void) {
|
||||
LLVMModuleRef M = llvm_load_module(false, false);
|
||||
LLVMValueRef f;
|
||||
|
||||
f = LLVMGetFirstFunction(M);
|
||||
while (f) {
|
||||
if (LLVMIsDeclaration(f)) {
|
||||
printf("FunctionDeclaration: %s\n", LLVMGetValueName(f));
|
||||
} else {
|
||||
LLVMBasicBlockRef bb;
|
||||
LLVMValueRef isn;
|
||||
unsigned nisn = 0;
|
||||
unsigned nbb = 0;
|
||||
|
||||
printf("FunctionDefinition: %s [#bb=%u]\n", LLVMGetValueName(f),
|
||||
LLVMCountBasicBlocks(f));
|
||||
|
||||
for (bb = LLVMGetFirstBasicBlock(f); bb;
|
||||
bb = LLVMGetNextBasicBlock(bb)) {
|
||||
nbb++;
|
||||
for (isn = LLVMGetFirstInstruction(bb); isn;
|
||||
isn = LLVMGetNextInstruction(isn)) {
|
||||
nisn++;
|
||||
if (LLVMIsACallInst(isn)) {
|
||||
LLVMValueRef callee =
|
||||
LLVMGetOperand(isn, LLVMGetNumOperands(isn) - 1);
|
||||
printf(" calls: %s\n", LLVMGetValueName(callee));
|
||||
}
|
||||
}
|
||||
}
|
||||
printf(" #isn: %u\n", nisn);
|
||||
printf(" #bb: %u\n\n", nbb);
|
||||
}
|
||||
f = LLVMGetNextFunction(f);
|
||||
}
|
||||
|
||||
LLVMDisposeModule(M);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int llvm_module_list_globals(void) {
|
||||
LLVMModuleRef M = llvm_load_module(false, false);
|
||||
LLVMValueRef g;
|
||||
|
||||
g = LLVMGetFirstGlobal(M);
|
||||
while (g) {
|
||||
LLVMTypeRef T = LLVMTypeOf(g);
|
||||
char *s = LLVMPrintTypeToString(T);
|
||||
|
||||
printf("Global%s: %s %s\n",
|
||||
LLVMIsDeclaration(g) ? "Declaration" : "Definition",
|
||||
LLVMGetValueName(g), s);
|
||||
|
||||
LLVMDisposeMessage(s);
|
||||
|
||||
g = LLVMGetNextGlobal(g);
|
||||
}
|
||||
|
||||
LLVMDisposeModule(M);
|
||||
|
||||
return 0;
|
||||
}
|
87
external/llvm/tools/llvm-c-test/object.c
vendored
87
external/llvm/tools/llvm-c-test/object.c
vendored
@ -1,87 +0,0 @@
|
||||
/*===-- object.c - tool for testing libLLVM and llvm-c API ----------------===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file implements the --object-list-sections and --object-list-symbols *|
|
||||
|* commands in llvm-c-test. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c-test.h"
|
||||
#include "llvm-c/Object.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int llvm_object_list_sections(void) {
|
||||
LLVMMemoryBufferRef MB;
|
||||
LLVMObjectFileRef O;
|
||||
LLVMSectionIteratorRef sect;
|
||||
char *msg = NULL;
|
||||
|
||||
if (LLVMCreateMemoryBufferWithSTDIN(&MB, &msg)) {
|
||||
fprintf(stderr, "Error reading file: %s\n", msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
O = LLVMCreateObjectFile(MB);
|
||||
if (!O) {
|
||||
fprintf(stderr, "Error reading object\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sect = LLVMGetSections(O);
|
||||
while (!LLVMIsSectionIteratorAtEnd(O, sect)) {
|
||||
printf("'%s': @0x%08" PRIx64 " +%" PRIu64 "\n", LLVMGetSectionName(sect),
|
||||
LLVMGetSectionAddress(sect), LLVMGetSectionSize(sect));
|
||||
|
||||
LLVMMoveToNextSection(sect);
|
||||
}
|
||||
|
||||
LLVMDisposeSectionIterator(sect);
|
||||
|
||||
LLVMDisposeObjectFile(O);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int llvm_object_list_symbols(void) {
|
||||
LLVMMemoryBufferRef MB;
|
||||
LLVMObjectFileRef O;
|
||||
LLVMSectionIteratorRef sect;
|
||||
LLVMSymbolIteratorRef sym;
|
||||
char *msg = NULL;
|
||||
|
||||
if (LLVMCreateMemoryBufferWithSTDIN(&MB, &msg)) {
|
||||
fprintf(stderr, "Error reading file: %s\n", msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
O = LLVMCreateObjectFile(MB);
|
||||
if (!O) {
|
||||
fprintf(stderr, "Error reading object\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sect = LLVMGetSections(O);
|
||||
sym = LLVMGetSymbols(O);
|
||||
while (!LLVMIsSymbolIteratorAtEnd(O, sym)) {
|
||||
|
||||
LLVMMoveToContainingSection(sect, sym);
|
||||
printf("%s @0x%08" PRIx64 " +%" PRIu64 " (%s)\n", LLVMGetSymbolName(sym),
|
||||
LLVMGetSymbolAddress(sym), LLVMGetSymbolSize(sym),
|
||||
LLVMGetSectionName(sect));
|
||||
|
||||
LLVMMoveToNextSymbol(sym);
|
||||
}
|
||||
|
||||
LLVMDisposeSymbolIterator(sym);
|
||||
|
||||
LLVMDisposeObjectFile(O);
|
||||
|
||||
return 0;
|
||||
}
|
30
external/llvm/tools/llvm-c-test/targets.c
vendored
30
external/llvm/tools/llvm-c-test/targets.c
vendored
@ -1,30 +0,0 @@
|
||||
/*===-- targets.c - tool for testing libLLVM and llvm-c API ---------------===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file implements the --targets command in llvm-c-test. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c/TargetMachine.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int llvm_targets_list(void) {
|
||||
LLVMTargetRef t;
|
||||
LLVMInitializeAllTargetInfos();
|
||||
LLVMInitializeAllTargets();
|
||||
|
||||
for (t = LLVMGetFirstTarget(); t; t = LLVMGetNextTarget(t)) {
|
||||
printf("%s", LLVMGetTargetName(t));
|
||||
if (LLVMTargetHasJIT(t))
|
||||
printf(" (+jit)");
|
||||
printf("\n - %s\n", LLVMGetTargetDescription(t));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user