Skip to content

Commit fd9afe6

Browse files
committed
Add tests
1 parent ba02fef commit fd9afe6

File tree

5 files changed

+270
-109
lines changed

5 files changed

+270
-109
lines changed

Sources/LLVM/IRBuilder.swift

Lines changed: 3 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -214,111 +214,6 @@ public enum AtomicOrdering: Comparable {
214214
}
215215
}
216216

217-
/// `BinaryOperation` enumerates the subset of opcodes that are binary operations.
218-
public enum BinaryOperation {
219-
/// The `add` instruction.
220-
case add
221-
/// The `fadd` instruction.
222-
case fadd
223-
/// The `sub` instruction.
224-
case sub
225-
/// The `fsub` instruction.
226-
case fsub
227-
/// The `mul` instruction.
228-
case mul
229-
/// The `fmul` instruction.
230-
case fmul
231-
/// The `udiv` instruction.
232-
case udiv
233-
/// The `sdiv` instruction.
234-
case sdiv
235-
/// The `fdiv` instruction.
236-
case fdiv
237-
/// The `urem` instruction.
238-
case urem
239-
/// The `srem` instruction.
240-
case srem
241-
/// The `frem` instruction.
242-
case frem
243-
244-
/// The `shl` instruction.
245-
case shl
246-
/// The `lshr` instruction.
247-
case lshr
248-
/// The `ashr` instruction.
249-
case ashr
250-
/// The `and` instruction.
251-
case and
252-
/// The `or` instruction.
253-
case or
254-
/// The `xor` instruction.
255-
case xor
256-
257-
static let binaryOperationMap: [BinaryOperation: LLVMOpcode] = [
258-
.add: LLVMAdd, .fadd: LLVMFAdd, .sub: LLVMSub, .fsub: LLVMFSub,
259-
.mul: LLVMMul, .fmul: LLVMFMul, .udiv: LLVMUDiv, .sdiv: LLVMSDiv,
260-
.fdiv: LLVMFDiv, .urem: LLVMURem, .srem: LLVMSRem, .frem: LLVMFRem,
261-
.shl: LLVMShl, .lshr: LLVMLShr, .ashr: LLVMAShr, .and: LLVMAnd,
262-
.or: LLVMOr, .xor: LLVMXor,
263-
]
264-
265-
/// Retrieves the corresponding `LLVMOpcode`.
266-
public var llvm: LLVMOpcode {
267-
return BinaryOperation.binaryOperationMap[self]!
268-
}
269-
}
270-
271-
/// `CastOperation` enumerates the subset of opcodes that are cast operations.
272-
public enum CastOperation {
273-
/// The `trunc` instruction.
274-
case trunc
275-
/// The `zext` instruction.
276-
case zext
277-
/// The `sext` instruction.
278-
case sext
279-
/// The `fpToUI` instruction.
280-
case fpToUI
281-
/// The `fpToSI` instruction.
282-
case fpToSI
283-
/// The `uiToFP` instruction.
284-
case uiToFP
285-
/// The `siToFP` instruction.
286-
case siToFP
287-
/// The `fpTrunc` instruction.
288-
case fpTrunc
289-
/// The `fpext` instruction.
290-
case fpext
291-
/// The `ptrToInt` instruction.
292-
case ptrToInt
293-
/// The `intToPtr` instruction.
294-
case intToPtr
295-
/// The `bitCast` instruction.
296-
case bitCast
297-
/// The `addrSpaceCast` instruction.
298-
case addrSpaceCast
299-
300-
static let castOperationMap: [CastOperation: LLVMOpcode] = [
301-
.trunc: LLVMTrunc,
302-
.zext: LLVMZExt,
303-
.sext: LLVMSExt,
304-
.fpToUI: LLVMFPToUI,
305-
.fpToSI: LLVMFPToSI,
306-
.uiToFP: LLVMUIToFP,
307-
.siToFP: LLVMSIToFP,
308-
.fpTrunc: LLVMFPTrunc,
309-
.fpext: LLVMFPExt,
310-
.ptrToInt: LLVMPtrToInt,
311-
.intToPtr: LLVMIntToPtr,
312-
.bitCast: LLVMBitCast,
313-
.addrSpaceCast: LLVMAddrSpaceCast,
314-
]
315-
316-
/// Retrieves the corresponding `LLVMOpcode`.
317-
public var llvm: LLVMOpcode {
318-
return CastOperation.castOperationMap[self]!
319-
}
320-
}
321-
322217
/// `AtomicReadModifyWriteOperation` enumerates the kinds of supported atomic
323218
/// read-write-modify operations.
324219
public enum AtomicReadModifyWriteOperation {
@@ -537,7 +432,7 @@ public class IRBuilder {
537432
///
538433
/// - returns: A value representing the result of perfomring the given binary
539434
/// operation with the given values as arguments.
540-
public func buildBinaryOperation(_ op: BinaryOperation, _ lhs: IRValue, _ rhs: IRValue, name: String = "") -> IRValue {
435+
public func buildBinaryOperation(_ op: OpCode.Binary, _ lhs: IRValue, _ rhs: IRValue, name: String = "") -> IRValue {
541436
return LLVMBuildBinOp(llvm, op.llvm, lhs.asLLVM(), rhs.asLLVM(), name)
542437
}
543438

@@ -551,7 +446,7 @@ public class IRBuilder {
551446
///
552447
/// - returns: A value representing the result of casting the given value to
553448
/// the given destination type using the given operation.
554-
public func buildCast(_ op: CastOperation, value: IRValue, type: IRType, name: String = "") -> IRValue {
449+
public func buildCast(_ op: OpCode.Cast, value: IRValue, type: IRType, name: String = "") -> IRValue {
555450
return LLVMBuildCast(llvm, op.llvm, value.asLLVM(), type.asLLVM(), name)
556451
}
557452

@@ -1176,7 +1071,7 @@ public class IRBuilder {
11761071
/// This instruction is used to implement the `va_arg` macro in C.
11771072
///
11781073
/// - parameter list: A value of type `va_list*`
1179-
/// - parameter type: THe type of values in the variable argument area.
1074+
/// - parameter type: The type of values in the variable argument area.
11801075
/// - parameter name: The name for the newly inserted instruction.
11811076
///
11821077
/// - returns: A value of the specified argument type. In addition, the

Sources/LLVM/OpCode.swift

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,110 @@ public enum OpCode {
227227
}
228228
}
229229
}
230+
231+
extension OpCode {
232+
/// `BinaryOperation` enumerates the subset of opcodes that are binary operations.
233+
public enum Binary {
234+
/// The `add` instruction.
235+
case add
236+
/// The `fadd` instruction.
237+
case fadd
238+
/// The `sub` instruction.
239+
case sub
240+
/// The `fsub` instruction.
241+
case fsub
242+
/// The `mul` instruction.
243+
case mul
244+
/// The `fmul` instruction.
245+
case fmul
246+
/// The `udiv` instruction.
247+
case udiv
248+
/// The `sdiv` instruction.
249+
case sdiv
250+
/// The `fdiv` instruction.
251+
case fdiv
252+
/// The `urem` instruction.
253+
case urem
254+
/// The `srem` instruction.
255+
case srem
256+
/// The `frem` instruction.
257+
case frem
258+
259+
/// The `shl` instruction.
260+
case shl
261+
/// The `lshr` instruction.
262+
case lshr
263+
/// The `ashr` instruction.
264+
case ashr
265+
/// The `and` instruction.
266+
case and
267+
/// The `or` instruction.
268+
case or
269+
/// The `xor` instruction.
270+
case xor
271+
272+
static let binaryOperationMap: [Binary: LLVMOpcode] = [
273+
.add: LLVMAdd, .fadd: LLVMFAdd, .sub: LLVMSub, .fsub: LLVMFSub,
274+
.mul: LLVMMul, .fmul: LLVMFMul, .udiv: LLVMUDiv, .sdiv: LLVMSDiv,
275+
.fdiv: LLVMFDiv, .urem: LLVMURem, .srem: LLVMSRem, .frem: LLVMFRem,
276+
.shl: LLVMShl, .lshr: LLVMLShr, .ashr: LLVMAShr, .and: LLVMAnd,
277+
.or: LLVMOr, .xor: LLVMXor,
278+
]
279+
280+
/// Retrieves the corresponding `LLVMOpcode`.
281+
public var llvm: LLVMOpcode {
282+
return Binary.binaryOperationMap[self]!
283+
}
284+
}
285+
286+
/// `CastOperation` enumerates the subset of opcodes that are cast operations.
287+
public enum Cast {
288+
/// The `trunc` instruction.
289+
case trunc
290+
/// The `zext` instruction.
291+
case zext
292+
/// The `sext` instruction.
293+
case sext
294+
/// The `fpToUI` instruction.
295+
case fpToUI
296+
/// The `fpToSI` instruction.
297+
case fpToSI
298+
/// The `uiToFP` instruction.
299+
case uiToFP
300+
/// The `siToFP` instruction.
301+
case siToFP
302+
/// The `fpTrunc` instruction.
303+
case fpTrunc
304+
/// The `fpext` instruction.
305+
case fpext
306+
/// The `ptrToInt` instruction.
307+
case ptrToInt
308+
/// The `intToPtr` instruction.
309+
case intToPtr
310+
/// The `bitCast` instruction.
311+
case bitCast
312+
/// The `addrSpaceCast` instruction.
313+
case addrSpaceCast
314+
315+
static let castOperationMap: [Cast: LLVMOpcode] = [
316+
.trunc: LLVMTrunc,
317+
.zext: LLVMZExt,
318+
.sext: LLVMSExt,
319+
.fpToUI: LLVMFPToUI,
320+
.fpToSI: LLVMFPToSI,
321+
.uiToFP: LLVMUIToFP,
322+
.siToFP: LLVMSIToFP,
323+
.fpTrunc: LLVMFPTrunc,
324+
.fpext: LLVMFPExt,
325+
.ptrToInt: LLVMPtrToInt,
326+
.intToPtr: LLVMIntToPtr,
327+
.bitCast: LLVMBitCast,
328+
.addrSpaceCast: LLVMAddrSpaceCast,
329+
]
330+
331+
/// Retrieves the corresponding `LLVMOpcode`.
332+
public var llvm: LLVMOpcode {
333+
return Cast.castOperationMap[self]!
334+
}
335+
}
336+
}

Tests/LLVMTests/FileCheck.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ private struct CheckString {
11671167
}
11681168

11691169
// Re-calc it as the offset relative to the start of the original string.
1170-
var matchPos = range.location + startPos
1170+
let matchPos = range.location + startPos
11711171
if !notStrings.isEmpty {
11721172
if matchPos < lastPos {
11731173
// Reordered?

0 commit comments

Comments
 (0)