Skip to content

Commit dece2fc

Browse files
authored
Merge pull request #156 from CodaFi/mistakes
Correct some constant mistakes
2 parents a4e59f7 + 228ab7e commit dece2fc

File tree

6 files changed

+28
-27
lines changed

6 files changed

+28
-27
lines changed

Sources/LLVM/ArrayType.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public struct ArrayType: IRType {
2424
/// - parameter type: The type of the provided IR values.
2525
///
2626
/// - returns: A constant array value containing the given values.
27-
public static func constant(_ values: [IRValue], type: IRType) -> IRValue {
27+
public static func constant(_ values: [IRValue], type: IRType) -> IRConstant {
2828
var vals = values.map { $0.asLLVM() as Optional }
2929
return vals.withUnsafeMutableBufferPointer { buf in
30-
return LLVMConstArray(type.asLLVM(), buf.baseAddress, UInt32(buf.count))
30+
return Constant<Struct>(llvm: LLVMConstArray(type.asLLVM(), buf.baseAddress, UInt32(buf.count)))
3131
}
3232
}
3333

@@ -39,9 +39,9 @@ public struct ArrayType: IRType {
3939
///
4040
/// - returns: A null terminated constant array value containing
4141
/// `string.utf8.count + 1` i8's.
42-
public static func constant(string: String, in context: Context = .global) -> IRValue {
42+
public static func constant(string: String, in context: Context = .global) -> IRConstant {
4343
let length = string.utf8.count
44-
return LLVMConstStringInContext(context.llvm, string, UInt32(length), 0)
44+
return Constant<Struct>(llvm: LLVMConstStringInContext(context.llvm, string, UInt32(length), 0))
4545
}
4646

4747
/// Retrieves the underlying LLVM type object.

Sources/LLVM/CallingConvention.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public enum CallingConvention {
4242
/// floating-point parameters.
4343
///
4444
/// This calling convention supports `tail call
45-
/// optimization <CodeGenerator.html#id80>`_ but requires both the
46-
/// caller and callee are using it.
45+
/// optimization but requires both the caller and callee are using it.
4746
case ghc
4847
/// This calling convention has been implemented specifically for use by
4948
/// the High-Performance Erlang (HiPE) compiler, *the*

Sources/LLVM/Constant.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ import cllvm
77
/// addresses are constant, and constant expressions.
88
public protocol IRConstant: IRValue {}
99

10+
extension IRConstant {
11+
/// Perform a GEP (Get Element Pointer) with this value as the base.
12+
///
13+
/// - parameter indices: A list of indices that indicate which of the elements
14+
/// of the aggregate object are indexed.
15+
///
16+
/// - returns: A value representing the address of a subelement of the given
17+
/// aggregate data structure value.
18+
public func constGEP(indices: [IRConstant]) -> IRConstant {
19+
var idxs = indices.map { $0.asLLVM() as Optional }
20+
return idxs.withUnsafeMutableBufferPointer { buf in
21+
return Constant<Struct>(llvm: LLVMConstGEP(asLLVM(), buf.baseAddress, UInt32(buf.count)))
22+
}
23+
}
24+
}
25+
1026
/// A protocol to which the phantom types for a constant's representation conform.
1127
public protocol ConstantRepresentation {}
1228
/// A protocol to which the phantom types for all numerical constants conform.

Sources/LLVM/IRType.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public protocol IRType {
1111

1212
public extension IRType {
1313
/// Returns the special `null` value for this type.
14-
public func null() -> IRValue {
15-
return LLVMConstNull(asLLVM())
14+
public func null() -> IRConstant {
15+
return Constant<Struct>(llvm: LLVMConstNull(asLLVM()))
1616
}
1717

1818
/// Returns the special LLVM `undef` value for this type.
@@ -26,8 +26,8 @@ public extension IRType {
2626

2727
/// Returns the special LLVM constant `null` pointer value for this type
2828
/// initialized to `null`.
29-
public func constPointerNull() -> IRValue {
30-
return LLVMConstPointerNull(asLLVM())
29+
public func constPointerNull() -> IRConstant {
30+
return Constant<Struct>(llvm: LLVMConstPointerNull(asLLVM()))
3131
}
3232

3333
/// Returns the context associated with this type

Sources/LLVM/IRValue.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,6 @@ public extension IRValue {
4141
}
4242
}
4343

44-
/// Perform a GEP (Get Element Pointer) with this value as the base.
45-
///
46-
/// - parameter indices: A list of indices that indicate which of the elements
47-
/// of the aggregate object are indexed.
48-
///
49-
/// - returns: A value representing the address of a subelement of the given
50-
/// aggregate data structure value.
51-
public func constGEP(indices: [IRValue]) -> IRValue {
52-
var idxs = indices.map { $0.asLLVM() as Optional }
53-
return idxs.withUnsafeMutableBufferPointer { buf in
54-
return LLVMConstGEP(asLLVM(), buf.baseAddress, UInt32(buf.count))
55-
}
56-
}
57-
5844
/// Replaces all uses of this value with the specified value.
5945
///
6046
/// - parameter value: The new value to swap in.

Sources/LLVM/IntType.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public struct IntType: IRType {
4141
/// zero-bits.
4242
///
4343
/// - returns: A value consisting of all zero-bits of this type's bit width.
44-
public func zero() -> IRValue {
44+
public func zero() -> IRConstant {
4545
return null()
4646
}
4747

@@ -91,8 +91,8 @@ public struct IntType: IRType {
9191
/// one-bits.
9292
///
9393
/// - returns: A value consisting of all one-bits of this type's bit width.
94-
public func allOnes() -> IRValue {
95-
return LLVMConstAllOnes(asLLVM())
94+
public func allOnes() -> IRConstant {
95+
return Constant<Struct>(llvm: LLVMConstAllOnes(asLLVM()))
9696
}
9797

9898
/// Retrieves the underlying LLVM type object.

0 commit comments

Comments
 (0)