1ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon/* 2ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon * Copyright (C) 2017 The Android Open Source Project 3ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon * 4ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon * Licensed under the Apache License, Version 2.0 (the "License"); 5ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon * you may not use this file except in compliance with the License. 6ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon * You may obtain a copy of the License at 7ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon * 8ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon * http://www.apache.org/licenses/LICENSE-2.0 9ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon * 10ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon * Unless required by applicable law or agreed to in writing, software 11ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon * distributed under the License is distributed on an "AS IS" BASIS, 12ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon * See the License for the specific language governing permissions and 14ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon * limitations under the License. 15ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon */ 16ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon 17ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushonpackage com.android.dx.io.instructions; 18ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon 19ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushonimport com.android.dx.io.IndexType; 20ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon 21ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon/** A decoded invoke-polymorphic/range instruction. */ 22ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushonpublic class InvokePolymorphicRangeDecodedInstruction extends DecodedInstruction { 23ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon 24ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon private final int c; 25ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon private final int registerCount; 26ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon private final int protoIndex; 27ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon 28ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon public InvokePolymorphicRangeDecodedInstruction( 29ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon InstructionCodec format, 30ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon int opcode, 31ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon int methodIndex, 32ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon IndexType indexType, 33ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon int c, 34ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon int registerCount, 35ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon int protoIndex) { 36ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon super(format, opcode, methodIndex, indexType, 0, 0); 37ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon if (protoIndex != (short) protoIndex) { 38ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon throw new IllegalArgumentException("protoIndex doesn't fit in a short: " + protoIndex); 39ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon } 40ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon this.c = c; 41ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon this.registerCount = registerCount; 42ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon this.protoIndex = protoIndex; 43ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon } 44ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon 45ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon @Override 46ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon public int getRegisterCount() { 47ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon return registerCount; 48ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon } 49ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon 50ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon @Override 51ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon public int getC() { 52ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon return c; 53ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon } 54ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon 55ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon @Override 56ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon public DecodedInstruction withProtoIndex(int newIndex, int newProtoIndex) { 57ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon return new InvokePolymorphicRangeDecodedInstruction( 58ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon getFormat(), 59ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon getOpcode(), 60ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon newIndex, 61ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon getIndexType(), 62ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon c, 63ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon registerCount, 64ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon newProtoIndex); 65ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon } 66ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon 67ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon @Override 68ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon public DecodedInstruction withIndex(int newIndex) { 69ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon throw new UnsupportedOperationException( 70ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon "use withProtoIndex to update both the method and proto indices for " 71ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon + "invoke-polymorphic/range"); 72ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon } 73ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon 74ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon @Override 75ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon public short getProtoIndex() { 76ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon return (short) protoIndex; 77ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon } 78ebf02b65aed5b5e5f9b1e1e9ab345fea82dc2341Liam Miller-Cushon} 79