llvm.org GIT mirror llvm / bc866fe
[LLVM-C] Move DIBuilder Bindings For Block Scopes Summary: Move LLVMDIBuilderCreateFunction , LLVMDIBuilderCreateLexicalBlock, and LLVMDIBuilderCreateLexicalBlockFile from Go to LLVM-C. Reviewers: whitequark, harlanhaskins, deadalnix Reviewed By: whitequark, harlanhaskins Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D45352 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329488 91177308-0d34-0410-b5e6-96231b3b80d8 Robert Widmann 2 years ago
9 changed file(s) with 155 addition(s) and 67 deletion(s). Raw diff Collapse all Expand all
1717 #include "llvm/IR/Module.h"
1818
1919 using namespace llvm;
20
21 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref,
22 LLVMMetadataRef Scope,
23 LLVMMetadataRef File,
24 unsigned Line,
25 unsigned Column) {
26 DIBuilder *D = unwrap(Dref);
27 auto *LB = D->createLexicalBlock(unwrap(Scope),
28 unwrap(File), Line, Column);
29 return wrap(LB);
30 }
31
32 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref,
33 LLVMMetadataRef Scope,
34 LLVMMetadataRef File,
35 unsigned Discriminator) {
36 DIBuilder *D = unwrap(Dref);
37 return wrap(D->createLexicalBlockFile(unwrap(Scope),
38 unwrap(File), Discriminator));
39 }
40
41 LLVMMetadataRef LLVMDIBuilderCreateFunction(
42 LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
43 const char *LinkageName, LLVMMetadataRef File, unsigned Line,
44 LLVMMetadataRef CompositeType, int IsLocalToUnit, int IsDefinition,
45 unsigned ScopeLine, unsigned Flags, int IsOptimized) {
46 DIBuilder *D = unwrap(Dref);
47 return wrap(D->createFunction(
48 unwrap(Scope), Name, LinkageName,
49 File ? unwrap(File) : nullptr, Line,
50 unwrap(CompositeType), IsLocalToUnit, IsDefinition,
51 ScopeLine, static_cast(Flags), IsOptimized));
52 }
5320
5421 LLVMMetadataRef LLVMDIBuilderCreateAutoVariable(
5522 LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
2626 // LLVM in other languages.
2727
2828 typedef struct LLVMOpaqueDIBuilder *LLVMDIBuilderRef;
29
30 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef D,
31 LLVMMetadataRef Scope,
32 LLVMMetadataRef File,
33 unsigned Line, unsigned Column);
34
35 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef D,
36 LLVMMetadataRef Scope,
37 LLVMMetadataRef File,
38 unsigned Discriminator);
39
40 LLVMMetadataRef LLVMDIBuilderCreateFunction(
41 LLVMDIBuilderRef D, LLVMMetadataRef Scope, const char *Name,
42 const char *LinkageName, LLVMMetadataRef File, unsigned Line,
43 LLVMMetadataRef CompositeType, int IsLocalToUnit, int IsDefinition,
44 unsigned ScopeLine, unsigned Flags, int IsOptimized);
4529
4630 LLVMMetadataRef LLVMDIBuilderCreateAutoVariable(
4731 LLVMDIBuilderRef D, LLVMMetadataRef Scope, const char *Name,
8383 return md;
8484 }
8585
86 void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP) {
87 unwrap(Func)->setSubprogram(unwrap(SP));
88 }
5252
5353 struct LLVMDebugLocMetadata LLVMGetCurrentDebugLocation2(LLVMBuilderRef Bref);
5454
55 void LLVMSetSubprogram(LLVMValueRef Fn, LLVMMetadataRef SP);
56
5755 #ifdef __cplusplus
5856 }
5957
206206 result := C.LLVMDIBuilderCreateFunction(
207207 d.ref,
208208 diScope.C,
209 name,
210 linkageName,
209 name, C.size_t(len(f.Name)),
210 linkageName, C.size_t(len(f.LinkageName)),
211211 f.File.C,
212212 C.unsigned(f.Line),
213213 f.Type.C,
214 boolToCInt(f.LocalToUnit),
215 boolToCInt(f.IsDefinition),
214 C.LLVMBool(boolToCInt(f.LocalToUnit)),
215 C.LLVMBool(boolToCInt(f.IsDefinition)),
216216 C.unsigned(f.ScopeLine),
217 C.unsigned(f.Flags),
218 boolToCInt(f.Optimized),
217 C.LLVMDIFlags(f.Flags),
218 C.LLVMBool(boolToCInt(f.Optimized)),
219219 )
220220 return Metadata{C: result}
221221 }
389389 C.unsigned(0), // Optional Objective-C runtime version.
390390 t.VTableHolder.C,
391391 uniqueID,
392 C.uint64_t(len(t.UniqueID)),
392 C.size_t(len(t.UniqueID)),
393393 )
394394 return Metadata{C: result}
395395 }
217217 size_t DirectoryLen);
218218
219219 /**
220 * Create a new descriptor for the specified subprogram.
221 * \param Builder The \c DIBuilder.
222 * \param Scope Function scope.
223 * \param Name Function name.
224 * \param NameLen Length of enumeration name.
225 * \param LinkageName Mangled function name.
226 * \param LinkageNameLen Length of linkage name.
227 * \param File File where this variable is defined.
228 * \param LineNo Line number.
229 * \param Ty Function type.
230 * \param IsLocalToUnit True if this function is not externally visible.
231 * \param IsDefinition True if this is a function definition.
232 * \param ScopeLine Set to the beginning of the scope this starts
233 * \param Flags E.g.: \c LLVMDIFlagLValueReference. These flags are
234 * used to emit dwarf attributes.
235 * \param IsOptimized True if optimization is ON.
236 */
237 LLVMMetadataRef LLVMDIBuilderCreateFunction(
238 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
239 size_t NameLen, const char *LinkageName, size_t LinkageNameLen,
240 LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
241 LLVMBool IsLocalToUnit, LLVMBool IsDefinition,
242 unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized);
243
244 /**
245 * Create a descriptor for a lexical block with the specified parent context.
246 * \param Builder The \c DIBuilder.
247 * \param Scope Parent lexical block.
248 * \param File Source file.
249 * \param Line The line in the source file.
250 * \param Column The column in the source file.
251 */
252 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(
253 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope,
254 LLVMMetadataRef File, unsigned Line, unsigned Column);
255
256 /**
257 * Create a descriptor for a lexical block with a new file attached.
258 * \param Builder The \c DIBuilder.
259 * \param Scope Lexical block.
260 * \param File Source file.
261 * \param Discriminator DWARF path discriminator value.
262 */
263 LLVMMetadataRef
264 LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Builder,
265 LLVMMetadataRef Scope,
266 LLVMMetadataRef File,
267 unsigned Discriminator);
268
269 /**
220270 * Creates a new DebugLocation that describes a source location.
221271 * \param Line The line in the source file.
222272 * \param Column The column in the source file.
559609 LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder,
560610 LLVMMetadataRef Type);
561611
612 /**
613 * Get the metadata of the subprogram attached to a function.
614 *
615 * @see llvm::Function::getSubprogram()
616 */
617 LLVMMetadataRef LLVMGetSubprogram(LLVMValueRef Func);
618
619 /**
620 * Set the subprogram attached to a function.
621 *
622 * @see llvm::Function::setSubprogram()
623 */
624 void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP);
625
562626 #ifdef __cplusplus
563627 } /* end extern "C" */
564628 #endif
753753 StringRef(Directory, DirectoryLen)));
754754 }
755755
756 LLVMMetadataRef LLVMDIBuilderCreateFunction(
757 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
758 size_t NameLen, const char *LinkageName, size_t LinkageNameLen,
759 LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
760 LLVMBool IsLocalToUnit, LLVMBool IsDefinition,
761 unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized) {
762 return wrap(unwrap(Builder)->createFunction(
763 unwrapDI(Scope), {Name, NameLen}, {LinkageName, LinkageNameLen},
764 unwrapDI(File), LineNo, unwrapDI(Ty),
765 IsLocalToUnit, IsDefinition, ScopeLine, map_from_llvmDIFlags(Flags),
766 IsOptimized, nullptr, nullptr, nullptr));
767 }
768
769
770 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(
771 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope,
772 LLVMMetadataRef File, unsigned Line, unsigned Col) {
773 return wrap(unwrap(Builder)->createLexicalBlock(unwrapDI(Scope),
774 unwrapDI(File),
775 Line, Col));
776 }
777
778 LLVMMetadataRef
779 LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Builder,
780 LLVMMetadataRef Scope,
781 LLVMMetadataRef File,
782 unsigned Discriminator) {
783 return wrap(unwrap(Builder)->createLexicalBlockFile(unwrapDI(Scope),
784 unwrapDI(File),
785 Discriminator));
786 }
787
756788 LLVMMetadataRef
757789 LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line,
758790 unsigned Column, LLVMMetadataRef Scope,
941973 return wrap(unwrap(Builder)->createSubroutineType(
942974 Elts, map_from_llvmDIFlags(Flags)));
943975 }
976
977 LLVMMetadataRef LLVMGetSubprogram(LLVMValueRef Func) {
978 return wrap(unwrap(Func)->getSubprogram());
979 }
980
981 void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP) {
982 unwrap(Func)->setSubprogram(unwrap(SP));
983 }
22 ; CHECK: ; ModuleID = 'debuginfo.c'
33 ; CHECK-NEXT: source_filename = "debuginfo.c"
44
5 ; CHECK: declare !dbg !7 i64 @foo(i64, i64)
6
7 ; CHECK: declare !dbg !10 i64 @foo_inner_scope(i64, i64)
8
59 ; CHECK: !llvm.dbg.cu = !{!0}
6 ; CHECK-NEXT: !FooType = !{!2}
10 ; CHECK-NEXT: !FooType = !{!3}
711
8 ; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false)
12 ; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false)
913 ; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".")
10 ; CHECK-NEXT: !2 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !3, size: 192, dwarfAddressSpace: 0)
11 ; CHECK-NEXT: !3 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", file: !1, size: 192, elements: !4, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
12 ; CHECK-NEXT: !4 = !{!5, !5, !5}
13 ; CHECK-NEXT: !5 = !DIBasicType(name: "Int64", size: 64)
14 ; CHECK-NEXT: !2 = !{}
15 ; CHECK-NEXT: !3 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !4, size: 192, dwarfAddressSpace: 0)
16 ; CHECK-NEXT: !4 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", file: !1, size: 192, elements: !5, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
17 ; CHECK-NEXT: !5 = !{!6, !6, !6}
18 ; CHECK-NEXT: !6 = !DIBasicType(name: "Int64", size: 64)
19 ; CHECK-NEXT: !7 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !8, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, variables: !2)
20 ; CHECK-NEXT: !8 = !DISubroutineType(types: !9)
21 ; CHECK-NEXT: !9 = !{!6, !6}
22 ; CHECK-NEXT: !10 = distinct !DISubprogram(name: "foo_inner_scope", linkageName: "foo_inner_scope", scope: !11, file: !1, line: 42, type: !8, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, variables: !2)
23 ; CHECK-NEXT: !11 = distinct !DILexicalBlock(scope: !7, file: !1, line: 42)
4343 LLVMAddNamedMetadataOperand(M, "FooType",
4444 LLVMMetadataAsValue(LLVMGetModuleContext(M), StructDbgPtrTy));
4545
46
47 LLVMTypeRef FooParamTys[] = { LLVMInt64Type(), LLVMInt64Type() };
48 LLVMTypeRef FooFuncTy = LLVMFunctionType(LLVMInt64Type(), FooParamTys, 2, 0);
49 LLVMValueRef FooFunction = LLVMAddFunction(M, "foo", FooFuncTy);
50
51 LLVMMetadataRef ParamTypes[] = {Int64Ty, Int64Ty};
52 LLVMMetadataRef FunctionTy =
53 LLVMDIBuilderCreateSubroutineType(DIB, File, ParamTypes, 2, 0);
54 LLVMMetadataRef FunctionMetadata =
55 LLVMDIBuilderCreateFunction(DIB, File, "foo", 3, "foo", 3,
56 File, 42, FunctionTy, true, true,
57 42, 0, false);
58 LLVMSetSubprogram(FooFunction, FunctionMetadata);
59
60 LLVMMetadataRef FooLexicalBlock =
61 LLVMDIBuilderCreateLexicalBlock(DIB, FunctionMetadata, File, 42, 0);
62
63 LLVMValueRef InnerFooFunction =
64 LLVMAddFunction(M, "foo_inner_scope", FooFuncTy);
65 LLVMMetadataRef InnerFunctionMetadata =
66 LLVMDIBuilderCreateFunction(DIB, FooLexicalBlock, "foo_inner_scope", 15,
67 "foo_inner_scope", 15,
68 File, 42, FunctionTy, true, true,
69 42, 0, false);
70 LLVMSetSubprogram(InnerFooFunction, InnerFunctionMetadata);
71
72 LLVMDIBuilderFinalize(DIB);
73
4674 char *MStr = LLVMPrintModuleToString(M);
4775 puts(MStr);
4876 LLVMDisposeMessage(MStr);