blob: 3606c618d610d0b426c20bd9e63cb5963451111d [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#include "dex2oat_options.h"
18
19#include <memory>
20
21#include "cmdline_parser.h"
22#include "driver/compiler_options_map-inl.h"
23
24namespace art {
25
26template<>
27struct CmdlineType<InstructionSet> : CmdlineTypeParser<InstructionSet> {
28 Result Parse(const std::string& option) {
29 InstructionSet set = GetInstructionSetFromString(option.c_str());
30 if (set == kNone) {
31 return Result::Failure(std::string("Not a valid instruction set: '") + option + "'");
32 }
33 return Result::Success(set);
34 }
35
36 static const char* Name() { return "InstructionSet"; }
37};
38
39#define COMPILER_OPTIONS_MAP_TYPE Dex2oatArgumentMap
40#define COMPILER_OPTIONS_MAP_KEY_TYPE Dex2oatArgumentMapKey
41#include "driver/compiler_options_map-storage.h"
42
43// Specify storage for the Dex2oatOptions keys.
44
45#define DEX2OAT_OPTIONS_KEY(Type, Name, ...) \
46 const Dex2oatArgumentMap::Key<Type> Dex2oatArgumentMap::Name {__VA_ARGS__}; // NOLINT [readability/braces] [4]
47#include "dex2oat_options.def"
48
49#pragma GCC diagnostic push
50#pragma GCC diagnostic ignored "-Wframe-larger-than="
51
52using M = Dex2oatArgumentMap;
53using Parser = CmdlineParser<Dex2oatArgumentMap, Dex2oatArgumentMap::Key>;
54using Builder = Parser::Builder;
55
56static void AddInputMappings(Builder& builder) {
57 builder.
58 Define("--dex-file=_")
59 .WithType<std::vector<std::string>>().AppendValues()
60 .IntoKey(M::DexFiles)
61 .Define("--dex-location=_")
62 .WithType<std::vector<std::string>>().AppendValues()
63 .IntoKey(M::DexLocations)
64 .Define("--zip-fd=_")
65 .WithType<int>()
66 .IntoKey(M::ZipFd)
67 .Define("--zip-location=_")
68 .WithType<std::string>()
69 .IntoKey(M::ZipLocation)
70 .Define("--boot-image=_")
71 .WithType<std::string>()
72 .IntoKey(M::BootImage);
73}
74
75static void AddGeneratedArtifactMappings(Builder& builder) {
76 builder.
77 Define("--input-vdex-fd=_")
78 .WithType<int>()
79 .IntoKey(M::InputVdexFd)
80 .Define("--input-vdex=_")
81 .WithType<std::string>()
82 .IntoKey(M::InputVdex)
83 .Define("--output-vdex-fd=_")
84 .WithType<int>()
85 .IntoKey(M::OutputVdexFd)
86 .Define("--output-vdex=_")
87 .WithType<std::string>()
88 .IntoKey(M::OutputVdex)
89 .Define("--oat-file=_")
90 .WithType<std::vector<std::string>>().AppendValues()
91 .IntoKey(M::OatFiles)
92 .Define("--oat-symbols=_")
93 .WithType<std::vector<std::string>>().AppendValues()
94 .IntoKey(M::OatSymbols)
95 .Define("--oat-fd=_")
96 .WithType<int>()
97 .IntoKey(M::OatFd)
98 .Define("--oat-location=_")
99 .WithType<std::string>()
100 .IntoKey(M::OatLocation);
101}
102
103static void AddImageMappings(Builder& builder) {
104 builder.
105 Define("--image=_")
106 .WithType<std::vector<std::string>>().AppendValues()
107 .IntoKey(M::ImageFilenames)
108 .Define("--image-classes=_")
109 .WithType<std::string>()
110 .IntoKey(M::ImageClasses)
111 .Define("--image-classes-zip=_")
112 .WithType<std::string>()
113 .IntoKey(M::ImageClassesZip)
114 .Define("--base=_")
115 .WithType<std::string>()
116 .IntoKey(M::Base)
117 .Define("--app-image-file=_")
118 .WithType<std::string>()
119 .IntoKey(M::AppImageFile)
120 .Define("--app-image-fd=_")
121 .WithType<int>()
122 .IntoKey(M::AppImageFileFd)
123 .Define("--multi-image")
124 .IntoKey(M::MultiImage)
125 .Define("--dirty-image-objects=_")
126 .WithType<std::string>()
127 .IntoKey(M::DirtyImageObjects)
128 .Define("--image-format=_")
129 .WithType<ImageHeader::StorageMode>()
130 .WithValueMap({{"lz4", ImageHeader::kStorageModeLZ4},
131 {"lz4hc", ImageHeader::kStorageModeLZ4HC},
132 {"uncompressed", ImageHeader::kStorageModeUncompressed}})
133 .IntoKey(M::ImageFormat);
134}
135
136static void AddSwapMappings(Builder& builder) {
137 builder.
138 Define("--swap-file=_")
139 .WithType<std::string>()
140 .IntoKey(M::SwapFile)
141 .Define("--swap-fd=_")
142 .WithType<int>()
143 .IntoKey(M::SwapFileFd)
144 .Define("--swap-dex-size-threshold=_")
145 .WithType<unsigned int>()
146 .IntoKey(M::SwapDexSizeThreshold)
147 .Define("--swap-dex-count-threshold=_")
148 .WithType<unsigned int>()
149 .IntoKey(M::SwapDexCountThreshold);
150}
151
152static void AddCompilerMappings(Builder& builder) {
153 builder.
154 Define("--compiled-classes=_")
155 .WithType<std::string>()
156 .IntoKey(M::CompiledClasses)
157 .Define("--compiled-classes-zip=_")
158 .WithType<std::string>()
159 .IntoKey(M::CompiledClassesZip)
160 .Define("--compiled-methods=_")
161 .WithType<std::string>()
162 .IntoKey(M::CompiledMethods)
163 .Define("--compiled-methods-zip=_")
164 .WithType<std::string>()
165 .IntoKey(M::CompiledMethodsZip)
166 .Define("--run-passes=_")
167 .WithType<std::string>()
168 .IntoKey(M::Passes)
169 .Define("--profile-file=_")
170 .WithType<std::string>()
171 .IntoKey(M::Profile)
172 .Define("--profile-file-fd=_")
173 .WithType<int>()
174 .IntoKey(M::ProfileFd)
175 .Define("--no-inline-from=_")
176 .WithType<std::string>()
177 .IntoKey(M::NoInlineFrom);
178}
179
180static void AddTargetMappings(Builder& builder) {
181 builder.
182 Define("--instruction-set=_")
183 .WithType<InstructionSet>()
184 .IntoKey(M::TargetInstructionSet)
185 .Define("--instruction-set-variant=_")
186 .WithType<std::string>()
187 .IntoKey(M::TargetInstructionSetVariant)
188 .Define("--instruction-set-features=_")
189 .WithType<std::string>()
190 .IntoKey(M::TargetInstructionSetFeatures);
191}
192
193static Parser CreateArgumentParser() {
194 std::unique_ptr<Builder> parser_builder = std::unique_ptr<Builder>(new Builder());
195
196 AddInputMappings(*parser_builder);
197 AddGeneratedArtifactMappings(*parser_builder);
198 AddImageMappings(*parser_builder);
199 AddSwapMappings(*parser_builder);
200 AddCompilerMappings(*parser_builder);
201 AddTargetMappings(*parser_builder);
202
203 parser_builder->
204 Define({"--watch-dog", "--no-watch-dog"})
205 .WithValues({true, false})
206 .IntoKey(M::Watchdog)
207 .Define("--watchdog-timeout=_")
208 .WithType<int>()
209 .IntoKey(M::WatchdogTimeout)
210 .Define("-j_")
211 .WithType<unsigned int>()
212 .IntoKey(M::Threads)
213 .Define("--android-root=_")
214 .WithType<std::string>()
215 .IntoKey(M::AndroidRoot)
216 .Define("--compiler-backend=_")
217 .WithType<Compiler::Kind>()
218 .WithValueMap({{"Quick", Compiler::Kind::kQuick},
219 {"Optimizing", Compiler::Kind::kOptimizing}})
220 .IntoKey(M::Backend)
221 .Define("--host")
222 .IntoKey(M::Host)
223 .Define("--dump-timing")
224 .IntoKey(M::DumpTiming)
225 .Define("--dump-passes")
226 .IntoKey(M::DumpPasses)
227 .Define("--dump-stats")
228 .IntoKey(M::DumpStats)
229 .Define("--avoid-storing-invocation")
230 .IntoKey(M::AvoidStoringInvocation)
231 .Define("--very-large-app-threshold=_")
232 .WithType<unsigned int>()
233 .IntoKey(M::VeryLargeAppThreshold)
234 .Define("--force-determinism")
235 .IntoKey(M::ForceDeterminism)
236 .Define("--classpath-dir=_")
237 .WithType<std::string>()
238 .IntoKey(M::ClasspathDir)
239 .Define("--class-loader-context=_")
240 .WithType<std::string>()
241 .IntoKey(M::ClassLoaderContext)
Mathieu Chartiereafe2a52017-10-19 15:29:42 -0700242 .Define("--compact-dex-level=_")
243 .WithType<CompactDexLevel>()
244 .WithValueMap({{"none", CompactDexLevel::kCompactDexLevelNone},
245 {"fast", CompactDexLevel::kCompactDexLevelFast}})
246 .IntoKey(M::CompactDexLevel)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700247 .Define("--runtime-arg _")
248 .WithType<std::vector<std::string>>().AppendValues()
249 .IntoKey(M::RuntimeOptions);
250
251 AddCompilerOptionsArgumentParserOptions<Dex2oatArgumentMap>(*parser_builder);
252
253 parser_builder->IgnoreUnrecognized(false);
254
255 return parser_builder->Build();
256}
257
258#pragma GCC diagnostic pop
259
260std::unique_ptr<Dex2oatArgumentMap> Dex2oatArgumentMap::Parse(int argc,
261 const char** argv,
262 std::string* error_msg) {
263 Parser parser = CreateArgumentParser();
264 CmdlineResult parse_result = parser.Parse(argv, argc);
265 if (!parse_result.IsSuccess()) {
266 *error_msg = parse_result.GetMessage();
267 return nullptr;
268 }
269
270 return std::unique_ptr<Dex2oatArgumentMap>(new Dex2oatArgumentMap(parser.ReleaseArgumentsMap()));
271}
272
273} // namespace art