Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 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 | |
Johnny Chen | 4bee32e | 2011-05-13 20:21:08 +0000 | [diff] [blame] | 10 | #include "lldb/Interpreter/OptionGroupArchitecture.h" |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Johnny Chen | 7c575b3 | 2011-09-10 00:48:33 +0000 | [diff] [blame] | 16 | #include "lldb/Utility/Utils.h" |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 21 | OptionGroupArchitecture::OptionGroupArchitecture() : m_arch_str() {} |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 22 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | OptionGroupArchitecture::~OptionGroupArchitecture() {} |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 24 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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."}, |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 29 | }; |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 30 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 31 | uint32_t OptionGroupArchitecture::GetNumDefinitions() { |
| 32 | return llvm::array_lengthof(g_option_table); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 35 | const OptionDefinition *OptionGroupArchitecture::GetDefinitions() { |
| 36 | return g_option_table; |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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(); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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; |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 53 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | switch (short_option) { |
| 55 | case 'a': |
| 56 | m_arch_str.assign(option_arg); |
| 57 | break; |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 58 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 59 | default: |
| 60 | error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); |
| 61 | break; |
| 62 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 63 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | return error; |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 67 | void OptionGroupArchitecture::OptionParsingStarting( |
| 68 | ExecutionContext *execution_context) { |
| 69 | m_arch_str.clear(); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 70 | } |