Greg Clayton | abe0fed | 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 | a0f3469 | 2011-05-13 20:21:08 +0000 | [diff] [blame] | 10 | #include "lldb/Interpreter/OptionGroupArchitecture.h" |
Greg Clayton | abe0fed | 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 | 4003f57 | 2011-09-10 00:48:33 +0000 | [diff] [blame] | 16 | #include "lldb/Utility/Utils.h" |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
| 21 | OptionGroupArchitecture::OptionGroupArchitecture() : |
| 22 | m_arch_str () |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | OptionGroupArchitecture::~OptionGroupArchitecture () |
| 27 | { |
| 28 | } |
| 29 | |
Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 30 | static OptionDefinition |
| 31 | g_option_table[] = |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 32 | { |
Johnny Chen | 4003f57 | 2011-09-10 00:48:33 +0000 | [diff] [blame] | 33 | { LLDB_OPT_SET_1 , false, "arch" , 'a', required_argument, NULL, 0, eArgTypeArchitecture , "Specify the architecture for the target."}, |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 34 | }; |
Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 35 | |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 36 | uint32_t |
| 37 | OptionGroupArchitecture::GetNumDefinitions () |
| 38 | { |
Johnny Chen | 08af598 | 2012-05-15 23:21:36 +0000 | [diff] [blame] | 39 | return llvm::array_lengthof(g_option_table); |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | const OptionDefinition * |
| 43 | OptionGroupArchitecture::GetDefinitions () |
| 44 | { |
Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 45 | return g_option_table; |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | bool |
| 49 | OptionGroupArchitecture::GetArchitecture (Platform *platform, ArchSpec &arch) |
| 50 | { |
| 51 | if (m_arch_str.empty()) |
| 52 | arch.Clear(); |
| 53 | else |
| 54 | arch.SetTriple(m_arch_str.c_str(), platform); |
| 55 | return arch.IsValid(); |
| 56 | } |
| 57 | |
| 58 | |
| 59 | Error |
| 60 | OptionGroupArchitecture::SetOptionValue (CommandInterpreter &interpreter, |
| 61 | uint32_t option_idx, |
| 62 | const char *option_arg) |
| 63 | { |
| 64 | Error error; |
Greg Clayton | 6475c42 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 65 | const int short_option = g_option_table[option_idx].short_option; |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 66 | |
| 67 | switch (short_option) |
| 68 | { |
| 69 | case 'a': |
| 70 | m_arch_str.assign (option_arg); |
| 71 | break; |
| 72 | |
| 73 | default: |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 74 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 75 | break; |
| 76 | } |
| 77 | |
| 78 | return error; |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | OptionGroupArchitecture::OptionParsingStarting (CommandInterpreter &interpreter) |
| 83 | { |
| 84 | m_arch_str.clear(); |
| 85 | } |
| 86 | |