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 #include "lldb/Utility/Utils.h"
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 
21 OptionGroupArchitecture::OptionGroupArchitecture() : m_arch_str() {}
22 
23 OptionGroupArchitecture::~OptionGroupArchitecture() {}
24 
25 static OptionDefinition g_option_table[] = {
26     {LLDB_OPT_SET_1, false, "arch", 'a', OptionParser::eRequiredArgument,
27      nullptr, nullptr, 0, eArgTypeArchitecture,
28      "Specify the architecture for the target."},
29 };
30 
31 uint32_t OptionGroupArchitecture::GetNumDefinitions() {
32   return llvm::array_lengthof(g_option_table);
33 }
34 
35 const OptionDefinition *OptionGroupArchitecture::GetDefinitions() {
36   return g_option_table;
37 }
38 
39 bool OptionGroupArchitecture::GetArchitecture(Platform *platform,
40                                               ArchSpec &arch) {
41   if (m_arch_str.empty())
42     arch.Clear();
43   else
44     arch.SetTriple(m_arch_str.c_str(), platform);
45   return arch.IsValid();
46 }
47 
48 Error OptionGroupArchitecture::SetOptionValue(
49     uint32_t option_idx, const char *option_arg,
50     ExecutionContext *execution_context) {
51   Error error;
52   const int short_option = g_option_table[option_idx].short_option;
53 
54   switch (short_option) {
55   case 'a':
56     m_arch_str.assign(option_arg);
57     break;
58 
59   default:
60     error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
61     break;
62   }
63 
64   return error;
65 }
66 
67 void OptionGroupArchitecture::OptionParsingStarting(
68     ExecutionContext *execution_context) {
69   m_arch_str.clear();
70 }
71