Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 24 | namespace art { |
| 25 | |
| 26 | template<> |
| 27 | struct CmdlineType<InstructionSet> : CmdlineTypeParser<InstructionSet> { |
| 28 | Result Parse(const std::string& option) { |
| 29 | InstructionSet set = GetInstructionSetFromString(option.c_str()); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 30 | if (set == InstructionSet::kNone) { |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 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, ...) \ |
Igor Murashkin | 5573c37 | 2017-11-16 13:34:30 -0800 | [diff] [blame] | 46 | const Dex2oatArgumentMap::Key<Type> Dex2oatArgumentMap::Name {__VA_ARGS__}; |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 47 | #include "dex2oat_options.def" |
| 48 | |
| 49 | #pragma GCC diagnostic push |
| 50 | #pragma GCC diagnostic ignored "-Wframe-larger-than=" |
| 51 | |
| 52 | using M = Dex2oatArgumentMap; |
| 53 | using Parser = CmdlineParser<Dex2oatArgumentMap, Dex2oatArgumentMap::Key>; |
| 54 | using Builder = Parser::Builder; |
| 55 | |
| 56 | static 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 | |
| 75 | static 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 Geoffray | baeaa9b | 2018-01-26 14:31:17 +0000 | [diff] [blame] | 89 | .Define("--dm-fd=_") |
| 90 | .WithType<int>() |
| 91 | .IntoKey(M::DmFd) |
| 92 | .Define("--dm-file=_") |
| 93 | .WithType<std::string>() |
| 94 | .IntoKey(M::DmFile) |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 95 | .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 Srbecky | de91fd4 | 2018-07-05 22:27:08 +0100 | [diff] [blame] | 101 | .Define("--strip") |
| 102 | .IntoKey(M::Strip) |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 103 | .Define("--oat-fd=_") |
| 104 | .WithType<int>() |
| 105 | .IntoKey(M::OatFd) |
| 106 | .Define("--oat-location=_") |
| 107 | .WithType<std::string>() |
| 108 | .IntoKey(M::OatLocation); |
| 109 | } |
| 110 | |
| 111 | static void AddImageMappings(Builder& builder) { |
| 112 | builder. |
| 113 | Define("--image=_") |
| 114 | .WithType<std::vector<std::string>>().AppendValues() |
| 115 | .IntoKey(M::ImageFilenames) |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 116 | .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 | |
| 138 | static 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 | |
| 154 | static void AddCompilerMappings(Builder& builder) { |
| 155 | builder. |
Andreas Gampe | bd600e3 | 2018-04-12 14:25:39 -0700 | [diff] [blame] | 156 | Define("--run-passes=_") |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 157 | .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 | |
| 170 | static 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 | |
| 183 | static Parser CreateArgumentParser() { |
Yi Kong | c57c680 | 2018-10-29 14:28:56 -0700 | [diff] [blame] | 184 | std::unique_ptr<Builder> parser_builder = std::make_unique<Builder>(); |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 185 | |
| 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 Hodson | ffc791c | 2019-11-14 19:19:28 +0000 | [diff] [blame] | 203 | .Define("--cpu-set=_") |
| 204 | .WithType<std::vector<int32_t>>() |
| 205 | .IntoKey(M::CpuSet) |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 206 | .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 Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 216 | .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 Chartier | 792111c | 2018-02-15 13:02:15 -0800 | [diff] [blame] | 223 | .Define("--copy-dex-files=_") |
Andreas Gampe | 1554417 | 2018-06-25 15:09:06 -0700 | [diff] [blame] | 224 | .WithType<linker::CopyOption>() |
| 225 | .WithValueMap({{"true", linker::CopyOption::kOnlyIfCompressed}, |
| 226 | {"false", linker::CopyOption::kNever}, |
| 227 | {"always", linker::CopyOption::kAlways}}) |
Mathieu Chartier | 792111c | 2018-02-15 13:02:15 -0800 | [diff] [blame] | 228 | .IntoKey(M::CopyDexFiles) |
Alex Light | 62afcf5 | 2018-12-18 14:19:25 -0800 | [diff] [blame] | 229 | .Define("--write-invocation-to=_") |
| 230 | .WithType<std::string>() |
| 231 | .IntoKey(M::InvocationFile) |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 232 | .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 Brazdil | 8982186 | 2019-03-19 13:57:43 +0000 | [diff] [blame] | 238 | .Define("--class-loader-context-fds=_") |
| 239 | .WithType<std::string>() |
| 240 | .IntoKey(M::ClassLoaderContextFds) |
Mathieu Chartier | f5abfc4 | 2018-03-23 21:51:54 -0700 | [diff] [blame] | 241 | .Define("--stored-class-loader-context=_") |
| 242 | .WithType<std::string>() |
| 243 | .IntoKey(M::StoredClassLoaderContext) |
Mathieu Chartier | eafe2a5 | 2017-10-19 15:29:42 -0700 | [diff] [blame] | 244 | .Define("--compact-dex-level=_") |
| 245 | .WithType<CompactDexLevel>() |
| 246 | .WithValueMap({{"none", CompactDexLevel::kCompactDexLevelNone}, |
| 247 | {"fast", CompactDexLevel::kCompactDexLevelFast}}) |
| 248 | .IntoKey(M::CompactDexLevel) |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 249 | .Define("--runtime-arg _") |
| 250 | .WithType<std::vector<std::string>>().AppendValues() |
Calin Juravle | 0e09dfc | 2018-02-12 19:01:09 -0800 | [diff] [blame] | 251 | .IntoKey(M::RuntimeOptions) |
| 252 | .Define("--compilation-reason=_") |
| 253 | .WithType<std::string>() |
| 254 | .IntoKey(M::CompilationReason); |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 255 | |
| 256 | AddCompilerOptionsArgumentParserOptions<Dex2oatArgumentMap>(*parser_builder); |
| 257 | |
| 258 | parser_builder->IgnoreUnrecognized(false); |
| 259 | |
| 260 | return parser_builder->Build(); |
| 261 | } |
| 262 | |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 263 | std::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 Kong | c57c680 | 2018-10-29 14:28:56 -0700 | [diff] [blame] | 273 | return std::make_unique<Dex2oatArgumentMap>(parser.ReleaseArgumentsMap()); |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Pirama Arumuga Nainar | cc57c0c | 2018-01-18 16:30:22 -0800 | [diff] [blame] | 276 | #pragma GCC diagnostic pop |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 277 | } // namespace art |