15#include "llvm/ADT/STLExtras.h"
16#include "llvm/BinaryFormat/COFF.h"
17#include "llvm/BinaryFormat/ELF.h"
18#include "llvm/BinaryFormat/MachO.h"
19#include "llvm/Support/Compiler.h"
20#include "llvm/TargetParser/ARMTargetParser.h"
26 bool try_inverse,
bool enforce_exact_match);
250 "make sure we have one core definition for each core");
277#define CPU_ANY (UINT32_MAX)
284#define SUBTYPE_MASK 0x00FFFFFFu
364 0xFFFFFFFFu, 0xFFFFFFFFu},
366 0xFFFFFFFFu, 0xFFFFFFFFu},
368 0xFFFFFFFFu, 0xFFFFFFFFu},
370 0xFFFFFFFFu, 0xFFFFFFFFu},
376 0xFFFFFFFFu, 0xFFFFFFFFu},
378 0xFFFFFFFFu, 0xFFFFFFFFu},
380 0xFFFFFFFFu, 0xFFFFFFFFu},
384 0xFFFFFFFFu, 0xFFFFFFFFu},
386 0xFFFFFFFFu, 0xFFFFFFFFu},
398 0xFFFFFFFFu, 0xFFFFFFFFu},
410 0xFFFFFFFFu, 0xFFFFFFFFu},
414 0xFFFFFFFFu, 0xFFFFFFFFu},
473 if (def->type == arch_type)
482 if (name.equals_insensitive(def.name))
502 if (entries[i].cpu == (cpu & entries[i].cpu_mask))
503 if (entries[i].sub == (sub & entries[i].sub_mask))
516 if (entries[i].core == core)
555 return core_def->
name;
587 if (elf_abi ==
"n64")
589 else if (elf_abi ==
"n32")
591 else if (elf_abi ==
"o32")
647 cpu = llvm::ARM::getARMCPUForArch(
GetTriple(),
"").str();
657 return arch_def->
cpu;
669 return arch_def->
sub;
688 return llvm::Triple::UnknownArch;
694 if (core_def->
machine == llvm::Triple::mips64 ||
695 core_def->
machine == llvm::Triple::mips64el) {
717 case llvm::Triple::aarch64:
718 case llvm::Triple::aarch64_32:
719 case llvm::Triple::aarch64_be:
720 case llvm::Triple::arm:
721 case llvm::Triple::armeb:
722 case llvm::Triple::thumb:
723 case llvm::Triple::thumbeb:
726 case llvm::Triple::ppc:
727 case llvm::Triple::ppc64:
730 case llvm::Triple::ppc64le:
731 case llvm::Triple::systemz:
732 case llvm::Triple::xcore:
733 case llvm::Triple::arc:
756 if (triple_str.empty())
759 size_t pos = triple_str.find_first_of(
"-.");
760 if (pos == llvm::StringRef::npos)
763 llvm::StringRef cpu_str = triple_str.substr(0, pos);
764 llvm::StringRef remainder = triple_str.substr(pos + 1);
765 if (cpu_str.empty() || remainder.empty())
768 llvm::StringRef sub_str;
769 llvm::StringRef vendor;
771 std::tie(sub_str, remainder) = remainder.split(
'-');
772 std::tie(vendor, os) = remainder.split(
'-');
776 if (cpu_str.getAsInteger(10, cpu) || sub_str.getAsInteger(10, sub))
781 if (!vendor.empty() && !os.empty()) {
790 if (triple.empty()) {
798 SetTriple(llvm::Triple(llvm::Triple::normalize(triple)));
803 return !normalized_triple.getArchName().empty() &&
804 normalized_triple.getOSName().empty() &&
805 normalized_triple.getVendorName().empty() &&
806 normalized_triple.getEnvironmentName().empty();
811 if ((
GetTriple().getOS() == llvm::Triple::MacOSX ||
812 GetTriple().getOS() == llvm::Triple::UnknownOS) &&
813 other.
GetTriple().getOS() == llvm::Triple::IOS &&
814 other.
GetTriple().getEnvironment() == llvm::Triple::MacABI) {
823 if (
GetTriple().getArch() == llvm::Triple::UnknownArch) {
839 if (
GetTriple().getArch() == llvm::Triple::arm &&
840 other.
GetTriple().getArch() == llvm::Triple::arm &&
852 uint32_t sub, uint32_t os) {
854 bool update_triple =
true;
859 if (arch_def_entry) {
863 update_triple =
false;
869 m_triple.setVendor(llvm::Triple::Apple);
881 case llvm::ELF::ELFOSABI_AIX:
882 m_triple.setOS(llvm::Triple::OSType::AIX);
884 case llvm::ELF::ELFOSABI_FREEBSD:
885 m_triple.setOS(llvm::Triple::OSType::FreeBSD);
887 case llvm::ELF::ELFOSABI_GNU:
888 m_triple.setOS(llvm::Triple::OSType::Linux);
890 case llvm::ELF::ELFOSABI_NETBSD:
891 m_triple.setOS(llvm::Triple::OSType::NetBSD);
893 case llvm::ELF::ELFOSABI_OPENBSD:
894 m_triple.setOS(llvm::Triple::OSType::OpenBSD);
896 case llvm::ELF::ELFOSABI_SOLARIS:
897 m_triple.setOS(llvm::Triple::OSType::Solaris);
899 case llvm::ELF::ELFOSABI_STANDALONE:
900 m_triple.setOS(llvm::Triple::OSType::UnknownOS);
903 }
else if (arch_type ==
eArchTypeCOFF && os == llvm::Triple::Win32) {
904 m_triple.setVendor(llvm::Triple::PC);
905 m_triple.setOS(llvm::Triple::Win32);
907 m_triple.setVendor(llvm::Triple::UnknownVendor);
908 m_triple.setOS(llvm::Triple::UnknownOS);
912 if (
m_triple.getArch() == llvm::Triple::UnknownArch)
918 "Unable to find a core definition for cpu 0x%" PRIx32
942 llvm::Triple::EnvironmentType rhs) {
949 if (lhs == llvm::Triple::Simulator || rhs == llvm::Triple::Simulator)
953 if (lhs == llvm::Triple::UnknownEnvironment ||
954 rhs == llvm::Triple::UnknownEnvironment)
961 if ((lhs == llvm::Triple::Android && rhs == llvm::Triple::EABI) ||
962 (rhs == llvm::Triple::Android && lhs == llvm::Triple::EABI) ||
963 (lhs == llvm::Triple::GNUEABI && rhs == llvm::Triple::EABI) ||
964 (rhs == llvm::Triple::GNUEABI && lhs == llvm::Triple::EABI) ||
965 (lhs == llvm::Triple::GNUEABIHF && rhs == llvm::Triple::EABIHF) ||
966 (rhs == llvm::Triple::GNUEABIHF && lhs == llvm::Triple::EABIHF))
977 const llvm::Triple &lhs_triple =
GetTriple();
978 const llvm::Triple &rhs_triple = rhs.
GetTriple();
980 const llvm::Triple::VendorType lhs_triple_vendor = lhs_triple.getVendor();
981 const llvm::Triple::VendorType rhs_triple_vendor = rhs_triple.getVendor();
983 const llvm::Triple::OSType lhs_triple_os = lhs_triple.getOS();
984 const llvm::Triple::OSType rhs_triple_os = rhs_triple.getOS();
986 bool both_windows = lhs_triple.isOSWindows() && rhs_triple.isOSWindows();
990 if ((lhs_triple_vendor != rhs_triple_vendor) &&
996 if (rhs_vendor_specified && lhs_vendor_specified)
1000 if (lhs_triple_vendor != llvm::Triple::UnknownVendor &&
1001 rhs_triple_vendor != llvm::Triple::UnknownVendor)
1005 const llvm::Triple::EnvironmentType lhs_triple_env =
1006 lhs_triple.getEnvironment();
1007 const llvm::Triple::EnvironmentType rhs_triple_env =
1008 rhs_triple.getEnvironment();
1012 if ((lhs_triple_os == llvm::Triple::IOS &&
1013 lhs_triple_env == llvm::Triple::MacABI &&
1014 rhs_triple_os == llvm::Triple::MacOSX) ||
1015 (lhs_triple_os == llvm::Triple::MacOSX &&
1016 rhs_triple_os == llvm::Triple::IOS &&
1017 rhs_triple_env == llvm::Triple::MacABI))
1022 if (lhs_triple_os == llvm::Triple::IOS &&
1023 rhs_triple_os == llvm::Triple::IOS &&
1024 (lhs_triple_env == llvm::Triple::MacABI ||
1025 rhs_triple_env == llvm::Triple::MacABI) &&
1026 lhs_triple_env != rhs_triple_env)
1029 if (lhs_triple_os != rhs_triple_os) {
1033 if (lhs_os_specified && rhs_os_specified)
1038 ((!lhs_os_specified && !lhs_triple.hasEnvironment()) ||
1039 (!rhs_os_specified && !rhs_triple.hasEnvironment())))
1050 llvm::StringRef arch_name(
m_triple.getArchName());
1070 m_triple = llvm::Triple(core_def->
name,
"unknown",
"unknown");
1083 bool try_inverse,
bool enforce_exact_match) {
1092 if (enforce_exact_match)
1145 if (!enforce_exact_match) {
1163 if (!enforce_exact_match) {
1181 if (!enforce_exact_match) {
1190 try_inverse =
false;
1199 if (!enforce_exact_match) {
1204 try_inverse =
false;
1209 if (!enforce_exact_match) {
1210 try_inverse =
false;
1217 if (!enforce_exact_match) {
1224 try_inverse =
false;
1229 if (!enforce_exact_match) {
1236 try_inverse =
false;
1240 if (!enforce_exact_match) {
1247 try_inverse =
false;
1252 if (!enforce_exact_match) {
1259 try_inverse =
false;
1264 if (!enforce_exact_match) {
1267 try_inverse =
false;
1272 if (!enforce_exact_match) {
1276 try_inverse =
false;
1281 if (!enforce_exact_match) {
1290 if (!enforce_exact_match) {
1297 try_inverse =
false;
1302 if (!enforce_exact_match) {
1309 try_inverse =
false;
1316 if (!enforce_exact_match) {
1321 try_inverse =
false;
1328 if (!enforce_exact_match) {
1333 try_inverse =
false;
1340 if (!enforce_exact_match) {
1349 if (!enforce_exact_match) {
1356 if (!enforce_exact_match) {
1363 if (!enforce_exact_match) {
1371 if (!enforce_exact_match) {
1380 if (!enforce_exact_match) {
1394 return cores_match(core2, core1,
false, enforce_exact_match);
1401 return lhs_core < rhs_core;
1416 const unsigned unspecified = 0;
1417 const llvm::Triple &triple =
GetTriple();
1418 if (triple.isOSDarwin() && triple.getOSMajorVersion() == unspecified)
1426 if (
GetTriple().getArch() == llvm::Triple::arm ||
1427 GetTriple().getArch() == llvm::Triple::thumb) {
1452 const llvm::Triple &triple =
GetTriple();
1453 llvm::StringRef arch_str = triple.getArchName();
1454 llvm::StringRef vendor_str = triple.getVendorName();
1455 llvm::StringRef os_str = triple.getOSName();
1456 llvm::StringRef environ_str = triple.getEnvironmentName();
1458 s << llvm::formatv(
"{0}-{1}-{2}", arch_str.empty() ?
"*" : arch_str,
1459 vendor_str.empty() ?
"*" : vendor_str,
1460 os_str.empty() ?
"*" : os_str);
1462 if (!environ_str.empty())
1463 s <<
"-" << environ_str;
static const ArchDefinition g_elf_arch_def
static const CoreDefinition * FindCoreDefinition(llvm::StringRef name)
static const ArchDefinitionEntry * FindArchDefinitionEntry(const ArchDefinition *def, uint32_t cpu, uint32_t sub)
static const ArchDefinitionEntry g_macho_arch_entries[]
static const ArchDefinitionEntry g_coff_arch_entries[]
static const ArchDefinitionEntry g_elf_arch_entries[]
static const ArchDefinition * FindArchDefinition(ArchitectureType arch_type)
static bool cores_match(const ArchSpec::Core core1, const ArchSpec::Core core2, bool try_inverse, bool enforce_exact_match)
static const CoreDefinition g_core_definitions[]
static const ArchDefinition * g_arch_definitions[]
static const ArchDefinition g_coff_arch_def
static bool IsCompatibleEnvironment(llvm::Triple::EnvironmentType lhs, llvm::Triple::EnvironmentType rhs)
static const ArchDefinition g_macho_arch_def
#define LLDB_LOGF(log,...)
An architecture specification class.
static void ListSupportedArchNames(StringList &list)
bool IsFullySpecifiedTriple() const
@ eLoongArchSubType_loongarch64
@ eLoongArchSubType_loongarch32
@ eCore_hexagon_hexagonv5
@ eCore_hexagon_hexagonv4
static void AutoComplete(CompletionRequest &request)
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
uint32_t GetCodeByteSize() const
Architecture code byte width accessor.
bool IsValid() const
Tests if this ArchSpec is valid.
void Clear()
Clears the object state.
llvm::Triple & GetTriple()
Architecture triple accessor.
void SetFlags(uint32_t flags)
bool IsAlwaysThumbInstructions() const
Detect whether this architecture uses thumb code exclusively.
bool TripleEnvironmentWasSpecified() const
bool IsMatch(const ArchSpec &rhs, MatchType match) const
Compare this ArchSpec to another ArchSpec.
bool SetTriple(const llvm::Triple &triple)
Architecture triple setter.
lldb::ByteOrder GetDefaultEndian() const
Returns the default endianness of the architecture.
lldb::ByteOrder m_byte_order
bool SetArchitecture(ArchitectureType arch_type, uint32_t cpu, uint32_t sub, uint32_t os=0)
Change the architecture object type, CPU type and OS type.
void MergeFrom(const ArchSpec &other)
Merges fields from another ArchSpec into this ArchSpec.
void DumpTriple(llvm::raw_ostream &s) const
uint32_t GetMachOCPUSubType() const
void CoreUpdated(bool update_triple)
bool IsMIPS() const
if MIPS architecture return true.
uint32_t GetDataByteSize() const
Architecture data byte width accessor.
bool IsCompatibleMatch(const ArchSpec &rhs) const
Shorthand for IsMatch(rhs, CompatibleMatch).
bool CharIsSignedByDefault() const
Returns true if 'char' is a signed type by default in the architecture false otherwise.
ArchSpec()
Default constructor.
uint32_t GetMachOCPUType() const
std::string GetTargetABI() const
Return a string representing target application ABI.
uint32_t GetMinimumOpcodeByteSize() const
uint32_t GetFlags() const
@ eMIPSSubType_mips32r6el
@ eMIPSSubType_mips64r6el
@ eMIPSSubType_mips64r2el
@ eMIPSSubType_mips32r2el
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
std::string GetClangTargetCPU() const
Returns a string representing current architecture as a target CPU for tools like compiler,...
uint32_t GetMaximumOpcodeByteSize() const
bool TripleVendorWasSpecified() const
bool TripleOSWasSpecified() const
static bool ContainsOnlyArch(const llvm::Triple &normalized_triple)
Returns true if the OS, vendor and environment fields of the triple are unset.
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
"lldb/Utility/ArgCompletionRequest.h"
void TryCompleteCurrentArg(llvm::StringRef completion, llvm::StringRef description="")
Adds a possible completion string if the completion would complete the current argument.
void AppendString(const std::string &s)
#define LLDB_INVALID_CPUTYPE
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
bool ParseMachCPUDashSubtypeTriple(llvm::StringRef triple_str, ArchSpec &arch)
bool operator==(const Address &lhs, const Address &rhs)
bool operator<(const Address &lhs, const Address &rhs)
ByteOrder
Byte ordering definitions.
const ArchDefinitionEntry * entries
uint32_t max_opcode_byte_size
llvm::Triple::ArchType machine
ByteOrder default_byte_order
uint32_t min_opcode_byte_size