Home | History | Annotate | Download | only in form
      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 
     17 package com.android.dexgen.dex.code.form;
     18 
     19 import com.android.dexgen.dex.code.DalvInsn;
     20 import com.android.dexgen.dex.code.DalvOps;
     21 import com.android.dexgen.dex.code.InsnFormat;
     22 import com.android.dexgen.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  */
     32 public 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