blob: eef5fa5c9b68ccd9b6f796f2431b823cb2f1d2f8 [file] [log] [blame]
Mads Ager418d1ca2017-05-22 09:35:49 +02001// 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.
4package com.android.tools.r8.code;
5
6import com.android.tools.r8.dex.Constants;
7import com.android.tools.r8.dex.IndexedItemCollection;
8import com.android.tools.r8.graph.ObjectToOffsetMapping;
9import com.android.tools.r8.naming.ClassNameMapper;
10import com.android.tools.r8.utils.StringUtils;
11import java.nio.ShortBuffer;
12
13public abstract class Format22s extends Base2Format {
14
Mads Ager88e4a922017-08-04 13:58:11 +020015 public final byte A;
16 public final byte B;
17 public final short CCCC;
Mads Ager418d1ca2017-05-22 09:35:49 +020018
19 // vB | vA | op | #+CCCC
20 /*package*/ Format22s(int high, BytecodeStream stream) {
21 super(stream);
Mads Ager88e4a922017-08-04 13:58:11 +020022 A = (byte) (high & 0xf);
23 B = (byte) ((high >> 4) & 0xf);
Mads Ager418d1ca2017-05-22 09:35:49 +020024 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 Ager88e4a922017-08-04 13:58:11 +020031 this.A = (byte) A;
32 this.B = (byte) B;
33 this.CCCC = (short) CCCC;
Mads Ager418d1ca2017-05-22 09:35:49 +020034 }
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}