Files
swift-mirror/libswift/Sources/SIL/Function.swift
Erik Eckstein 99fb82952a libswift: don't use the internal C++ namespace
Because this can be different in various C++ libraries.

Fixes a build problem on Ubuntu 20.04
2021-11-04 20:03:06 +01:00

63 lines
1.8 KiB
Swift

//===--- Function.swift - Defines the Function class ----------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import SILBridging
final public class Function : CustomStringConvertible {
public var name: String {
return SILFunction_getName(bridged).string
}
final public var description: String {
var s = SILFunction_debugDescription(bridged)
return String(cString: s.c_str())
}
public var entryBlock: BasicBlock {
SILFunction_firstBlock(bridged).block!
}
public var blocks : List<BasicBlock> {
return List(startAt: SILFunction_firstBlock(bridged).block)
}
public var reverseBlocks : ReverseList<BasicBlock> {
return ReverseList(startAt: SILFunction_lastBlock(bridged).block)
}
public var arguments: LazyMapSequence<ArgumentArray, FunctionArgument> {
entryBlock.arguments.lazy.map { $0 as! FunctionArgument }
}
public var numIndirectResultArguments: Int {
SILFunction_numIndirectResultArguments(bridged)
}
public var hasSelfArgument: Bool {
SILFunction_getSelfArgumentIndex(bridged) >= 0
}
public var selfArgumentIndex: Int {
let selfIdx = SILFunction_getSelfArgumentIndex(bridged)
assert(selfIdx >= 0)
return selfIdx
}
public var bridged: BridgedFunction { BridgedFunction(obj: SwiftObject(self)) }
}
// Bridging utilities
extension BridgedFunction {
public var function: Function { obj.getAs(Function.self) }
}