Form10x.java revision 917cb222329ee8c035c3ffaf947e4265761b9367
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.dexgen.dex.code.form;
18
19import com.android.dexgen.dex.code.DalvInsn;
20import com.android.dexgen.dex.code.InsnFormat;
21import com.android.dexgen.dex.code.SimpleInsn;
22import com.android.dexgen.util.AnnotatedOutput;
23
24/**
25 * Instruction format {@code 10x}. See the instruction format spec
26 * for details.
27 */
28public final class Form10x extends InsnFormat {
29    /** {@code non-null;} unique instance of this class */
30    public static final InsnFormat THE_ONE = new Form10x();
31
32    /**
33     * Constructs an instance. This class is not publicly
34     * instantiable. Use {@link #THE_ONE}.
35     */
36    private Form10x() {
37        // This space intentionally left blank.
38    }
39
40    /** {@inheritDoc} */
41    @Override
42    public String insnArgString(DalvInsn insn) {
43        // This format has no arguments.
44        return "";
45    }
46
47    /** {@inheritDoc} */
48    @Override
49    public String insnCommentString(DalvInsn insn, boolean noteIndices) {
50        // This format has no comment.
51        return "";
52    }
53
54    /** {@inheritDoc} */
55    @Override
56    public int codeSize() {
57        return 1;
58    }
59
60    /** {@inheritDoc} */
61    @Override
62    public boolean isCompatible(DalvInsn insn) {
63        return (insn instanceof SimpleInsn) &&
64            (insn.getRegisters().size() == 0);
65    }
66
67    /** {@inheritDoc} */
68    @Override
69    public InsnFormat nextUp() {
70        return null;
71    }
72
73    /** {@inheritDoc} */
74    @Override
75    public void writeTo(AnnotatedOutput out, DalvInsn insn) {
76        write(out, opcodeUnit(insn, 0));
77    }
78}
79