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 llvm::ArrayRef<OptionDefinition> OptionGroupArchitecture::GetDefinitions() { 32 return llvm::makeArrayRef(g_option_table); 33 } 34 35 bool OptionGroupArchitecture::GetArchitecture(Platform *platform, 36 ArchSpec &arch) { 37 if (m_arch_str.empty()) 38 arch.Clear(); 39 else 40 arch.SetTriple(m_arch_str.c_str(), platform); 41 return arch.IsValid(); 42 } 43 44 Error OptionGroupArchitecture::SetOptionValue( 45 uint32_t option_idx, llvm::StringRef option_arg, 46 ExecutionContext *execution_context) { 47 Error error; 48 const int short_option = g_option_table[option_idx].short_option; 49 50 switch (short_option) { 51 case 'a': 52 m_arch_str.assign(option_arg); 53 break; 54 55 default: 56 error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); 57 break; 58 } 59 60 return error; 61 } 62 63 void OptionGroupArchitecture::OptionParsingStarting( 64 ExecutionContext *execution_context) { 65 m_arch_str.clear(); 66 } 67