blob: 6736d7e54a14ced4f7f7ac7c82916172227a60f8 [file] [log] [blame]
// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.ir.code;
import com.android.tools.r8.code.Sput;
import com.android.tools.r8.code.SputBoolean;
import com.android.tools.r8.code.SputByte;
import com.android.tools.r8.code.SputChar;
import com.android.tools.r8.code.SputObject;
import com.android.tools.r8.code.SputShort;
import com.android.tools.r8.code.SputWide;
import com.android.tools.r8.dex.Constants;
import com.android.tools.r8.errors.Unreachable;
import com.android.tools.r8.graph.AppInfo;
import com.android.tools.r8.graph.DexEncodedField;
import com.android.tools.r8.graph.DexField;
import com.android.tools.r8.graph.DexType;
import com.android.tools.r8.ir.conversion.DexBuilder;
public class StaticPut extends FieldInstruction {
public StaticPut(MemberType type, Value source, DexField field) {
super(type, field, null, source);
}
public Value inValue() {
assert inValues.size() == 1;
return inValues.get(0);
}
@Override
public void buildDex(DexBuilder builder) {
com.android.tools.r8.code.Instruction instruction;
int src = builder.allocatedRegister(inValue(), getNumber());
switch (type) {
case SINGLE:
instruction = new Sput(src, field);
break;
case WIDE:
instruction = new SputWide(src, field);
break;
case OBJECT:
instruction = new SputObject(src, field);
break;
case BOOLEAN:
instruction = new SputBoolean(src, field);
break;
case BYTE:
instruction = new SputByte(src, field);
break;
case CHAR:
instruction = new SputChar(src, field);
break;
case SHORT:
instruction = new SputShort(src, field);
break;
default:
throw new Unreachable("Unexpected type " + type);
}
builder.add(this, instruction);
}
@Override
public boolean instructionTypeCanThrow() {
// This can cause <clinit> to run.
return true;
}
@Override
public int maxInValueRegister() {
return Constants.U8BIT_MAX;
}
@Override
public int maxOutValueRegister() {
assert false : "StaticPut instructions define no values.";
return 0;
}
@Override
public boolean identicalNonValueParts(Instruction other) {
StaticPut o = other.asStaticPut();
return o.field == field && o.type == type;
}
@Override
public int compareNonValueParts(Instruction other) {
StaticPut o = other.asStaticPut();
int result;
result = field.slowCompareTo(o.field);
if (result != 0) {
return result;
}
return type.ordinal() - o.type.ordinal();
}
@Override
DexEncodedField lookupTarget(DexType type, AppInfo appInfo) {
return appInfo.lookupStaticTarget(type, field);
}
@Override
public String toString() {
return super.toString() + "; field: " + field.toSourceString();
}
@Override
public boolean isStaticPut() {
return true;
}
@Override
public StaticPut asStaticPut() {
return this;
}
}