Support throwNpe intrinsic
This commit is contained in:
+20
-6
@@ -82,7 +82,12 @@ open class IrIntrinsicFunction(
|
|||||||
TODO("not implemented for $this")
|
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) +
|
val args = listOfNotNull(expression.dispatchReceiver, expression.extensionReceiver) +
|
||||||
expression.descriptor.valueParameters.mapIndexed { i, descriptor ->
|
expression.descriptor.valueParameters.mapIndexed { i, descriptor ->
|
||||||
expression.getValueArgument(i) ?:
|
expression.getValueArgument(i) ?:
|
||||||
@@ -103,8 +108,7 @@ open class IrIntrinsicFunction(
|
|||||||
genArg(irExpression, codegen, i, data)
|
genArg(irExpression, codegen, i, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
genInvokeInstruction(v)
|
return StackValue.onStack(genInvokeInstructionWithResult(v))
|
||||||
return StackValue.onStack(returnType)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun genArg(expression: IrExpression, codegen: ExpressionCodegen, index: Int, data: BlockInfo) {
|
open fun genArg(expression: IrExpression, codegen: ExpressionCodegen, index: Int, data: BlockInfo) {
|
||||||
@@ -118,9 +122,19 @@ open class IrIntrinsicFunction(
|
|||||||
argsTypes: List<Type> = expression.argTypes(context),
|
argsTypes: List<Type> = expression.argTypes(context),
|
||||||
invokeInstuction: IrIntrinsicFunction.(InstructionAdapter) -> Unit): IrIntrinsicFunction {
|
invokeInstuction: IrIntrinsicFunction.(InstructionAdapter) -> Unit): IrIntrinsicFunction {
|
||||||
return object : IrIntrinsicFunction(expression, signature, context, argsTypes) {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
@@ -39,6 +39,7 @@ class IrIntrinsicMethods(irBuiltIns: IrBuiltIns) {
|
|||||||
irMapping.put(irBuiltIns.gteq0, compare)
|
irMapping.put(irBuiltIns.gteq0, compare)
|
||||||
irMapping.put(irBuiltIns.enumValueOf, IrEnumValueOf())
|
irMapping.put(irBuiltIns.enumValueOf, IrEnumValueOf())
|
||||||
irMapping.put(irBuiltIns.noWhenBranchMatchedException, IrNoWhenBranchMatchedException())
|
irMapping.put(irBuiltIns.noWhenBranchMatchedException, IrNoWhenBranchMatchedException())
|
||||||
|
irMapping.put(irBuiltIns.throwNpe, ThrowNPE())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getIntrinsic(descriptor: CallableMemberDescriptor): IntrinsicMethod? {
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user