Skip to content

Commit eee41b5

Browse files
committed
Fixup COMDAT selection kind
- fix the example the documentation - Rename ComdatSelectionKind to Comdat.SelectionKind
1 parent 917b32e commit eee41b5

File tree

1 file changed

+56
-54
lines changed

1 file changed

+56
-54
lines changed

Sources/LLVM/Comdat.swift

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import cllvm
4242
///
4343
/// var g1 = builder.addGlobal("g1", initializer: IntType.int8.constant(42))
4444
/// g1.comdat = foo
45-
/// var g2 = builder.addGlobal("g1", initializer: IntType.int8.constant(42))
45+
/// var g2 = builder.addGlobal("g2", initializer: IntType.int8.constant(42))
4646
/// g2.comdat = bar
4747
///
4848
/// From the object file perspective, this requires the creation of two sections
@@ -57,66 +57,68 @@ public class Comdat {
5757
}
5858

5959
/// The selection kind for this COMDAT section.
60-
public var selectionKind: ComdatSelectionKind {
61-
get { return ComdatSelectionKind(llvm: LLVMGetComdatSelectionKind(self.llvm)) }
60+
public var selectionKind: Comdat.SelectionKind {
61+
get { return Comdat.SelectionKind(llvm: LLVMGetComdatSelectionKind(self.llvm)) }
6262
set { LLVMSetComdatSelectionKind(self.llvm, newValue.llvm) }
6363
}
6464
}
6565

66-
/// A `ComdatSelectionKind` describes the behavior of the linker when
67-
/// linking COMDAT sections.
68-
public enum ComdatSelectionKind {
69-
/// The linker may choose any COMDAT section with a matching key.
70-
///
71-
/// This selection kind is the most relaxed - any section with the same key
72-
/// but not necessarily identical size or contents can be chosen. Precisely
73-
/// which section is chosen is implementation-defined.
74-
///
75-
/// This selection kind is the default for all newly-inserted sections.
76-
case any
77-
/// The linker may choose any identically-keyed COMDAT section and requires
78-
/// all other referenced data to match its selection's referenced data.
79-
///
80-
/// This selection kind requires that the data in each COMDAT section be
81-
/// identical in length and content. Inclusion of multiple non-identical
82-
/// COMDAT sections with the same key is an error.
83-
///
84-
/// For global objects in LLVM, identical contents is defined to mean that
85-
/// their initializers point to the same global `IRValue`.
86-
case exactMatch
87-
/// The linker chooses the identically-keyed COMDAT section with the largest
88-
/// size, ignoring content.
89-
case largest
90-
/// The COMDAT section with this key is unique.
91-
///
92-
/// This selection requires that no other COMDAT section have the same key
93-
/// as this section, making the choice of selection unambiguous. Inclusion
94-
/// of any other COMDAT section with the same key is an error.
95-
case noDuplicates
96-
/// The linker may choose any identically-keyed COMDAT section and requires
97-
/// all other sections to have the same size as its selection.
98-
case sameSize
66+
extension Comdat {
67+
/// A `Comdat.SelectionKind` describes the behavior of the linker when
68+
/// linking COMDAT sections.
69+
public enum SelectionKind {
70+
/// The linker may choose any COMDAT section with a matching key.
71+
///
72+
/// This selection kind is the most relaxed - any section with the same key
73+
/// but not necessarily identical size or contents can be chosen. Precisely
74+
/// which section is chosen is implementation-defined.
75+
///
76+
/// This selection kind is the default for all newly-inserted sections.
77+
case any
78+
/// The linker may choose any identically-keyed COMDAT section and requires
79+
/// all other referenced data to match its selection's referenced data.
80+
///
81+
/// This selection kind requires that the data in each COMDAT section be
82+
/// identical in length and content. Inclusion of multiple non-identical
83+
/// COMDAT sections with the same key is an error.
84+
///
85+
/// For global objects in LLVM, identical contents is defined to mean that
86+
/// their initializers point to the same global `IRValue`.
87+
case exactMatch
88+
/// The linker chooses the identically-keyed COMDAT section with the largest
89+
/// size, ignoring content.
90+
case largest
91+
/// The COMDAT section with this key is unique.
92+
///
93+
/// This selection requires that no other COMDAT section have the same key
94+
/// as this section, making the choice of selection unambiguous. Inclusion
95+
/// of any other COMDAT section with the same key is an error.
96+
case noDuplicates
97+
/// The linker may choose any identically-keyed COMDAT section and requires
98+
/// all other sections to have the same size as its selection.
99+
case sameSize
99100

100-
internal init(llvm: LLVMComdatSelectionKind) {
101-
switch llvm {
102-
case LLVMAnyComdatSelectionKind: self = .any
103-
case LLVMExactMatchComdatSelectionKind: self = .exactMatch
104-
case LLVMLargestComdatSelectionKind: self = .largest
105-
case LLVMNoDuplicatesComdatSelectionKind: self = .noDuplicates
106-
case LLVMSameSizeComdatSelectionKind: self = .sameSize
107-
default: fatalError("unknown comdat selection kind \(llvm)")
101+
internal init(llvm: LLVMComdatSelectionKind) {
102+
switch llvm {
103+
case LLVMAnyComdatSelectionKind: self = .any
104+
case LLVMExactMatchComdatSelectionKind: self = .exactMatch
105+
case LLVMLargestComdatSelectionKind: self = .largest
106+
case LLVMNoDuplicatesComdatSelectionKind: self = .noDuplicates
107+
case LLVMSameSizeComdatSelectionKind: self = .sameSize
108+
default: fatalError("unknown comdat selection kind \(llvm)")
109+
}
108110
}
109-
}
110111

111-
private static let comdatMapping: [ComdatSelectionKind: LLVMComdatSelectionKind] = [
112-
.any: LLVMAnyComdatSelectionKind,
113-
.exactMatch: LLVMExactMatchComdatSelectionKind,
114-
.largest: LLVMLargestComdatSelectionKind,
115-
.noDuplicates: LLVMNoDuplicatesComdatSelectionKind,
116-
.sameSize: LLVMSameSizeComdatSelectionKind,
117-
]
112+
private static let comdatMapping: [Comdat.SelectionKind: LLVMComdatSelectionKind] = [
113+
.any: LLVMAnyComdatSelectionKind,
114+
.exactMatch: LLVMExactMatchComdatSelectionKind,
115+
.largest: LLVMLargestComdatSelectionKind,
116+
.noDuplicates: LLVMNoDuplicatesComdatSelectionKind,
117+
.sameSize: LLVMSameSizeComdatSelectionKind,
118+
]
118119

119-
fileprivate var llvm: LLVMComdatSelectionKind {
120-
return ComdatSelectionKind.comdatMapping[self]!
120+
fileprivate var llvm: LLVMComdatSelectionKind {
121+
return SelectionKind.comdatMapping[self]!
122+
}
121123
}
122124
}

0 commit comments

Comments
 (0)