Support throwNpe intrinsic

This commit is contained in:
Mikhael Bogdanov
2018-01-10 12:16:39 +01:00
parent d62a7cc9d1
commit 9d7eca1376
3 changed files with 46 additions and 6 deletions
@@ -82,7 +82,12 @@ open class IrIntrinsicFunction(
TODO("not implemented for $this")
}
open fun invoke(v: InstructionAdapter, codegen: ExpressionCodegen, data: BlockInfo):StackValue {
open fun genInvokeInstructionWithResult(v: InstructionAdapter): Type {
genInvokeInstruction(v)
return returnType
}
open fun invoke(v: InstructionAdapter, codegen: ExpressionCodegen, data: BlockInfo): StackValue {
val args = listOfNotNull(expression.dispatchReceiver, expression.extensionReceiver) +
expression.descriptor.valueParameters.mapIndexed { i, descriptor ->
expression.getValueArgument(i) ?:
@@ -103,8 +108,7 @@ open class IrIntrinsicFunction(
genArg(irExpression, codegen, i, data)
}
}
genInvokeInstruction(v)
return StackValue.onStack(returnType)
return StackValue.onStack(genInvokeInstructionWithResult(v))
}
open fun genArg(expression: IrExpression, codegen: ExpressionCodegen, index: Int, data: BlockInfo) {
@@ -118,9 +122,19 @@ open class IrIntrinsicFunction(
argsTypes: List<Type> = expression.argTypes(context),
invokeInstuction: IrIntrinsicFunction.(InstructionAdapter) -> Unit): IrIntrinsicFunction {
return object : IrIntrinsicFunction(expression, signature, context, argsTypes) {
override fun genInvokeInstruction(v: InstructionAdapter) {
invokeInstuction(v)
}
override fun genInvokeInstruction(v: InstructionAdapter) = invokeInstuction(v)
}
}
fun createWithResult(expression: IrMemberAccessExpression,
signature: JvmMethodSignature,
context: JvmBackendContext,
argsTypes: List<Type> = expression.argTypes(context),
invokeInstuction: IrIntrinsicFunction.(InstructionAdapter) -> Type): IrIntrinsicFunction {
return object : IrIntrinsicFunction(expression, signature, context, argsTypes) {
override fun genInvokeInstructionWithResult(v: InstructionAdapter) = invokeInstuction(v)
}
}
@@ -39,6 +39,7 @@ class IrIntrinsicMethods(irBuiltIns: IrBuiltIns) {
irMapping.put(irBuiltIns.gteq0, compare)
irMapping.put(irBuiltIns.enumValueOf, IrEnumValueOf())
irMapping.put(irBuiltIns.noWhenBranchMatchedException, IrNoWhenBranchMatchedException())
irMapping.put(irBuiltIns.throwNpe, ThrowNPE())
}
fun getIntrinsic(descriptor: CallableMemberDescriptor): IntrinsicMethod? {
@@ -0,0 +1,25 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.backend.jvm.intrinsics
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
import org.jetbrains.org.objectweb.asm.Type
class ThrowNPE : IntrinsicMethod() {
override fun toCallable(
expression: IrMemberAccessExpression,
signature: JvmMethodSignature,
context: JvmBackendContext
): IrIntrinsicFunction {
return IrIntrinsicFunction.createWithResult(expression, signature, context) {
it.invokestatic(IntrinsicMethods.INTRINSICS_CLASS_NAME, "throwNpe", "()V", false)
Type.VOID_TYPE
}
}
}