1*0b57cec5SDimitry Andric //===-- OptionGroupArchitecture.cpp ---------------------------------------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric 
9*0b57cec5SDimitry Andric #include "lldb/Interpreter/OptionGroupArchitecture.h"
10*0b57cec5SDimitry Andric #include "lldb/Host/OptionParser.h"
11*0b57cec5SDimitry Andric #include "lldb/Target/Platform.h"
12*0b57cec5SDimitry Andric 
13*0b57cec5SDimitry Andric using namespace lldb;
14*0b57cec5SDimitry Andric using namespace lldb_private;
15*0b57cec5SDimitry Andric 
16*0b57cec5SDimitry Andric static constexpr OptionDefinition g_option_table[] = {
17*0b57cec5SDimitry Andric     {LLDB_OPT_SET_1, false, "arch", 'a', OptionParser::eRequiredArgument,
18*0b57cec5SDimitry Andric      nullptr, {}, 0, eArgTypeArchitecture,
19*0b57cec5SDimitry Andric      "Specify the architecture for the target."},
20*0b57cec5SDimitry Andric };
21*0b57cec5SDimitry Andric 
GetDefinitions()22*0b57cec5SDimitry Andric llvm::ArrayRef<OptionDefinition> OptionGroupArchitecture::GetDefinitions() {
23*0b57cec5SDimitry Andric   return llvm::ArrayRef(g_option_table);
24*0b57cec5SDimitry Andric }
25*0b57cec5SDimitry Andric 
GetArchitecture(Platform * platform,ArchSpec & arch)26*0b57cec5SDimitry Andric bool OptionGroupArchitecture::GetArchitecture(Platform *platform,
27*0b57cec5SDimitry Andric                                               ArchSpec &arch) {
28*0b57cec5SDimitry Andric   arch = Platform::GetAugmentedArchSpec(platform, m_arch_str);
29*0b57cec5SDimitry Andric   return arch.IsValid();
30*0b57cec5SDimitry Andric }
31*0b57cec5SDimitry Andric 
32*0b57cec5SDimitry Andric Status
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)33*0b57cec5SDimitry Andric OptionGroupArchitecture::SetOptionValue(uint32_t option_idx,
34*0b57cec5SDimitry Andric                                         llvm::StringRef option_arg,
35*0b57cec5SDimitry Andric                                         ExecutionContext *execution_context) {
36*0b57cec5SDimitry Andric   Status error;
37*0b57cec5SDimitry Andric   const int short_option = g_option_table[option_idx].short_option;
38*0b57cec5SDimitry Andric 
39*0b57cec5SDimitry Andric   switch (short_option) {
40*0b57cec5SDimitry Andric   case 'a':
41*0b57cec5SDimitry Andric     m_arch_str.assign(std::string(option_arg));
42*0b57cec5SDimitry Andric     break;
43*0b57cec5SDimitry Andric 
44*0b57cec5SDimitry Andric   default:
45*0b57cec5SDimitry Andric     llvm_unreachable("Unimplemented option");
46*0b57cec5SDimitry Andric   }
47*0b57cec5SDimitry Andric 
48*0b57cec5SDimitry Andric   return error;
49*0b57cec5SDimitry Andric }
50*0b57cec5SDimitry Andric 
OptionParsingStarting(ExecutionContext * execution_context)51*0b57cec5SDimitry Andric void OptionGroupArchitecture::OptionParsingStarting(
52*0b57cec5SDimitry Andric     ExecutionContext *execution_context) {
53*0b57cec5SDimitry Andric   m_arch_str.clear();
54*0b57cec5SDimitry Andric }
55*0b57cec5SDimitry Andric