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 23x}. See the instruction format spec 27 * for details. 28 */ 29public final class Form23x extends InsnFormat { 30 /** {@code non-null;} unique instance of this class */ 31 public static final InsnFormat THE_ONE = new Form23x(); 32 33 /** 34 * Constructs an instance. This class is not publicly 35 * instantiable. Use {@link #THE_ONE}. 36 */ 37 private Form23x() { 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() + ", " + regs.get(1).regString() + 46 ", " + regs.get(2).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 2; 60 } 61 62 /** {@inheritDoc} */ 63 @Override 64 public boolean isCompatible(DalvInsn insn) { 65 RegisterSpecList regs = insn.getRegisters(); 66 67 return (insn instanceof SimpleInsn) && 68 (regs.size() == 3) && 69 unsignedFitsInByte(regs.get(0).getReg()) && 70 unsignedFitsInByte(regs.get(1).getReg()) && 71 unsignedFitsInByte(regs.get(2).getReg()); 72 } 73 74 /** {@inheritDoc} */ 75 @Override 76 public InsnFormat nextUp() { 77 return Form32x.THE_ONE; 78 } 79 80 /** {@inheritDoc} */ 81 @Override 82 public void writeTo(AnnotatedOutput out, DalvInsn insn) { 83 RegisterSpecList regs = insn.getRegisters(); 84 write(out, 85 opcodeUnit(insn, regs.get(0).getReg()), 86 codeUnit(regs.get(1).getReg(), regs.get(2).getReg())); 87 } 88} 89