1/*
2 * Copyright (C) 2011 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
17package com.android.dx.io.instructions;
18
19/**
20 * A decoded Dalvik instruction which contains the payload for
21 * a {@code packed-switch} instruction.
22 */
23public final class FillArrayDataPayloadDecodedInstruction
24        extends DecodedInstruction {
25    /** data array */
26    private final Object data;
27
28    /** number of elements */
29    private final int size;
30
31    /** element width */
32    private final int elementWidth;
33
34    /**
35     * Constructs an instance. This private instance doesn't check the
36     * type of the data array.
37     */
38    private FillArrayDataPayloadDecodedInstruction(InstructionCodec format,
39            int opcode, Object data, int size, int elementWidth) {
40        super(format, opcode, 0, null, 0, 0L);
41
42        this.data = data;
43        this.size = size;
44        this.elementWidth = elementWidth;
45    }
46
47    /**
48     * Constructs an instance.
49     */
50    public FillArrayDataPayloadDecodedInstruction(InstructionCodec format,
51            int opcode, byte[] data) {
52        this(format, opcode, data, data.length, 1);
53    }
54
55    /**
56     * Constructs an instance.
57     */
58    public FillArrayDataPayloadDecodedInstruction(InstructionCodec format,
59            int opcode, short[] data) {
60        this(format, opcode, data, data.length, 2);
61    }
62
63    /**
64     * Constructs an instance.
65     */
66    public FillArrayDataPayloadDecodedInstruction(InstructionCodec format,
67            int opcode, int[] data) {
68        this(format, opcode, data, data.length, 4);
69    }
70
71    /**
72     * Constructs an instance.
73     */
74    public FillArrayDataPayloadDecodedInstruction(InstructionCodec format,
75            int opcode, long[] data) {
76        this(format, opcode, data, data.length, 8);
77    }
78
79    /** @inheritDoc */
80    public int getRegisterCount() {
81        return 0;
82    }
83
84    public short getElementWidthUnit() {
85        return (short) elementWidth;
86    }
87
88    public int getSize() {
89        return size;
90    }
91
92    public Object getData() {
93        return data;
94    }
95
96    /** @inheritDoc */
97    public DecodedInstruction withIndex(int newIndex) {
98        throw new UnsupportedOperationException("no index in instruction");
99    }
100}
101