1097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe/*
2097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe * Copyright (C) 2017 The Android Open Source Project
3097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe *
4097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe * Licensed under the Apache License, Version 2.0 (the "License");
5097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe * you may not use this file except in compliance with the License.
6097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe * You may obtain a copy of the License at
7097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe *
8097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe *      http://www.apache.org/licenses/LICENSE-2.0
9097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe *
10097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe * Unless required by applicable law or agreed to in writing, software
11097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe * distributed under the License is distributed on an "AS IS" BASIS,
12097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe * See the License for the specific language governing permissions and
14097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe * limitations under the License.
15097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe */
16097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
17097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe#include "dex2oat_options.h"
18097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
19097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe#include <memory>
20097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
21097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe#include "cmdline_parser.h"
22097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe#include "driver/compiler_options_map-inl.h"
23097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
24097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampenamespace art {
25097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
26097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampetemplate<>
27097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampestruct CmdlineType<InstructionSet> : CmdlineTypeParser<InstructionSet> {
28097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  Result Parse(const std::string& option) {
29097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe    InstructionSet set = GetInstructionSetFromString(option.c_str());
3033bff25bcd7a02d35c54f63740eadb1a4833fc92Vladimir Marko    if (set == InstructionSet::kNone) {
31097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      return Result::Failure(std::string("Not a valid instruction set: '") + option + "'");
32097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe    }
33097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe    return Result::Success(set);
34097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  }
35097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
36097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  static const char* Name() { return "InstructionSet"; }
37097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe};
38097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
39097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe#define COMPILER_OPTIONS_MAP_TYPE Dex2oatArgumentMap
40097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe#define COMPILER_OPTIONS_MAP_KEY_TYPE Dex2oatArgumentMapKey
41097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe#include "driver/compiler_options_map-storage.h"
42097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
43097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe// Specify storage for the Dex2oatOptions keys.
44097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
45097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe#define DEX2OAT_OPTIONS_KEY(Type, Name, ...) \
465573c37e795668eca81a8488078f798d977685c3Igor Murashkin  const Dex2oatArgumentMap::Key<Type> Dex2oatArgumentMap::Name {__VA_ARGS__};
47097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe#include "dex2oat_options.def"
48097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
49097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe#pragma GCC diagnostic push
50097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe#pragma GCC diagnostic ignored "-Wframe-larger-than="
51097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
52097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampeusing M = Dex2oatArgumentMap;
53097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampeusing Parser = CmdlineParser<Dex2oatArgumentMap, Dex2oatArgumentMap::Key>;
54097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampeusing Builder = Parser::Builder;
55097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
56097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampestatic void AddInputMappings(Builder& builder) {
57097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  builder.
58097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      Define("--dex-file=_")
59097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::vector<std::string>>().AppendValues()
60097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::DexFiles)
61097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--dex-location=_")
62097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::vector<std::string>>().AppendValues()
63097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::DexLocations)
64097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--zip-fd=_")
65097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<int>()
66097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::ZipFd)
67097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--zip-location=_")
68097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
69097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::ZipLocation)
70097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--boot-image=_")
71097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
72097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::BootImage);
73097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe}
74097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
75097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampestatic void AddGeneratedArtifactMappings(Builder& builder) {
76097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  builder.
77097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      Define("--input-vdex-fd=_")
78097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<int>()
79097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::InputVdexFd)
80097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--input-vdex=_")
81097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
82097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::InputVdex)
83097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--output-vdex-fd=_")
84097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<int>()
85097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::OutputVdexFd)
86097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--output-vdex=_")
87097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
88097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::OutputVdex)
89baeaa9b4517cfb8876369ff33c2bb92ff9c79ef1Nicolas Geoffray      .Define("--dm-fd=_")
90baeaa9b4517cfb8876369ff33c2bb92ff9c79ef1Nicolas Geoffray          .WithType<int>()
91baeaa9b4517cfb8876369ff33c2bb92ff9c79ef1Nicolas Geoffray          .IntoKey(M::DmFd)
92baeaa9b4517cfb8876369ff33c2bb92ff9c79ef1Nicolas Geoffray      .Define("--dm-file=_")
93baeaa9b4517cfb8876369ff33c2bb92ff9c79ef1Nicolas Geoffray          .WithType<std::string>()
94baeaa9b4517cfb8876369ff33c2bb92ff9c79ef1Nicolas Geoffray          .IntoKey(M::DmFile)
95097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--oat-file=_")
96097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::vector<std::string>>().AppendValues()
97097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::OatFiles)
98097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--oat-symbols=_")
99097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::vector<std::string>>().AppendValues()
100097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::OatSymbols)
101097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--oat-fd=_")
102097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<int>()
103097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::OatFd)
104097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--oat-location=_")
105097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
106097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::OatLocation);
107097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe}
108097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
109097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampestatic void AddImageMappings(Builder& builder) {
110097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  builder.
111097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      Define("--image=_")
112097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::vector<std::string>>().AppendValues()
113097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::ImageFilenames)
114097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--image-classes=_")
115097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
116097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::ImageClasses)
117097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--image-classes-zip=_")
118097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
119097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::ImageClassesZip)
120097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--base=_")
121097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
122097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::Base)
123097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--app-image-file=_")
124097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
125097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::AppImageFile)
126097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--app-image-fd=_")
127097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<int>()
128097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::AppImageFileFd)
129097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--multi-image")
130097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::MultiImage)
131097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--dirty-image-objects=_")
132097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
133097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::DirtyImageObjects)
134097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--image-format=_")
135097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<ImageHeader::StorageMode>()
136097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithValueMap({{"lz4", ImageHeader::kStorageModeLZ4},
137097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe                         {"lz4hc", ImageHeader::kStorageModeLZ4HC},
138097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe                         {"uncompressed", ImageHeader::kStorageModeUncompressed}})
139097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::ImageFormat);
140097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe}
141097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
142097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampestatic void AddSwapMappings(Builder& builder) {
143097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  builder.
144097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      Define("--swap-file=_")
145097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
146097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::SwapFile)
147097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--swap-fd=_")
148097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<int>()
149097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::SwapFileFd)
150097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--swap-dex-size-threshold=_")
151097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<unsigned int>()
152097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::SwapDexSizeThreshold)
153097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--swap-dex-count-threshold=_")
154097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<unsigned int>()
155097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::SwapDexCountThreshold);
156097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe}
157097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
158097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampestatic void AddCompilerMappings(Builder& builder) {
159097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  builder.
160097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      Define("--compiled-classes=_")
161097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
162097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::CompiledClasses)
163097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--compiled-classes-zip=_")
164097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
165097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::CompiledClassesZip)
166097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--compiled-methods=_")
167097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
168097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::CompiledMethods)
169097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--compiled-methods-zip=_")
170097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
171097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::CompiledMethodsZip)
172097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--run-passes=_")
173097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
174097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::Passes)
175097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--profile-file=_")
176097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
177097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::Profile)
178097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--profile-file-fd=_")
179097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<int>()
180097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::ProfileFd)
181097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--no-inline-from=_")
182097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
183097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::NoInlineFrom);
184097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe}
185097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
186097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampestatic void AddTargetMappings(Builder& builder) {
187097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  builder.
188097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      Define("--instruction-set=_")
189097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<InstructionSet>()
190097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::TargetInstructionSet)
191097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--instruction-set-variant=_")
192097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
193097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::TargetInstructionSetVariant)
194097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--instruction-set-features=_")
195097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
196097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::TargetInstructionSetFeatures);
197097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe}
198097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
199097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampestatic Parser CreateArgumentParser() {
200097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  std::unique_ptr<Builder> parser_builder = std::unique_ptr<Builder>(new Builder());
201097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
202097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  AddInputMappings(*parser_builder);
203097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  AddGeneratedArtifactMappings(*parser_builder);
204097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  AddImageMappings(*parser_builder);
205097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  AddSwapMappings(*parser_builder);
206097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  AddCompilerMappings(*parser_builder);
207097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  AddTargetMappings(*parser_builder);
208097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
209097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  parser_builder->
210097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      Define({"--watch-dog", "--no-watch-dog"})
211097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithValues({true, false})
212097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::Watchdog)
213097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--watchdog-timeout=_")
214097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<int>()
215097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::WatchdogTimeout)
216097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("-j_")
217097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<unsigned int>()
218097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::Threads)
219097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--android-root=_")
220097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
221097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::AndroidRoot)
222097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--compiler-backend=_")
223097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<Compiler::Kind>()
224097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithValueMap({{"Quick", Compiler::Kind::kQuick},
225097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe                         {"Optimizing", Compiler::Kind::kOptimizing}})
226097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::Backend)
227097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--host")
228097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::Host)
229097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--avoid-storing-invocation")
230097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::AvoidStoringInvocation)
231097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--very-large-app-threshold=_")
232097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<unsigned int>()
233097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::VeryLargeAppThreshold)
234097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--force-determinism")
235097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::ForceDeterminism)
236792111ca6220a771adb95d5741c82f06116cba73Mathieu Chartier      .Define("--copy-dex-files=_")
23766ff8a8b82ff103d48d40e8dad01342c2d6f6d0dNicolas Geoffray          .WithType<CopyOption>()
23866ff8a8b82ff103d48d40e8dad01342c2d6f6d0dNicolas Geoffray          .WithValueMap({{"true", CopyOption::kOnlyIfCompressed},
23966ff8a8b82ff103d48d40e8dad01342c2d6f6d0dNicolas Geoffray                         {"false", CopyOption::kNever},
24066ff8a8b82ff103d48d40e8dad01342c2d6f6d0dNicolas Geoffray                         {"always", CopyOption::kAlways}})
241792111ca6220a771adb95d5741c82f06116cba73Mathieu Chartier          .IntoKey(M::CopyDexFiles)
242097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--classpath-dir=_")
243097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
244097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::ClasspathDir)
245097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--class-loader-context=_")
246097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::string>()
247097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .IntoKey(M::ClassLoaderContext)
2488548de1c9f403b917eb2ad74a9922127da61171dMathieu Chartier      .Define("--stored-class-loader-context=_")
2498548de1c9f403b917eb2ad74a9922127da61171dMathieu Chartier          .WithType<std::string>()
2508548de1c9f403b917eb2ad74a9922127da61171dMathieu Chartier          .IntoKey(M::StoredClassLoaderContext)
251eafe2a5a057c32eaf972cb09fe447cfbffae71caMathieu Chartier      .Define("--compact-dex-level=_")
252eafe2a5a057c32eaf972cb09fe447cfbffae71caMathieu Chartier          .WithType<CompactDexLevel>()
253eafe2a5a057c32eaf972cb09fe447cfbffae71caMathieu Chartier          .WithValueMap({{"none", CompactDexLevel::kCompactDexLevelNone},
254eafe2a5a057c32eaf972cb09fe447cfbffae71caMathieu Chartier                         {"fast", CompactDexLevel::kCompactDexLevelFast}})
255eafe2a5a057c32eaf972cb09fe447cfbffae71caMathieu Chartier          .IntoKey(M::CompactDexLevel)
256097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe      .Define("--runtime-arg _")
257097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe          .WithType<std::vector<std::string>>().AppendValues()
2580e09dfc9cbdd6c2510dbe50dba95cf9d2d815e79Calin Juravle          .IntoKey(M::RuntimeOptions)
2590e09dfc9cbdd6c2510dbe50dba95cf9d2d815e79Calin Juravle      .Define("--compilation-reason=_")
2600e09dfc9cbdd6c2510dbe50dba95cf9d2d815e79Calin Juravle          .WithType<std::string>()
2610e09dfc9cbdd6c2510dbe50dba95cf9d2d815e79Calin Juravle          .IntoKey(M::CompilationReason);
262097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
263097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  AddCompilerOptionsArgumentParserOptions<Dex2oatArgumentMap>(*parser_builder);
264097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
265097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  parser_builder->IgnoreUnrecognized(false);
266097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
267097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  return parser_builder->Build();
268097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe}
269097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
270097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampestd::unique_ptr<Dex2oatArgumentMap> Dex2oatArgumentMap::Parse(int argc,
271097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe                                                              const char** argv,
272097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe                                                              std::string* error_msg) {
273097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  Parser parser = CreateArgumentParser();
274097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  CmdlineResult parse_result = parser.Parse(argv, argc);
275097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  if (!parse_result.IsSuccess()) {
276097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe    *error_msg = parse_result.GetMessage();
277097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe    return nullptr;
278097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  }
279097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
280097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe  return std::unique_ptr<Dex2oatArgumentMap>(new Dex2oatArgumentMap(parser.ReleaseArgumentsMap()));
281097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe}
282097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe
283cc57c0cb24b1bba67dabf5af1d50ed3d47aab76bPirama Arumuga Nainar#pragma GCC diagnostic pop
284097f34cc09caf46945ec17e198f57ac9c156e904Andreas Gampe}  // namespace art
285