Compiler backend - transforming IR into the target executable format.
Implementations of backends for specific Kotlin targets are located in backend.* modules, except for the Kotlin/Native backend, which is located under /kotlin-native/backend.native.
IR is a lower-level representation of kotlin code, used at the backend stage of compilation. Despite this, it still has similar structure to the source code.
For example:
fun abs(num: Int): Int { return if (num >= 0) num else -num }
may be represented in IR as (simplified textual representation):
IrSimpleFunction name:abs visibility:public modality:FINAL returnType:kotlin.Int
IrValueParameter name:num index:0 type:kotlin.Int
IrBlockBody
IrReturn type:kotlin.Int
IrWhen type:kotlin.Int origin:IF
IrBranch
condition: IrCall symbol:'fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean'
arg0: IrGetValue symbol:'num' type:kotlin.Int
arg1: IrConst type:kotlin.Int value:0
result: IrGetValue symbol:'num' type:kotlin.Int
IrBranch
condition: IrConst type:kotlin.Boolean value:true
result: IrCall symbol:'fun minus (arg0: kotlin.Int): kotlin.Int'
arg0: IrGetValue symbol:'num' type:kotlin.Int
The classes of all IR elements inherit from IrElement and most of them are generated from specification in IrTree.kt.
IR is used by all kotlin backends for:
./serialization.common/ReadMe.md