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