blob: cb03fc6ceca1277974a4e34ed930d98e20b6741e [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)
203 .Define("--android-root=_")
204 .WithType<std::string>()
205 .IntoKey(M::AndroidRoot)
206 .Define("--compiler-backend=_")
207 .WithType<Compiler::Kind>()
208 .WithValueMap({{"Quick", Compiler::Kind::kQuick},
209 {"Optimizing", Compiler::Kind::kOptimizing}})
210 .IntoKey(M::Backend)
211 .Define("--host")
212 .IntoKey(M::Host)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700213 .Define("--avoid-storing-invocation")
214 .IntoKey(M::AvoidStoringInvocation)
215 .Define("--very-large-app-threshold=_")
216 .WithType<unsigned int>()
217 .IntoKey(M::VeryLargeAppThreshold)
218 .Define("--force-determinism")
219 .IntoKey(M::ForceDeterminism)
Mathieu Chartier792111c2018-02-15 13:02:15 -0800220 .Define("--copy-dex-files=_")
Andreas Gampe15544172018-06-25 15:09:06 -0700221 .WithType<linker::CopyOption>()
222 .WithValueMap({{"true", linker::CopyOption::kOnlyIfCompressed},
223 {"false", linker::CopyOption::kNever},
224 {"always", linker::CopyOption::kAlways}})
Mathieu Chartier792111c2018-02-15 13:02:15 -0800225 .IntoKey(M::CopyDexFiles)
Alex Light62afcf52018-12-18 14:19:25 -0800226 .Define("--write-invocation-to=_")
227 .WithType<std::string>()
228 .IntoKey(M::InvocationFile)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700229 .Define("--classpath-dir=_")
230 .WithType<std::string>()
231 .IntoKey(M::ClasspathDir)
232 .Define("--class-loader-context=_")
233 .WithType<std::string>()
234 .IntoKey(M::ClassLoaderContext)
David Brazdil89821862019-03-19 13:57:43 +0000235 .Define("--class-loader-context-fds=_")
236 .WithType<std::string>()
237 .IntoKey(M::ClassLoaderContextFds)
Mathieu Chartierf5abfc42018-03-23 21:51:54 -0700238 .Define("--stored-class-loader-context=_")
239 .WithType<std::string>()
240 .IntoKey(M::StoredClassLoaderContext)
Mathieu Chartiereafe2a52017-10-19 15:29:42 -0700241 .Define("--compact-dex-level=_")
242 .WithType<CompactDexLevel>()
243 .WithValueMap({{"none", CompactDexLevel::kCompactDexLevelNone},
244 {"fast", CompactDexLevel::kCompactDexLevelFast}})
245 .IntoKey(M::CompactDexLevel)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700246 .Define("--runtime-arg _")
247 .WithType<std::vector<std::string>>().AppendValues()
Calin Juravle0e09dfc2018-02-12 19:01:09 -0800248 .IntoKey(M::RuntimeOptions)
249 .Define("--compilation-reason=_")
250 .WithType<std::string>()
251 .IntoKey(M::CompilationReason);
Andreas Gampe097f34c2017-08-23 08:57:51 -0700252
253 AddCompilerOptionsArgumentParserOptions<Dex2oatArgumentMap>(*parser_builder);
254
255 parser_builder->IgnoreUnrecognized(false);
256
257 return parser_builder->Build();
258}
259
Andreas Gampe097f34c2017-08-23 08:57:51 -0700260std::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
Yi Kongc57c6802018-10-29 14:28:56 -0700270 return std::make_unique<Dex2oatArgumentMap>(parser.ReleaseArgumentsMap());
Andreas Gampe097f34c2017-08-23 08:57:51 -0700271}
272
Pirama Arumuga Nainarcc57c0c2018-01-18 16:30:22 -0800273#pragma GCC diagnostic pop
Andreas Gampe097f34c2017-08-23 08:57:51 -0700274} // namespace art