swift的静态绑定
Swift Calling Convention @convention(swift)
func foo(_ x:Int, y:Int)
sil @foo : $(x:Int, y:Int) -> () {
entry(%x : $Int, %y : $Int):
...
}
func bar(_ x:Int, y:(Int, Int))
sil @bar : $(x:Int, y:(Int, Int)) -> () {
entry(%x : $Int, %y0 : $Int, %y1 : $Int):
...
}
func call_foo_and_bar() {
foo(1, 2)
bar(4, (5, 6))
}
sil @call_foo_and_bar : $() -> () {
entry:
...
%foo = function_ref @foo : $(x:Int, y:Int) -> ()
%foo_result = apply %foo(%1, %2) : $(x:Int, y:Int) -> ()
...
%bar = function_ref @bar : $(x:Int, y:(Int, Int)) -> ()
%bar_result = apply %bar(%4, %5, %6) : $(x:Int, y:(Int, Int)) -> ()
}
Swift Method Calling Convention @convention(method)
The method calling convention is currently identical to the freestanding function convention. Methods are considered to be curried functions, taking the "self" argument as their outer argument clause, and the method arguments as the inner argument clause(s). When uncurried, the "self" argument is thus passed last:
struct Foo {
func method(_ x:Int) -> Int {}
}
sil @Foo_method_1 : $((x : Int), @inout Foo) -> Int { ... }
//例子
class NSObjectBase: NSObject {
func Msg_Second(str:String){}
}
// NSObjectBase.Msg_Second(str:)
sil hidden @NSObjectBase.NSObjectBase.Msg_Second(str: Swift.String) -> () : $@convention(method) (@guaranteed String, @guaranteed NSObjectBase) -> ()
sil_vtable NSObjectBase {
#NSObjectBase.Msg_Second!1: (NSObjectBase) -> (String) -> () : @NSObjectBase.NSObjectBase.Msg_Second(str: Swift.String) -> () // NSObjectBase.Msg_Second(str:)
}
Objective-C Calling Convention @convention(objc_method)
https://github.com/apple/swift/blob/master/docs/SIL.rst#objective-c-calling-convention-convention-objc-method
------------------越是喧嚣的世界,越需要宁静的思考------------------ 合抱之木,生于毫末;九层之台,起于垒土;千里之行,始于足下。 积土成山,风雨兴焉;积水成渊,蛟龙生焉;积善成德,而神明自得,圣心备焉。故不积跬步,无以至千里;不积小流,无以成江海。骐骥一跃,不能十步;驽马十驾,功在不舍。锲而舍之,朽木不折;锲而不舍,金石可镂。蚓无爪牙之利,筋骨之强,上食埃土,下饮黄泉,用心一也。蟹六跪而二螯,非蛇鳝之穴无可寄托者,用心躁也。