1
- #if !NO_SWIFTPM
1
+ #if SWIFT_PACKAGE
2
2
import cllvm
3
3
#endif
4
4
@@ -584,8 +584,11 @@ public final class DIBuilder {
584
584
585
585
/// Creates a new DebugLocation that describes a source location.
586
586
public func createDebugLocation( at loc : ( line: Int , column: Int ) , in scope: Scope , inlinedAt: Scope ? = nil ) -> DebugLocation {
587
- guard let loc = LLVMDIBuilderCreateDebugLocation ( self . module. context. llvm, UInt32 ( loc. line) , UInt32 ( loc. column) , scope. llvm, inlinedAt? . llvm) else {
588
- fatalError ( )
587
+ guard let loc = LLVMDIBuilderCreateDebugLocation (
588
+ self . module. context. llvm, UInt32 ( loc. line) , UInt32 ( loc. column) ,
589
+ scope. llvm, inlinedAt? . llvm
590
+ ) else {
591
+ fatalError ( " Failed to allocate metadata for a debug location " )
589
592
}
590
593
return DebugLocation ( llvm: loc)
591
594
}
@@ -610,14 +613,18 @@ public final class DIBuilder {
610
613
}
611
614
612
615
/// Create a file descriptor to hold debugging information for a file.
613
- public func createFile( named name: String , in directory: String ) -> FileMetadata ? {
614
- guard let file = LLVMDIBuilderCreateFile ( self . llvm, name, directory) else { return nil }
616
+ public func createFile( named name: String , in directory: String ) -> FileMetadata {
617
+ guard let file = LLVMDIBuilderCreateFile ( self . llvm, name, directory) else {
618
+ fatalError ( " Failed to allocate metadata for a file " )
619
+ }
615
620
return FileMetadata ( llvm: file)
616
621
}
617
622
618
623
/// Create debugging information temporary entry for a macro file.
619
- public func createTemporaryMacroFile( at line: UInt32 , in file: FileMetadata , withParent parent: FileMetadata ? = nil ) -> FileMetadata ? {
620
- guard let file = LLVMDIBuilderCreateTempMacroFile ( self . llvm, parent? . llvm, line, file. llvm) else { return nil }
624
+ public func createTemporaryMacroFile( at line: Int , in file: FileMetadata , withParent parent: FileMetadata ? = nil ) -> FileMetadata {
625
+ guard let file = LLVMDIBuilderCreateTempMacroFile ( self . llvm, parent? . llvm, UInt32 ( line) , file. llvm) else {
626
+ fatalError ( " Failed to allocate metadata for a temporary macro file " )
627
+ }
621
628
return FileMetadata ( llvm: file)
622
629
}
623
630
@@ -654,17 +661,68 @@ public final class DIBuilder {
654
661
isOptimized ? 1 : 0 ,
655
662
body. llvm, nil , 0 , nil
656
663
) else {
657
- fatalError ( )
664
+ fatalError ( " Failed to allocate metadata for a function " )
658
665
}
659
666
return Scope ( llvm: gn)
660
667
}
661
668
}
662
669
670
+ /// Identical to LLVMDIBuilderCreateFunction,
671
+ /// except that the resulting DbgNode is meant to be RAUWed.
672
+ public func createTemporaryFunctionForwardDeclaration(
673
+ in scope: Scope , named name: String , linkageName mangled: String ,
674
+ in file: FileMetadata , at line: Int , body: Function ,
675
+ isLocal: Bool , isDefinition: Bool ,
676
+ scopeLine: Int ,
677
+ flags: DebugInfoFlags = . zero,
678
+ isOptimized: Bool = false
679
+ ) -> Scope {
680
+ // HACK: Functions come in as function pointers.
681
+ let bodyTy : FunctionType
682
+ if let pfty = body. type as? PointerType , pfty. pointee is FunctionType {
683
+ bodyTy = pfty. pointee as! FunctionType
684
+ } else {
685
+ bodyTy = body. type as! FunctionType
686
+ }
687
+ var elemMetadata = bodyTy. argTypes. map { ( ty) -> LLVMMetadataRef ? in
688
+ if let elemDI = ty as? DIType {
689
+ return elemDI. asMetadata ( with: self )
690
+ } else {
691
+ return LLVMDIBuilderCreateUnspecifiedType ( self . llvm, " <unspecified> " )
692
+ }
693
+ }
694
+ return elemMetadata. withUnsafeMutableBufferPointer { buf in
695
+ let fnTy = LLVMDIBuilderCreateSubroutineType ( self . llvm, file. llvm, buf. baseAddress!, UInt32 ( elemMetadata. count) )
696
+ guard let tffd = LLVMDIBuilderCreateTempFunctionFwdDecl (
697
+ self . llvm, scope. llvm, name, mangled, file. llvm, UInt32 ( line) , fnTy,
698
+ isLocal ? 1 : 0 ,
699
+ isDefinition ? 1 : 0 ,
700
+ UInt32 ( scopeLine) , flags. llvm,
701
+ isOptimized ? 1 : 0 ,
702
+ body. llvm, nil , 0 , nil
703
+ ) else {
704
+ fatalError ( " Failed to allocate metadata for a temporary forward declaration " )
705
+ }
706
+ return Scope ( llvm: tffd)
707
+ }
708
+ }
709
+
710
+
711
+ /// This creates a descriptor for a lexical block with a new file
712
+ /// attached. This merely extends the existing
713
+ /// lexical block as it crosses a file.
714
+ public func createLexicalBlockFile( in scope: Scope , in file: FileMetadata ) -> Scope {
715
+ guard let scope = LLVMDIBuilderCreateLexicalBlockFile ( self . llvm, scope. llvm, file. llvm) else {
716
+ fatalError ( " Failed to allocate metadata for a lexical block file extension " )
717
+ }
718
+ return Scope ( llvm: scope)
719
+ }
720
+
663
721
/// This creates a descriptor for a lexical block with the
664
722
/// specified parent context.
665
723
public func createLexicalBlock( in scope: Scope , in file: FileMetadata , at loc : ( line: Int , column: Int ) ) -> Scope {
666
724
guard let scope = LLVMDIBuilderCreateLexicalBlock ( self . llvm, scope. llvm, file. llvm, UInt32 ( loc. line) , UInt32 ( loc. column) ) else {
667
- fatalError ( )
725
+ fatalError ( " Failed to allocate metadata for a lexical block " )
668
726
}
669
727
return Scope ( llvm: scope)
670
728
}
@@ -673,35 +731,56 @@ public final class DIBuilder {
673
731
/// parent scope.
674
732
public func createModule( in scope: Scope , named name: String , macros: [ String ] , include ipath: String , _ isysRoot: String ) -> DIModule {
675
733
guard let module = LLVMDIBuilderCreateModule ( self . llvm, scope. llvm, name, macros. joined ( separator: " " ) , ipath, isysRoot) else {
676
- fatalError ( )
734
+ fatalError ( " Failed to allocate metadata for a module " )
677
735
}
678
736
return DIModule ( llvm: module)
679
737
}
680
738
681
739
/// Create debugging information entry for a macro.
682
- public func createMacro( in parent: FileMetadata , at line: Int , type macroTy: MachineInfoRecordType , name: String ) -> Macro ! {
740
+ public func createMacro( in parent: FileMetadata , at line: Int , type macroTy: MachineInfoRecordType , name: String ) -> Macro {
683
741
guard let macro = LLVMDIBuilderCreateMacro ( self . llvm, parent. asMetadata ( ) , UInt32 ( line) , macroTy. rawValue, name) else {
684
- fatalError ( )
742
+ fatalError ( " Failed to allocate metadata for a macro " )
685
743
}
686
744
return Macro ( llvm: macro)
687
745
}
688
746
689
747
/// Create debugging information entry for a typedef.
690
748
public func createTypedef( of type: DIType , named name: String , in file: FileMetadata , at line: Int , in scope: Scope ) -> DIType {
691
749
guard let typedef = LLVMDIBuilderCreateTypedef ( self . llvm, type. asMetadata ( with: self ) , name, file. llvm, UInt32 ( line) , scope. llvm) else {
692
- fatalError ( )
750
+ fatalError ( " Failed to allocate metadata for a typedef " )
693
751
}
694
752
return AnyDIType ( llvm: typedef)
695
753
}
696
754
697
755
/// Create a new DIType with "artificial" flag set.
698
756
public func createArtificialType( of type: DIType ) -> DIType {
699
757
guard let ty = LLVMDIBuilderCreateArtificialType ( self . llvm, type. asMetadata ( with: self ) ) else {
700
- fatalError ( )
758
+ fatalError ( " Failed to allocate metadata for an artificial type " )
701
759
}
702
760
return AnyDIType ( llvm: ty)
703
761
}
704
762
763
+ /// Create a permanent forward-declared type.
764
+ public func createForwardDecl( in scope: Scope , named name: String , in file: FileMetadata , at line: Int , tag: Int ) -> DIType {
765
+ guard let fd = LLVMDIBuilderCreateForwardDecl ( self . llvm, UInt32 ( tag) , name, scope. llvm, file. llvm, UInt32 ( line) ) else {
766
+ fatalError ( " Failed to allocate metadata for a forward declaration " )
767
+ }
768
+ return AnyDIType ( llvm: fd)
769
+ }
770
+
771
+ /// Create a new descriptor for a parameter variable.
772
+ public func createParameterVariable( in scope: Scope , named name: String , at index: UInt32 , in file: FileMetadata , at line: Int , type: DIType , _ alwaysPreserve: Bool = true , flags: DebugInfoFlags = . zero) -> VariableMetadata {
773
+ guard let pv = LLVMDIBuilderCreateParameterVariable (
774
+ self . llvm, scope. llvm, name, UInt32 ( index) , file. llvm, UInt32 ( line) ,
775
+ type. asMetadata ( with: self ) ,
776
+ alwaysPreserve ? 1 : 0 , flags. llvm
777
+ ) else {
778
+ fatalError ( " Failed to allocate metadata for a parameter variable " )
779
+ }
780
+ return VariableMetadata ( llvm: pv)
781
+ }
782
+
783
+
705
784
/// Create a new descriptor for an auto variable. This is a local variable
706
785
/// that is not a subprogram parameter.
707
786
public func createAutoVariable( in scope: Scope , named name: String , in file: FileMetadata , at line: Int , type: DIType , alwaysPreserve: Bool , flags: DebugInfoFlags , aligned alignInBits: Int ) -> VariableMetadata {
@@ -718,7 +797,7 @@ public final class DIBuilder {
718
797
}
719
798
720
799
/// Create debugging information entry for a struct.
721
- public func createStructType( for type: StructType , in scope: Scope , in file: FileMetadata , at line: Int , flags: DebugInfoFlags = DebugInfoFlags . zero, uniqueID: String ) -> Metadata {
800
+ public func createStructType( for type: StructType , in scope: Scope , in file: FileMetadata , at line: Int , flags: DebugInfoFlags = DebugInfoFlags . zero, uniqueID: String ) -> DIType {
722
801
var elemMetadata = type. elementTypes. map { ( ty) -> LLVMMetadataRef ? in
723
802
if let elemDI = ty as? DIType {
724
803
return elemDI. asMetadata ( with: self )
@@ -728,7 +807,7 @@ public final class DIBuilder {
728
807
}
729
808
730
809
return elemMetadata. withUnsafeMutableBufferPointer { buf in
731
- return AnyMetadata ( llvm:
810
+ return AnyDIType ( llvm:
732
811
LLVMDIBuilderCreateStructType (
733
812
self . llvm, scope. llvm, type. name, file. llvm, UInt32 ( line) ,
734
813
UInt64 ( self . module. dataLayout. sizeOfTypeInBits ( type) ) ,
@@ -752,10 +831,6 @@ public final class DIBuilder {
752
831
753
832
/*
754
833
755
- /// Identical to LLVMDIBuilderCreateFunction,
756
- /// except that the resulting DbgNode is meant to be RAUWed.
757
- public func LLVMDIBuilderCreateTempFunctionFwdDecl(_ Builder: LLVMDIBuilderRef!, _ Scope: LLVMMetadataRef!, _ Name: UnsafePointer<Int8>!, _ LinkageName: UnsafePointer<Int8>!, _ File: LLVMMetadataRef!, _ LineNo: UInt32, _ Ty: LLVMMetadataRef!, _ IsLocalToUnit: UInt8, _ IsDefinition: UInt8, _ ScopeLine: UInt32, _ Flags: LLVMDIFlags, _ IsOptimized: UInt8, _ Fn: LLVMValueRef!, _ TemplateParams: UnsafeMutablePointer<LLVMMetadataRef?>!, _ NumTemplateParams: UInt32, _ Decl: LLVMMetadataRef!) -> LLVMMetadataRef!
758
-
759
834
/// Create debugging information entry for a class.
760
835
/// \param Scope Scope in which this class is defined.
761
836
/// \param Name class name.
@@ -799,9 +874,6 @@ public func LLVMDIBuilderCreateGlobalVariableExpression(_ Builder: LLVMDIBuilder
799
874
/// \param Type Parent type.
800
875
public func LLVMDIBuilderCreateBitFieldMemberType(_ Builder: LLVMDIBuilderRef!, _ Scope: LLVMMetadataRef!, _ Name: UnsafePointer<Int8>!, _ File: LLVMMetadataRef!, _ LineNumber: UInt32, _ SizeInBits: UInt64, _ OffsetInBits: UInt64, _ StorageOffsetInBits: UInt64, _ Flags: LLVMDIFlags, _ Type: LLVMMetadataRef!) -> LLVMMetadataRef!
801
876
802
- /// Create a permanent forward-declared type.
803
- public func LLVMDIBuilderCreateForwardDecl(_ Builder: LLVMDIBuilderRef!, _ Tag: UInt32, _ Name: UnsafePointer<Int8>!, _ Scope: LLVMMetadataRef!, _ File: LLVMMetadataRef!, _ Line: UInt32) -> LLVMMetadataRef!
804
-
805
877
/// Create a new descriptor for the specified C++ method.
806
878
/// See comments in \a DISubprogram* for descriptions of these fields.
807
879
/// \param Scope Function scope.
@@ -937,63 +1009,6 @@ public func LLVMDIBuilderCreateUnspecifiedParameter(_ Builder: LLVMDIBuilderRef!
937
1009
/// Create a DWARF unspecified type.
938
1010
public func LLVMDIBuilderCreateUnspecifiedType(_ Builder: LLVMDIBuilderRef!, _ Name: UnsafePointer<Int8>!) -> LLVMMetadataRef!
939
1011
940
-
941
- /// Create a new descriptor for a parameter variable.
942
- ///
943
- /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually
944
- /// leads to a \a DISubprogram.
945
- ///
946
- /// \c ArgNo is the index (starting from \c 1) of this variable in the
947
- /// subprogram parameters. \c ArgNo should not conflict with other
948
- /// parameters of the same subprogram.
949
- ///
950
- /// If \c AlwaysPreserve, this variable will be referenced from its
951
- /// containing subprogram, and will survive some optimizations.
952
- public func LLVMDIBuilderCreateParameterVariable(_ Builder: LLVMDIBuilderRef!, _ Scope: LLVMMetadataRef!, _ Name: UnsafePointer<Int8>!, _ ArgNum: UInt32, _ File: LLVMMetadataRef!, _ LineNum: UInt32, _ Type: LLVMMetadataRef!, _ AlwaysPreserve: UInt8, _ Flags: LLVMDIFlags) -> LLVMMetadataRef!
953
-
954
- /// This creates a descriptor for a lexical block with a new file
955
- /// attached. This merely extends the existing
956
- /// lexical block as it crosses a file.
957
- /// \param Builder The DIBuilder.
958
- /// \param Scope Lexical block.
959
- /// \param File Source file.
960
- /// \param Discriminator DWARF path discriminator value.
961
- public func LLVMDIBuilderCreateLexicalBlockFile(_ Builder: LLVMDIBuilderRef!, _ Scope: LLVMMetadataRef!, _ File: LLVMMetadataRef!) -> LLVMMetadataRef!
962
-
963
- /// Create an expression for a variable that does not have an address, but
964
- /// does have a constant value.
965
- public func LLVMDIBuilderCreateConstantValueExpression(_ Builder: LLVMDIBuilderRef!, _ Val: UInt64) -> LLVMMetadataRef!
966
-
967
- /// Create a descriptor to describe one part
968
- /// of aggregate variable that is fragmented across multiple Values.
969
- ///
970
- /// \param Builder The DIBuilder.
971
- /// \param OffsetInBits Offset of the piece in bits.
972
- /// \param SizeInBits Size of the piece in bits.
973
- public func LLVMDIBuilderCreateFragmentExpression(_ Builder: LLVMDIBuilderRef!, _ OffsetInBits: UInt32, _ SizeInBits: UInt32) -> LLVMMetadataRef!
974
-
975
- /// Create a new descriptor for the specified
976
- /// variable which has a complex address expression for its address.
977
- /// \param Builder The DIBuilder.
978
- /// \param Addrs One or more complex address operations.
979
- /// \param NumAddrs The number of addresses that \c Addrs points to.
980
- public func LLVMDIBuilderCreateExpression(_ Builder: LLVMDIBuilderRef!, _ Addrs: UnsafeMutablePointer<Int64>!, _ NumAddrs: UInt32) -> LLVMMetadataRef!
981
-
982
- /// Create debugging information entry for an array.
983
- /// \param Builder The DIBuilder.
984
- /// \param Size Array size.
985
- /// \param AlignInBits Alignment.
986
- /// \param Ty Element type.
987
- /// \param Subscripts Subscripts.
988
- public func LLVMDIBuilderCreateArrayType(_ Builder: LLVMDIBuilderRef!, _ Size: UInt64, _ AlignInBits: UInt32, _ Ty: LLVMMetadataRef!, _ Subscripts: UnsafeMutablePointer<LLVMMetadataRef?>!, _ NumSubscripts: UInt32) -> LLVMMetadataRef!
989
-
990
- /// Create debugging information entry for a vector type.
991
- /// \param Size Array size.
992
- /// \param AlignInBits Alignment.
993
- /// \param Ty Element type.
994
- /// \param Subscripts Subscripts.
995
- public func LLVMDIBuilderCreateVectorType(_ Builder: LLVMDIBuilderRef!, _ Size: UInt64, _ AlignInBits: UInt32, _ Ty: LLVMMetadataRef!, _ Subscripts: UnsafeMutablePointer<LLVMMetadataRef?>!, _ NumSubscripts: UInt32) -> LLVMMetadataRef!
996
-
997
1012
/// Create a descriptor for a value range. This
998
1013
/// implicitly uniques the values returned.
999
1014
public func LLVMDIBuilderGetOrCreateSubrange(_ Builder: LLVMDIBuilderRef!, _ Lo: Int64, _ Count: Int64) -> LLVMMetadataRef!
0 commit comments