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) |
| 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 Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 213 | .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 Chartier | 792111c | 2018-02-15 13:02:15 -0800 | [diff] [blame] | 220 | .Define("--copy-dex-files=_") |
Andreas Gampe | 1554417 | 2018-06-25 15:09:06 -0700 | [diff] [blame] | 221 | .WithType<linker::CopyOption>() |
| 222 | .WithValueMap({{"true", linker::CopyOption::kOnlyIfCompressed}, |
| 223 | {"false", linker::CopyOption::kNever}, |
| 224 | {"always", linker::CopyOption::kAlways}}) |
Mathieu Chartier | 792111c | 2018-02-15 13:02:15 -0800 | [diff] [blame] | 225 | .IntoKey(M::CopyDexFiles) |
Alex Light | 62afcf5 | 2018-12-18 14:19:25 -0800 | [diff] [blame] | 226 | .Define("--write-invocation-to=_") |
| 227 | .WithType<std::string>() |
| 228 | .IntoKey(M::InvocationFile) |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 229 | .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 Brazdil | 8982186 | 2019-03-19 13:57:43 +0000 | [diff] [blame] | 235 | .Define("--class-loader-context-fds=_") |
| 236 | .WithType<std::string>() |
| 237 | .IntoKey(M::ClassLoaderContextFds) |
Mathieu Chartier | f5abfc4 | 2018-03-23 21:51:54 -0700 | [diff] [blame] | 238 | .Define("--stored-class-loader-context=_") |
| 239 | .WithType<std::string>() |
| 240 | .IntoKey(M::StoredClassLoaderContext) |
Mathieu Chartier | eafe2a5 | 2017-10-19 15:29:42 -0700 | [diff] [blame] | 241 | .Define("--compact-dex-level=_") |
| 242 | .WithType<CompactDexLevel>() |
| 243 | .WithValueMap({{"none", CompactDexLevel::kCompactDexLevelNone}, |
| 244 | {"fast", CompactDexLevel::kCompactDexLevelFast}}) |
| 245 | .IntoKey(M::CompactDexLevel) |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 246 | .Define("--runtime-arg _") |
| 247 | .WithType<std::vector<std::string>>().AppendValues() |
Calin Juravle | 0e09dfc | 2018-02-12 19:01:09 -0800 | [diff] [blame] | 248 | .IntoKey(M::RuntimeOptions) |
| 249 | .Define("--compilation-reason=_") |
| 250 | .WithType<std::string>() |
| 251 | .IntoKey(M::CompilationReason); |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 252 | |
| 253 | AddCompilerOptionsArgumentParserOptions<Dex2oatArgumentMap>(*parser_builder); |
| 254 | |
| 255 | parser_builder->IgnoreUnrecognized(false); |
| 256 | |
| 257 | return parser_builder->Build(); |
| 258 | } |
| 259 | |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 260 | std::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 Kong | c57c680 | 2018-10-29 14:28:56 -0700 | [diff] [blame] | 270 | return std::make_unique<Dex2oatArgumentMap>(parser.ReleaseArgumentsMap()); |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Pirama Arumuga Nainar | cc57c0c | 2018-01-18 16:30:22 -0800 | [diff] [blame] | 273 | #pragma GCC diagnostic pop |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 274 | } // namespace art |