Add StackValue.put(InstructionAdapter) for convenience

This commit is contained in:
Alexander Udalov
2018-11-22 15:13:48 +01:00
parent f9be21c935
commit dd0b087b92
10 changed files with 28 additions and 27 deletions
@@ -420,8 +420,7 @@ public class ConstructorCodegen {
// Super constructor requires OUTER parameter, but our OUTER instance may be different from what is expected by the super
// constructor. We need to traverse our outer classes from the bottom up, to find the needed class. See innerExtendsOuter.kt
ClassDescriptor outerForSuper = (ClassDescriptor) superConstructor.getContainingDeclaration().getContainingDeclaration();
StackValue outer = codegen.generateThisOrOuter(outerForSuper, true, true);
outer.put(outer.type, codegen.v);
codegen.generateThisOrOuter(outerForSuper, true, true).put(codegen.v);
superIndex++;
}
else if (kind == JvmMethodParameterKind.SUPER_CALL_PARAM || kind == JvmMethodParameterKind.ENUM_NAME_OR_ORDINAL) {
@@ -1556,7 +1556,7 @@ public class FunctionCodegen {
iv.load(2, returnType);
}
else {
StackValue.constant(typeSafeBarrierDescription.getDefaultValue(), returnType).put(returnType, iv);
StackValue.constant(typeSafeBarrierDescription.getDefaultValue(), returnType).put(iv);
}
iv.areturn(returnType);
@@ -1619,7 +1619,7 @@ public class FunctionCodegen {
InstructionAdapter iv = new InstructionAdapter(mv);
iv.load(0, OBJECT_TYPE);
field.put(field.type, iv);
field.put(iv);
for (int i = 0, reg = 1; i < argTypes.length; i++) {
StackValue.local(reg, argTypes[i]).put(originalArgTypes[i], iv);
//noinspection AssignmentToForLoopParameter
@@ -913,7 +913,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if (state.getClassBuilderMode().generateBodies && info.defaultValue == null) {
ExpressionCodegen codegen = createOrGetClInitCodegen();
int companionObjectIndex = putCompanionObjectInLocalVar(codegen);
StackValue.local(companionObjectIndex, OBJECT_TYPE).put(OBJECT_TYPE, codegen.v);
StackValue.local(companionObjectIndex, OBJECT_TYPE).put(codegen.v);
copyFieldFromCompanionObject(property);
}
}
@@ -49,8 +49,7 @@ class JvmStaticInCompanionObjectGenerator(
override fun doGenerateBody(codegen: ExpressionCodegen, signature: JvmMethodSignature) {
val iv = codegen.v
val classDescriptor = descriptor.containingDeclaration as ClassDescriptor
val singletonValue = StackValue.singleton(classDescriptor, typeMapper)
singletonValue.put(singletonValue.type, iv)
StackValue.singleton(classDescriptor, typeMapper).put(iv)
var index = 0
val asmMethod = signature.asmMethod
for (paramType in asmMethod.argumentTypes) {
@@ -103,14 +103,18 @@ public abstract class StackValue {
put(type, kotlinType, v);
}
public void put(@NotNull Type type, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v) {
put(type, kotlinType, v, false);
public void put(@NotNull InstructionAdapter v) {
put(type, null, v, false);
}
public void put(@NotNull Type type, @NotNull InstructionAdapter v) {
put(type, null, v, false);
}
public void put(@NotNull Type type, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v) {
put(type, kotlinType, v, false);
}
public void put(@NotNull Type type, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v, boolean skipReceiver) {
if (!skipReceiver) {
putReceiver(v, true);
@@ -22,10 +22,9 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.org.objectweb.asm.Type
class ArraySize : IntrinsicPropertyGetter() {
override fun generate(
resolvedCall: ResolvedCall<*>?, codegen: ExpressionCodegen, returnType: Type, receiver: StackValue
) = StackValue.operation(returnType) {
receiver.put(receiver.type, it)
it.arraylength()
}
override fun generate(resolvedCall: ResolvedCall<*>?, codegen: ExpressionCodegen, returnType: Type, receiver: StackValue) =
StackValue.operation(returnType) { iv ->
receiver.put(iv)
iv.arraylength()
}
}
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.isInlineClassType
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.UNIT_TYPE
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.getType
import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
@@ -53,7 +52,7 @@ object JavaClassProperty : IntrinsicPropertyGetter() {
when {
type == Type.VOID_TYPE -> {
receiver.put(Type.VOID_TYPE, v)
StackValue.unit().put(UNIT_TYPE, v)
StackValue.unit().put(v)
invokeVirtualGetClassMethod()
}
@@ -456,7 +456,7 @@ class ExpressionCodegen(
override fun visitGetField(expression: IrGetField, data: BlockInfo): StackValue {
expression.markLineNumber(startOffset = true)
val value = generateFieldValue(expression, data)
value.put(value.type, mv)
value.put(mv)
return onStack(value.type)
}
@@ -511,7 +511,7 @@ class ExpressionCodegen(
private fun generateLocal(symbol: IrSymbol, type: Type): StackValue {
val index = findLocalIndex(symbol)
StackValue.local(index, type).put(type, mv)
StackValue.local(index, type).put(mv)
return onStack(type)
}
@@ -549,7 +549,7 @@ class ExpressionCodegen(
expression.markLineNumber(startOffset = true)
val value = expression.value
val type = expression.asmType
StackValue.constant(value, type).put(type, mv)
StackValue.constant(value, type).put(mv)
return expression.onStack
}
@@ -643,7 +643,7 @@ class ExpressionCodegen(
val elementKotlinType = classCodegen.context.builtIns.getArrayElementType(outType.toKotlinType()!!)
for ((i, element) in expression.elements.withIndex()) {
mv.dup()
StackValue.constant(i).put(Type.INT_TYPE, mv)
StackValue.constant(i).put(mv)
val rightSide = gen(element, elementType, data)
StackValue
.arrayElement(
@@ -822,7 +822,7 @@ class ExpressionCodegen(
val type = boxType(asmType)
generateIsCheck(mv, expression.typeOperand.toKotlinType(), type, state.languageVersionSettings.isReleaseCoroutines())
if (IrTypeOperator.NOT_INSTANCEOF == expression.operator) {
StackValue.not(StackValue.onStack(Type.BOOLEAN_TYPE)).put(Type.BOOLEAN_TYPE, mv)
StackValue.not(StackValue.onStack(Type.BOOLEAN_TYPE)).put(mv)
}
}
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.codegen.AsmUtil.boxType
import org.jetbrains.kotlin.codegen.AsmUtil.isPrimitive
import org.jetbrains.kotlin.codegen.StackValue
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.InstructionAdapter
@@ -38,7 +37,7 @@ object JavaClassProperty : IntrinsicMethod() {
val type = value.type
when {
type == Type.VOID_TYPE -> {
StackValue.unit().put(AsmTypes.UNIT_TYPE, v)
StackValue.unit().put(v)
v.invokevirtual("java/lang/Object", "getClass", "()Ljava/lang/Class;", false)
}
isPrimitive(type) -> {
@@ -17,8 +17,10 @@
package org.jetbrains.kotlin.backend.jvm.intrinsics
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
import org.jetbrains.kotlin.codegen.*
import org.jetbrains.kotlin.ir.expressions.IrCall
import org.jetbrains.kotlin.codegen.Callable
import org.jetbrains.kotlin.codegen.CallableMethod
import org.jetbrains.kotlin.codegen.ExpressionCodegen
import org.jetbrains.kotlin.codegen.StackValue
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
import org.jetbrains.kotlin.psi.KtPrefixExpression
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
@@ -28,7 +30,7 @@ import org.jetbrains.org.objectweb.asm.Type
class Not : IntrinsicMethod() {
override fun toCallable(expression: IrMemberAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
return IrIntrinsicFunction.create(expression, signature, context) {
StackValue.not(StackValue.onStack(Type.BOOLEAN_TYPE)).put(Type.BOOLEAN_TYPE, it)
StackValue.not(StackValue.onStack(Type.BOOLEAN_TYPE)).put(it)
}
}