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_DEX2OAT_DEX2OAT_OPTIONS_H_ 18 #define ART_DEX2OAT_DEX2OAT_OPTIONS_H_ 19 20 #include <cstdio> 21 #include <string> 22 #include <vector> 23 24 #include "arch/instruction_set.h" 25 #include "base/variant_map.h" 26 #include "cmdline_types.h" // TODO: don't need to include this file here 27 #include "compiler.h" 28 #include "driver/compiler_options_map.h" 29 #include "linker/oat_writer.h" 30 #include "oat/image.h" 31 32 namespace art { 33 34 template <typename TVariantMap, 35 template <typename TKeyValue> class TVariantMapKey> 36 struct CmdlineParser; 37 38 // Define a key that is usable with a Dex2oatArgumentMap. 39 // This key will *not* work with other subtypes of VariantMap. 40 template <typename TValue> 41 struct Dex2oatArgumentMapKey : VariantMapKey<TValue> { Dex2oatArgumentMapKeyDex2oatArgumentMapKey42 Dex2oatArgumentMapKey() {} Dex2oatArgumentMapKeyDex2oatArgumentMapKey43 explicit Dex2oatArgumentMapKey(TValue default_value) 44 : VariantMapKey<TValue>(std::move(default_value)) {} 45 // Don't ODR-use constexpr default values, which means that Struct::Fields 46 // that are declared 'static constexpr T Name = Value' don't need to have a matching definition. 47 }; 48 49 // Defines a type-safe heterogeneous key->value map. 50 // Use the VariantMap interface to look up or to store a Dex2oatArgumentMapKey,Value pair. 51 // 52 // Example: 53 // auto map = Dex2oatArgumentMap(); 54 // map.Set(Dex2oatArgumentMap::ZipFd, -1); 55 // int *target_utilization = map.Get(Dex2oatArgumentMap::ZipFd); 56 // 57 struct Dex2oatArgumentMap : CompilerOptionsMap<Dex2oatArgumentMap, Dex2oatArgumentMapKey> { 58 // This 'using' line is necessary to inherit the variadic constructor. 59 using CompilerOptionsMap<Dex2oatArgumentMap, Dex2oatArgumentMapKey>::CompilerOptionsMap; 60 61 static std::unique_ptr<Dex2oatArgumentMap> Parse(int argc, 62 const char** argv, 63 std::string* error_msg); 64 65 // Make the next many usages of Key slightly shorter to type. 66 template <typename TValue> 67 using Key = Dex2oatArgumentMapKey<TValue>; 68 69 // List of key declarations, shorthand for 'static const Key<T> Name' 70 #define DEX2OAT_OPTIONS_KEY(Type, Name, ...) static const Key<Type> (Name); 71 #include "dex2oat_options.def" 72 }; 73 74 CmdlineParser<Dex2oatArgumentMap, Dex2oatArgumentMap::Key> CreateDex2oatArgumentParser(); 75 76 extern template struct CompilerOptionsMap<Dex2oatArgumentMap, Dex2oatArgumentMapKey>; 77 78 } // namespace art 79 80 #endif // ART_DEX2OAT_DEX2OAT_OPTIONS_H_ 81