Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8c6ad9a

Browse files
authored
Merge pull request #204 from CodaFi/denature
Remove extraneous labels from FunctionType
2 parents c469d30 + fe576ab commit 8c6ad9a

20 files changed

+123
-124
lines changed

‎README.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ Defining a function and moving the cursor to a point where we can begin insertin
2020
```swift
2121
let builder = IRBuilder(module: module)
2222

23-
let main = builder.addFunction(
24-
"main",
25-
type: FunctionType(argTypes: [],
26-
returnType: IntType.int64)
27-
)
23+
let main = builder.addFunction("main",
24+
type: FunctionType([], IntType.int64))
2825
let entry = main.appendBasicBlock(named: "entry")
2926
builder.positionAtEnd(of: entry)
3027
```
@@ -95,11 +92,9 @@ func calculateFibs(_ backward : Bool) -> Double {
9592
Notice that the value of `retVal` depends on the path the flow of control takes through this program, so we must emit a PHI node to properly initialize it:
9693

9794
```swift
98-
let function = builder.addFunction(
99-
"calculateFibs",
100-
type: FunctionType(argTypes: [IntType.int1],
101-
returnType: FloatType.double)
102-
)
95+
let function = builder.addFunction("calculateFibs",
96+
type: FunctionType([IntType.int1],
97+
FloatType.double))
10398
let entryBB = function.appendBasicBlock(named: "entry")
10499
builder.positionAtEnd(of: entryBB)
105100

‎Sources/LLVM/BasicBlock.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import cllvm
2424
///
2525
/// let module = Module(name: "Example")
2626
/// let fun = builder.addFunction("example",
27-
/// type: FunctionType(argTypes: [],
28-
/// returnType: VoidType()))
27+
/// type: FunctionType([], VoidType()))
2928
///
3029
/// // This basic block is "floating" outside of a function.
3130
/// let floatingBB = BasicBlock(name: "floating")
@@ -37,8 +36,7 @@ import cllvm
3736
///
3837
/// let module = Module(name: "Example")
3938
/// let fun = builder.addFunction("example",
40-
/// type: FunctionType(argTypes: [],
41-
/// returnType: VoidType()))
39+
/// type: FunctionType([], VoidType()))
4240
///
4341
/// // This basic block is "attached" to the example function.
4442
/// let attachedBB = fun.appendBasicBlock(named: "attached")

‎Sources/LLVM/Function.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import llvmshims
2222
/// let module = Module(name: "Example")
2323
/// let builder = IRBuilder(module: module)
2424
/// let fun = builder.addFunction("example",
25-
/// type: FunctionType(argTypes: [],
26-
/// returnType: VoidType()))
25+
/// type: FunctionType([], VoidType()))
2726
/// // Create and append the entry block
2827
/// let entryBB = fun.appendBasicBlock(named: "entry")
2928
/// // Create and append a standalone basic block
@@ -46,8 +45,7 @@ import llvmshims
4645
/// let module = Module(name: "Example")
4746
/// let builder = IRBuilder(module: module)
4847
/// let fun = builder.addFunction("example",
49-
/// type: FunctionType(argTypes: [],
50-
/// returnType: VoidType()))
48+
/// type: FunctionType([], VoidType()))
5149
/// // Switch to swiftcc
5250
/// fun.callingConvention = .swift
5351
///
@@ -70,8 +68,7 @@ import llvmshims
7068
/// let module = Module(name: "Example")
7169
/// let builder = IRBuilder(module: module)
7270
/// let fun = builder.addFunction("example",
73-
/// type: FunctionType(argTypes: [],
74-
/// returnType: VoidType()))
71+
/// type: FunctionType([], VoidType()))
7572
/// // Attach the metadata
7673
/// fun.addMetadata(hotAttr, kind: .sectionPrefix)
7774
///

‎Sources/LLVM/FunctionType.swift

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import cllvm
88
/// and `MetadataType`.
99
public struct FunctionType: IRType {
1010
/// The list of argument types.
11-
public let argTypes: [IRType]
11+
public let parameterTypes: [IRType]
1212
/// The return type of this function type.
1313
public let returnType: IRType
1414
/// Returns whether this function is variadic.
15-
public let isVarArg: Bool
15+
public let isVariadic: Bool
1616

1717
/// Creates a function type with the given argument types and return type.
1818
///
@@ -21,24 +21,58 @@ public struct FunctionType: IRType {
2121
/// - parameter isVarArg: Indicates whether this function type is variadic.
2222
/// Defaults to `false`.
2323
/// - note: The context of this type is taken from it's `returnType`
24+
@available(*, deprecated, message: "Use the more concise initializer instead")
2425
public init(argTypes: [IRType], returnType: IRType, isVarArg: Bool = false) {
25-
self.argTypes = argTypes
26+
self.parameterTypes = argTypes
2627
self.returnType = returnType
27-
self.isVarArg = isVarArg
28+
self.isVariadic = isVarArg
29+
}
30+
31+
/// Creates a function type with the given argument types and return type.
32+
///
33+
/// - parameter parameterTypes: A list of the argument types of the function
34+
/// type.
35+
/// - parameter returnType: The return type of the function type.
36+
/// - parameter variadic: Indicates whether this function type is variadic.
37+
/// Defaults to `false`.
38+
/// - note: The context of this type is taken from it's `returnType`
39+
public init(
40+
_ parameterTypes: [IRType],
41+
_ returnType: IRType,
42+
variadic: Bool = false
43+
) {
44+
self.parameterTypes = parameterTypes
45+
self.returnType = returnType
46+
self.isVariadic = variadic
2847
}
2948

3049
/// Retrieves the underlying LLVM type object.
3150
public func asLLVM() -> LLVMTypeRef {
32-
var argIRTypes = argTypes.map { 0ドル.asLLVM() as Optional }
51+
var argIRTypes = parameterTypes.map { 0ドル.asLLVM() as Optional }
3352
return argIRTypes.withUnsafeMutableBufferPointer { buf in
3453
return LLVMFunctionType(returnType.asLLVM(),
3554
buf.baseAddress,
3655
UInt32(buf.count),
37-
isVarArg.llvm)!
56+
isVariadic.llvm)!
3857
}
3958
}
4059
}
4160

61+
// MARK: Legacy Accessors
62+
63+
extension FunctionType {
64+
/// The list of argument types.
65+
@available(*, deprecated, message: "Use FunctionType.parameterTypes instead")
66+
public var argTypes: [IRType] {
67+
return self.parameterTypes
68+
}
69+
/// Returns whether this function is variadic.
70+
@available(*, deprecated, message: "Use FunctionType.isVariadic instead")
71+
public var isVarArg: Bool {
72+
return self.isVariadic
73+
}
74+
}
75+
4276
extension FunctionType: Equatable {
4377
public static func == (lhs: FunctionType, rhs: FunctionType) -> Bool {
4478
return lhs.asLLVM() == rhs.asLLVM()

‎Sources/LLVM/IRBuilder.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ import llvmshims
7171
/// let module = Module(name: "Example")
7272
/// let builder = IRBuilder(module: module)
7373
/// let fun = builder.addFunction("test",
74-
/// type: FunctionType(argTypes: [
74+
/// type: FunctionType([
7575
/// IntType.int8,
7676
/// IntType.int8,
77-
/// ], returnType: FloatType.float))
77+
/// ], FloatType.float))
7878
/// let entry = fun.appendBasicBlock(named: "entry")
7979
/// // Set the insertion point to the entry block of this function
8080
/// builder.positionAtEnd(of: entry)
@@ -99,11 +99,11 @@ import llvmshims
9999
/// let module = Module(name: "Example")
100100
/// let builder = IRBuilder(module: module)
101101
/// let select = builder.addFunction("select",
102-
/// type: FunctionType(argTypes: [
102+
/// type: FunctionType([
103103
/// IntType.int1,
104104
/// FloatType.float,
105105
/// FloatType.float,
106-
/// ], returnType: FloatType.float))
106+
/// ], FloatType.float))
107107
/// let entry = select.appendBasicBlock(named: "entry")
108108
/// builder.positionAtEnd(of: entry)
109109
///

‎Sources/LLVM/IRType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ internal func convertType(_ type: LLVMTypeRef) -> IRType {
7171
}
7272
let ret = convertType(LLVMGetReturnType(type))
7373
let isVarArg = LLVMIsFunctionVarArg(type) != 0
74-
return FunctionType(argTypes:params, returnType:ret, isVarArg: isVarArg)
74+
return FunctionType(params, ret, variadic: isVarArg)
7575
case LLVMStructTypeKind:
7676
return StructType(llvm: type)
7777
case LLVMArrayTypeKind:

‎Sources/LLVM/Module.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import cllvm
2222
/// let module = Module(name: "Example")
2323
/// let builder = IRBuilder(module: module)
2424
/// let main = builder.addFunction("main",
25-
/// type: FunctionType(argTypes: [],
26-
/// returnType: VoidType()))
25+
/// type: FunctionType([], VoidType()))
2726
/// let entry = main.appendBasicBlock(named: "entry")
2827
/// builder.positionAtEnd(of: entry)
2928
/// builder.buildRet(main.address(of: entry)!)

‎Tests/LLVMTests/APIntSpec.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,7 @@ class APIntSpec : XCTestCase {
294294
let intType = IntType(width: 420)
295295
// ARBITRARY: define i420 @test() {
296296
let main = builder.addFunction("test",
297-
type: FunctionType(argTypes: [],
298-
returnType: intType))
297+
type: FunctionType([], intType))
299298
// ARBITRARY-NEXT: entry:
300299
let entry = main.appendBasicBlock(named: "entry")
301300
builder.positionAtEnd(of: entry)

‎Tests/LLVMTests/BFC.swift

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ private enum Externs {
153153
switch self {
154154
case .getchar:
155155
let f = builder.addFunction("readchar",
156-
type: FunctionType(argTypes:[],
157-
returnType:cellType))
156+
type: FunctionType([],
157+
cellType))
158158
let getCharExtern = builder.addFunction("getchar",
159-
type: FunctionType(argTypes:[],
160-
returnType:cellType))
159+
type: FunctionType([],
160+
cellType))
161161
let entry = f.appendBasicBlock(named: "entry")
162162
builder.positionAtEnd(of: entry)
163163
let charValue = builder.buildCall(getCharExtern, args: [])
@@ -167,19 +167,18 @@ private enum Externs {
167167
return f
168168
case .putchar:
169169
return builder.addFunction("putchar",
170-
type: FunctionType(argTypes:[
171-
cellType
172-
], returnType:VoidType()))
170+
type: FunctionType([
171+
cellType
172+
], VoidType()))
173173
case .flush:
174174
let f = builder.addFunction("flush",
175-
type: FunctionType(argTypes: [],
176-
returnType: VoidType()))
175+
type: FunctionType([], VoidType()))
177176
let entry = f.appendBasicBlock(named: "entry")
178177
builder.positionAtEnd(of: entry)
179178
let ptrTy = PointerType(pointee: IntType.int8)
180179
let fflushExtern = builder.addFunction("fflush",
181-
type: FunctionType(argTypes:[ ptrTy ],
182-
returnType:IntType.int32))
180+
type: FunctionType([ ptrTy ],
181+
IntType.int32))
183182
_ = builder.buildCall(fflushExtern, args: [ ptrTy.constPointerNull() ])
184183
builder.buildRetVoid()
185184
return f
@@ -194,8 +193,8 @@ private func compile(at column: Int = #column, line: Int = #line, _ program: Str
194193
let cellTape = module.addGlobal("tape", initializer: cellTapeType.null())
195194

196195
let main = builder.addFunction("main",
197-
type: FunctionType(argTypes:[],
198-
returnType:IntType.int32))
196+
type: FunctionType([],
197+
IntType.int32))
199198

200199
let sourceFile = #file.components(separatedBy: "/").last!
201200
let sourceDir = #file.components(separatedBy: "/").dropLast().joined(separator: "/")

‎Tests/LLVMTests/ConstantSpec.swift

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ class ConstantSpec : XCTestCase {
1212
let builder = IRBuilder(module: module)
1313
// SIGNEDCONST: define void @main() {
1414
let main = builder.addFunction("main",
15-
type: FunctionType(argTypes: [],
16-
returnType: VoidType()))
15+
type: FunctionType([], VoidType()))
1716
let constant = IntType.int64.constant(42)
1817

1918
// SIGNEDCONST-NEXT: entry:
@@ -42,8 +41,7 @@ class ConstantSpec : XCTestCase {
4241
let builder = IRBuilder(module: module)
4342
// UNSIGNEDCONST: define i64 @main() {
4443
let main = builder.addFunction("main",
45-
type: FunctionType(argTypes: [],
46-
returnType: IntType.int64))
44+
type: FunctionType([], IntType.int64))
4745
let constant = IntType.int64.constant(UInt64(42))
4846

4947
// UNSIGNEDCONST-NEXT: entry:
@@ -70,8 +68,7 @@ class ConstantSpec : XCTestCase {
7068
let builder = IRBuilder(module: module)
7169
// FLOATINGCONST: define i64 @main() {
7270
let main = builder.addFunction("main",
73-
type: FunctionType(argTypes: [],
74-
returnType: IntType.int64))
71+
type: FunctionType([], IntType.int64))
7572
let constant = FloatType.double.constant(42.0)
7673

7774
// FLOATINGCONST-NEXT: entry:
@@ -98,8 +95,7 @@ class ConstantSpec : XCTestCase {
9895
let builder = IRBuilder(module: module)
9996
// STRUCTCONST: define i64 @main() {
10097
let main = builder.addFunction("main",
101-
type: FunctionType(argTypes: [],
102-
returnType: IntType.int64))
98+
type: FunctionType([], IntType.int64))
10399

104100
let constant = StructType(elementTypes: [IntType.int64])
105101
.constant(values: [42])
@@ -121,8 +117,7 @@ class ConstantSpec : XCTestCase {
121117
let builder = IRBuilder(module: module)
122118
// STRUCTCONSTGETELEMENT: define i64 @main() {
123119
let main = builder.addFunction("main",
124-
type: FunctionType(argTypes: [],
125-
returnType: IntType.int64))
120+
type: FunctionType([], IntType.int64))
126121

127122
let constant = StructType(elementTypes: [IntType.int64])
128123
.constant(values: [42])
@@ -148,8 +143,7 @@ class ConstantSpec : XCTestCase {
148143
let vecTy = VectorType(elementType: IntType.int32, count: 4)
149144
// VECTORCONSTSHUFFLE-IDENTITY: define <4 x i32> @main() {
150145
let main = builder.addFunction("main",
151-
type: FunctionType(argTypes: [],
152-
returnType: vecTy))
146+
type: FunctionType([], vecTy))
153147

154148
let vec1 = vecTy.constant([ 1, 2, 3, 4 ] as [Int32])
155149
let mask = vecTy.constant([ 0, 1, 2, 3 ] as [Int32])
@@ -175,8 +169,7 @@ class ConstantSpec : XCTestCase {
175169
let maskTy = VectorType(elementType: IntType.int32, count: 8)
176170
// VECTORCONSTSHUFFLE: define <8 x i32> @main() {
177171
let main = builder.addFunction("main",
178-
type: FunctionType(argTypes: [],
179-
returnType: maskTy))
172+
type: FunctionType([], maskTy))
180173

181174
let vecTy = VectorType(elementType: IntType.int32, count: 4)
182175
let vec1 = vecTy.constant([ 1, 2, 3, 4 ] as [Int32])

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /