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   int api_level;
29   int file_offset_bits;
30 
31  private:
tieCompilationType32   auto tie() const {
33     return std::tie(arch, api_level, file_offset_bits);
34   }
35 
36  public:
37   bool operator<(const CompilationType& other) const {
38     return tie() < other.tie();
39   }
40 
41   bool operator==(const CompilationType& other) const {
42     return tie() == other.tie();
43   }
44 };
45 
46 namespace std {
47 template <>
48 struct hash<CompilationType> {
49   size_t operator()(CompilationType type) const {
50     struct {
51       int32_t arch : 3;
52       int32_t api_level : 6;
53       int32_t file_offset_bits : 1;
54       int32_t padding : 22;
55     } packed;
56     packed.arch = static_cast<int32_t>(type.arch);
57     packed.api_level = type.api_level;
58     packed.file_offset_bits = (type.file_offset_bits == 64);
59     packed.padding = 0;
60     int32_t value;
61     memcpy(&value, &packed, sizeof(value));
62     return std::hash<int32_t>()(value);
63   }
64 };
65 }
66 
67 std::string to_string(const CompilationType& type);
68