Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2016 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 #pragma once
     18 
     19 #include <stdint.h>
     20 
     21 #include <functional>
     22 #include <utility>
     23 
     24 #include "Arch.h"
     25 
     26 struct CompilationType {
     27   Arch arch;
     28   bool cpp;
     29   int api_level;
     30   int file_offset_bits;
     31 
     32  private:
     33   auto tie() const {
     34     return std::tie(arch, cpp, api_level, file_offset_bits);
     35   }
     36 
     37  public:
     38   bool operator<(const CompilationType& other) const {
     39     return tie() < other.tie();
     40   }
     41 
     42   bool operator==(const CompilationType& other) const {
     43     return tie() == other.tie();
     44   }
     45 };
     46 
     47 namespace std {
     48 template <>
     49 struct hash<CompilationType> {
     50   size_t operator()(CompilationType type) const {
     51     struct {
     52       int32_t arch : 3;
     53       int32_t cpp : 1;
     54       int32_t api_level : 6;
     55       int32_t file_offset_bits : 1;
     56       int32_t padding : 21;
     57     } packed;
     58     packed.arch = static_cast<int32_t>(type.arch);
     59     packed.cpp = type.cpp;
     60     packed.api_level = type.api_level;
     61     packed.file_offset_bits = (type.file_offset_bits == 64);
     62     packed.padding = 0;
     63     int32_t value;
     64     memcpy(&value, &packed, sizeof(value));
     65     return std::hash<int32_t>()(value);
     66   }
     67 };
     68 }
     69 
     70 std::string to_string(const CompilationType& type);
     71