Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1 | // Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | package com.android.tools.r8.code; |
| 5 | |
| 6 | import com.android.tools.r8.dex.Constants; |
| 7 | import com.android.tools.r8.dex.IndexedItemCollection; |
| 8 | import com.android.tools.r8.graph.ObjectToOffsetMapping; |
| 9 | import com.android.tools.r8.naming.ClassNameMapper; |
| 10 | import com.android.tools.r8.utils.StringUtils; |
| 11 | import java.nio.ShortBuffer; |
| 12 | |
| 13 | public abstract class Format22s extends Base2Format { |
| 14 | |
Mads Ager | 88e4a92 | 2017-08-04 13:58:11 +0200 | [diff] [blame] | 15 | public final byte A; |
| 16 | public final byte B; |
| 17 | public final short CCCC; |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 18 | |
| 19 | // vB | vA | op | #+CCCC |
| 20 | /*package*/ Format22s(int high, BytecodeStream stream) { |
| 21 | super(stream); |
Mads Ager | 88e4a92 | 2017-08-04 13:58:11 +0200 | [diff] [blame] | 22 | A = (byte) (high & 0xf); |
| 23 | B = (byte) ((high >> 4) & 0xf); |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 24 | CCCC = readSigned16BitValue(stream); |
| 25 | } |
| 26 | |
| 27 | /*package*/ Format22s(int A, int B, int CCCC) { |
| 28 | assert 0 <= A && A <= Constants.U4BIT_MAX; |
| 29 | assert 0 <= B && B <= Constants.U4BIT_MAX; |
| 30 | assert Short.MIN_VALUE <= CCCC && CCCC <= Short.MAX_VALUE; |
Mads Ager | 88e4a92 | 2017-08-04 13:58:11 +0200 | [diff] [blame] | 31 | this.A = (byte) A; |
| 32 | this.B = (byte) B; |
| 33 | this.CCCC = (short) CCCC; |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | public void write(ShortBuffer dest, ObjectToOffsetMapping mapping) { |
| 37 | writeFirst(B, A, dest); |
| 38 | write16BitValue(CCCC, dest); |
| 39 | } |
| 40 | |
| 41 | public final int hashCode() { |
| 42 | return ((CCCC << 8) | (A << 4) | B) ^ getClass().hashCode(); |
| 43 | } |
| 44 | |
| 45 | public final boolean equals(Object other) { |
| 46 | if (other == null || this.getClass() != other.getClass()) { |
| 47 | return false; |
| 48 | } |
| 49 | Format22s o = (Format22s) other; |
| 50 | return o.A == A && o.B == B && o.CCCC == CCCC; |
| 51 | } |
| 52 | |
| 53 | public String toString(ClassNameMapper naming) { |
| 54 | return formatString("v" + A + ", v" + B + ", #" + CCCC); |
| 55 | } |
| 56 | |
| 57 | public String toSmaliString(ClassNameMapper naming) { |
| 58 | return formatSmaliString( |
| 59 | "v" + A + ", v" + B + ", 0x" + StringUtils.hexString(CCCC, 4) + " # " + CCCC); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public void collectIndexedItems(IndexedItemCollection indexedItems) { |
| 64 | // No references. |
| 65 | } |
| 66 | } |