Intrinsic fixes
This commit is contained in:
committed by
Dmitry Petrov
parent
fc754e533d
commit
866def0d20
@@ -17,13 +17,15 @@
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
|
||||
class ArrayGet : IntrinsicMethod() {
|
||||
override fun toCallable(expression: IrMemberAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
||||
val type = expressionType(expression, context)
|
||||
return IrIntrinsicFunction.create(expression, signature, context) {
|
||||
val type = AsmUtil.correctElementType(calcReceiverType(expression, context))
|
||||
return IrIntrinsicFunction.create(expression, signature, context, listOf(calcReceiverType(expression, context), Type.INT_TYPE)) {
|
||||
it.aload(type)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ class BinaryOp(private val opcode: Int) : IntrinsicMethod() {
|
||||
private fun shift(): Boolean =
|
||||
opcode == ISHL || opcode == ISHR || opcode == IUSHR
|
||||
|
||||
/*TODO new return type*/
|
||||
override fun toCallable(expression: IrMemberAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
||||
val owner = context.state.typeMapper.mapOwner(expression.descriptor)
|
||||
val returnType = signature.returnType
|
||||
|
||||
@@ -19,17 +19,16 @@ package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
|
||||
class Clone : IntrinsicMethod() {
|
||||
|
||||
override fun toCallable(expression: IrMemberAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
||||
return IrIntrinsicFunction.create(expression, signature, context) {
|
||||
val resultType = context.state.typeMapper.mapType(expression.type)
|
||||
return IrIntrinsicFunction.create(expression, signature.newReturnType(AsmTypes.OBJECT_TYPE), context) {
|
||||
val opcode = if (expression is IrCall && expression.superQualifier != null) Opcodes.INVOKESPECIAL else Opcodes.INVOKEVIRTUAL
|
||||
it.visitMethodInsn(opcode, "java/lang/Object", "clone", "()Ljava/lang/Object;", false)
|
||||
it.checkcast(resultType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -21,8 +21,10 @@ import org.jetbrains.kotlin.codegen.Callable
|
||||
import org.jetbrains.kotlin.codegen.CallableMethod
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.org.objectweb.asm.commons.Method
|
||||
|
||||
abstract class IntrinsicMethod {
|
||||
|
||||
@@ -47,5 +49,12 @@ abstract class IntrinsicMethod {
|
||||
fun expressionType(expression: IrExpression, context: JvmBackendContext): Type {
|
||||
return context.state.typeMapper.mapType(expression.type)
|
||||
}
|
||||
|
||||
fun JvmMethodSignature.newReturnType(type: Type): JvmMethodSignature {
|
||||
val newMethod = with(asmMethod) {
|
||||
Method(name, type, argumentTypes)
|
||||
}
|
||||
return JvmMethodSignature(newMethod, valueParameters)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class Inv : IntrinsicMethod() {
|
||||
override fun toCallable(expression: IrMemberAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
||||
val returnType = signature.returnType
|
||||
val type = numberFunctionOperandType(returnType)
|
||||
return IrIntrinsicFunction.create(expression, signature, context) {
|
||||
return IrIntrinsicFunction.create(expression, signature, context, type) {
|
||||
if (returnType == Type.LONG_TYPE) {
|
||||
it.lconst(-1)
|
||||
}
|
||||
|
||||
+1
-7
@@ -26,18 +26,12 @@ import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.org.objectweb.asm.commons.Method
|
||||
|
||||
class IteratorNext : IntrinsicMethod() {
|
||||
|
||||
/*TODO new return type*/
|
||||
override fun toCallable(expression: IrMemberAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
||||
val type = AsmUtil.unboxType(signature.returnType)
|
||||
val newMethod = with(signature.asmMethod) {
|
||||
Method(name, type, argumentTypes)
|
||||
}
|
||||
|
||||
val newSignature = JvmMethodSignature(newMethod, signature.valueParameters)
|
||||
val newSignature = signature.newReturnType(type)
|
||||
return IrIntrinsicFunction.create(expression, newSignature, context, AsmTypes.OBJECT_TYPE) {
|
||||
val primitiveClassName = getKotlinPrimitiveClassName(type)
|
||||
it.invokevirtual(
|
||||
|
||||
Reference in New Issue
Block a user