Skip to content

Commit cc10dff

Browse files
committed
Document Global
1 parent 0ad6b1c commit cc10dff

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

Sources/LLVMSwift/Global.swift

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
11
import cllvm
22

3+
/// A `Global` represents a region of memory allocated at compile time instead
4+
/// of at runtime. A global variable must either have an initializer, or make
5+
/// reference to an external definition that has an initializer.
36
public struct Global: IRValue {
4-
internal let llvm: LLVMValueRef
5-
6-
public var isExternallyInitialized: Bool {
7-
get { return LLVMIsExternallyInitialized(llvm) != 0 }
8-
set { LLVMSetExternallyInitialized(llvm, newValue.llvm) }
9-
}
10-
11-
public var initializer: IRValue {
12-
get { return LLVMGetInitializer(asLLVM()) }
13-
set { LLVMSetInitializer(asLLVM(), newValue.asLLVM()) }
14-
}
15-
16-
public var isGlobalConstant: Bool {
17-
get { return LLVMIsGlobalConstant(asLLVM()) != 0 }
18-
set { LLVMSetGlobalConstant(asLLVM(), newValue.llvm) }
19-
}
20-
21-
public var isThreadLocal: Bool {
22-
get { return LLVMIsThreadLocal(asLLVM()) != 0 }
23-
set { LLVMSetThreadLocal(asLLVM(), newValue.llvm) }
24-
}
25-
26-
public func asLLVM() -> LLVMValueRef {
27-
return llvm
28-
}
7+
internal let llvm: LLVMValueRef
8+
9+
/// Returns whether this global variable has no initializer because it makes
10+
/// reference to an initialized value in another translation unit.
11+
public var isExternallyInitialized: Bool {
12+
get { return LLVMIsExternallyInitialized(llvm) != 0 }
13+
set { LLVMSetExternallyInitialized(llvm, newValue.llvm) }
14+
}
15+
16+
/// Retrieves the initializer for this global variable, if it exists.
17+
public var initializer: IRValue? {
18+
get { return LLVMGetInitializer(asLLVM()) }
19+
set { LLVMSetInitializer(asLLVM(), newValue!.asLLVM()) }
20+
}
21+
22+
/// Returns whether this global variable is a constant, whether or not the
23+
/// final definition of the global is not.
24+
public var isGlobalConstant: Bool {
25+
get { return LLVMIsGlobalConstant(asLLVM()) != 0 }
26+
set { LLVMSetGlobalConstant(asLLVM(), newValue.llvm) }
27+
}
28+
29+
/// Returns whether this global variable is thread-local. That is, returns
30+
/// if this variable is not shared by multiple threads.
31+
public var isThreadLocal: Bool {
32+
get { return LLVMIsThreadLocal(asLLVM()) != 0 }
33+
set { LLVMSetThreadLocal(asLLVM(), newValue.llvm) }
34+
}
35+
36+
/// Retrieves the underlying LLVM value object.
37+
public func asLLVM() -> LLVMValueRef {
38+
return llvm
39+
}
2940
}

0 commit comments

Comments
 (0)