whitequark | 789164d | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 1 | /*===-- 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 Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 14 | #include "llvm-c-test.h" |
| 15 | #include "llvm-c/Core.h" |
whitequark | 789164d | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 16 | #include "llvm-c/DebugInfo.h" |
whitequark | 789164d | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 17 | #include <stdio.h> |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 18 | #include <string.h> |
whitequark | 789164d | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 19 | |
Galina Kistanova | 5f8c84c | 2017-12-16 02:54:17 +0000 | [diff] [blame] | 20 | int llvm_test_dibuilder(void) { |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 21 | const char *Filename = "debuginfo.c"; |
| 22 | LLVMModuleRef M = LLVMModuleCreateWithName(Filename); |
whitequark | 789164d | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 23 | LLVMDIBuilderRef DIB = LLVMCreateDIBuilder(M); |
| 24 | |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 25 | LLVMMetadataRef File = LLVMDIBuilderCreateFile(DIB, Filename, |
| 26 | strlen(Filename), ".", 1); |
whitequark | 789164d | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 27 | |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 28 | LLVMMetadataRef CompileUnit = LLVMDIBuilderCreateCompileUnit(DIB, |
whitequark | 789164d | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 29 | LLVMDWARFSourceLanguageC, File,"llvm-c-test", 11, 0, NULL, 0, 0, |
| 30 | NULL, 0, LLVMDWARFEmissionFull, 0, 0, 0); |
| 31 | |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 32 | 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 | |
whitequark | 789164d | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 47 | char *MStr = LLVMPrintModuleToString(M); |
| 48 | puts(MStr); |
| 49 | LLVMDisposeMessage(MStr); |
| 50 | |
| 51 | LLVMDisposeDIBuilder(DIB); |
| 52 | LLVMDisposeModule(M); |
| 53 | |
| 54 | return 0; |
| 55 | } |