llvm.org GIT mirror llvm / e9654fe
[LLVM-C] Add DIBuilder Bindings For ObjC Classes Summary: Add LLVMDIBuilderCreateObjCIVar, LLVMDIBuilderCreateObjCProperty, and LLVMDIBuilderCreateInheritance to allow declaring metadata for Objective-C class hierarchies and their associated properties and instance variables. Reviewers: whitequark, deadalnix Reviewed By: whitequark Subscribers: harlanhaskins, llvm-commits Differential Revision: https://reviews.llvm.org/D47123 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332850 91177308-0d34-0410-b5e6-96231b3b80d8 Robert Widmann 1 year, 3 months ago
4 changed file(s) with 163 addition(s) and 38 deletion(s). Raw diff Collapse all Expand all
631631 uint64_t SizeInBits,
632632 uint32_t AlignInBits,
633633 LLVMDIFlags Flags);
634 /**
635 * Create debugging information entry for Objective-C instance variable.
636 * \param Builder The DIBuilder.
637 * \param Name Member name.
638 * \param NameLen The length of the C string passed to \c Name.
639 * \param File File where this member is defined.
640 * \param LineNo Line number.
641 * \param SizeInBits Member size.
642 * \param AlignInBits Member alignment.
643 * \param OffsetInBits Member offset.
644 * \param Flags Flags to encode member attribute, e.g. private
645 * \param Ty Parent type.
646 * \param PropertyNode Property associated with this ivar.
647 */
648 LLVMMetadataRef
649 LLVMDIBuilderCreateObjCIVar(LLVMDIBuilderRef Builder,
650 const char *Name, size_t NameLen,
651 LLVMMetadataRef File, unsigned LineNo,
652 uint64_t SizeInBits, uint32_t AlignInBits,
653 uint64_t OffsetInBits, LLVMDIFlags Flags,
654 LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode);
655
656 /**
657 * Create debugging information entry for Objective-C property.
658 * \param Builder The DIBuilder.
659 * \param Name Property name.
660 * \param NameLen The length of the C string passed to \c Name.
661 * \param File File where this property is defined.
662 * \param LineNo Line number.
663 * \param GetterName Name of the Objective C property getter selector.
664 * \param GetterNameLen The length of the C string passed to \c GetterName.
665 * \param SetterName Name of the Objective C property setter selector.
666 * \param SetterNameLen The length of the C string passed to \c SetterName.
667 * \param PropertyAttributes Objective C property attributes.
668 * \param Ty Type.
669 */
670 LLVMMetadataRef
671 LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder,
672 const char *Name, size_t NameLen,
673 LLVMMetadataRef File, unsigned LineNo,
674 const char *GetterName, size_t GetterNameLen,
675 const char *SetterName, size_t SetterNameLen,
676 unsigned PropertyAttributes,
677 LLVMMetadataRef Ty);
634678
635679 /**
636680 * Create a new DIType* with the "object pointer"
680724 * \param File File where this type is defined.
681725 * \param LineNo Line number.
682726 * \param Scope The surrounding context for the typedef.
683 */
727 */
684728 LLVMMetadataRef
685729 LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type,
686730 const char *Name, size_t NameLen,
687731 LLVMMetadataRef File, unsigned LineNo,
688732 LLVMMetadataRef Scope);
733
734 /**
735 * Create debugging information entry to establish inheritance relationship
736 * between two types.
737 * \param Builder The DIBuilder.
738 * \param Ty Original type.
739 * \param BaseTy Base type. Ty is inherits from base.
740 * \param BaseOffset Base offset.
741 * \param VBPtrOffset Virtual base pointer offset.
742 * \param Flags Flags to describe inheritance attribute, e.g. private
743 */
744 LLVMMetadataRef
745 LLVMDIBuilderCreateInheritance(LLVMDIBuilderRef Builder,
746 LLVMMetadataRef Ty, LLVMMetadataRef BaseTy,
747 uint64_t BaseOffset, uint32_t VBPtrOffset,
748 LLVMDIFlags Flags);
689749
690750 /**
691751 * Create a permanent forward-declared type.
10121012 }
10131013
10141014 LLVMMetadataRef
1015 LLVMDIBuilderCreateObjCIVar(LLVMDIBuilderRef Builder,
1016 const char *Name, size_t NameLen,
1017 LLVMMetadataRef File, unsigned LineNo,
1018 uint64_t SizeInBits, uint32_t AlignInBits,
1019 uint64_t OffsetInBits, LLVMDIFlags Flags,
1020 LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode) {
1021 return wrap(unwrap(Builder)->createObjCIVar(
1022 {Name, NameLen}, unwrapDI(File), LineNo,
1023 SizeInBits, AlignInBits, OffsetInBits,
1024 map_from_llvmDIFlags(Flags), unwrapDI(Ty),
1025 unwrapDI(PropertyNode)));
1026 }
1027
1028 LLVMMetadataRef
1029 LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder,
1030 const char *Name, size_t NameLen,
1031 LLVMMetadataRef File, unsigned LineNo,
1032 const char *GetterName, size_t GetterNameLen,
1033 const char *SetterName, size_t SetterNameLen,
1034 unsigned PropertyAttributes,
1035 LLVMMetadataRef Ty) {
1036 return wrap(unwrap(Builder)->createObjCProperty(
1037 {Name, NameLen}, unwrapDI(File), LineNo,
1038 {GetterName, GetterNameLen}, {SetterName, SetterNameLen},
1039 PropertyAttributes, unwrapDI(Ty)));
1040 }
1041
1042 LLVMMetadataRef
10151043 LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
10161044 LLVMMetadataRef Type) {
10171045 return wrap(unwrap(Builder)->createObjectPointerType(unwrapDI(Type)));
10261054 unwrapDI(Type), {Name, NameLen},
10271055 unwrapDI(File), LineNo,
10281056 unwrapDI(Scope)));
1057 }
1058
1059 LLVMMetadataRef
1060 LLVMDIBuilderCreateInheritance(LLVMDIBuilderRef Builder,
1061 LLVMMetadataRef Ty, LLVMMetadataRef BaseTy,
1062 uint64_t BaseOffset, uint32_t VBPtrOffset,
1063 LLVMDIFlags Flags) {
1064 return wrap(unwrap(Builder)->createInheritance(
1065 unwrapDI(Ty), unwrapDI(BaseTy),
1066 BaseOffset, VBPtrOffset, map_from_llvmDIFlags(Flags)));
10291067 }
10301068
10311069 LLVMMetadataRef
22 ; CHECK: ; ModuleID = 'debuginfo.c'
33 ; CHECK-NEXT: source_filename = "debuginfo.c"
44
5 ; CHECK: define i64 @foo(i64, i64, <10 x i64>) !dbg !17 {
5 ; CHECK: define i64 @foo(i64, i64, <10 x i64>) !dbg !20 {
66 ; CHECK-NEXT: entry:
7 ; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !24, metadata !DIExpression()), !dbg !29
8 ; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !25, metadata !DIExpression()), !dbg !29
9 ; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !26, metadata !DIExpression()), !dbg !29
10 ; CHECK: vars:
11 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 0, metadata !27, metadata !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)), !dbg !30
7 ; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !27, metadata !DIExpression()), !dbg !32
8 ; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !28, metadata !DIExpression()), !dbg !32
9 ; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !29, metadata !DIExpression()), !dbg !32
10 ; CHECK: vars: ; No predecessors!
11 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 0, metadata !30, metadata !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)), !dbg !33
1212 ; CHECK-NEXT: }
1313
14 ; CHECK: declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
15 ; CHECK: declare void @llvm.dbg.value(metadata, metadata, metadata) #0
14 ; CHECK: ; Function Attrs: nounwind readnone speculatable
15 ; CHECK-NEXT: declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
1616
17 ; CHECK: !llvm.dbg.cu = !{!0}
18 ; CHECK: !FooType = !{!13}
17 ; CHECK: ; Function Attrs: nounwind readnone speculatable
18 ; CHECK-NEXT: declare void @llvm.dbg.value(metadata, metadata, metadata) #0
1919
20 ; 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: !9, splitDebugInlining: false)
20 ; CHECK: attributes #0 = { nounwind readnone speculatable }
21
22 ; CHECK: !llvm.dbg.cu = !{!0}
23 ; CHECK-NEXT: !FooType = !{!16}
24
25 ; 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: !12, splitDebugInlining: false)
2126 ; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".")
2227 ; CHECK-NEXT: !2 = !{}
23 ; CHECK-NEXT: !3 = !{!4}
28 ; CHECK-NEXT: !3 = !{!4, !8}
2429 ; CHECK-NEXT: !4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value))
25 ; CHECK-NEXT: !5 = distinct !DIGlobalVariable(name: "global", scope: !6, file: !1, line: 1, type: !7, isLocal: true, isDefinition: true)
30 ; CHECK-NEXT: !5 = distinct !DIGlobalVariable(name: "globalClass", scope: !6, file: !1, line: 1, type: !7, isLocal: true, isDefinition: true)
2631 ; CHECK-NEXT: !6 = !DIModule(scope: null, name: "llvm-c-test", includePath: "/test/include/llvm-c-test.h")
27 ; CHECK-NEXT: !7 = !DIDerivedType(tag: DW_TAG_typedef, name: "int64_t", scope: !1, file: !1, line: 42, baseType: !8)
28 ; CHECK-NEXT: !8 = !DIBasicType(name: "Int64", size: 64)
29 ; CHECK-NEXT: !9 = !{!10, !12}
30 ; CHECK-NEXT: !10 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !6, entity: !11, file: !1, line: 42)
31 ; CHECK-NEXT: !11 = !DIModule(scope: null, name: "llvm-c-test-import", includePath: "/test/include/llvm-c-test-import.h")
32 ; CHECK-NEXT: !12 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !6, entity: !10, file: !1, line: 42)
33 ; CHECK-NEXT: !13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 192, dwarfAddressSpace: 0)
34 ; CHECK-NEXT: !14 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !15, file: !1, size: 192, elements: !16, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
35 ; CHECK-NEXT: !15 = !DINamespace(name: "NameSpace", scope: !6)
36 ; CHECK-NEXT: !16 = !{!8, !8, !8}
37 ; CHECK-NEXT: !17 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !18, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, retainedNodes: !23)
38 ; CHECK-NEXT: !18 = !DISubroutineType(types: !19)
39 ; CHECK-NEXT: !19 = !{!8, !8, !20}
40 ; CHECK-NEXT: !20 = !DICompositeType(tag: DW_TAG_array_type, baseType: !8, size: 640, flags: DIFlagVector, elements: !21)
41 ; CHECK-NEXT: !21 = !{!22}
42 ; CHECK-NEXT: !22 = !DISubrange(count: 10)
43 ; CHECK-NEXT: !23 = !{!24, !25, !26, !27}
44 ; CHECK-NEXT: !24 = !DILocalVariable(name: "a", arg: 1, scope: !17, file: !1, line: 42, type: !8)
45 ; CHECK-NEXT: !25 = !DILocalVariable(name: "b", arg: 2, scope: !17, file: !1, line: 42, type: !8)
46 ; CHECK-NEXT: !26 = !DILocalVariable(name: "c", arg: 3, scope: !17, file: !1, line: 42, type: !20)
47 ; CHECK-NEXT: !27 = !DILocalVariable(name: "d", scope: !28, file: !1, line: 43, type: !8)
48 ; CHECK-NEXT: !28 = distinct !DILexicalBlock(scope: !17, file: !1, line: 42)
49 ; CHECK-NEXT: !29 = !DILocation(line: 42, scope: !17)
50 ; CHECK-NEXT: !30 = !DILocation(line: 43, scope: !17)
32 ; CHECK-NEXT: !7 = !DICompositeType(tag: DW_TAG_structure_type, name: "TestClass", scope: !1, file: !1, line: 42, size: 64, flags: DIFlagObjcClassComplete, elements: !2)
33 ; CHECK-NEXT: !8 = !DIGlobalVariableExpression(var: !9, expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value))
34 ; CHECK-NEXT: !9 = distinct !DIGlobalVariable(name: "global", scope: !6, file: !1, line: 1, type: !10, isLocal: true, isDefinition: true)
35 ; CHECK-NEXT: !10 = !DIDerivedType(tag: DW_TAG_typedef, name: "int64_t", scope: !1, file: !1, line: 42, baseType: !11)
36 ; CHECK-NEXT: !11 = !DIBasicType(name: "Int64", size: 64)
37 ; CHECK-NEXT: !12 = !{!13, !15}
38 ; CHECK-NEXT: !13 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !6, entity: !14, file: !1, line: 42)
39 ; CHECK-NEXT: !14 = !DIModule(scope: null, name: "llvm-c-test-import", includePath: "/test/include/llvm-c-test-import.h")
40 ; CHECK-NEXT: !15 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !6, entity: !13, file: !1, line: 42)
41 ; CHECK-NEXT: !16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !17, size: 192, dwarfAddressSpace: 0)
42 ; CHECK-NEXT: !17 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !18, file: !1, size: 192, elements: !19, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
43 ; CHECK-NEXT: !18 = !DINamespace(name: "NameSpace", scope: !6)
44 ; CHECK-NEXT: !19 = !{!11, !11, !11}
45 ; CHECK-NEXT: !20 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !21, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, retainedNodes: !26)
46 ; CHECK-NEXT: !21 = !DISubroutineType(types: !22)
47 ; CHECK-NEXT: !22 = !{!11, !11, !23}
48 ; CHECK-NEXT: !23 = !DICompositeType(tag: DW_TAG_array_type, baseType: !11, size: 640, flags: DIFlagVector, elements: !24)
49 ; CHECK-NEXT: !24 = !{!25}
50 ; CHECK-NEXT: !25 = !DISubrange(count: 10)
51 ; CHECK-NEXT: !26 = !{!27, !28, !29, !30}
52 ; CHECK-NEXT: !27 = !DILocalVariable(name: "a", arg: 1, scope: !20, file: !1, line: 42, type: !11)
53 ; CHECK-NEXT: !28 = !DILocalVariable(name: "b", arg: 2, scope: !20, file: !1, line: 42, type: !11)
54 ; CHECK-NEXT: !29 = !DILocalVariable(name: "c", arg: 3, scope: !20, file: !1, line: 42, type: !23)
55 ; CHECK-NEXT: !30 = !DILocalVariable(name: "d", scope: !31, file: !1, line: 43, type: !11)
56 ; CHECK-NEXT: !31 = distinct !DILexicalBlock(scope: !20, file: !1, line: 42)
57 ; CHECK-NEXT: !32 = !DILocation(line: 42, scope: !20)
58 ; CHECK-NEXT: !33 = !DILocation(line: 43, scope: !20)
1515 #include "llvm-c/DebugInfo.h"
1616 #include
1717 #include
18
19 static LLVMMetadataRef
20 declare_objc_class(LLVMDIBuilderRef DIB, LLVMMetadataRef File) {
21 LLVMMetadataRef Decl = LLVMDIBuilderCreateStructType(DIB, File, "TestClass", 9, File, 42, 64, 0, LLVMDIFlagObjcClassComplete, NULL, NULL, 0, 0, NULL, NULL, 0);
22 LLVMMetadataRef SuperDecl = LLVMDIBuilderCreateStructType(DIB, File, "TestSuperClass", 14, File, 42, 64, 0, LLVMDIFlagObjcClassComplete, NULL, NULL, 0, 0, NULL, NULL, 0);
23 LLVMDIBuilderCreateInheritance(DIB, Decl, SuperDecl, 0, 0, 0);
24 LLVMMetadataRef TestProperty =
25 LLVMDIBuilderCreateObjCProperty(DIB, "test", 4, File, 42, "getTest", 7, "setTest", 7, 0x20 /*copy*/ | 0x40 /*nonatomic*/, SuperDecl);
26 LLVMDIBuilderCreateObjCIVar(DIB, "_test", 5, File, 42, 64, 0, 64, LLVMDIFlagPublic, SuperDecl, TestProperty);
27 return Decl;
28 }
1829
1930 int llvm_test_dibuilder(void) {
2031 const char *Filename = "debuginfo.c";
4657 File, 42);
4758 LLVMDIBuilderCreateImportedModuleFromAlias(DIB, Module, ImportedModule,
4859 File, 42);
60
61 LLVMMetadataRef ClassTy = declare_objc_class(DIB, File);
62 LLVMMetadataRef GlobalClassValueExpr =
63 LLVMDIBuilderCreateConstantValueExpression(DIB, 0);
64 LLVMDIBuilderCreateGlobalVariableExpression(DIB, Module, "globalClass", 11,
65 "", 0, File, 1, ClassTy,
66 true, GlobalClassValueExpr,
67 NULL, 0);
4968
5069 LLVMMetadataRef Int64Ty =
5170 LLVMDIBuilderCreateBasicType(DIB, "Int64", 5, 64, 0);