blob: dbb00c22e94606447345b6f54fdea2560b6de31e [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());
Vladimir Marko33bff252017-11-01 14:35:42 +000030 if (set == InstructionSet::kNone) {
Andreas Gampe097f34c2017-08-23 08:57:51 -070031 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, ...) \
Igor Murashkin5573c372017-11-16 13:34:30 -080046 const Dex2oatArgumentMap::Key<Type> Dex2oatArgumentMap::Name {__VA_ARGS__};
Andreas Gampe097f34c2017-08-23 08:57:51 -070047#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)
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +000089 .Define("--dm-fd=_")
90 .WithType<int>()
91 .IntoKey(M::DmFd)
92 .Define("--dm-file=_")
93 .WithType<std::string>()
94 .IntoKey(M::DmFile)
Andreas Gampe097f34c2017-08-23 08:57:51 -070095 .Define("--oat-file=_")
96 .WithType<std::vector<std::string>>().AppendValues()
97 .IntoKey(M::OatFiles)
98 .Define("--oat-symbols=_")
99 .WithType<std::vector<std::string>>().AppendValues()
100 .IntoKey(M::OatSymbols)
101 .Define("--oat-fd=_")
102 .WithType<int>()
103 .IntoKey(M::OatFd)
104 .Define("--oat-location=_")
105 .WithType<std::string>()
106 .IntoKey(M::OatLocation);
107}
108
109static void AddImageMappings(Builder& builder) {
110 builder.
111 Define("--image=_")
112 .WithType<std::vector<std::string>>().AppendValues()
113 .IntoKey(M::ImageFilenames)
114 .Define("--image-classes=_")
115 .WithType<std::string>()
116 .IntoKey(M::ImageClasses)
117 .Define("--image-classes-zip=_")
118 .WithType<std::string>()
119 .IntoKey(M::ImageClassesZip)
120 .Define("--base=_")
121 .WithType<std::string>()
122 .IntoKey(M::Base)
123 .Define("--app-image-file=_")
124 .WithType<std::string>()
125 .IntoKey(M::AppImageFile)
126 .Define("--app-image-fd=_")
127 .WithType<int>()
128 .IntoKey(M::AppImageFileFd)
129 .Define("--multi-image")
130 .IntoKey(M::MultiImage)
131 .Define("--dirty-image-objects=_")
132 .WithType<std::string>()
133 .IntoKey(M::DirtyImageObjects)
134 .Define("--image-format=_")
135 .WithType<ImageHeader::StorageMode>()
136 .WithValueMap({{"lz4", ImageHeader::kStorageModeLZ4},
137 {"lz4hc", ImageHeader::kStorageModeLZ4HC},
138 {"uncompressed", ImageHeader::kStorageModeUncompressed}})
139 .IntoKey(M::ImageFormat);
140}
141
142static void AddSwapMappings(Builder& builder) {
143 builder.
144 Define("--swap-file=_")
145 .WithType<std::string>()
146 .IntoKey(M::SwapFile)
147 .Define("--swap-fd=_")
148 .WithType<int>()
149 .IntoKey(M::SwapFileFd)
150 .Define("--swap-dex-size-threshold=_")
151 .WithType<unsigned int>()
152 .IntoKey(M::SwapDexSizeThreshold)
153 .Define("--swap-dex-count-threshold=_")
154 .WithType<unsigned int>()
155 .IntoKey(M::SwapDexCountThreshold);
156}
157
158static void AddCompilerMappings(Builder& builder) {
159 builder.
Andreas Gampebd600e32018-04-12 14:25:39 -0700160 Define("--run-passes=_")
Andreas Gampe097f34c2017-08-23 08:57:51 -0700161 .WithType<std::string>()
162 .IntoKey(M::Passes)
163 .Define("--profile-file=_")
164 .WithType<std::string>()
165 .IntoKey(M::Profile)
166 .Define("--profile-file-fd=_")
167 .WithType<int>()
168 .IntoKey(M::ProfileFd)
169 .Define("--no-inline-from=_")
170 .WithType<std::string>()
171 .IntoKey(M::NoInlineFrom);
172}
173
174static void AddTargetMappings(Builder& builder) {
175 builder.
176 Define("--instruction-set=_")
177 .WithType<InstructionSet>()
178 .IntoKey(M::TargetInstructionSet)
179 .Define("--instruction-set-variant=_")
180 .WithType<std::string>()
181 .IntoKey(M::TargetInstructionSetVariant)
182 .Define("--instruction-set-features=_")
183 .WithType<std::string>()
184 .IntoKey(M::TargetInstructionSetFeatures);
185}
186
187static Parser CreateArgumentParser() {
188 std::unique_ptr<Builder> parser_builder = std::unique_ptr<Builder>(new Builder());
189
190 AddInputMappings(*parser_builder);
191 AddGeneratedArtifactMappings(*parser_builder);
192 AddImageMappings(*parser_builder);
193 AddSwapMappings(*parser_builder);
194 AddCompilerMappings(*parser_builder);
195 AddTargetMappings(*parser_builder);
196
197 parser_builder->
198 Define({"--watch-dog", "--no-watch-dog"})
199 .WithValues({true, false})
200 .IntoKey(M::Watchdog)
201 .Define("--watchdog-timeout=_")
202 .WithType<int>()
203 .IntoKey(M::WatchdogTimeout)
204 .Define("-j_")
205 .WithType<unsigned int>()
206 .IntoKey(M::Threads)
207 .Define("--android-root=_")
208 .WithType<std::string>()
209 .IntoKey(M::AndroidRoot)
210 .Define("--compiler-backend=_")
211 .WithType<Compiler::Kind>()
212 .WithValueMap({{"Quick", Compiler::Kind::kQuick},
213 {"Optimizing", Compiler::Kind::kOptimizing}})
214 .IntoKey(M::Backend)
215 .Define("--host")
216 .IntoKey(M::Host)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700217 .Define("--avoid-storing-invocation")
218 .IntoKey(M::AvoidStoringInvocation)
219 .Define("--very-large-app-threshold=_")
220 .WithType<unsigned int>()
221 .IntoKey(M::VeryLargeAppThreshold)
222 .Define("--force-determinism")
223 .IntoKey(M::ForceDeterminism)
Mathieu Chartier792111c2018-02-15 13:02:15 -0800224 .Define("--copy-dex-files=_")
Nicolas Geoffray66ff8a82018-02-28 13:27:55 +0000225 .WithType<CopyOption>()
226 .WithValueMap({{"true", CopyOption::kOnlyIfCompressed},
227 {"false", CopyOption::kNever},
228 {"always", CopyOption::kAlways}})
Mathieu Chartier792111c2018-02-15 13:02:15 -0800229 .IntoKey(M::CopyDexFiles)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700230 .Define("--classpath-dir=_")
231 .WithType<std::string>()
232 .IntoKey(M::ClasspathDir)
233 .Define("--class-loader-context=_")
234 .WithType<std::string>()
235 .IntoKey(M::ClassLoaderContext)
Mathieu Chartierf5abfc42018-03-23 21:51:54 -0700236 .Define("--stored-class-loader-context=_")
237 .WithType<std::string>()
238 .IntoKey(M::StoredClassLoaderContext)
Mathieu Chartiereafe2a52017-10-19 15:29:42 -0700239 .Define("--compact-dex-level=_")
240 .WithType<CompactDexLevel>()
241 .WithValueMap({{"none", CompactDexLevel::kCompactDexLevelNone},
242 {"fast", CompactDexLevel::kCompactDexLevelFast}})
243 .IntoKey(M::CompactDexLevel)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700244 .Define("--runtime-arg _")
245 .WithType<std::vector<std::string>>().AppendValues()
Calin Juravle0e09dfc2018-02-12 19:01:09 -0800246 .IntoKey(M::RuntimeOptions)
247 .Define("--compilation-reason=_")
248 .WithType<std::string>()
249 .IntoKey(M::CompilationReason);
Andreas Gampe097f34c2017-08-23 08:57:51 -0700250
251 AddCompilerOptionsArgumentParserOptions<Dex2oatArgumentMap>(*parser_builder);
252
253 parser_builder->IgnoreUnrecognized(false);
254
255 return parser_builder->Build();
256}
257
Andreas Gampe097f34c2017-08-23 08:57:51 -0700258std::unique_ptr<Dex2oatArgumentMap> Dex2oatArgumentMap::Parse(int argc,
259 const char** argv,
260 std::string* error_msg) {
261 Parser parser = CreateArgumentParser();
262 CmdlineResult parse_result = parser.Parse(argv, argc);
263 if (!parse_result.IsSuccess()) {
264 *error_msg = parse_result.GetMessage();
265 return nullptr;
266 }
267
268 return std::unique_ptr<Dex2oatArgumentMap>(new Dex2oatArgumentMap(parser.ReleaseArgumentsMap()));
269}
270
Pirama Arumuga Nainarcc57c0c2018-01-18 16:30:22 -0800271#pragma GCC diagnostic pop
Andreas Gampe097f34c2017-08-23 08:57:51 -0700272} // namespace art