1 //===-- OptionGroupArchitecture.cpp -----------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/Interpreter/OptionGroupArchitecture.h"
11 
12 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project includes
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
20 OptionGroupArchitecture::OptionGroupArchitecture() : m_arch_str() {}
21 
22 OptionGroupArchitecture::~OptionGroupArchitecture() {}
23 
24 static OptionDefinition g_option_table[] = {
25     {LLDB_OPT_SET_1, false, "arch", 'a', OptionParser::eRequiredArgument,
26      nullptr, nullptr, 0, eArgTypeArchitecture,
27      "Specify the architecture for the target."},
28 };
29 
30 llvm::ArrayRef<OptionDefinition> OptionGroupArchitecture::GetDefinitions() {
31   return llvm::makeArrayRef(g_option_table);
32 }
33 
34 bool OptionGroupArchitecture::GetArchitecture(Platform *platform,
35                                               ArchSpec &arch) {
36   if (m_arch_str.empty())
37     arch.Clear();
38   else
39     arch.SetTriple(m_arch_str.c_str(), platform);
40   return arch.IsValid();
41 }
42 
43 Error OptionGroupArchitecture::SetOptionValue(
44     uint32_t option_idx, llvm::StringRef option_arg,
45     ExecutionContext *execution_context) {
46   Error error;
47   const int short_option = g_option_table[option_idx].short_option;
48 
49   switch (short_option) {
50   case 'a':
51     m_arch_str.assign(option_arg);
52     break;
53 
54   default:
55     error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
56     break;
57   }
58 
59   return error;
60 }
61 
62 void OptionGroupArchitecture::OptionParsingStarting(
63     ExecutionContext *execution_context) {
64   m_arch_str.clear();
65 }
66