blob: 51245a851c575f5bb91d349a692369f65bb2ccf5 [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
Zachary Turner1f0f5b52016-09-22 20:22:55 +000031llvm::ArrayRef<OptionDefinition> OptionGroupArchitecture::GetDefinitions() {
Zachary Turner70602432016-09-22 21:06:13 +000032 return llvm::makeArrayRef(g_option_table);
Greg Clayton7260f622011-04-18 08:33:37 +000033}
34
Kate Stoneb9c1b512016-09-06 20:57:50 +000035bool 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();
Greg Clayton7260f622011-04-18 08:33:37 +000042}
43
Kate Stoneb9c1b512016-09-06 20:57:50 +000044Error OptionGroupArchitecture::SetOptionValue(
Zachary Turner8cef4b02016-09-23 17:48:13 +000045 uint32_t option_idx, llvm::StringRef option_arg,
Kate Stoneb9c1b512016-09-06 20:57:50 +000046 ExecutionContext *execution_context) {
47 Error error;
48 const int short_option = g_option_table[option_idx].short_option;
Greg Clayton7260f622011-04-18 08:33:37 +000049
Kate Stoneb9c1b512016-09-06 20:57:50 +000050 switch (short_option) {
51 case 'a':
52 m_arch_str.assign(option_arg);
53 break;
Greg Clayton7260f622011-04-18 08:33:37 +000054
Kate Stoneb9c1b512016-09-06 20:57:50 +000055 default:
56 error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
57 break;
58 }
Greg Clayton7260f622011-04-18 08:33:37 +000059
Kate Stoneb9c1b512016-09-06 20:57:50 +000060 return error;
Greg Clayton7260f622011-04-18 08:33:37 +000061}
62
Kate Stoneb9c1b512016-09-06 20:57:50 +000063void OptionGroupArchitecture::OptionParsingStarting(
64 ExecutionContext *execution_context) {
65 m_arch_str.clear();
Greg Clayton7260f622011-04-18 08:33:37 +000066}