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.CstInsn; 20 import com.android.dx.dex.code.DalvInsn; 21 import com.android.dx.dex.code.InsnFormat; 22 import com.android.dx.rop.code.RegisterSpecList; 23 import com.android.dx.rop.cst.Constant; 24 import com.android.dx.rop.cst.CstLiteral64; 25 import com.android.dx.rop.cst.CstLiteralBits; 26 import com.android.dx.util.AnnotatedOutput; 27 import java.util.BitSet; 28 29 /** 30 * Instruction format {@code 51l}. See the instruction format spec 31 * for details. 32 */ 33 public final class Form51l extends InsnFormat { 34 /** {@code non-null;} unique instance of this class */ 35 public static final InsnFormat THE_ONE = new Form51l(); 36 37 /** 38 * Constructs an instance. This class is not publicly 39 * instantiable. Use {@link #THE_ONE}. 40 */ 41 private Form51l() { 42 // This space intentionally left blank. 43 } 44 45 /** {@inheritDoc} */ 46 @Override 47 public String insnArgString(DalvInsn insn) { 48 RegisterSpecList regs = insn.getRegisters(); 49 CstLiteralBits value = (CstLiteralBits) ((CstInsn) insn).getConstant(); 50 51 return regs.get(0).regString() + ", " + literalBitsString(value); 52 } 53 54 /** {@inheritDoc} */ 55 @Override 56 public String insnCommentString(DalvInsn insn, boolean noteIndices) { 57 CstLiteralBits value = (CstLiteralBits) ((CstInsn) insn).getConstant(); 58 return literalBitsComment(value, 64); 59 } 60 61 /** {@inheritDoc} */ 62 @Override 63 public int codeSize() { 64 return 5; 65 } 66 67 /** {@inheritDoc} */ 68 @Override 69 public boolean isCompatible(DalvInsn insn) { 70 RegisterSpecList regs = insn.getRegisters(); 71 if (!((insn instanceof CstInsn) && 72 (regs.size() == 1) && 73 unsignedFitsInByte(regs.get(0).getReg()))) { 74 return false; 75 } 76 77 CstInsn ci = (CstInsn) insn; 78 Constant cst = ci.getConstant(); 79 80 return (cst instanceof CstLiteral64); 81 } 82 83 /** {@inheritDoc} */ 84 @Override 85 public BitSet compatibleRegs(DalvInsn insn) { 86 RegisterSpecList regs = insn.getRegisters(); 87 BitSet bits = new BitSet(1); 88 89 bits.set(0, unsignedFitsInByte(regs.get(0).getReg())); 90 return bits; 91 } 92 93 /** {@inheritDoc} */ 94 @Override 95 public void writeTo(AnnotatedOutput out, DalvInsn insn) { 96 RegisterSpecList regs = insn.getRegisters(); 97 long value = 98 ((CstLiteral64) ((CstInsn) insn).getConstant()).getLongBits(); 99 100 write(out, opcodeUnit(insn, regs.get(0).getReg()), value); 101 } 102 } 103