Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Sources/LLVM/IRGlobal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ extension IRGlobal {
get { return Visibility(llvm: LLVMGetVisibility(asLLVM())) }
set { LLVMSetVisibility(asLLVM(), newValue.llvm) }
}

/// Retrieves the storage class for this global declaration. For use with
/// Portable Executable files.
public var storageClass: StorageClass {
get { return StorageClass(llvm: LLVMGetDLLStorageClass(asLLVM())) }
set { LLVMSetDLLStorageClass(asLLVM(), newValue.llvm) }
}
}
38 changes: 38 additions & 0 deletions Sources/LLVM/Linkage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,41 @@ public enum Linkage {
return Linkage.linkageMapping[self]!
}
}

/// `StorageClass` enumerates the storage classes for globals in a Portable
/// Executable file.
public enum StorageClass {
/// The default storage class for declarations is neither imported nor
/// exported to/from a DLL.
case `default`
/// The storage class that guarantees the existence of a function in a DLL.
///
/// Using this attribute can produce tighter code because the compiler may
/// skip emitting a thunk and instead directly jump to a particular address.
case dllImport
/// The storage class for symbols that should be exposed outside of this DLL.
///
/// This storage class augments the use of a `.DEF` file, but cannot
/// completely replace them.
case dllExport

private static let storageMapping: [StorageClass: LLVMDLLStorageClass] = [
.`default`: LLVMDefaultStorageClass,
.dllImport: LLVMDLLImportStorageClass,
.dllExport: LLVMDLLExportStorageClass,
]

internal init(llvm: LLVMDLLStorageClass) {
switch llvm {
case LLVMDefaultStorageClass: self = .`default`
case LLVMDLLImportStorageClass: self = .dllImport
case LLVMDLLExportStorageClass: self = .dllExport
default: fatalError("unknown DLL storage class \(llvm)")
}
}

/// Retrieves the corresponding `LLVMDLLStorageClass`.
public var llvm: LLVMDLLStorageClass {
return StorageClass.storageMapping[self]!
}
}