blob: a35d63e6ae8e8ddeb52636567e364085ea12b622 [file] [log] [blame]
whitequark789164d2017-11-01 22:18:52 +00001/*===-- debuginfo.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|* Tests for the LLVM C DebugInfo API *|
11|* *|
12\*===----------------------------------------------------------------------===*/
13
Harlan Haskinsb7881bb2018-04-02 00:17:40 +000014#include "llvm-c-test.h"
15#include "llvm-c/Core.h"
whitequark789164d2017-11-01 22:18:52 +000016#include "llvm-c/DebugInfo.h"
whitequark789164d2017-11-01 22:18:52 +000017#include <stdio.h>
Harlan Haskinsb7881bb2018-04-02 00:17:40 +000018#include <string.h>
whitequark789164d2017-11-01 22:18:52 +000019
Galina Kistanova5f8c84c2017-12-16 02:54:17 +000020int llvm_test_dibuilder(void) {
Harlan Haskinsb7881bb2018-04-02 00:17:40 +000021 const char *Filename = "debuginfo.c";
22 LLVMModuleRef M = LLVMModuleCreateWithName(Filename);
whitequark789164d2017-11-01 22:18:52 +000023 LLVMDIBuilderRef DIB = LLVMCreateDIBuilder(M);
24
Harlan Haskinsb7881bb2018-04-02 00:17:40 +000025 LLVMMetadataRef File = LLVMDIBuilderCreateFile(DIB, Filename,
26 strlen(Filename), ".", 1);
whitequark789164d2017-11-01 22:18:52 +000027
Harlan Haskinsb7881bb2018-04-02 00:17:40 +000028 LLVMMetadataRef CompileUnit = LLVMDIBuilderCreateCompileUnit(DIB,
whitequark789164d2017-11-01 22:18:52 +000029 LLVMDWARFSourceLanguageC, File,"llvm-c-test", 11, 0, NULL, 0, 0,
30 NULL, 0, LLVMDWARFEmissionFull, 0, 0, 0);
31
Harlan Haskinsb7881bb2018-04-02 00:17:40 +000032 LLVMMetadataRef Int64Ty =
33 LLVMDIBuilderCreateBasicType(DIB, "Int64", 5, 64, 0);
34
35 LLVMMetadataRef StructDbgElts[] = {Int64Ty, Int64Ty, Int64Ty};
36 LLVMMetadataRef StructDbgTy =
37 LLVMDIBuilderCreateStructType(DIB, CompileUnit, "MyStruct",
38 8, File, 0, 192, 0, 0, NULL, StructDbgElts, 3,
39 LLVMDWARFSourceLanguageC, NULL, "MyStruct", 8);
40
41 LLVMMetadataRef StructDbgPtrTy =
42 LLVMDIBuilderCreatePointerType(DIB, StructDbgTy, 192, 0, 0, "", 0);
43
44 LLVMAddNamedMetadataOperand(M, "FooType",
45 LLVMMetadataAsValue(LLVMGetModuleContext(M), StructDbgPtrTy));
46
whitequark789164d2017-11-01 22:18:52 +000047 char *MStr = LLVMPrintModuleToString(M);
48 puts(MStr);
49 LLVMDisposeMessage(MStr);
50
51 LLVMDisposeDIBuilder(DIB);
52 LLVMDisposeModule(M);
53
54 return 0;
55}