llvm-project/lldb/source/Interpreter/OptionGroupArchitecture.cpp
Pavel Labath 7263f1bda6 Invert ArchSpec<->Platform dependency
Summary:
ArchSpec::SetTriple was taking a Platform as an argument, and used it to
fill in missing pieces of the specified triple. I invert the dependency
by moving this code to other classes. For this purpose, I've created
three new functions.
- HostInfo::GetAugmentedArchSpec: fills in the triple using the host
  platform (this used to be implemented by passing a null platform
  pointer). By putting this code in the Host module, we can provide a
  way to anyone who does not have a platform instance (lldb-server) an
  easy way to get Host data.
- Platform::GetAugmentedArchSpec: if you have a platform instance, you
  can call this to let it fill in the triple.
- static Platform::GetAugmentedArchSpec: implements the "if platform ==
  0 then use_host() else use_platform()" part.

Reviewers: zturner, jingham, clayborg

Subscribers: mgorny, javed.absar, lldb-commits

Differential Revision: https://reviews.llvm.org/D39387

llvm-svn: 316987
2017-10-31 10:56:03 +00:00

61 lines
1.8 KiB
C++

//===-- OptionGroupArchitecture.cpp -----------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/Interpreter/OptionGroupArchitecture.h"
#include "lldb/Host/OptionParser.h"
#include "lldb/Target/Platform.h"
using namespace lldb;
using namespace lldb_private;
OptionGroupArchitecture::OptionGroupArchitecture() : m_arch_str() {}
OptionGroupArchitecture::~OptionGroupArchitecture() {}
static OptionDefinition g_option_table[] = {
{LLDB_OPT_SET_1, false, "arch", 'a', OptionParser::eRequiredArgument,
nullptr, nullptr, 0, eArgTypeArchitecture,
"Specify the architecture for the target."},
};
llvm::ArrayRef<OptionDefinition> OptionGroupArchitecture::GetDefinitions() {
return llvm::makeArrayRef(g_option_table);
}
bool OptionGroupArchitecture::GetArchitecture(Platform *platform,
ArchSpec &arch) {
arch = Platform::GetAugmentedArchSpec(platform, m_arch_str);
return arch.IsValid();
}
Status
OptionGroupArchitecture::SetOptionValue(uint32_t option_idx,
llvm::StringRef option_arg,
ExecutionContext *execution_context) {
Status error;
const int short_option = g_option_table[option_idx].short_option;
switch (short_option) {
case 'a':
m_arch_str.assign(option_arg);
break;
default:
error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
break;
}
return error;
}
void OptionGroupArchitecture::OptionParsingStarting(
ExecutionContext *execution_context) {
m_arch_str.clear();
}