Skip to content

Commit 4d3a12d

Browse files
committed
DIType
1 parent c99b8d1 commit 4d3a12d

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

Sources/LLVM/DIBuilder.swift

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#if !NO_SWIFTPM
2-
import cllvm
2+
import cllvm
33
#endif
44

55
public struct DebugInfoFlags: OptionSet {
@@ -362,6 +362,30 @@ public enum DWARFTypeEncoding {
362362
case ucs
363363

364364
case ascii
365+
366+
static let typeEncodingMapping: [DWARFTypeEncoding: LLVMDWARFTypeEncoding] = [
367+
.address: LLVMDWARFTypeEncoding_address,
368+
.boolean: LLVMDWARFTypeEncoding_boolean,
369+
.complexFloat: LLVMDWARFTypeEncoding_complex_float,
370+
.float: LLVMDWARFTypeEncoding_float, .signed: LLVMDWARFTypeEncoding_signed,
371+
.signedChar: LLVMDWARFTypeEncoding_signed_char,
372+
.unsigned: LLVMDWARFTypeEncoding_unsigned,
373+
.unsignedChar: LLVMDWARFTypeEncoding_unsigned_char,
374+
.imaginaryFloat: LLVMDWARFTypeEncoding_imaginary_float,
375+
.packedDecimal: LLVMDWARFTypeEncoding_packed_decimal,
376+
.numericString: LLVMDWARFTypeEncoding_numeric_string,
377+
.edited: LLVMDWARFTypeEncoding_edited,
378+
.signedFixed: LLVMDWARFTypeEncoding_signed_fixed,
379+
.unsignedFixed: LLVMDWARFTypeEncoding_unsigned_fixed,
380+
.decimalFloat: LLVMDWARFTypeEncoding_decimal_float,
381+
.utf: LLVMDWARFTypeEncoding_UTF, .ucs: LLVMDWARFTypeEncoding_UCS,
382+
.ascii: LLVMDWARFTypeEncoding_ASCII,
383+
]
384+
385+
/// Retrieves the corresponding `LLVMDWARFTypeEncoding`.
386+
public var llvm: LLVMDWARFTypeEncoding {
387+
return DWARFTypeEncoding.typeEncodingMapping[self]!
388+
}
365389
}
366390

367391
/// The amount of debug information to emit.

Sources/LLVM/DIType.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#if !NO_SWIFTPM
2+
import cllvm
3+
#endif
4+
5+
public protocol DIType {
6+
func asMetadata(with builder: DIBuilder) -> LLVMMetadataRef
7+
}

Sources/LLVM/FloatType.swift

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import cllvm
44

55
/// `FloatType` enumerates representations of a floating value of a particular
66
/// bit width and semantics.
7-
public enum FloatType: IRType {
7+
public enum FloatType: IRType, DIType {
88
/// 16-bit floating point value
99
case half
1010
/// 32-bit floating point value
@@ -34,4 +34,28 @@ public enum FloatType: IRType {
3434
case .ppcFP128: return LLVMPPCFP128Type()
3535
}
3636
}
37+
38+
public func asMetadata(with builder: DIBuilder) -> LLVMMetadataRef {
39+
let name: String
40+
switch self {
41+
case .half:
42+
name = "half"
43+
case .float:
44+
name = "float"
45+
case .double:
46+
name = "double"
47+
case .x86FP80:
48+
name = "float80"
49+
case .fp128:
50+
name = "float128"
51+
case .ppcFP128:
52+
name = "ppcfloat128"
53+
}
54+
return LLVMDIBuilderCreateBasicType(
55+
builder.llvm,
56+
name,
57+
UInt64(builder.module.dataLayout.sizeOfTypeInBits(self)),
58+
DWARFTypeEncoding.float.llvm
59+
)
60+
}
3761
}

0 commit comments

Comments
 (0)