• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 instruction. */
22 public class InvokePolymorphicDecodedInstruction extends DecodedInstruction {
23 
24     private final int protoIndex;
25     private final int[] registers;
26 
InvokePolymorphicDecodedInstruction( InstructionCodec format, int opcode, int methodIndex, IndexType indexType, int protoIndex, int[] registers)27     public InvokePolymorphicDecodedInstruction(
28             InstructionCodec format,
29             int opcode,
30             int methodIndex,
31             IndexType indexType,
32             int protoIndex,
33             int[] registers) {
34         super(format, opcode, methodIndex, indexType, 0, 0);
35         if (protoIndex != (short) protoIndex) {
36           throw new IllegalArgumentException("protoIndex doesn't fit in a short: " + protoIndex);
37         }
38         this.protoIndex = protoIndex;
39         this.registers = registers;
40     }
41 
42     @Override
getRegisterCount()43     public int getRegisterCount() {
44         return registers.length;
45     }
46 
47     @Override
withIndex(int newIndex)48     public DecodedInstruction withIndex(int newIndex) {
49         throw new UnsupportedOperationException(
50                 "use withProtoIndex to update both the method and proto indices for"
51                         + " invoke-polymorphic");
52     }
53 
54     @Override
withProtoIndex(int newIndex, int newProtoIndex)55     public DecodedInstruction withProtoIndex(int newIndex, int newProtoIndex) {
56         return new InvokePolymorphicDecodedInstruction(
57                 getFormat(), getOpcode(), newIndex, getIndexType(), newProtoIndex, registers);
58     }
59 
60     @Override
getC()61     public int getC() {
62         return registers.length > 0 ? registers[0] : 0;
63     }
64 
65     @Override
getD()66     public int getD() {
67         return registers.length > 1 ? registers[1] : 0;
68     }
69 
70     @Override
getE()71     public int getE() {
72         return registers.length > 2 ? registers[2] : 0;
73     }
74 
getF()75     public int getF() {
76         return registers.length > 3 ? registers[3] : 0;
77     }
78 
getG()79     public int getG() {
80         return registers.length > 4 ? registers[4] : 0;
81     }
82 
83     @Override
getProtoIndex()84     public short getProtoIndex() {
85         return (short) protoIndex;
86     }
87 }
88