Measures Concepts
GitHub icon

SIL

SIL - Intermediate representation language

< >

SIL, aka Swift Intermediate Language, is an intermediate representation language created in 2012.

#503on PLDB 12Years Old

SIL is an SSA-form IR with high-level semantic information designed to implement the Swift programming language. In contrast to LLVM IR, SIL is a generally target-independent format representation that can be used for code distribution, but it can also express target-specific concepts as well as LLVM can.


Example from the web:
// SIL is reliant on Swift's type system and declarations, so SIL syntax is an extension of Swift's. A .sil file is a Swift source file with added SIL definitions. The Swift source is parsed only for its declarations; Swift func bodies (except for nested declarations) and top-level code are ignored by the SIL parser. In a .sil file, there are no implicit imports; the swift and/or Builtin standard modules must be imported explicitly if used. sil_stage canonical import Swift // Define types used by the SIL function. struct Point { var x : Double var y : Double } class Button { func onClick() func onMouseDown() func onMouseUp() } // Declare a Swift function. The body is ignored by SIL. func taxicabNorm(_ a:Point) -> Double { return a.x + a.y } // Define a SIL function. // The name @_T5norms11taxicabNormfT1aV5norms5Point_Sd is the mangled name // of the taxicabNorm Swift function. sil @_T5norms11taxicabNormfT1aV5norms5Point_Sd : $(Point) -> Double { bb0(%0 : $Point): // func Swift.+(Double, Double) -> Double %1 = function_ref @_Tsoi1pfTSdSd_Sd %2 = struct_extract %0 : $Point, #Point.x %3 = struct_extract %0 : $Point, #Point.y %4 = apply %1(%2, %3) : $(Double, Double) -> Double return %4 : Double } // Define a SIL vtable. This matches dynamically-dispatched method // identifiers to their implementations for a known static class type. sil_vtable Button { #Button.onClick: @_TC5norms6Button7onClickfS0_FT_T_ #Button.onMouseDown: @_TC5norms6Button11onMouseDownfS0_FT_T_ #Button.onMouseUp: @_TC5norms6Button9onMouseUpfS0_FT_T_ }
Example from hello-world:
print Hello World

Language features

Feature Supported Token Example
Print() Debugging ✓ print
Comments ✓
// A comment
Line Comments ✓ //
// A comment
Semantic Indentation X

View source

- Build the next great programming language · Search · Add Language · Features · Creators · Resources · About · Blog · Acknowledgements · Queries · Stats · Sponsor · Day 605 · feedback@pldb.io · Logout