Create separate constructor for ir interpreter with only ir builtins

By introducing this constructor, ir interpreter will no longer find ir
exceptions in module and so interpreter is creating faster for fir2ir
goals
This commit is contained in:
Ivan Kylchik
2020-06-26 17:59:06 +03:00
parent de2b20482a
commit 13f7b6a22e
2 changed files with 16 additions and 7 deletions
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyFunction
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl
@@ -32,10 +33,8 @@ import kotlin.concurrent.thread
private const val MAX_COMMANDS = 500_000
class IrInterpreter(irModule: IrModuleFragment, private val bodyMap: Map<IdSignature, IrBody> = emptyMap()) {
private val irBuiltIns = irModule.irBuiltins
private val irExceptions = irModule.files.flatMap { it.declarations }.filterIsInstance<IrClass>()
.filter { it.isSubclassOf(irBuiltIns.throwableClass.owner) }
class IrInterpreter(private val irBuiltIns: IrBuiltIns, private val bodyMap: Map<IdSignature, IrBody> = emptyMap()) {
private val irExceptions = mutableListOf<IrClass>()
private val stack = StackImpl()
private var commandCount = 0
@@ -43,6 +42,15 @@ class IrInterpreter(irModule: IrModuleFragment, private val bodyMap: Map<IdSigna
private val mapOfEnums = mutableMapOf<IrSymbol, Complex>()
private val mapOfObjects = mutableMapOf<IrSymbol, Complex>()
constructor(irModule: IrModuleFragment): this(irModule.irBuiltins) {
irExceptions.addAll(
irModule.files
.flatMap { it.declarations }
.filterIsInstance<IrClass>()
.filter { it.isSubclassOf(irBuiltIns.throwableClass.owner) }
)
}
private fun Any?.getType(defaultType: IrType): IrType {
return when (this) {
is Boolean -> irBuiltIns.booleanType