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.DalvOps;
21import com.android.dx.dex.code.InsnFormat;
22import com.android.dx.util.AnnotatedOutput;
23
24/**
25 * Instruction format for nonstandard format instructions, which aren't
26 * generally real instructions but do end up appearing in instruction
27 * lists. Most of the overridden methods on this class end up throwing
28 * exceptions, as code should know (implicitly or explicitly) to avoid
29 * using this class. The one exception is {@link #isCompatible}, which
30 * always returns {@code true}.
31 */
32public final class SpecialFormat extends InsnFormat {
33    /** {@code non-null;} unique instance of this class */
34    public static final InsnFormat THE_ONE = new SpecialFormat();
35
36    /**
37     * Constructs an instance. This class is not publicly
38     * instantiable. Use {@link #THE_ONE}.
39     */
40    private SpecialFormat() {
41        // This space intentionally left blank.
42    }
43
44    /** {@inheritDoc} */
45    @Override
46    public String insnArgString(DalvInsn insn) {
47        throw new RuntimeException("unsupported");
48    }
49
50    /** {@inheritDoc} */
51    @Override
52    public String insnCommentString(DalvInsn insn, boolean noteIndices) {
53        throw new RuntimeException("unsupported");
54    }
55
56    /** {@inheritDoc} */
57    @Override
58    public int codeSize() {
59        throw new RuntimeException("unsupported");
60    }
61
62    /** {@inheritDoc} */
63    @Override
64    public boolean isCompatible(DalvInsn insn) {
65        return true;
66    }
67
68    /** {@inheritDoc} */
69    @Override
70    public InsnFormat nextUp() {
71        throw new RuntimeException("unsupported");
72    }
73
74    /** {@inheritDoc} */
75    @Override
76    public void writeTo(AnnotatedOutput out, DalvInsn insn) {
77        throw new RuntimeException("unsupported");
78    }
79}
80