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