• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 package com.android.tools.r8.ir.code;
6 
7 import com.android.tools.r8.errors.InternalCompilerError;
8 import com.android.tools.r8.errors.Unreachable;
9 import com.android.tools.r8.graph.DexType;
10 
11 public enum MoveType {
12   SINGLE,
13   WIDE,
14   OBJECT;
15 
requiredRegisters()16   public int requiredRegisters() {
17     return this == MoveType.WIDE ? 2 : 1;
18   }
19 
fromMemberType(MemberType type)20   public static MoveType fromMemberType(MemberType type) {
21     switch (type) {
22       case BOOLEAN:
23       case BYTE:
24       case CHAR:
25       case SHORT:
26       case SINGLE:
27         return MoveType.SINGLE;
28       case WIDE:
29         return MoveType.WIDE;
30       case OBJECT:
31         return MoveType.OBJECT;
32     }
33     assert false;
34     return null;
35   }
36 
fromTypeDescriptorChar(char descriptor)37   public static MoveType fromTypeDescriptorChar(char descriptor) {
38     switch (descriptor) {
39       case 'L':  // object
40       case '[':  // array
41         return MoveType.OBJECT;
42       case 'Z':  // boolean
43       case 'B':  // byte
44       case 'S':  // short
45       case 'C':  // char
46       case 'I':  // int
47       case 'F':  // float
48         return MoveType.SINGLE;
49       case 'J':  // long
50       case 'D':  // double
51         return MoveType.WIDE;
52       case 'V':
53         throw new InternalCompilerError("No move type for void type.");
54       default:
55         throw new Unreachable("Invalid descriptor char '" + descriptor + "'");
56     }
57   }
58 
fromDexType(DexType type)59   public static MoveType fromDexType(DexType type) {
60     return fromTypeDescriptorChar((char) type.descriptor.content[0]);
61   }
62 
fromConstType(ConstType type)63   public static MoveType fromConstType(ConstType type) {
64     switch (type) {
65       case INT:
66       case FLOAT:
67       case INT_OR_FLOAT:
68         return MoveType.SINGLE;
69       case OBJECT:
70         return MoveType.OBJECT;
71       case LONG:
72       case DOUBLE:
73       case LONG_OR_DOUBLE:
74         return MoveType.WIDE;
75       default:
76         throw new Unreachable("Invalid const type '" + type + "'");
77     }
78   }
79 
fromNumericType(NumericType type)80   public static MoveType fromNumericType(NumericType type) {
81     switch (type) {
82       case BYTE:
83       case CHAR:
84       case SHORT:
85       case INT:
86       case FLOAT:
87         return MoveType.SINGLE;
88       case LONG:
89       case DOUBLE:
90         return MoveType.WIDE;
91       default:
92         throw new Unreachable("Invalid numeric type '" + type + "'");
93     }
94   }
95 }
96