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