blob: 74d0f8f4238d842e7a9a7314ed40e11b7362ed4f [file] [log] [blame]
Josh Gaobfb6bae2016-07-15 17:25:21 -07001/*
Elliott Hughesdfb74c52016-10-24 12:53:17 -07002 * Copyright (C) 2016 The Android Open Source Project
Josh Gaobfb6bae2016-07-15 17:25:21 -07003 *
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 *
Elliott Hughesdfb74c52016-10-24 12:53:17 -07008 * http://www.apache.org/licenses/LICENSE-2.0
Josh Gaobfb6bae2016-07-15 17:25:21 -07009 *
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 <stdlib.h>
20
21#include <array>
22#include <initializer_list>
Logan Chien9c123232018-10-23 10:47:17 +080023#include <optional>
Josh Gaobfb6bae2016-07-15 17:25:21 -070024#include <set>
25#include <string>
Logan Chien9c123232018-10-23 10:47:17 +080026#include <unordered_map>
Josh Gaobfb6bae2016-07-15 17:25:21 -070027
28enum class Arch : size_t {
29 arm = 0,
30 arm64,
Josh Gaobfb6bae2016-07-15 17:25:21 -070031 x86,
32 x86_64,
33};
34
35std::string to_string(const Arch& arch);
Logan Chien9c123232018-10-23 10:47:17 +080036std::optional<Arch> arch_from_string(const std::string& name);
Josh Gaobfb6bae2016-07-15 17:25:21 -070037
38template <typename T>
39class ArchMapIterator;
40
41template <typename T>
42class ArchMap {
43 public:
44 ArchMap() {
45 }
46
47 ArchMap(std::initializer_list<std::pair<Arch, T>> initializer) {
48 for (auto& pair : initializer) {
49 this->operator[](pair.first) = pair.second;
50 }
51 }
52
53 T& operator[](Arch arch) {
54 return data_[size_t(arch)];
55 }
56
57 const T& operator[](Arch arch) const {
58 return data_[size_t(arch)];
59 }
60
61 bool operator==(const ArchMap& other) const {
62 for (size_t i = 0; i < data_.size(); ++i) {
63 if (data_[i] != other.data_[i]) {
64 return false;
65 }
66 }
67 return true;
68 }
69
70 ArchMapIterator<T> begin() const {
71 return ArchMapIterator<T>(*this, Arch::arm);
72 }
73
74 ArchMapIterator<T> end() const {
75 return ArchMapIterator<T>(*this, Arch(size_t(Arch::x86_64) + 1));
76 }
77
78 private:
Josh Gao16057882016-08-02 14:54:09 -070079 std::array<T, size_t(Arch::x86_64) + 1> data_ = {};
Josh Gaobfb6bae2016-07-15 17:25:21 -070080};
81
82template <typename T>
83class ArchMapIterator {
84 const ArchMap<T>& map_;
85 Arch arch_ = Arch::arm;
86
87 public:
88 ArchMapIterator() = delete;
89
90 ArchMapIterator(const ArchMap<T>& map, Arch arch) : map_(map), arch_(arch) {
91 }
92
93 bool operator==(const ArchMapIterator<T>& rhs) const {
94 return map_ == rhs.map_ && arch_ == rhs.arch_;
95 }
96
97 bool operator!=(const ArchMapIterator<T>& rhs) const {
98 return !(*this == rhs);
99 }
100
101 ArchMapIterator& operator++() {
102 arch_ = Arch(size_t(arch_) + 1);
103 return *this;
104 }
105
106 ArchMapIterator operator++(int) {
107 ArchMapIterator result = *this;
108 ++*this;
109 return result;
110 }
111
112 std::pair<const Arch&, const T&> operator*() const {
113 return std::tie(arch_, map_[arch_]);
114 }
115
116 std::pair<const Arch&, const T&> operator->() const {
117 return std::tie(arch_, map_[arch_]);
118 }
119};
120
121static const std::set<Arch> supported_archs = {
122 Arch::arm,
123 Arch::arm64,
Josh Gaobfb6bae2016-07-15 17:25:21 -0700124 Arch::x86,
125 Arch::x86_64,
126};
127
128static ArchMap<std::string> arch_targets = {
129 { Arch::arm, "arm-linux-androideabi" },
130 { Arch::arm64, "aarch64-linux-android" },
Josh Gaobfb6bae2016-07-15 17:25:21 -0700131 { Arch::x86, "i686-linux-android" },
132 { Arch::x86_64, "x86_64-linux-android" },
133};
134
Logan Chien8fd8b992019-08-27 10:45:42 -0700135static const std::set<int> default_levels = {
136 14, 15, 16, 17, 18, 19, 21, 23, 24, 25, 26, 27, 28, 29, 30,
137};
Josh Gaobfb6bae2016-07-15 17:25:21 -0700138
139static const ArchMap<int> arch_min_api = {
140 { Arch::arm, 9 },
141 { Arch::arm64, 21 },
Josh Gaobfb6bae2016-07-15 17:25:21 -0700142 { Arch::x86, 9 },
143 { Arch::x86_64, 21 },
144};
Logan Chien9c123232018-10-23 10:47:17 +0800145
Logan Chien9c123232018-10-23 10:47:17 +0800146static const std::unordered_map<std::string, int> api_codename_map{
147 {"G", 9},
148 {"I", 14},
149 {"J", 16},
150 {"J-MR1", 17},
151 {"J-MR2", 18},
152 {"K", 19},
153 {"L", 21},
154 {"L-MR1", 22},
155 {"M", 23},
156 {"N", 24},
157 {"N-MR1", 25},
158 {"O", 26},
159 {"O-MR1", 27},
160 {"P", 28},
Elliott Hughes52700172019-03-14 13:34:21 -0700161 {"Q", 29},
Logan Chien8fd8b992019-08-27 10:45:42 -0700162 {"R", 30},
Logan Chien9c123232018-10-23 10:47:17 +0800163};