Skip to content

Commit c70e301

Browse files
authored
Merge pull request #76 from CodaFi/uhaul
Provide declspec attributes
2 parents 66a0be4 + 3eeeeef commit c70e301

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

Sources/LLVM/IRGlobal.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,11 @@ extension IRGlobal {
1818
get { return Visibility(llvm: LLVMGetVisibility(asLLVM())) }
1919
set { LLVMSetVisibility(asLLVM(), newValue.llvm) }
2020
}
21+
22+
/// Retrieves the storage class for this global declaration. For use with
23+
/// Portable Executable files.
24+
public var storageClass: StorageClass {
25+
get { return StorageClass(llvm: LLVMGetDLLStorageClass(asLLVM())) }
26+
set { LLVMSetDLLStorageClass(asLLVM(), newValue.llvm) }
27+
}
2128
}

Sources/LLVM/Linkage.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,41 @@ public enum Linkage {
178178
return Linkage.linkageMapping[self]!
179179
}
180180
}
181+
182+
/// `StorageClass` enumerates the storage classes for globals in a Portable
183+
/// Executable file.
184+
public enum StorageClass {
185+
/// The default storage class for declarations is neither imported nor
186+
/// exported to/from a DLL.
187+
case `default`
188+
/// The storage class that guarantees the existence of a function in a DLL.
189+
///
190+
/// Using this attribute can produce tighter code because the compiler may
191+
/// skip emitting a thunk and instead directly jump to a particular address.
192+
case dllImport
193+
/// The storage class for symbols that should be exposed outside of this DLL.
194+
///
195+
/// This storage class augments the use of a `.DEF` file, but cannot
196+
/// completely replace them.
197+
case dllExport
198+
199+
private static let storageMapping: [StorageClass: LLVMDLLStorageClass] = [
200+
.`default`: LLVMDefaultStorageClass,
201+
.dllImport: LLVMDLLImportStorageClass,
202+
.dllExport: LLVMDLLExportStorageClass,
203+
]
204+
205+
internal init(llvm: LLVMDLLStorageClass) {
206+
switch llvm {
207+
case LLVMDefaultStorageClass: self = .`default`
208+
case LLVMDLLImportStorageClass: self = .dllImport
209+
case LLVMDLLExportStorageClass: self = .dllExport
210+
default: fatalError("unknown DLL storage class \(llvm)")
211+
}
212+
}
213+
214+
/// Retrieves the corresponding `LLVMDLLStorageClass`.
215+
public var llvm: LLVMDLLStorageClass {
216+
return StorageClass.storageMapping[self]!
217+
}
218+
}

0 commit comments

Comments
 (0)