2
2
import cllvm
3
3
#endif
4
4
5
+ // FIXME: This should be in the bindings.
6
+ public enum MachineInfoRecordType : UInt32 {
7
+ // Macinfo Type Encodings
8
+ case define = 0x01
9
+ case undef = 0x02
10
+ case startFile = 0x03
11
+ case endFile = 0x04
12
+ case vendorExt = 0xff
13
+ }
14
+
5
15
public struct DebugInfoFlags : OptionSet {
6
16
public let rawValue : LLVMDIFlags . RawValue
7
17
@@ -363,7 +373,7 @@ public enum DWARFTypeEncoding {
363
373
364
374
case ascii
365
375
366
- static let typeEncodingMapping : [ DWARFTypeEncoding : LLVMDWARFTypeEncoding ] = [
376
+ private static let typeEncodingMapping : [ DWARFTypeEncoding : LLVMDWARFTypeEncoding ] = [
367
377
. address: LLVMDWARFTypeEncoding_address,
368
378
. boolean: LLVMDWARFTypeEncoding_boolean,
369
379
. complexFloat: LLVMDWARFTypeEncoding_complex_float,
@@ -395,13 +405,67 @@ public enum DWARFEmissionKind {
395
405
case lineTablesOnly
396
406
}
397
407
398
- public struct MetaData {
408
+ public protocol Metadata {
409
+ func asMetadata( ) -> LLVMMetadataRef
410
+ }
411
+
412
+ struct AnyMetadata : Metadata {
413
+ let llvm : LLVMMetadataRef
414
+
415
+ func asMetadata( ) -> LLVMMetadataRef {
416
+ return llvm
417
+ }
418
+ }
419
+
420
+ struct AnyDIType : Metadata , DIType {
421
+ let llvm : LLVMMetadataRef
422
+
423
+ func asMetadata( ) -> LLVMMetadataRef {
424
+ return llvm
425
+ }
426
+
427
+ func asMetadata( with builder: DIBuilder ) -> LLVMMetadataRef {
428
+ return llvm
429
+ }
430
+ }
431
+
432
+ public struct FileMetadata : Metadata {
433
+ internal let llvm : LLVMMetadataRef
434
+
435
+ public func asMetadata( ) -> LLVMMetadataRef {
436
+ return llvm
437
+ }
438
+ }
439
+
440
+ public struct Scope : Metadata {
441
+ internal let llvm : LLVMMetadataRef
442
+
443
+ public func asMetadata( ) -> LLVMMetadataRef {
444
+ return llvm
445
+ }
446
+ }
447
+
448
+ public struct Macro : Metadata {
449
+ internal let llvm : LLVMMetadataRef
450
+
451
+ public func asMetadata( ) -> LLVMMetadataRef {
452
+ return llvm
453
+ }
454
+ }
455
+
456
+ public struct DIModule : Metadata {
399
457
internal let llvm : LLVMMetadataRef
400
458
401
- /// Find subprogram that is enclosing this scope.
402
- var subprogram : MetaData ? {
403
- guard let prgm = LLVMGetSubprogram ( self . llvm) else { return nil }
404
- return MetaData ( llvm: prgm)
459
+ public func asMetadata( ) -> LLVMMetadataRef {
460
+ return llvm
461
+ }
462
+ }
463
+
464
+ public struct DebugLocation : Metadata {
465
+ internal let llvm : LLVMMetadataRef
466
+
467
+ public func asMetadata( ) -> LLVMMetadataRef {
468
+ return llvm
405
469
}
406
470
}
407
471
@@ -416,27 +480,78 @@ public final class DIBuilder {
416
480
self . llvm = LLVMDIBuilderCreate ( module. llvm, allowUnresolved ? 1 : 0 )
417
481
}
418
482
483
+ /// Creates a new DebugLocation that describes a source location.
484
+ public func createDebugLocation( at loc : ( line: Int , column: Int ) , in scope: Scope , inlinedAt: Scope ? = nil ) -> DebugLocation {
485
+ guard let loc = LLVMDIBuilderCreateDebugLocation ( self . module. context. llvm, UInt32 ( loc. line) , UInt32 ( loc. column) , scope. llvm, inlinedAt? . llvm) else {
486
+ fatalError ( )
487
+ }
488
+ return DebugLocation ( llvm: loc)
489
+ }
490
+
419
491
/// Create a file descriptor to hold debugging information for a file.
420
- public func createFile( named name: String , in directory: String ) -> MetaData ? {
492
+ public func createFile( named name: String , in directory: String ) -> FileMetadata ? {
421
493
guard let file = LLVMDIBuilderCreateFile ( self . llvm, name, directory) else { return nil }
422
- return MetaData ( llvm: file)
494
+ return FileMetadata ( llvm: file)
423
495
}
424
496
425
497
/// Create debugging information temporary entry for a macro file.
426
- public func createTemporaryMacroFile( at line: UInt32 , in file: MetaData , withParent parent: MetaData ? = nil ) -> MetaData ? {
498
+ public func createTemporaryMacroFile( at line: UInt32 , in file: FileMetadata , withParent parent: FileMetadata ? = nil ) -> FileMetadata ? {
427
499
guard let file = LLVMDIBuilderCreateTempMacroFile ( self . llvm, parent? . llvm, line, file. llvm) else { return nil }
428
- return MetaData ( llvm: file)
500
+ return FileMetadata ( llvm: file)
501
+ }
502
+
503
+ /// This creates a descriptor for a lexical block with the
504
+ /// specified parent context.
505
+ public func createLexicalBlock( in scope: Scope , in file: FileMetadata , at loc : ( line: Int , column: Int ) ) -> Scope {
506
+ guard let scope = LLVMDIBuilderCreateLexicalBlock ( self . llvm, scope. llvm, file. llvm, UInt32 ( loc. line) , UInt32 ( loc. column) ) else {
507
+ fatalError ( )
508
+ }
509
+ return Scope ( llvm: scope)
510
+ }
511
+
512
+ /// This creates new descriptor for a module with the specified
513
+ /// parent scope.
514
+ public func createModule( in scope: Scope , named name: String , macros: [ String ] , include ipath: String , _ isysRoot: String ) -> DIModule {
515
+ guard let module = LLVMDIBuilderCreateModule ( self . llvm, scope. llvm, name, macros. joined ( separator: " " ) , ipath, isysRoot) else {
516
+ fatalError ( )
517
+ }
518
+ return DIModule ( llvm: module)
519
+ }
520
+
521
+ /// Create debugging information entry for a macro.
522
+ public func createMacro( in parent: FileMetadata , at line: Int , type macroTy: MachineInfoRecordType , name: String ) -> Macro ! {
523
+ guard let macro = LLVMDIBuilderCreateMacro ( self . llvm, parent. asMetadata ( ) , UInt32 ( line) , macroTy. rawValue, name) else {
524
+ fatalError ( )
525
+ }
526
+ return Macro ( llvm: macro)
429
527
}
430
528
431
- /// Create subroutine type.
432
- public func createSubroutineType( in file: MetaData , types: [ MetaData ] ) -> MetaData ? {
433
- var vals = types. map { $0. llvm as Optional }
434
- return vals. withUnsafeMutableBufferPointer { buf in
435
- guard let file = LLVMDIBuilderCreateSubroutineType ( self . llvm, file. llvm, buf. baseAddress, UInt32 ( types. count) ) else { return nil }
436
- return MetaData ( llvm: file)
529
+ /// Create debugging information entry for a typedef.
530
+ public func createTypedef( of type: DIType , named name: String , in file: FileMetadata , at line: Int , in scope: Scope ) -> DIType {
531
+ guard let typedef = LLVMDIBuilderCreateTypedef ( self . llvm, type. asMetadata ( with: self ) , name, file. llvm, UInt32 ( line) , scope. llvm) else {
532
+ fatalError ( )
437
533
}
534
+ return AnyDIType ( llvm: typedef)
438
535
}
439
536
537
+ /// Create a new DIType with "artificial" flag set.
538
+ public func createArtificialType( of type: DIType ) -> DIType {
539
+ guard let ty = LLVMDIBuilderCreateArtificialType ( self . llvm, type. asMetadata ( with: self ) ) else {
540
+ fatalError ( )
541
+ }
542
+ return AnyDIType ( llvm: ty)
543
+ }
544
+
545
+ /// Create a new descriptor for an auto variable. This is a local variable
546
+ /// that is not a subprogram parameter.
547
+ public func createAutoVariable( in scope: Scope , named name: String , in file: FileMetadata , at line: Int , type: DIType , alwaysPreserve: Bool , flags: DebugInfoFlags , aligned alignInBits: Int ) -> Metadata {
548
+ guard let vari = LLVMDIBuilderCreateAutoVariable ( self . llvm, scope. llvm, name, file. llvm, UInt32 ( line) , type. asMetadata ( with: self ) , alwaysPreserve ? 1 : 0 , flags. llvm, UInt32 ( alignInBits) ) else {
549
+ fatalError ( )
550
+ }
551
+ return AnyMetadata ( llvm: vari)
552
+ }
553
+
554
+
440
555
/// Construct any deferred debug info descriptors.
441
556
public func finalize( ) {
442
557
LLVMDIBuilderFinalize ( self . llvm)
@@ -495,20 +610,6 @@ public func LLVMDIBuilderCreateFunction(_ Builder: LLVMDIBuilderRef!, _ Scope: L
495
610
/// except that the resulting DbgNode is meant to be RAUWed.
496
611
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!
497
612
498
- /// Create C++11 nullptr type.
499
-
500
- /// This creates new descriptor for a module with the specified
501
- /// parent scope.
502
- /// \param Builder The DIBuilder.
503
- /// \param Scope Parent scope
504
- /// \param Name Name of this module
505
- /// \param ConfigurationMacros
506
- /// A space-separated shell-quoted list of -D macro
507
- /// definitions as they would appear on a command line.
508
- /// \param IncludePath The path to the module map file.
509
- /// \param ISysRoot The clang system root (value of -isysroot).
510
- public func LLVMDIBuilderCreateModule(_ Builder: LLVMDIBuilderRef!, _ Scope: LLVMMetadataRef!, _ Name: UnsafePointer<Int8>!, _ ConfigurationMacros: UnsafePointer<Int8>!, _ IncludePath: UnsafePointer<Int8>!, _ ISysRoot: UnsafePointer<Int8>!) -> LLVMMetadataRef!
511
-
512
613
/// Create debugging information entry for a class.
513
614
/// \param Scope Scope in which this class is defined.
514
615
/// \param Name class name.
@@ -523,19 +624,6 @@ public func LLVMDIBuilderCreateModule(_ Builder: LLVMDIBuilderRef!, _ Scope: LLV
523
624
/// \param TemplateParms Template type parameters.
524
625
public func LLVMDIBuilderCreateClassType(_ Builder: LLVMDIBuilderRef!, _ Scope: LLVMMetadataRef!, _ Name: UnsafePointer<Int8>!, _ File: LLVMMetadataRef!, _ LineNumber: UInt32, _ SizeInBits: UInt64, _ AlignInBits: UInt32, _ OffsetInBits: UInt64, _ Flags: LLVMDIFlags, _ Elements: UnsafeMutablePointer<LLVMMetadataRef?>!, _ NumElements: UInt32, _ DerivedFrom: LLVMMetadataRef!, _ TemplateParamsNode: LLVMMetadataRef!) -> LLVMMetadataRef!
525
626
526
- /// Create a new DIType* with "artificial" flag set.
527
- public func LLVMDIBuilderCreateArtificialType(_ Builder: LLVMDIBuilderRef!, _ Type: LLVMMetadataRef!) -> LLVMMetadataRef!
528
-
529
- /// Create a new descriptor for an auto variable. This is a local variable
530
- /// that is not a subprogram parameter.
531
- ///
532
- /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually
533
- /// leads to a \a DISubprogram.
534
- ///
535
- /// If \c AlwaysPreserve, this variable will be referenced from its
536
- /// containing subprogram, and will survive some optimizations.
537
- public func LLVMDIBuilderCreateAutoVariable(_ Builder: LLVMDIBuilderRef!, _ Scope: LLVMMetadataRef!, _ Name: UnsafePointer<Int8>!, _ File: LLVMMetadataRef!, _ LineNo: UInt32, _ Type: LLVMMetadataRef!, _ AlwaysPreserve: UInt8, _ Flags: LLVMDIFlags, _ AlignInBits: UInt32) -> LLVMMetadataRef!
538
-
539
627
/// Create a new descriptor for the specified variable.
540
628
/// \param Context Variable scope.
541
629
/// \param Name Name of the variable.
@@ -584,15 +672,6 @@ public func LLVMDIBuilderCreateForwardDecl(_ Builder: LLVMDIBuilderRef!, _ Tag:
584
672
/// \param TParams Function template parameters.
585
673
public func LLVMDIBuilderCreateMethod(_ Builder: LLVMDIBuilderRef!, _ Scope: LLVMMetadataRef!, _ Name: UnsafePointer<Int8>!, _ LinkageName: UnsafePointer<Int8>!, _ File: LLVMMetadataRef!, _ LineNumber: UInt32, _ FuncTy: LLVMMetadataRef!, _ Flags: LLVMDIFlags, _ IsLocalToUnit: UInt8, _ IsDefinition: UInt8, _ IsOptimized: UInt8, _ TemplateParameters: UnsafeMutablePointer<LLVMMetadataRef?>!, _ NumTemplateParameters: UInt32) -> LLVMMetadataRef!
586
674
587
- /// Create debugging information entry for a typedef.
588
- /// \param Builder The DIBuilder.
589
- /// \param Ty Original type.
590
- /// \param Name Typedef name.
591
- /// \param File File where this type is defined.
592
- /// \param LineNo Line number.
593
- /// \param Scope The surrounding context for the typedef.
594
- public func LLVMDIBuilderCreateTypedef(_ Builder: LLVMDIBuilderRef!, _ Type: LLVMMetadataRef!, _ Name: UnsafePointer<Int8>!, _ File: LLVMMetadataRef!, _ Line: UInt32, _ Scope: LLVMMetadataRef!) -> LLVMMetadataRef!
595
-
596
675
/// Create debugging information entry to establish
597
676
/// inheritance relationship between two types.
598
677
/// \param Builder The DIBuilder.
@@ -603,15 +682,6 @@ public func LLVMDIBuilderCreateTypedef(_ Builder: LLVMDIBuilderRef!, _ Type: LLV
603
682
/// e.g. private
604
683
public func LLVMDIBuilderCreateInheritance(_ Builder: LLVMDIBuilderRef!, _ Type: LLVMMetadataRef!, _ BaseType: LLVMMetadataRef!, _ BaseOffset: UInt64, _ Flags: LLVMDIFlags) -> LLVMMetadataRef!
605
684
606
- /// Create debugging information entry for a macro.
607
- /// \param Builder The DIBuilder.
608
- /// \param Parent Macro parent (could be nullptr).
609
- /// \param Line Source line number where the macro is defined.
610
- /// \param MacroType DW_MACINFO_define or DW_MACINFO_undef.
611
- /// \param Name Macro name.
612
- /// \param Value Macro value.
613
- public func LLVMDIBuilderCreateMacro(_ Builder: LLVMDIBuilderRef!, _ ParentMacroFile: LLVMMetadataRef!, _ Line: UInt32, _ MacroType: UInt32, _ Name: UnsafePointer<Int8>!) -> LLVMMetadataRef!
614
-
615
685
/// Create debugging information entry for a 'friend'.
616
686
public func LLVMDIBuilderCreateFriend(_ Builder: LLVMDIBuilderRef!, _ Type: LLVMMetadataRef!, _ FriendType: LLVMMetadataRef!) -> LLVMMetadataRef!
617
687
@@ -736,14 +806,6 @@ public func LLVMDIBuilderCreateUnspecifiedParameter(_ Builder: LLVMDIBuilderRef!
736
806
/// Create a DWARF unspecified type.
737
807
public func LLVMDIBuilderCreateUnspecifiedType(_ Builder: LLVMDIBuilderRef!, _ Name: UnsafePointer<Int8>!) -> LLVMMetadataRef!
738
808
739
- /// This creates a descriptor for a lexical block with the
740
- /// specified parent context.
741
- /// \param Builder The DIBuilder.
742
- /// \param Scope Parent lexical scope.
743
- /// \param File Source file.
744
- /// \param Line Line number.
745
- /// \param Col Column number.
746
- public func LLVMDIBuilderCreateLexicalBlock(_ Builder: LLVMDIBuilderRef!, _ Scope: LLVMMetadataRef!, _ File: LLVMMetadataRef!, _ Line: UInt32, _ Col: UInt32) -> LLVMMetadataRef!
747
809
748
810
/// Create a new descriptor for a parameter variable.
749
811
///
@@ -911,12 +973,4 @@ public func LLVMDIBuilderCreateNameSpace(_ Builder: LLVMDIBuilderRef!, _ Scope:
911
973
/// has a self-reference -- \a DIBuilder needs to track the array to
912
974
/// resolve cycles.
913
975
public func LLVMDICompositeTypeSetTypeArray(_ Builder: LLVMDIBuilderRef!, _ CompositeTy: LLVMMetadataRef!, _ Types: UnsafeMutablePointer<LLVMMetadataRef?>!, _ NumTypes: UInt32)
914
-
915
- /// Creates a new DebugLocation that describes a source location.
916
- /// \param Line The line in the source file.
917
- /// \param Column The column in the source file.
918
- /// \param Scope The scope in which the location resides.
919
- /// \param InlinedAt The scope where this location was inlined, if at all.
920
- /// (optional).
921
- public func LLVMDIBuilderCreateDebugLocation(_ Ctx: LLVMContextRef!, _ Line: UInt32, _ Column: UInt32, _ Scope: LLVMMetadataRef!, _ InlinedAt: LLVMMetadataRef!) -> LLVMMetadataRef!
922
976
*/
0 commit comments