blob: 2de0dd2493f0934d2cc42fd49aef50957285897d [file] [log] [blame]
Greg Clayton7260f622011-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 Chen4bee32e2011-05-13 20:21:08 +000010#include "lldb/Interpreter/OptionGroupArchitecture.h"
Greg Clayton7260f622011-04-18 08:33:37 +000011
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Johnny Chen7c575b32011-09-10 00:48:33 +000016#include "lldb/Utility/Utils.h"
Greg Clayton7260f622011-04-18 08:33:37 +000017
18using namespace lldb;
19using namespace lldb_private;
20
Kate Stoneb9c1b512016-09-06 20:57:50 +000021OptionGroupArchitecture::OptionGroupArchitecture() : m_arch_str() {}
Greg Clayton7260f622011-04-18 08:33:37 +000022
Kate Stoneb9c1b512016-09-06 20:57:50 +000023OptionGroupArchitecture::~OptionGroupArchitecture() {}
Greg Clayton7260f622011-04-18 08:33:37 +000024
Kate Stoneb9c1b512016-09-06 20:57:50 +000025static 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 Clayton7260f622011-04-18 08:33:37 +000029};
Greg Clayton84c39662011-04-27 22:04:39 +000030
Kate Stoneb9c1b512016-09-06 20:57:50 +000031uint32_t OptionGroupArchitecture::GetNumDefinitions() {
32 return llvm::array_lengthof(g_option_table);
Greg Clayton7260f622011-04-18 08:33:37 +000033}
34
Kate Stoneb9c1b512016-09-06 20:57:50 +000035const OptionDefinition *OptionGroupArchitecture::GetDefinitions() {
36 return g_option_table;
Greg Clayton7260f622011-04-18 08:33:37 +000037}
38
Kate Stoneb9c1b512016-09-06 20:57:50 +000039bool 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 Clayton7260f622011-04-18 08:33:37 +000046}
47
Kate Stoneb9c1b512016-09-06 20:57:50 +000048Error 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 Clayton7260f622011-04-18 08:33:37 +000053
Kate Stoneb9c1b512016-09-06 20:57:50 +000054 switch (short_option) {
55 case 'a':
56 m_arch_str.assign(option_arg);
57 break;
Greg Clayton7260f622011-04-18 08:33:37 +000058
Kate Stoneb9c1b512016-09-06 20:57:50 +000059 default:
60 error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
61 break;
62 }
Greg Clayton7260f622011-04-18 08:33:37 +000063
Kate Stoneb9c1b512016-09-06 20:57:50 +000064 return error;
Greg Clayton7260f622011-04-18 08:33:37 +000065}
66
Kate Stoneb9c1b512016-09-06 20:57:50 +000067void OptionGroupArchitecture::OptionParsingStarting(
68 ExecutionContext *execution_context) {
69 m_arch_str.clear();
Greg Clayton7260f622011-04-18 08:33:37 +000070}