blob: 29a288d84582ac20fdef75cacd3f8b650b30d6eb [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)
David Srbeckyde91fd42018-07-05 22:27:08 +0100101 .Define("--strip")
102 .IntoKey(M::Strip)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700103 .Define("--oat-fd=_")
104 .WithType<int>()
105 .IntoKey(M::OatFd)
106 .Define("--oat-location=_")
107 .WithType<std::string>()
108 .IntoKey(M::OatLocation);
109}
110
111static void AddImageMappings(Builder& builder) {
112 builder.
113 Define("--image=_")
114 .WithType<std::vector<std::string>>().AppendValues()
115 .IntoKey(M::ImageFilenames)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700116 .Define("--base=_")
117 .WithType<std::string>()
118 .IntoKey(M::Base)
119 .Define("--app-image-file=_")
120 .WithType<std::string>()
121 .IntoKey(M::AppImageFile)
122 .Define("--app-image-fd=_")
123 .WithType<int>()
124 .IntoKey(M::AppImageFileFd)
125 .Define("--multi-image")
126 .IntoKey(M::MultiImage)
127 .Define("--dirty-image-objects=_")
128 .WithType<std::string>()
129 .IntoKey(M::DirtyImageObjects)
130 .Define("--image-format=_")
131 .WithType<ImageHeader::StorageMode>()
132 .WithValueMap({{"lz4", ImageHeader::kStorageModeLZ4},
133 {"lz4hc", ImageHeader::kStorageModeLZ4HC},
134 {"uncompressed", ImageHeader::kStorageModeUncompressed}})
135 .IntoKey(M::ImageFormat);
136}
137
138static void AddSwapMappings(Builder& builder) {
139 builder.
140 Define("--swap-file=_")
141 .WithType<std::string>()
142 .IntoKey(M::SwapFile)
143 .Define("--swap-fd=_")
144 .WithType<int>()
145 .IntoKey(M::SwapFileFd)
146 .Define("--swap-dex-size-threshold=_")
147 .WithType<unsigned int>()
148 .IntoKey(M::SwapDexSizeThreshold)
149 .Define("--swap-dex-count-threshold=_")
150 .WithType<unsigned int>()
151 .IntoKey(M::SwapDexCountThreshold);
152}
153
154static void AddCompilerMappings(Builder& builder) {
155 builder.
Andreas Gampebd600e32018-04-12 14:25:39 -0700156 Define("--run-passes=_")
Andreas Gampe097f34c2017-08-23 08:57:51 -0700157 .WithType<std::string>()
158 .IntoKey(M::Passes)
159 .Define("--profile-file=_")
160 .WithType<std::string>()
161 .IntoKey(M::Profile)
162 .Define("--profile-file-fd=_")
163 .WithType<int>()
164 .IntoKey(M::ProfileFd)
165 .Define("--no-inline-from=_")
166 .WithType<std::string>()
167 .IntoKey(M::NoInlineFrom);
168}
169
170static void AddTargetMappings(Builder& builder) {
171 builder.
172 Define("--instruction-set=_")
173 .WithType<InstructionSet>()
174 .IntoKey(M::TargetInstructionSet)
175 .Define("--instruction-set-variant=_")
176 .WithType<std::string>()
177 .IntoKey(M::TargetInstructionSetVariant)
178 .Define("--instruction-set-features=_")
179 .WithType<std::string>()
180 .IntoKey(M::TargetInstructionSetFeatures);
181}
182
183static Parser CreateArgumentParser() {
Yi Kongc57c6802018-10-29 14:28:56 -0700184 std::unique_ptr<Builder> parser_builder = std::make_unique<Builder>();
Andreas Gampe097f34c2017-08-23 08:57:51 -0700185
186 AddInputMappings(*parser_builder);
187 AddGeneratedArtifactMappings(*parser_builder);
188 AddImageMappings(*parser_builder);
189 AddSwapMappings(*parser_builder);
190 AddCompilerMappings(*parser_builder);
191 AddTargetMappings(*parser_builder);
192
193 parser_builder->
194 Define({"--watch-dog", "--no-watch-dog"})
195 .WithValues({true, false})
196 .IntoKey(M::Watchdog)
197 .Define("--watchdog-timeout=_")
198 .WithType<int>()
199 .IntoKey(M::WatchdogTimeout)
200 .Define("-j_")
201 .WithType<unsigned int>()
202 .IntoKey(M::Threads)
Orion Hodsonffc791c2019-11-14 19:19:28 +0000203 .Define("--cpu-set=_")
204 .WithType<std::vector<int32_t>>()
205 .IntoKey(M::CpuSet)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700206 .Define("--android-root=_")
207 .WithType<std::string>()
208 .IntoKey(M::AndroidRoot)
209 .Define("--compiler-backend=_")
210 .WithType<Compiler::Kind>()
211 .WithValueMap({{"Quick", Compiler::Kind::kQuick},
212 {"Optimizing", Compiler::Kind::kOptimizing}})
213 .IntoKey(M::Backend)
214 .Define("--host")
215 .IntoKey(M::Host)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700216 .Define("--avoid-storing-invocation")
217 .IntoKey(M::AvoidStoringInvocation)
218 .Define("--very-large-app-threshold=_")
219 .WithType<unsigned int>()
220 .IntoKey(M::VeryLargeAppThreshold)
221 .Define("--force-determinism")
222 .IntoKey(M::ForceDeterminism)
Mathieu Chartier792111c2018-02-15 13:02:15 -0800223 .Define("--copy-dex-files=_")
Andreas Gampe15544172018-06-25 15:09:06 -0700224 .WithType<linker::CopyOption>()
225 .WithValueMap({{"true", linker::CopyOption::kOnlyIfCompressed},
226 {"false", linker::CopyOption::kNever},
227 {"always", linker::CopyOption::kAlways}})
Mathieu Chartier792111c2018-02-15 13:02:15 -0800228 .IntoKey(M::CopyDexFiles)
Alex Light62afcf52018-12-18 14:19:25 -0800229 .Define("--write-invocation-to=_")
230 .WithType<std::string>()
231 .IntoKey(M::InvocationFile)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700232 .Define("--classpath-dir=_")
233 .WithType<std::string>()
234 .IntoKey(M::ClasspathDir)
235 .Define("--class-loader-context=_")
236 .WithType<std::string>()
237 .IntoKey(M::ClassLoaderContext)
David Brazdil89821862019-03-19 13:57:43 +0000238 .Define("--class-loader-context-fds=_")
239 .WithType<std::string>()
240 .IntoKey(M::ClassLoaderContextFds)
Mathieu Chartierf5abfc42018-03-23 21:51:54 -0700241 .Define("--stored-class-loader-context=_")
242 .WithType<std::string>()
243 .IntoKey(M::StoredClassLoaderContext)
Mathieu Chartiereafe2a52017-10-19 15:29:42 -0700244 .Define("--compact-dex-level=_")
245 .WithType<CompactDexLevel>()
246 .WithValueMap({{"none", CompactDexLevel::kCompactDexLevelNone},
247 {"fast", CompactDexLevel::kCompactDexLevelFast}})
248 .IntoKey(M::CompactDexLevel)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700249 .Define("--runtime-arg _")
250 .WithType<std::vector<std::string>>().AppendValues()
Calin Juravle0e09dfc2018-02-12 19:01:09 -0800251 .IntoKey(M::RuntimeOptions)
252 .Define("--compilation-reason=_")
253 .WithType<std::string>()
254 .IntoKey(M::CompilationReason);
Andreas Gampe097f34c2017-08-23 08:57:51 -0700255
256 AddCompilerOptionsArgumentParserOptions<Dex2oatArgumentMap>(*parser_builder);
257
258 parser_builder->IgnoreUnrecognized(false);
259
260 return parser_builder->Build();
261}
262
Andreas Gampe097f34c2017-08-23 08:57:51 -0700263std::unique_ptr<Dex2oatArgumentMap> Dex2oatArgumentMap::Parse(int argc,
264 const char** argv,
265 std::string* error_msg) {
266 Parser parser = CreateArgumentParser();
267 CmdlineResult parse_result = parser.Parse(argv, argc);
268 if (!parse_result.IsSuccess()) {
269 *error_msg = parse_result.GetMessage();
270 return nullptr;
271 }
272
Yi Kongc57c6802018-10-29 14:28:56 -0700273 return std::make_unique<Dex2oatArgumentMap>(parser.ReleaseArgumentsMap());
Andreas Gampe097f34c2017-08-23 08:57:51 -0700274}
275
Pirama Arumuga Nainarcc57c0c2018-01-18 16:30:22 -0800276#pragma GCC diagnostic pop
Andreas Gampe097f34c2017-08-23 08:57:51 -0700277} // namespace art