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.ir.code; 5 6 import com.android.tools.r8.errors.Unreachable; 7 import com.android.tools.r8.graph.DexItemFactory; 8 import com.android.tools.r8.graph.DexType; 9 10 public enum NumericType { 11 BYTE, 12 CHAR, 13 SHORT, 14 INT, 15 LONG, 16 FLOAT, 17 DOUBLE; 18 moveTypeFor()19 public MoveType moveTypeFor() { 20 if (this == NumericType.DOUBLE || this == NumericType.LONG) { 21 return MoveType.WIDE; 22 } 23 return MoveType.SINGLE; 24 } 25 dexTypeFor(DexItemFactory factory)26 public DexType dexTypeFor(DexItemFactory factory) { 27 switch (this) { 28 case BYTE: 29 return factory.byteType; 30 case CHAR: 31 return factory.charType; 32 case SHORT: 33 return factory.shortType; 34 case INT: 35 return factory.intType; 36 case LONG: 37 return factory.longType; 38 case FLOAT: 39 return factory.floatType; 40 case DOUBLE: 41 return factory.doubleType; 42 default: 43 throw new Unreachable("Invalid numeric type '" + this + "'"); 44 } 45 } 46 fromDexType(DexType type)47 public static NumericType fromDexType(DexType type) { 48 switch (type.descriptor.content[0]) { 49 case 'B': // byte 50 return NumericType.BYTE; 51 case 'S': // short 52 return NumericType.SHORT; 53 case 'C': // char 54 return NumericType.CHAR; 55 case 'I': // int 56 return NumericType.INT; 57 case 'F': // float 58 return NumericType.FLOAT; 59 case 'J': // long 60 return NumericType.LONG; 61 case 'D': // double 62 return NumericType.DOUBLE; 63 default: 64 return null; 65 } 66 } 67 } 68