Home | History | Annotate | Download | only in optimizing
      1 /*
      2  * Copyright (C) 2017 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 #ifndef ART_COMPILER_OPTIMIZING_DATA_TYPE_INL_H_
     18 #define ART_COMPILER_OPTIMIZING_DATA_TYPE_INL_H_
     19 
     20 #include "data_type.h"
     21 #include "dex/primitive.h"
     22 
     23 namespace art {
     24 
     25 // Note: Not declared in data_type.h to avoid pulling in "primitive.h".
     26 constexpr DataType::Type DataTypeFromPrimitive(Primitive::Type type) {
     27   switch (type) {
     28     case Primitive::kPrimNot: return DataType::Type::kReference;
     29     case Primitive::kPrimBoolean: return DataType::Type::kBool;
     30     case Primitive::kPrimByte: return DataType::Type::kInt8;
     31     case Primitive::kPrimChar: return DataType::Type::kUint16;
     32     case Primitive::kPrimShort: return DataType::Type::kInt16;
     33     case Primitive::kPrimInt: return DataType::Type::kInt32;
     34     case Primitive::kPrimLong: return DataType::Type::kInt64;
     35     case Primitive::kPrimFloat: return DataType::Type::kFloat32;
     36     case Primitive::kPrimDouble: return DataType::Type::kFloat64;
     37     case Primitive::kPrimVoid: return DataType::Type::kVoid;
     38   }
     39   LOG(FATAL) << "Unreachable";
     40   UNREACHABLE();
     41 }
     42 
     43 constexpr DataType::Type DataType::FromShorty(char type) {
     44   return DataTypeFromPrimitive(Primitive::GetType(type));
     45 }
     46 
     47 constexpr char DataType::TypeId(DataType::Type type) {
     48   // Type id for visualizer.
     49   // Types corresponding to Java types are given a lower-case version of their shorty character.
     50   switch (type) {
     51     case DataType::Type::kBool: return 'z';       // Java boolean (Z).
     52     case DataType::Type::kUint8: return 'a';      // The character before Java byte's 'b'.
     53     case DataType::Type::kInt8: return 'b';       // Java byte (B).
     54     case DataType::Type::kUint16: return 'c';     // Java char (C).
     55     case DataType::Type::kInt16: return 's';      // Java short (S).
     56     case DataType::Type::kUint32: return 'u';     // Picked 'u' for unsigned.
     57     case DataType::Type::kInt32: return 'i';      // Java int (I).
     58     case DataType::Type::kUint64: return 'w';     // Picked 'w' for long unsigned.
     59     case DataType::Type::kInt64: return 'j';      // Java long (J).
     60     case DataType::Type::kFloat32: return 'f';    // Java float (F).
     61     case DataType::Type::kFloat64: return 'd';    // Java double (D).
     62     case DataType::Type::kReference: return 'l';  // Java reference (L).
     63     case DataType::Type::kVoid: return 'v';       // Java void (V).
     64   }
     65   LOG(FATAL) << "Unreachable";
     66   UNREACHABLE();
     67 }
     68 
     69 }  // namespace art
     70 
     71 #endif  // ART_COMPILER_OPTIMIZING_DATA_TYPE_INL_H_
     72