Last active
March 1, 2018 14:18
-
-
Save kitasuke/b974c02b3075550ba93c94e70245c65f to your computer and use it in GitHub Desktop.
Swift -> SIL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sil_stage canonical | |
import Builtin | |
import Swift | |
import SwiftShims | |
// main | |
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { | |
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): | |
%2 = integer_literal $Builtin.Int32, 0 // user: %3 | |
%3 = struct $Int32 (%2 : $Builtin.Int32) // user: %4 | |
return %3 : $Int32 // id: %4 | |
} // end sil function 'main' | |
// variable initialization expression of MyClass.x | |
sil hidden [transparent] @_T06sample7MyClassC1xSivfi : $@convention(thin) () -> Int { | |
bb0: | |
%0 = integer_literal $Builtin.Int64, 0 // user: %1 | |
%1 = struct $Int (%0 : $Builtin.Int64) // user: %2 | |
return %1 : $Int // id: %2 | |
} // end sil function '_T06sample7MyClassC1xSivfi' | |
// MyClass.x.getter | |
sil hidden [transparent] @_T06sample7MyClassC1xSifg : $@convention(method) (@guaranteed MyClass) -> Int { | |
// %0 // users: %2, %1 | |
bb0(%0 : $MyClass): | |
debug_value %0 : $MyClass, let, name "self", argno 1 // id: %1 | |
%2 = ref_element_addr %0 : $MyClass, #MyClass.x // user: %3 | |
%3 = load %2 : $*Int // user: %4 | |
return %3 : $Int // id: %4 | |
} // end sil function '_T06sample7MyClassC1xSifg' | |
// MyClass.x.setter | |
sil hidden [transparent] @_T06sample7MyClassC1xSifs : $@convention(method) (Int, @guaranteed MyClass) -> () { | |
// %0 // users: %5, %2 | |
// %1 // users: %4, %3 | |
bb0(%0 : $Int, %1 : $MyClass): | |
debug_value %0 : $Int, let, name "value", argno 1 // id: %2 | |
debug_value %1 : $MyClass, let, name "self", argno 2 // id: %3 | |
%4 = ref_element_addr %1 : $MyClass, #MyClass.x // user: %5 | |
store %0 to %4 : $*Int // id: %5 | |
%6 = tuple () // user: %7 | |
return %6 : $() // id: %7 | |
} // end sil function '_T06sample7MyClassC1xSifs' | |
// MyClass.x.materializeForSet | |
sil hidden [transparent] @_T06sample7MyClassC1xSifm : $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @guaranteed MyClass) -> (Builtin.RawPointer, Optional<Builtin.RawPointer>) { | |
// %2 // user: %3 | |
bb0(%0 : $Builtin.RawPointer, %1 : $*Builtin.UnsafeValueBuffer, %2 : $MyClass): | |
%3 = ref_element_addr %2 : $MyClass, #MyClass.x // user: %4 | |
%4 = address_to_pointer %3 : $*Int to $Builtin.RawPointer // user: %6 | |
%5 = enum $Optional<Builtin.RawPointer>, #Optional.none!enumelt // user: %6 | |
%6 = tuple (%4 : $Builtin.RawPointer, %5 : $Optional<Builtin.RawPointer>) // user: %7 | |
return %6 : $(Builtin.RawPointer, Optional<Builtin.RawPointer>) // id: %7 | |
} // end sil function '_T06sample7MyClassC1xSifm' | |
// variable initialization expression of MyClass.number | |
sil hidden [transparent] @_T06sample7MyClassC6numberSivfi : $@convention(thin) () -> Int { | |
bb0: | |
%0 = integer_literal $Builtin.Int64, 0 // user: %1 | |
%1 = struct $Int (%0 : $Builtin.Int64) // user: %2 | |
return %1 : $Int // id: %2 | |
} // end sil function '_T06sample7MyClassC6numberSivfi' | |
// MyClass.number.didset | |
sil hidden @_T06sample7MyClassC6numberSifW : $@convention(method) (Int, @guaranteed MyClass) -> () { | |
// %1 // users: %15, %5, %14, %2 | |
bb0(%0 : $Int, %1 : $MyClass): | |
debug_value %1 : $MyClass, let, name "self", argno 2 // id: %2 | |
%3 = integer_literal $Builtin.Int64, 333 // user: %4 | |
%4 = struct $Int (%3 : $Builtin.Int64) // users: %12, %9, %15 | |
checked_cast_br [exact] %1 : $MyClass to $MyClass, bb2, bb3 // id: %5 | |
bb1: // Preds: bb2 bb3 | |
%6 = tuple () // user: %7 | |
return %6 : $() // id: %7 | |
// %8 // users: %11, %10 | |
bb2(%8 : $MyClass): // Preds: bb0 | |
debug_value %4 : $Int, let, name "value", argno 1 // id: %9 | |
debug_value %8 : $MyClass, let, name "self", argno 2 // id: %10 | |
%11 = ref_element_addr %8 : $MyClass, #MyClass.x // user: %12 | |
store %4 to %11 : $*Int // id: %12 | |
br bb1 // id: %13 | |
bb3: // Preds: bb0 | |
%14 = class_method %1 : $MyClass, #MyClass.x!setter.1 : (MyClass) -> (Int) -> (), $@convention(method) (Int, @guaranteed MyClass) -> () // user: %15 | |
%15 = apply %14(%4, %1) : $@convention(method) (Int, @guaranteed MyClass) -> () | |
br bb1 // id: %16 | |
} // end sil function '_T06sample7MyClassC6numberSifW' | |
// MyClass.number.getter | |
sil hidden [transparent] @_T06sample7MyClassC6numberSifg : $@convention(method) (@guaranteed MyClass) -> Int { | |
// %0 // users: %2, %1 | |
bb0(%0 : $MyClass): | |
debug_value %0 : $MyClass, let, name "self", argno 1 // id: %1 | |
%2 = ref_element_addr %0 : $MyClass, #MyClass.number // user: %3 | |
%3 = load %2 : $*Int // user: %4 | |
return %3 : $Int // id: %4 | |
} // end sil function '_T06sample7MyClassC6numberSifg' | |
// MyClass.number.setter | |
sil hidden @_T06sample7MyClassC6numberSifs : $@convention(method) (Int, @guaranteed MyClass) -> () { | |
// %0 // users: %5, %2 | |
// %1 // users: %19, %9, %18, %6, %4, %3 | |
bb0(%0 : $Int, %1 : $MyClass): | |
debug_value %0 : $Int, let, name "newValue", argno 1 // id: %2 | |
debug_value %1 : $MyClass, let, name "self", argno 2 // id: %3 | |
%4 = ref_element_addr %1 : $MyClass, #MyClass.number // user: %5 | |
store %0 to %4 : $*Int // id: %5 | |
debug_value %1 : $MyClass, let, name "self", argno 2 // id: %6 | |
%7 = integer_literal $Builtin.Int64, 333 // user: %8 | |
%8 = struct $Int (%7 : $Builtin.Int64) // users: %16, %13, %19 | |
checked_cast_br [exact] %1 : $MyClass to $MyClass, bb2, bb3 // id: %9 | |
bb1: // Preds: bb2 bb3 | |
%10 = tuple () // user: %11 | |
return %10 : $() // id: %11 | |
// %12 // users: %15, %14 | |
bb2(%12 : $MyClass): // Preds: bb0 | |
debug_value %8 : $Int, let, name "value", argno 1 // id: %13 | |
debug_value %12 : $MyClass, let, name "self", argno 2 // id: %14 | |
%15 = ref_element_addr %12 : $MyClass, #MyClass.x // user: %16 | |
store %8 to %15 : $*Int // id: %16 | |
br bb1 // id: %17 | |
bb3: // Preds: bb0 | |
%18 = class_method %1 : $MyClass, #MyClass.x!setter.1 : (MyClass) -> (Int) -> (), $@convention(method) (Int, @guaranteed MyClass) -> () // user: %19 | |
%19 = apply %18(%8, %1) : $@convention(method) (Int, @guaranteed MyClass) -> () | |
br bb1 // id: %20 | |
} // end sil function '_T06sample7MyClassC6numberSifs' | |
// closure #1 in MyClass.number.materializeForSet | |
sil private [transparent] @_T06sample7MyClassC6numberSifmytfU_ : $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout MyClass, @thick MyClass.Type) -> () { | |
// %0 // user: %5 | |
// %2 // user: %4 | |
bb0(%0 : $Builtin.RawPointer, %1 : $*Builtin.UnsafeValueBuffer, %2 : $*MyClass, %3 : $@thick MyClass.Type): | |
%4 = load %2 : $*MyClass // users: %24, %14, %23, %11, %9, %8 | |
%5 = pointer_to_address %0 : $Builtin.RawPointer to [strict] $*Int // user: %6 | |
%6 = load %5 : $*Int // users: %10, %7 | |
debug_value %6 : $Int, let, name "newValue", argno 1 // id: %7 | |
debug_value %4 : $MyClass, let, name "self", argno 2 // id: %8 | |
%9 = ref_element_addr %4 : $MyClass, #MyClass.number // user: %10 | |
store %6 to %9 : $*Int // id: %10 | |
debug_value %4 : $MyClass, let, name "self", argno 2 // id: %11 | |
%12 = integer_literal $Builtin.Int64, 333 // user: %13 | |
%13 = struct $Int (%12 : $Builtin.Int64) // users: %21, %18, %24 | |
checked_cast_br [exact] %4 : $MyClass to $MyClass, bb2, bb3 // id: %14 | |
bb1: // Preds: bb2 bb3 | |
%15 = tuple () // user: %16 | |
return %15 : $() // id: %16 | |
// %17 // users: %20, %19 | |
bb2(%17 : $MyClass): // Preds: bb0 | |
debug_value %13 : $Int, let, name "value", argno 1 // id: %18 | |
debug_value %17 : $MyClass, let, name "self", argno 2 // id: %19 | |
%20 = ref_element_addr %17 : $MyClass, #MyClass.x // user: %21 | |
store %13 to %20 : $*Int // id: %21 | |
br bb1 // id: %22 | |
bb3: // Preds: bb0 | |
%23 = class_method %4 : $MyClass, #MyClass.x!setter.1 : (MyClass) -> (Int) -> (), $@convention(method) (Int, @guaranteed MyClass) -> () // user: %24 | |
%24 = apply %23(%13, %4) : $@convention(method) (Int, @guaranteed MyClass) -> () | |
br bb1 // id: %25 | |
} // end sil function '_T06sample7MyClassC6numberSifmytfU_' | |
// MyClass.number.materializeForSet | |
sil hidden [transparent] @_T06sample7MyClassC6numberSifm : $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @guaranteed MyClass) -> (Builtin.RawPointer, Optional<Builtin.RawPointer>) { | |
// %0 // users: %10, %3 | |
// %2 // user: %4 | |
bb0(%0 : $Builtin.RawPointer, %1 : $*Builtin.UnsafeValueBuffer, %2 : $MyClass): | |
%3 = pointer_to_address %0 : $Builtin.RawPointer to [strict] $*Int // user: %6 | |
%4 = ref_element_addr %2 : $MyClass, #MyClass.number // user: %5 | |
%5 = load %4 : $*Int // user: %6 | |
store %5 to %3 : $*Int // id: %6 | |
// function_ref closure #1 in MyClass.number.materializeForSet | |
%7 = function_ref @_T06sample7MyClassC6numberSifmytfU_ : $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout MyClass, @thick MyClass.Type) -> () // user: %8 | |
%8 = thin_function_to_pointer %7 : $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout MyClass, @thick MyClass.Type) -> () to $Builtin.RawPointer // user: %9 | |
%9 = enum $Optional<Builtin.RawPointer>, #Optional.some!enumelt.1, %8 : $Builtin.RawPointer // user: %10 | |
%10 = tuple (%0 : $Builtin.RawPointer, %9 : $Optional<Builtin.RawPointer>) // user: %11 | |
return %10 : $(Builtin.RawPointer, Optional<Builtin.RawPointer>) // id: %11 | |
} // end sil function '_T06sample7MyClassC6numberSifm' | |
// MyClass.__allocating_init() | |
sil hidden @_T06sample7MyClassCACycfC : $@convention(method) (@thick MyClass.Type) -> @owned MyClass { | |
bb0(%0 : $@thick MyClass.Type): | |
%1 = alloc_ref $MyClass // users: %15, %11, %9, %17, %5, %4, %3, %2 | |
debug_value %1 : $MyClass, let, name "self" // id: %2 | |
%3 = ref_element_addr %1 : $MyClass, #MyClass.x // user: %16 | |
%4 = ref_element_addr %1 : $MyClass, #MyClass.number // user: %10 | |
debug_value %1 : $MyClass, let, name "self", argno 1 // id: %5 | |
%6 = integer_literal $Builtin.Int64, 555 // user: %7 | |
%7 = struct $Int (%6 : $Builtin.Int64) // users: %10, %8 | |
debug_value %7 : $Int, let, name "newValue", argno 1 // id: %8 | |
debug_value %1 : $MyClass, let, name "self", argno 2 // id: %9 | |
store %7 to %4 : $*Int // id: %10 | |
debug_value %1 : $MyClass, let, name "self", argno 2 // id: %11 | |
%12 = integer_literal $Builtin.Int64, 333 // user: %13 | |
%13 = struct $Int (%12 : $Builtin.Int64) // users: %16, %14 | |
debug_value %13 : $Int, let, name "value", argno 1 // id: %14 | |
debug_value %1 : $MyClass, let, name "self", argno 2 // id: %15 | |
store %13 to %3 : $*Int // id: %16 | |
return %1 : $MyClass // id: %17 | |
} // end sil function '_T06sample7MyClassCACycfC' | |
// MyClass.init() | |
sil hidden @_T06sample7MyClassCACycfc : $@convention(method) (@owned MyClass) -> @owned MyClass { | |
// %0 // users: %31, %26, %25, %29, %30, %11, %28, %8, %4, %6, %12, %1 | |
bb0(%0 : $MyClass): | |
debug_value %0 : $MyClass, let, name "self" // id: %1 | |
%2 = integer_literal $Builtin.Int64, 0 // user: %3 | |
%3 = struct $Int (%2 : $Builtin.Int64) // users: %7, %5 | |
%4 = ref_element_addr %0 : $MyClass, #MyClass.x // user: %5 | |
store %3 to %4 : $*Int // id: %5 | |
%6 = ref_element_addr %0 : $MyClass, #MyClass.number // user: %7 | |
store %3 to %6 : $*Int // id: %7 | |
debug_value %0 : $MyClass, let, name "self", argno 1 // id: %8 | |
%9 = integer_literal $Builtin.Int64, 555 // user: %10 | |
%10 = struct $Int (%9 : $Builtin.Int64) // users: %17, %14, %30 | |
checked_cast_br [exact] %0 : $MyClass to $MyClass, bb2, bb3 // id: %11 | |
bb1: // Preds: bb2 bb3 | |
return %0 : $MyClass // id: %12 | |
// %13 // users: %22, %23, %18, %16, %15 | |
bb2(%13 : $MyClass): // Preds: bb0 | |
debug_value %10 : $Int, let, name "newValue", argno 1 // id: %14 | |
debug_value %13 : $MyClass, let, name "self", argno 2 // id: %15 | |
%16 = ref_element_addr %13 : $MyClass, #MyClass.number // user: %17 | |
store %10 to %16 : $*Int // id: %17 | |
debug_value %13 : $MyClass, let, name "self", argno 2 // id: %18 | |
%19 = integer_literal $Builtin.Int64, 333 // user: %20 | |
%20 = struct $Int (%19 : $Builtin.Int64) // users: %24, %21 | |
debug_value %20 : $Int, let, name "value", argno 1 // id: %21 | |
debug_value %13 : $MyClass, let, name "self", argno 2 // id: %22 | |
%23 = ref_element_addr %13 : $MyClass, #MyClass.x // user: %24 | |
store %20 to %23 : $*Int // id: %24 | |
strong_retain %0 : $MyClass // id: %25 | |
strong_release %0 : $MyClass // id: %26 | |
br bb1 // id: %27 | |
bb3: // Preds: bb0 | |
%28 = class_method %0 : $MyClass, #MyClass.number!setter.1 : (MyClass) -> (Int) -> (), $@convention(method) (Int, @guaranteed MyClass) -> () // user: %30 | |
strong_retain %0 : $MyClass // id: %29 | |
%30 = apply %28(%10, %0) : $@convention(method) (Int, @guaranteed MyClass) -> () | |
strong_release %0 : $MyClass // id: %31 | |
br bb1 // id: %32 | |
} // end sil function '_T06sample7MyClassCACycfc' | |
// MyClass.deinit | |
sil hidden @_T06sample7MyClassCfd : $@convention(method) (@guaranteed MyClass) -> @owned Builtin.NativeObject { | |
// %0 // users: %2, %1 | |
bb0(%0 : $MyClass): | |
debug_value %0 : $MyClass, let, name "self", argno 1 // id: %1 | |
%2 = unchecked_ref_cast %0 : $MyClass to $Builtin.NativeObject // user: %3 | |
return %2 : $Builtin.NativeObject // id: %3 | |
} // end sil function '_T06sample7MyClassCfd' | |
// MyClass.__deallocating_deinit | |
sil hidden @_T06sample7MyClassCfD : $@convention(method) (@owned MyClass) -> () { | |
// %0 // users: %3, %2, %1 | |
bb0(%0 : $MyClass): | |
debug_value %0 : $MyClass, let, name "self", argno 1 // id: %1 | |
debug_value %0 : $MyClass, let, name "self", argno 1 // id: %2 | |
dealloc_ref %0 : $MyClass // id: %3 | |
%4 = tuple () // user: %5 | |
return %4 : $() // id: %5 | |
} // end sil function '_T06sample7MyClassCfD' | |
sil_vtable MyClass { | |
#MyClass.x!getter.1: (MyClass) -> () -> Int : _T06sample7MyClassC1xSifg // MyClass.x.getter | |
#MyClass.x!setter.1: (MyClass) -> (Int) -> () : _T06sample7MyClassC1xSifs // MyClass.x.setter | |
#MyClass.x!materializeForSet.1: (MyClass) -> (Builtin.RawPointer, inout Builtin.UnsafeValueBuffer) -> (Builtin.RawPointer, Builtin.RawPointer?) : _T06sample7MyClassC1xSifm // MyClass.x.materializeForSet | |
#MyClass.number!getter.1: (MyClass) -> () -> Int : _T06sample7MyClassC6numberSifg // MyClass.number.getter | |
#MyClass.number!setter.1: (MyClass) -> (Int) -> () : _T06sample7MyClassC6numberSifs // MyClass.number.setter | |
#MyClass.number!materializeForSet.1: (MyClass) -> (Builtin.RawPointer, inout Builtin.UnsafeValueBuffer) -> (Builtin.RawPointer, Builtin.RawPointer?) : _T06sample7MyClassC6numberSifm // MyClass.number.materializeForSet | |
#MyClass.init!initializer.1: (MyClass.Type) -> () -> MyClass : _T06sample7MyClassCACycfc // MyClass.init() | |
#MyClass.deinit!deallocator: _T06sample7MyClassCfD // MyClass.__deallocating_deinit | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass { | |
var x: Int = 0 | |
var number: Int = 0 { | |
didSet { | |
x = 333 | |
} | |
} | |
init() { | |
defer { | |
number = 555 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment