|
| 1 | +#if !NO_SWIFTPM |
| 2 | +import cllvm |
| 3 | +#endif |
| 4 | + |
| 5 | +/// Represents a simple function call. |
| 6 | +public struct Call: IRValue { |
| 7 | + let llvm: LLVMValueRef |
| 8 | + |
| 9 | + /// Retrieves the underlying LLVM value object. |
| 10 | + public func asLLVM() -> LLVMValueRef { |
| 11 | + return self.llvm |
| 12 | + } |
| 13 | + |
| 14 | + /// Retrieves the number of argument operands passed by this call. |
| 15 | + public var argumentCount: Int { |
| 16 | + return Int(LLVMGetNumArgOperands(self.llvm)) |
| 17 | + } |
| 18 | + |
| 19 | + /// Accesses the calling convention for this function call. |
| 20 | + public var callingConvention: CallingConvention { |
| 21 | + get { return CallingConvention(rawValue: LLVMGetInstructionCallConv(self.llvm))! } |
| 22 | + set { LLVMSetInstructionCallConv(self.llvm, newValue.rawValue) } |
| 23 | + } |
| 24 | + |
| 25 | + /// Returns whether this function call is a tail call. That is, if the callee |
| 26 | + /// may reuse the stack memory of the caller. |
| 27 | + /// |
| 28 | + /// This attribute requires support from the target architecture. |
| 29 | + public var isTailCall: Bool { |
| 30 | + get { return LLVMIsTailCall(self.llvm) != 0 } |
| 31 | + set { LLVMSetTailCall(self.llvm, newValue.llvm) } |
| 32 | + } |
| 33 | + |
| 34 | + /// Retrieves the alignment of the parameter at the given index. |
| 35 | + /// |
| 36 | + /// This property is currently set-only due to limitations of the LLVM C API. |
| 37 | + /// |
| 38 | + /// - parameter i: The index of the parameter to retrieve. |
| 39 | + /// - parameter alignment: The alignment to apply to the parameter. |
| 40 | + public func setParameterAlignment(at i : Int, to alignment: Int) { |
| 41 | + LLVMSetInstrParamAlignment(self.llvm, UInt32(i), UInt32(alignment)) |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +/// Represents a function call that may transfer control to an exception handler. |
| 46 | +public struct Invoke: IRValue { |
| 47 | + let llvm: LLVMValueRef |
| 48 | + |
| 49 | + /// Retrieves the underlying LLVM value object. |
| 50 | + public func asLLVM() -> LLVMValueRef { |
| 51 | + return self.llvm |
| 52 | + } |
| 53 | + |
| 54 | + /// Accesses the destination block the flow of control will transfer to if an |
| 55 | + /// exception does not occur. |
| 56 | + public var normalDestination: BasicBlock { |
| 57 | + get { return BasicBlock(llvm: LLVMGetNormalDest(self.llvm)) } |
| 58 | + set { LLVMSetNormalDest(self.llvm, newValue.asLLVM()) } |
| 59 | + } |
| 60 | + |
| 61 | + /// Accesses the destination block that exception unwinding will jump to. |
| 62 | + public var unwindDestination: BasicBlock { |
| 63 | + get { return BasicBlock(llvm: LLVMGetUnwindDest(self.llvm)) } |
| 64 | + set { LLVMSetUnwindDest(self.llvm, newValue.asLLVM()) } |
| 65 | + } |
| 66 | +} |
0 commit comments