Skip to content

Commit af34716

Browse files
committed
XXX
1 parent 51312b1 commit af34716

File tree

1 file changed

+126
-34
lines changed

1 file changed

+126
-34
lines changed

Sources/LLVM/DIBuilder.swift

Lines changed: 126 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,17 @@ public struct DebugInfoFlags: OptionSet {
8282

8383
/// Source languages known by DWARF.
8484
public enum DWARFSourceLanguage {
85+
case ada83
86+
87+
case ada95
88+
8589
case c
8690

8791
case c89
8892

89-
case c11
93+
case c99
9094

91-
case ada83
95+
case c11
9296

9397
case cPlusPlus
9498

@@ -106,16 +110,16 @@ public enum DWARFSourceLanguage {
106110

107111
case fortran90
108112

113+
case fortran03
114+
115+
case fortran08
116+
109117
case pascal83
110118

111119
case modula2
112120

113121
case java
114122

115-
case c99
116-
117-
case ada95
118-
119123
case fortran95
120124

121125
case PLI
@@ -147,10 +151,6 @@ public enum DWARFSourceLanguage {
147151
case julia
148152

149153
case dylan
150-
151-
case fortran03
152-
153-
case fortran08
154154

155155
case renderScript
156156

@@ -163,6 +163,53 @@ public enum DWARFSourceLanguage {
163163
case googleRenderScript
164164

165165
case borlandDelphi
166+
167+
168+
private static let languageMapping: [DWARFSourceLanguage: LLVMDWARFSourceLanguage] = [
169+
.c: LLVMDWARFSourceLanguageC, .c89: LLVMDWARFSourceLanguageC89,
170+
.c99: LLVMDWARFSourceLanguageC99, .c11: LLVMDWARFSourceLanguageC11,
171+
.ada83: LLVMDWARFSourceLanguageAda83,
172+
.cPlusPlus: LLVMDWARFSourceLanguageC_plus_plus,
173+
.cPlusPlus03: LLVMDWARFSourceLanguageC_plus_plus_03,
174+
.cPlusPlus11: LLVMDWARFSourceLanguageC_plus_plus_11,
175+
.cPlusPlus14: LLVMDWARFSourceLanguageC_plus_plus_14,
176+
.cobol74: LLVMDWARFSourceLanguageCobol74,
177+
.cobol85: LLVMDWARFSourceLanguageCobol85,
178+
.fortran77: LLVMDWARFSourceLanguageFortran77,
179+
.fortran90: LLVMDWARFSourceLanguageFortran90,
180+
.pascal83: LLVMDWARFSourceLanguagePascal83,
181+
.modula2: LLVMDWARFSourceLanguageModula2,
182+
.java: LLVMDWARFSourceLanguageJava,
183+
.ada95: LLVMDWARFSourceLanguageAda95,
184+
.fortran95: LLVMDWARFSourceLanguageFortran95,
185+
.PLI: LLVMDWARFSourceLanguagePLI,
186+
.objC: LLVMDWARFSourceLanguageObjC,
187+
.objCPlusPlus: LLVMDWARFSourceLanguageObjC_plus_plus,
188+
.UPC: LLVMDWARFSourceLanguageUPC,
189+
.D: LLVMDWARFSourceLanguageD,
190+
.python: LLVMDWARFSourceLanguagePython,
191+
.openCL: LLVMDWARFSourceLanguageOpenCL,
192+
.go: LLVMDWARFSourceLanguageGo,
193+
.modula3: LLVMDWARFSourceLanguageModula3,
194+
.haskell: LLVMDWARFSourceLanguageHaskell,
195+
.ocaml: LLVMDWARFSourceLanguageOCaml,
196+
.rust: LLVMDWARFSourceLanguageRust,
197+
.swift: LLVMDWARFSourceLanguageSwift,
198+
.julia: LLVMDWARFSourceLanguageJulia,
199+
.dylan: LLVMDWARFSourceLanguageDylan,
200+
.fortran03: LLVMDWARFSourceLanguageFortran03,
201+
.fortran08: LLVMDWARFSourceLanguageFortran08,
202+
.renderScript: LLVMDWARFSourceLanguageRenderScript,
203+
.BLISS: LLVMDWARFSourceLanguageBLISS,
204+
.mipsAssembler: LLVMDWARFSourceLanguageMips_Assembler,
205+
.googleRenderScript: LLVMDWARFSourceLanguageGOOGLE_RenderScript,
206+
.borlandDelphi: LLVMDWARFSourceLanguageBORLAND_Delphi,
207+
]
208+
209+
/// Retrieves the corresponding `LLVMDWARFSourceLanguage`.
210+
public var llvm: LLVMDWARFSourceLanguage {
211+
return DWARFSourceLanguage.languageMapping[self]!
212+
}
166213
}
167214

168215
/// Qualifiers for types, e.g. \c const.
@@ -403,6 +450,16 @@ public enum DWARFEmissionKind {
403450
case none
404451
case full
405452
case lineTablesOnly
453+
454+
private static let emissionMapping: [DWARFEmissionKind: LLVMDWARFEmissionKind] = [
455+
.none: LLVMDWARFEmissionNone, .full: LLVMDWARFEmissionFull,
456+
.lineTablesOnly: LLVMDWARFEmissionLineTablesOnly,
457+
]
458+
459+
/// Retrieves the corresponding `LLVMDWARFEmissionKind`.
460+
public var llvm: LLVMDWARFEmissionKind {
461+
return DWARFEmissionKind.emissionMapping[self]!
462+
}
406463
}
407464

408465
public protocol Metadata {
@@ -461,6 +518,15 @@ public struct DIModule: Metadata {
461518
}
462519
}
463520

521+
public struct DICompileUnit: Metadata {
522+
internal let llvm: LLVMMetadataRef
523+
524+
public func asMetadata() -> LLVMMetadataRef {
525+
return llvm
526+
}
527+
}
528+
529+
464530
public struct DebugLocation: Metadata {
465531
internal let llvm: LLVMMetadataRef
466532

@@ -480,6 +546,55 @@ public final class DIBuilder {
480546
self.llvm = LLVMDIBuilderCreate(module.llvm, allowUnresolved ? 1 : 0)
481547
}
482548

549+
/// A CompileUnit provides an anchor for all debugging
550+
/// information generated during this instance of compilation.
551+
/// \param Lang Source programming language, eg.
552+
/// \c LLVMDWARFSourceLanguageC99
553+
/// \param File File info.
554+
/// \param Producer Identify the producer of debugging information
555+
/// and code. Usually this is a compiler
556+
/// version string.
557+
/// \param isOptimized A boolean flag which indicates whether optimization
558+
/// is enabled or not.
559+
/// \param Flags This string lists command line options. This
560+
/// string is directly embedded in debug info
561+
/// output which may be used by a tool
562+
/// analyzing generated debugging information.
563+
/// \param RuntimeVer This indicates runtime version for languages like
564+
/// Objective-C.
565+
/// \param SplitName The name of the file that we'll split debug info
566+
/// out into.
567+
/// \param Kind The kind of debug information to generate.
568+
/// \param DWOId The DWOId if this is a split skeleton compile unit.
569+
/// \param SplitDebugInlining Whether to emit inline debug info.
570+
/// \param DebugInfoForProfiling Whether to emit extra debug info for
571+
/// profile collection.
572+
public func createCompileUnit(
573+
for lang: DWARFSourceLanguage,
574+
in file: FileMetadata,
575+
identity: String = "",
576+
optimized: Bool,
577+
flags: [String],
578+
runtimeVersion: Int,
579+
splitName: String,
580+
kind: DWARFEmissionKind,
581+
DWOId: UInt64,
582+
splitDebugInlining: Bool,
583+
debugInfoForProfiling: Bool
584+
) -> DICompileUnit {
585+
guard let cu = LLVMDIBuilderCreateCompileUnit(
586+
self.llvm, lang.llvm, file.llvm, identity,
587+
optimized ? 1 : 0,
588+
flags.joined(separator: " "), UInt32(runtimeVersion), splitName,
589+
kind.llvm, DWOId,
590+
splitDebugInlining ? 1 : 0,
591+
debugInfoForProfiling ? 1 : 0
592+
) else {
593+
fatalError()
594+
}
595+
return DICompileUnit(llvm: cu)
596+
}
597+
483598
/// Creates a new DebugLocation that describes a source location.
484599
public func createDebugLocation(at loc : (line: Int, column: Int), in scope: Scope, inlinedAt: Scope? = nil) -> DebugLocation {
485600
guard let loc = LLVMDIBuilderCreateDebugLocation(self.module.context.llvm, UInt32(loc.line), UInt32(loc.column), scope.llvm, inlinedAt?.llvm) else {
@@ -563,30 +678,7 @@ public final class DIBuilder {
563678
}
564679

565680
/*
566-
/// A CompileUnit provides an anchor for all debugging
567-
/// information generated during this instance of compilation.
568-
/// \param Lang Source programming language, eg.
569-
/// \c LLVMDWARFSourceLanguageC99
570-
/// \param File File info.
571-
/// \param Producer Identify the producer of debugging information
572-
/// and code. Usually this is a compiler
573-
/// version string.
574-
/// \param isOptimized A boolean flag which indicates whether optimization
575-
/// is enabled or not.
576-
/// \param Flags This string lists command line options. This
577-
/// string is directly embedded in debug info
578-
/// output which may be used by a tool
579-
/// analyzing generated debugging information.
580-
/// \param RuntimeVer This indicates runtime version for languages like
581-
/// Objective-C.
582-
/// \param SplitName The name of the file that we'll split debug info
583-
/// out into.
584-
/// \param Kind The kind of debug information to generate.
585-
/// \param DWOId The DWOId if this is a split skeleton compile unit.
586-
/// \param SplitDebugInlining Whether to emit inline debug info.
587-
/// \param DebugInfoForProfiling Whether to emit extra debug info for
588-
/// profile collection.
589-
public func LLVMDIBuilderCreateCompileUnit(_ Builder: LLVMDIBuilderRef!, _ Lang: LLVMDWARFSourceLanguage, _ FileRef: LLVMMetadataRef!, _ Producer: UnsafePointer<Int8>!, _ isOptimized: UInt8, _ Flags: UnsafePointer<Int8>!, _ RuntimeVer: UInt32, _ SplitName: UnsafePointer<Int8>!, _ Kind: LLVMDWARFEmissionKind, _ DWOId: UInt64, _ SplitDebugInlining: UInt8, _ DebugInfoForProfiling: UInt8) -> LLVMMetadataRef!
681+
590682

591683
/// Create a new descriptor for the specified subprogram.
592684
/// See comments in DISubprogram* for descriptions of these fields.

0 commit comments

Comments
 (0)