Skip to content

Commit aec494f

Browse files
committedApr 28, 2018
[LLVM-C] Add DIBuilder bindings to create import declarations
Summary: Add bindings to create import declarations for modules, functions, types, and other entities. This wraps the conveniences available in the existing DIBuilder API, but these seem C++-specific. Reviewers: whitequark, harlanhaskins, deadalnix Reviewed By: whitequark Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D46167 llvm-svn: 331123
1 parent da3e8c4 commit aec494f

File tree

4 files changed

+157
-25
lines changed

4 files changed

+157
-25
lines changed
 

‎llvm/include/llvm-c/DebugInfo.h

+66
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,72 @@ LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Builder,
303303
LLVMMetadataRef File,
304304
unsigned Discriminator);
305305

306+
/**
307+
* Create a descriptor for an imported namespace. Suitable for e.g. C++
308+
* using declarations.
309+
* \param Builder The \c DIBuilder.
310+
* \param Scope The scope this module is imported into
311+
* \param File File where the declaration is located.
312+
* \param Line Line number of the declaration.
313+
*/
314+
LLVMMetadataRef
315+
LLVMDIBuilderCreateImportedModuleFromNamespace(LLVMDIBuilderRef Builder,
316+
LLVMMetadataRef Scope,
317+
LLVMMetadataRef NS,
318+
LLVMMetadataRef File,
319+
unsigned Line);
320+
321+
/**
322+
* Create a descriptor for an imported module that aliases another
323+
* imported entity descriptor.
324+
* \param Builder The \c DIBuilder.
325+
* \param Scope The scope this module is imported into
326+
* \param ImportedEntity Previous imported entity to alias.
327+
* \param File File where the declaration is located.
328+
* \param Line Line number of the declaration.
329+
*/
330+
LLVMMetadataRef
331+
LLVMDIBuilderCreateImportedModuleFromAlias(LLVMDIBuilderRef Builder,
332+
LLVMMetadataRef Scope,
333+
LLVMMetadataRef ImportedEntity,
334+
LLVMMetadataRef File,
335+
unsigned Line);
336+
337+
/**
338+
* Create a descriptor for an imported module.
339+
* \param Builder The \c DIBuilder.
340+
* \param Scope The scope this module is imported into
341+
* \param M The module being imported here
342+
* \param File File where the declaration is located.
343+
* \param Line Line number of the declaration.
344+
*/
345+
LLVMMetadataRef
346+
LLVMDIBuilderCreateImportedModuleFromModule(LLVMDIBuilderRef Builder,
347+
LLVMMetadataRef Scope,
348+
LLVMMetadataRef M,
349+
LLVMMetadataRef File,
350+
unsigned Line);
351+
352+
/**
353+
* Create a descriptor for an imported function, type, or variable. Suitable
354+
* for e.g. FORTRAN-style USE declarations.
355+
* \param Builder The DIBuilder.
356+
* \param Scope The scope this module is imported into.
357+
* \param Decl The declaration (or definition) of a function, type,
358+
or variable.
359+
* \param File File where the declaration is located.
360+
* \param Line Line number of the declaration.
361+
* \param Name A name that uniquely identifies this imported declaration.
362+
* \param NameLen The length of the C string passed to \c Name.
363+
*/
364+
LLVMMetadataRef
365+
LLVMDIBuilderCreateImportedDeclaration(LLVMDIBuilderRef Builder,
366+
LLVMMetadataRef Scope,
367+
LLVMMetadataRef Decl,
368+
LLVMMetadataRef File,
369+
unsigned Line,
370+
const char *Name, size_t NameLen);
371+
306372
/**
307373
* Creates a new DebugLocation that describes a source location.
308374
* \param Line The line in the source file.

‎llvm/lib/IR/DebugInfo.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,55 @@ LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Builder,
828828
Discriminator));
829829
}
830830

831+
LLVMMetadataRef
832+
LLVMDIBuilderCreateImportedModuleFromNamespace(LLVMDIBuilderRef Builder,
833+
LLVMMetadataRef Scope,
834+
LLVMMetadataRef NS,
835+
LLVMMetadataRef File,
836+
unsigned Line) {
837+
return wrap(unwrap(Builder)->createImportedModule(unwrapDI<DIScope>(Scope),
838+
unwrapDI<DINamespace>(NS),
839+
unwrapDI<DIFile>(File),
840+
Line));
841+
}
842+
843+
LLVMMetadataRef
844+
LLVMDIBuilderCreateImportedModuleFromAlias(LLVMDIBuilderRef Builder,
845+
LLVMMetadataRef Scope,
846+
LLVMMetadataRef ImportedEntity,
847+
LLVMMetadataRef File,
848+
unsigned Line) {
849+
return wrap(unwrap(Builder)->createImportedModule(
850+
unwrapDI<DIScope>(Scope),
851+
unwrapDI<DIImportedEntity>(ImportedEntity),
852+
unwrapDI<DIFile>(File), Line));
853+
}
854+
855+
LLVMMetadataRef
856+
LLVMDIBuilderCreateImportedModuleFromModule(LLVMDIBuilderRef Builder,
857+
LLVMMetadataRef Scope,
858+
LLVMMetadataRef M,
859+
LLVMMetadataRef File,
860+
unsigned Line) {
861+
return wrap(unwrap(Builder)->createImportedModule(unwrapDI<DIScope>(Scope),
862+
unwrapDI<DIModule>(M),
863+
unwrapDI<DIFile>(File),
864+
Line));
865+
}
866+
867+
LLVMMetadataRef
868+
LLVMDIBuilderCreateImportedDeclaration(LLVMDIBuilderRef Builder,
869+
LLVMMetadataRef Scope,
870+
LLVMMetadataRef Decl,
871+
LLVMMetadataRef File,
872+
unsigned Line,
873+
const char *Name, size_t NameLen) {
874+
return wrap(unwrap(Builder)->createImportedDeclaration(
875+
unwrapDI<DIScope>(Scope),
876+
unwrapDI<DINode>(Decl),
877+
unwrapDI<DIFile>(File), Line, {Name, NameLen}));
878+
}
879+
831880
LLVMMetadataRef
832881
LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line,
833882
unsigned Column, LLVMMetadataRef Scope,

‎llvm/test/Bindings/llvm-c/debug_info.ll

+29-25
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,48 @@
33
; CHECK: ; ModuleID = 'debuginfo.c'
44
; CHECK-NEXT: source_filename = "debuginfo.c"
55

6-
; CHECK: define i64 @foo(i64, i64, <10 x i64>) !dbg !12 {
6+
; CHECK: define i64 @foo(i64, i64, <10 x i64>) !dbg !16 {
77
; CHECK-NEXT: entry:
8-
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !19, metadata !DIExpression()), !dbg !24
9-
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !20, metadata !DIExpression()), !dbg !24
10-
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !21, metadata !DIExpression()), !dbg !24
8+
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !23, metadata !DIExpression()), !dbg !28
9+
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !24, metadata !DIExpression()), !dbg !28
10+
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !25, metadata !DIExpression()), !dbg !28
1111
; CHECK: vars:
12-
; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 0, metadata !22, metadata !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)), !dbg !25
12+
; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 0, metadata !26, metadata !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)), !dbg !29
1313
; CHECK-NEXT: }
1414

1515
; CHECK: declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
1616
; CHECK: declare void @llvm.dbg.value(metadata, metadata, metadata) #0
1717

1818
; CHECK: !llvm.dbg.cu = !{!0}
19-
; CHECK: !FooType = !{!8}
19+
; CHECK: !FooType = !{!12}
2020

21-
; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, splitDebugInlining: false)
21+
; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, imports: !8, splitDebugInlining: false)
2222
; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".")
2323
; CHECK-NEXT: !2 = !{}
2424
; CHECK-NEXT: !3 = !{!4}
2525
; CHECK-NEXT: !4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value))
2626
; CHECK-NEXT: !5 = distinct !DIGlobalVariable(name: "global", scope: !6, file: !1, line: 1, type: !7, isLocal: true, isDefinition: true)
2727
; CHECK-NEXT: !6 = !DIModule(scope: null, name: "llvm-c-test", includePath: "/test/include/llvm-c-test.h")
2828
; CHECK-NEXT: !7 = !DIBasicType(name: "Int64", size: 64)
29-
; CHECK-NEXT: !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 192, dwarfAddressSpace: 0)
30-
; CHECK-NEXT: !9 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !10, file: !1, size: 192, elements: !11, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
31-
; CHECK-NEXT: !10 = !DINamespace(name: "NameSpace", scope: !6)
32-
; CHECK-NEXT: !11 = !{!7, !7, !7}
33-
; CHECK-NEXT: !12 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !13, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, variables: !18)
34-
; CHECK-NEXT: !13 = !DISubroutineType(types: !14)
35-
; CHECK-NEXT: !14 = !{!7, !7, !15}
36-
; CHECK-NEXT: !15 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 640, flags: DIFlagVector, elements: !16)
37-
; CHECK-NEXT: !16 = !{!17}
38-
; CHECK-NEXT: !17 = !DISubrange(count: 10)
39-
; CHECK-NEXT: !18 = !{!19, !20, !21, !22}
40-
; CHECK-NEXT: !19 = !DILocalVariable(name: "a", arg: 1, scope: !12, file: !1, line: 42, type: !7)
41-
; CHECK-NEXT: !20 = !DILocalVariable(name: "b", arg: 2, scope: !12, file: !1, line: 42, type: !7)
42-
; CHECK-NEXT: !21 = !DILocalVariable(name: "c", arg: 3, scope: !12, file: !1, line: 42, type: !15)
43-
; CHECK-NEXT: !22 = !DILocalVariable(name: "d", scope: !23, file: !1, line: 43, type: !7)
44-
; CHECK-NEXT: !23 = distinct !DILexicalBlock(scope: !12, file: !1, line: 42)
45-
; CHECK-NEXT: !24 = !DILocation(line: 42, scope: !12)
46-
; CHECK-NEXT: !25 = !DILocation(line: 43, scope: !12)
29+
; CHECK-NEXT: !8 = !{!9, !11}
30+
; CHECK-NEXT: !9 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !6, entity: !10, file: !1, line: 42)
31+
; CHECK-NEXT: !10 = !DIModule(scope: null, name: "llvm-c-test-import", includePath: "/test/include/llvm-c-test-import.h")
32+
; CHECK-NEXT: !11 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !6, entity: !9, file: !1, line: 42)
33+
; CHECK-NEXT: !12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 192, dwarfAddressSpace: 0)
34+
; CHECK-NEXT: !13 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !14, file: !1, size: 192, elements: !15, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
35+
; CHECK-NEXT: !14 = !DINamespace(name: "NameSpace", scope: !6)
36+
; CHECK-NEXT: !15 = !{!7, !7, !7}
37+
; CHECK-NEXT: !16 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !17, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, variables: !22)
38+
; CHECK-NEXT: !17 = !DISubroutineType(types: !18)
39+
; CHECK-NEXT: !18 = !{!7, !7, !19}
40+
; CHECK-NEXT: !19 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 640, flags: DIFlagVector, elements: !20)
41+
; CHECK-NEXT: !20 = !{!21}
42+
; CHECK-NEXT: !21 = !DISubrange(count: 10)
43+
; CHECK-NEXT: !22 = !{!23, !24, !25, !26}
44+
; CHECK-NEXT: !23 = !DILocalVariable(name: "a", arg: 1, scope: !16, file: !1, line: 42, type: !7)
45+
; CHECK-NEXT: !24 = !DILocalVariable(name: "b", arg: 2, scope: !16, file: !1, line: 42, type: !7)
46+
; CHECK-NEXT: !25 = !DILocalVariable(name: "c", arg: 3, scope: !16, file: !1, line: 42, type: !19)
47+
; CHECK-NEXT: !26 = !DILocalVariable(name: "d", scope: !27, file: !1, line: 43, type: !7)
48+
; CHECK-NEXT: !27 = distinct !DILexicalBlock(scope: !16, file: !1, line: 42)
49+
; CHECK-NEXT: !28 = !DILocation(line: 42, scope: !16)
50+
; CHECK-NEXT: !29 = !DILocation(line: 43, scope: !16)

‎llvm/tools/llvm-c-test/debuginfo.c

+13
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ int llvm_test_dibuilder(void) {
3636
"/test/include/llvm-c-test.h", 27,
3737
"", 0);
3838

39+
LLVMMetadataRef OtherModule =
40+
LLVMDIBuilderCreateModule(DIB, CompileUnit,
41+
"llvm-c-test-import", 18,
42+
"", 0,
43+
"/test/include/llvm-c-test-import.h", 34,
44+
"", 0);
45+
LLVMMetadataRef ImportedModule =
46+
LLVMDIBuilderCreateImportedModuleFromModule(DIB, Module, OtherModule,
47+
File, 42);
48+
LLVMMetadataRef AliasImportedModule =
49+
LLVMDIBuilderCreateImportedModuleFromAlias(DIB, Module, ImportedModule,
50+
File, 42);
51+
3952
LLVMMetadataRef Int64Ty =
4053
LLVMDIBuilderCreateBasicType(DIB, "Int64", 5, 64, 0);
4154
LLVMMetadataRef GlobalVarValueExpr =

0 commit comments

Comments
 (0)
Please sign in to comment.