2
2
import cllvm
3
3
#endif
4
4
5
+ /// An `IRConstant` is an entity whose value doees not change during the
6
+ /// runtime of a program. This includes global variables and functions, whose
7
+ /// addresses are constant, and constant expressions.
8
+ public protocol IRConstant : IRValue { }
9
+
5
10
/// A protocol to which the phantom types for a constant's representation conform.
6
11
public protocol ConstantRepresentation { }
7
12
/// A protocol to which the phantom types for all numerical constants conform.
@@ -29,7 +34,7 @@ public enum Vector: ConstantRepresentation {}
29
34
/// `Constant`s keep track of the values they represent at the type level to
30
35
/// disallow mixed-type arithmetic. Use the `cast` family of operations to
31
36
/// safely convert constants to other representations.
32
- public struct Constant < Repr: ConstantRepresentation > : IRValue {
37
+ public struct Constant < Repr: ConstantRepresentation > : IRConstant {
33
38
internal let llvm : LLVMValueRef
34
39
35
40
internal init ( llvm: LLVMValueRef ! ) {
@@ -1009,10 +1014,10 @@ extension Constant where Repr == Struct {
1009
1014
/// of the aggregate object are indexed.
1010
1015
///
1011
1016
/// - returns: The value in the struct at the provided index.
1012
- public func getElement( indices: [ Int ] ) -> IRValue {
1017
+ public func getElement( indices: [ Int ] ) -> IRConstant {
1013
1018
var indices = indices. map ( { UInt32 ( $0) } )
1014
1019
return indices. withUnsafeMutableBufferPointer { buf in
1015
- return LLVMConstExtractValue ( asLLVM ( ) , buf. baseAddress, UInt32 ( buf. count) )
1020
+ return Constant < Struct > ( llvm : LLVMConstExtractValue ( asLLVM ( ) , buf. baseAddress, UInt32 ( buf. count) ) )
1016
1021
}
1017
1022
}
1018
1023
@@ -1029,10 +1034,10 @@ extension Constant where Repr == Struct {
1029
1034
///
1030
1035
/// - returns: A value representing the address of a subelement of the given
1031
1036
/// aggregate data structure value.
1032
- public func getElementPointer( indices: [ IRValue ] ) -> IRValue {
1037
+ public func getElementPointer( indices: [ IRConstant ] ) -> IRConstant {
1033
1038
var indices = indices. map ( { $0. asLLVM ( ) as LLVMValueRef ? } )
1034
1039
return indices. withUnsafeMutableBufferPointer { buf in
1035
- return LLVMConstGEP ( asLLVM ( ) , buf. baseAddress, UInt32 ( buf. count) )
1040
+ return Constant < Struct > ( llvm : LLVMConstGEP ( asLLVM ( ) , buf. baseAddress, UInt32 ( buf. count) ) )
1036
1041
}
1037
1042
}
1038
1043
@@ -1047,10 +1052,10 @@ extension Constant where Repr == Struct {
1047
1052
///
1048
1053
/// - returns: A value representing the address of a subelement of the given
1049
1054
/// aggregate data structure value.
1050
- public func inBoundsGetElementPointer( indices: [ IRValue ] ) -> IRValue {
1055
+ public func inBoundsGetElementPointer( indices: [ IRConstant ] ) -> IRConstant {
1051
1056
var indices = indices. map ( { $0. asLLVM ( ) as LLVMValueRef ? } )
1052
1057
return indices. withUnsafeMutableBufferPointer { buf in
1053
- return LLVMConstInBoundsGEP ( asLLVM ( ) , buf. baseAddress, UInt32 ( buf. count) )
1058
+ return Constant < Struct > ( llvm : LLVMConstInBoundsGEP ( asLLVM ( ) , buf. baseAddress, UInt32 ( buf. count) ) )
1054
1059
}
1055
1060
}
1056
1061
}
0 commit comments