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