1/*
2 * Copyright (C) 2007 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.dex.code.form;
18
19import com.android.dx.dex.code.DalvInsn;
20import com.android.dx.dex.code.InsnFormat;
21import com.android.dx.dex.code.TargetInsn;
22import com.android.dx.util.AnnotatedOutput;
23
24/**
25 * Instruction format {@code 30t}. See the instruction format spec
26 * for details.
27 */
28public final class Form30t extends InsnFormat {
29    /** {@code non-null;} unique instance of this class */
30    public static final InsnFormat THE_ONE = new Form30t();
31
32    /**
33     * Constructs an instance. This class is not publicly
34     * instantiable. Use {@link #THE_ONE}.
35     */
36    private Form30t() {
37        // This space intentionally left blank.
38    }
39
40    /** {@inheritDoc} */
41    @Override
42    public String insnArgString(DalvInsn insn) {
43        return branchString(insn);
44    }
45
46    /** {@inheritDoc} */
47    @Override
48    public String insnCommentString(DalvInsn insn, boolean noteIndices) {
49        return branchComment(insn);
50    }
51
52    /** {@inheritDoc} */
53    @Override
54    public int codeSize() {
55        return 3;
56    }
57
58    /** {@inheritDoc} */
59    @Override
60    public boolean isCompatible(DalvInsn insn) {
61        if (!((insn instanceof TargetInsn) &&
62              (insn.getRegisters().size() == 0))) {
63            return false;
64        }
65
66        return true;
67    }
68
69    /** {@inheritDoc} */
70    @Override
71    public boolean branchFits(TargetInsn insn) {
72        return true;
73    }
74
75    /** {@inheritDoc} */
76    @Override
77    public InsnFormat nextUp() {
78        return null;
79    }
80
81    /** {@inheritDoc} */
82    @Override
83    public void writeTo(AnnotatedOutput out, DalvInsn insn) {
84        int offset = ((TargetInsn) insn).getTargetOffset();
85
86        write(out, opcodeUnit(insn, 0),
87                (short) offset,
88                (short) (offset >> 16));
89    }
90}
91