1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00
llvm-mirror/tools/llvm-c-test/debuginfo.c
Harlan Haskins 5b6ae512c2 Add C API bindings for DIBuilder 'Type' APIs
This patch adds a set of unstable C API bindings to the DIBuilder interface for
creating structure, function, and aggregate types.

This patch also removes the existing implementations of these functions from
the Go bindings and updates the Go API to fit the new C APIs.

llvm-svn: 328953
2018-04-02 00:17:40 +00:00

56 lines
2.2 KiB
C

/*===-- 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-test.h"
#include "llvm-c/Core.h"
#include "llvm-c/DebugInfo.h"
#include <stdio.h>
#include <string.h>
int llvm_test_dibuilder(void) {
const char *Filename = "debuginfo.c";
LLVMModuleRef M = LLVMModuleCreateWithName(Filename);
LLVMDIBuilderRef DIB = LLVMCreateDIBuilder(M);
LLVMMetadataRef File = LLVMDIBuilderCreateFile(DIB, Filename,
strlen(Filename), ".", 1);
LLVMMetadataRef CompileUnit = LLVMDIBuilderCreateCompileUnit(DIB,
LLVMDWARFSourceLanguageC, File,"llvm-c-test", 11, 0, NULL, 0, 0,
NULL, 0, LLVMDWARFEmissionFull, 0, 0, 0);
LLVMMetadataRef Int64Ty =
LLVMDIBuilderCreateBasicType(DIB, "Int64", 5, 64, 0);
LLVMMetadataRef StructDbgElts[] = {Int64Ty, Int64Ty, Int64Ty};
LLVMMetadataRef StructDbgTy =
LLVMDIBuilderCreateStructType(DIB, CompileUnit, "MyStruct",
8, File, 0, 192, 0, 0, NULL, StructDbgElts, 3,
LLVMDWARFSourceLanguageC, NULL, "MyStruct", 8);
LLVMMetadataRef StructDbgPtrTy =
LLVMDIBuilderCreatePointerType(DIB, StructDbgTy, 192, 0, 0, "", 0);
LLVMAddNamedMetadataOperand(M, "FooType",
LLVMMetadataAsValue(LLVMGetModuleContext(M), StructDbgPtrTy));
char *MStr = LLVMPrintModuleToString(M);
puts(MStr);
LLVMDisposeMessage(MStr);
LLVMDisposeDIBuilder(DIB);
LLVMDisposeModule(M);
return 0;
}