Home | History | Annotate | Download | only in code
      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.dx.dex.code;
     18 
     19 import com.android.dx.rop.code.RegisterSpecList;
     20 import com.android.dx.rop.code.SourcePosition;
     21 import com.android.dx.util.AnnotatedOutput;
     22 
     23 /**
     24  * Pseudo-instruction base class for zero-size (no code emitted)
     25  * instructions, which are generally used for tracking metainformation
     26  * about the code they are adjacent to.
     27  */
     28 public abstract class ZeroSizeInsn extends DalvInsn {
     29     /**
     30      * Constructs an instance. The output address of this instance is initially
     31      * unknown ({@code -1}).
     32      *
     33      * @param position {@code non-null;} source position
     34      */
     35     public ZeroSizeInsn(SourcePosition position) {
     36         super(Dops.SPECIAL_FORMAT, position, RegisterSpecList.EMPTY);
     37     }
     38 
     39     /** {@inheritDoc} */
     40     @Override
     41     public final int codeSize() {
     42         return 0;
     43     }
     44 
     45     /** {@inheritDoc} */
     46     @Override
     47     public final void writeTo(AnnotatedOutput out) {
     48         // Nothing to do here, for this class.
     49     }
     50 
     51     /** {@inheritDoc} */
     52     @Override
     53     public final DalvInsn withOpcode(Dop opcode) {
     54         throw new RuntimeException("unsupported");
     55     }
     56 
     57     /** {@inheritDoc} */
     58     @Override
     59     public DalvInsn withRegisterOffset(int delta) {
     60         return withRegisters(getRegisters().withOffset(delta));
     61     }
     62 }
     63