blob: af103bb0bd9d85f97d1b10cbc56c9311f187dc3b [file] [log] [blame]
Greg Claytonabe0fed2011-04-18 08:33:37 +00001//===-- 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 Chena0f34692011-05-13 20:21:08 +000010#include "lldb/Interpreter/OptionGroupArchitecture.h"
Greg Claytonabe0fed2011-04-18 08:33:37 +000011
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Johnny Chen4003f572011-09-10 00:48:33 +000016#include "lldb/Utility/Utils.h"
Greg Claytonabe0fed2011-04-18 08:33:37 +000017
18using namespace lldb;
19using namespace lldb_private;
20
21OptionGroupArchitecture::OptionGroupArchitecture() :
22 m_arch_str ()
23{
24}
25
26OptionGroupArchitecture::~OptionGroupArchitecture ()
27{
28}
29
Greg Clayton57b3c6b2011-04-27 22:04:39 +000030static OptionDefinition
31g_option_table[] =
Greg Claytonabe0fed2011-04-18 08:33:37 +000032{
Johnny Chen4003f572011-09-10 00:48:33 +000033 { LLDB_OPT_SET_1 , false, "arch" , 'a', required_argument, NULL, 0, eArgTypeArchitecture , "Specify the architecture for the target."},
Greg Claytonabe0fed2011-04-18 08:33:37 +000034};
Greg Clayton57b3c6b2011-04-27 22:04:39 +000035
Greg Claytonabe0fed2011-04-18 08:33:37 +000036uint32_t
37OptionGroupArchitecture::GetNumDefinitions ()
38{
Johnny Chen08af5982012-05-15 23:21:36 +000039 return llvm::array_lengthof(g_option_table);
Greg Claytonabe0fed2011-04-18 08:33:37 +000040}
41
42const OptionDefinition *
43OptionGroupArchitecture::GetDefinitions ()
44{
Greg Clayton57b3c6b2011-04-27 22:04:39 +000045 return g_option_table;
Greg Claytonabe0fed2011-04-18 08:33:37 +000046}
47
48bool
49OptionGroupArchitecture::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
59Error
60OptionGroupArchitecture::SetOptionValue (CommandInterpreter &interpreter,
61 uint32_t option_idx,
62 const char *option_arg)
63{
64 Error error;
Greg Clayton6475c422012-12-04 00:32:51 +000065 const int short_option = g_option_table[option_idx].short_option;
Greg Claytonabe0fed2011-04-18 08:33:37 +000066
67 switch (short_option)
68 {
69 case 'a':
70 m_arch_str.assign (option_arg);
71 break;
72
73 default:
Greg Clayton9c236732011-10-26 00:56:27 +000074 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
Greg Claytonabe0fed2011-04-18 08:33:37 +000075 break;
76 }
77
78 return error;
79}
80
81void
82OptionGroupArchitecture::OptionParsingStarting (CommandInterpreter &interpreter)
83{
84 m_arch_str.clear();
85}
86