File tree 3 files changed +18
-3
lines changed 3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,17 @@ extension IRConstant {
21
21
return Constant < Struct > ( llvm: LLVMConstGEP ( asLLVM ( ) , buf. baseAddress, UInt32 ( buf. count) ) )
22
22
}
23
23
}
24
+
25
+ /// Build a constant bitcast to convert the given value to a value of the
26
+ /// given type by just copying the bit pattern.
27
+ ///
28
+ /// - parameter type: The destination type.
29
+ ///
30
+ /// - returns: A constant value representing the result of bitcasting this
31
+ /// constant value to fit the given type.
32
+ public func bitCast( to type: IRType ) -> IRConstant {
33
+ return Constant < Struct > ( llvm: LLVMConstBitCast ( asLLVM ( ) , type. asLLVM ( ) ) )
34
+ }
24
35
}
25
36
26
37
/// A protocol to which the phantom types for a constant's representation conform.
@@ -1014,7 +1025,7 @@ extension Constant where Repr: IntegralConstantRepresentation {
1014
1025
///
1015
1026
/// - returns: An constant value representing the constant value of the given
1016
1027
/// pointer converted to the given integer type.
1017
- public static func pointerToInt( _ val: IRGlobal , _ intType: IntType ) -> Constant {
1028
+ public static func pointerToInt( _ val: IRConstant , _ intType: IntType ) -> Constant {
1018
1029
precondition ( val. isConstant, " May only convert global constant pointers to integers " )
1019
1030
return Constant < Repr > ( llvm: LLVMConstPtrToInt ( val. asLLVM ( ) , intType. asLLVM ( ) ) )
1020
1031
}
Original file line number Diff line number Diff line change @@ -79,9 +79,13 @@ public enum ThreadLocalModel {
79
79
/// A `Global` represents a region of memory allocated at compile time instead
80
80
/// of at runtime. A global variable must either have an initializer, or make
81
81
/// reference to an external definition that has an initializer.
82
- public struct Global : IRGlobal {
82
+ public final class Global : IRGlobal {
83
83
internal let llvm : LLVMValueRef
84
84
85
+ internal init ( llvm: LLVMValueRef ) {
86
+ self . llvm = llvm
87
+ }
88
+
85
89
/// Returns whether this global variable has no initializer because it makes
86
90
/// reference to an initialized value in another translation unit.
87
91
public var isExternallyInitialized : Bool {
Original file line number Diff line number Diff line change @@ -380,7 +380,7 @@ extension Module {
380
380
///
381
381
/// - returns: A value representing the newly inserted global variable.
382
382
public func addGlobal( _ name: String , initializer: IRValue , addressSpace: Int ? = nil ) -> Global {
383
- var global = addGlobal ( name, type: initializer. type)
383
+ let global = addGlobal ( name, type: initializer. type)
384
384
global. initializer = initializer
385
385
return global
386
386
}
You can’t perform that action at this time.
0 commit comments