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/BinaryFormat/XCOFF.h"
20#include "llvm/Support/Compiler.h"
21#include "llvm/TargetParser/ARMTargetParser.h"
27 bool try_inverse,
bool enforce_exact_match);
255 "make sure we have one core definition for each core");
282#define CPU_ANY (UINT32_MAX)
289#define SUBTYPE_MASK 0x00FFFFFFu
369 0xFFFFFFFFu, 0xFFFFFFFFu},
371 0xFFFFFFFFu, 0xFFFFFFFFu},
373 0xFFFFFFFFu, 0xFFFFFFFFu},
375 0xFFFFFFFFu, 0xFFFFFFFFu},
381 0xFFFFFFFFu, 0xFFFFFFFFu},
383 0xFFFFFFFFu, 0xFFFFFFFFu},
385 0xFFFFFFFFu, 0xFFFFFFFFu},
389 0xFFFFFFFFu, 0xFFFFFFFFu},
391 0xFFFFFFFFu, 0xFFFFFFFFu},
403 0xFFFFFFFFu, 0xFFFFFFFFu},
415 0xFFFFFFFFu, 0xFFFFFFFFu},
419 0xFFFFFFFFu, 0xFFFFFFFFu},
469 0xFFFFFFFFu, 0xFFFFFFFFu},
491 if (def->type == arch_type)
500 if (name.equals_insensitive(def.name))
520 if (entries[i].cpu == (cpu & entries[i].cpu_mask))
521 if (entries[i].sub == (sub & entries[i].sub_mask))
534 if (entries[i].core == core)
573 return core_def->
name;
605 if (elf_abi ==
"n64")
607 else if (elf_abi ==
"n32")
609 else if (elf_abi ==
"o32")
665 cpu = llvm::ARM::getARMCPUForArch(
GetTriple(),
"").str();
675 return arch_def->
cpu;
687 return arch_def->
sub;
706 return llvm::Triple::UnknownArch;
712 if (core_def->
machine == llvm::Triple::mips64 ||
713 core_def->
machine == llvm::Triple::mips64el) {
735 case llvm::Triple::aarch64:
736 case llvm::Triple::aarch64_32:
737 case llvm::Triple::aarch64_be:
738 case llvm::Triple::arm:
739 case llvm::Triple::armeb:
740 case llvm::Triple::thumb:
741 case llvm::Triple::thumbeb:
744 case llvm::Triple::ppc:
745 case llvm::Triple::ppc64:
748 case llvm::Triple::ppc64le:
749 case llvm::Triple::systemz:
750 case llvm::Triple::xcore:
751 case llvm::Triple::arc:
774 if (triple_str.empty())
777 size_t pos = triple_str.find_first_of(
"-.");
778 if (pos == llvm::StringRef::npos)
781 llvm::StringRef cpu_str = triple_str.substr(0, pos);
782 llvm::StringRef remainder = triple_str.substr(pos + 1);
783 if (cpu_str.empty() || remainder.empty())
786 llvm::StringRef sub_str;
787 llvm::StringRef vendor;
789 std::tie(sub_str, remainder) = remainder.split(
'-');
790 std::tie(vendor, os) = remainder.split(
'-');
794 if (cpu_str.getAsInteger(10, cpu) || sub_str.getAsInteger(10, sub))
799 if (!vendor.empty() && !os.empty()) {
808 if (triple.empty()) {
816 SetTriple(llvm::Triple(llvm::Triple::normalize(triple)));
821 return !normalized_triple.getArchName().empty() &&
822 normalized_triple.getOSName().empty() &&
823 normalized_triple.getVendorName().empty() &&
824 normalized_triple.getEnvironmentName().empty();
829 if ((
GetTriple().getOS() == llvm::Triple::MacOSX ||
830 GetTriple().getOS() == llvm::Triple::UnknownOS) &&
831 other.
GetTriple().getOS() == llvm::Triple::IOS &&
832 other.
GetTriple().getEnvironment() == llvm::Triple::MacABI) {
841 if (
GetTriple().getArch() == llvm::Triple::UnknownArch) {
857 if (
GetTriple().getArch() == llvm::Triple::arm &&
858 other.
GetTriple().getArch() == llvm::Triple::arm &&
870 uint32_t sub, uint32_t os) {
872 bool update_triple =
true;
877 if (arch_def_entry) {
881 update_triple =
false;
887 m_triple.setVendor(llvm::Triple::Apple);
899 case llvm::ELF::ELFOSABI_AIX:
900 m_triple.setOS(llvm::Triple::OSType::AIX);
902 case llvm::ELF::ELFOSABI_FREEBSD:
903 m_triple.setOS(llvm::Triple::OSType::FreeBSD);
905 case llvm::ELF::ELFOSABI_GNU:
906 m_triple.setOS(llvm::Triple::OSType::Linux);
908 case llvm::ELF::ELFOSABI_NETBSD:
909 m_triple.setOS(llvm::Triple::OSType::NetBSD);
911 case llvm::ELF::ELFOSABI_OPENBSD:
912 m_triple.setOS(llvm::Triple::OSType::OpenBSD);
914 case llvm::ELF::ELFOSABI_SOLARIS:
915 m_triple.setOS(llvm::Triple::OSType::Solaris);
917 case llvm::ELF::ELFOSABI_STANDALONE:
918 m_triple.setOS(llvm::Triple::OSType::UnknownOS);
921 }
else if (arch_type ==
eArchTypeCOFF && os == llvm::Triple::Win32) {
922 m_triple.setVendor(llvm::Triple::PC);
923 m_triple.setOS(llvm::Triple::Win32);
924 }
else if (arch_type ==
eArchTypeXCOFF && os == llvm::Triple::AIX) {
925 m_triple.setVendor(llvm::Triple::IBM);
928 m_triple.setVendor(llvm::Triple::UnknownVendor);
929 m_triple.setOS(llvm::Triple::UnknownOS);
933 if (
m_triple.getArch() == llvm::Triple::UnknownArch)
939 "Unable to find a core definition for cpu 0x%" PRIx32
963 llvm::Triple::EnvironmentType rhs) {
970 if (lhs == llvm::Triple::Simulator || rhs == llvm::Triple::Simulator)
974 if (lhs == llvm::Triple::UnknownEnvironment ||
975 rhs == llvm::Triple::UnknownEnvironment)
982 if ((lhs == llvm::Triple::Android && rhs == llvm::Triple::EABI) ||
983 (rhs == llvm::Triple::Android && lhs == llvm::Triple::EABI) ||
984 (lhs == llvm::Triple::GNUEABI && rhs == llvm::Triple::EABI) ||
985 (rhs == llvm::Triple::GNUEABI && lhs == llvm::Triple::EABI) ||
986 (lhs == llvm::Triple::GNUEABIHF && rhs == llvm::Triple::EABIHF) ||
987 (rhs == llvm::Triple::GNUEABIHF && lhs == llvm::Triple::EABIHF))
998 const llvm::Triple &lhs_triple =
GetTriple();
999 const llvm::Triple &rhs_triple = rhs.
GetTriple();
1001 const llvm::Triple::VendorType lhs_triple_vendor = lhs_triple.getVendor();
1002 const llvm::Triple::VendorType rhs_triple_vendor = rhs_triple.getVendor();
1004 const llvm::Triple::OSType lhs_triple_os = lhs_triple.getOS();
1005 const llvm::Triple::OSType rhs_triple_os = rhs_triple.getOS();
1007 bool both_windows = lhs_triple.isOSWindows() && rhs_triple.isOSWindows();
1011 if ((lhs_triple_vendor != rhs_triple_vendor) &&
1017 if (rhs_vendor_specified && lhs_vendor_specified)
1021 if (lhs_triple_vendor != llvm::Triple::UnknownVendor &&
1022 rhs_triple_vendor != llvm::Triple::UnknownVendor)
1026 const llvm::Triple::EnvironmentType lhs_triple_env =
1027 lhs_triple.getEnvironment();
1028 const llvm::Triple::EnvironmentType rhs_triple_env =
1029 rhs_triple.getEnvironment();
1033 if ((lhs_triple_os == llvm::Triple::IOS &&
1034 lhs_triple_env == llvm::Triple::MacABI &&
1035 rhs_triple_os == llvm::Triple::MacOSX) ||
1036 (lhs_triple_os == llvm::Triple::MacOSX &&
1037 rhs_triple_os == llvm::Triple::IOS &&
1038 rhs_triple_env == llvm::Triple::MacABI))
1043 if (lhs_triple_os == llvm::Triple::IOS &&
1044 rhs_triple_os == llvm::Triple::IOS &&
1045 (lhs_triple_env == llvm::Triple::MacABI ||
1046 rhs_triple_env == llvm::Triple::MacABI) &&
1047 lhs_triple_env != rhs_triple_env)
1050 if (lhs_triple_os != rhs_triple_os) {
1054 if (lhs_os_specified && rhs_os_specified)
1059 ((!lhs_os_specified && !lhs_triple.hasEnvironment()) ||
1060 (!rhs_os_specified && !rhs_triple.hasEnvironment())))
1071 llvm::StringRef arch_name(
m_triple.getArchName());
1091 m_triple = llvm::Triple(core_def->
name,
"unknown",
"unknown");
1104 bool try_inverse,
bool enforce_exact_match) {
1113 if (enforce_exact_match)
1166 if (!enforce_exact_match) {
1184 if (!enforce_exact_match) {
1202 if (!enforce_exact_match) {
1211 try_inverse =
false;
1220 if (!enforce_exact_match) {
1225 try_inverse =
false;
1230 if (!enforce_exact_match) {
1231 try_inverse =
false;
1238 if (!enforce_exact_match) {
1245 try_inverse =
false;
1250 if (!enforce_exact_match) {
1257 try_inverse =
false;
1261 if (!enforce_exact_match) {
1268 try_inverse =
false;
1273 if (!enforce_exact_match) {
1280 try_inverse =
false;
1285 if (!enforce_exact_match) {
1288 try_inverse =
false;
1293 if (!enforce_exact_match) {
1297 try_inverse =
false;
1302 if (!enforce_exact_match) {
1311 if (!enforce_exact_match) {
1318 try_inverse =
false;
1323 if (!enforce_exact_match) {
1330 try_inverse =
false;
1337 if (!enforce_exact_match) {
1342 try_inverse =
false;
1349 if (!enforce_exact_match) {
1354 try_inverse =
false;
1361 if (!enforce_exact_match) {
1370 if (!enforce_exact_match) {
1377 if (!enforce_exact_match) {
1384 if (!enforce_exact_match) {
1392 if (!enforce_exact_match) {
1401 if (!enforce_exact_match) {
1415 return cores_match(core2, core1,
false, enforce_exact_match);
1422 return lhs_core < rhs_core;
1437 const unsigned unspecified = 0;
1438 const llvm::Triple &triple =
GetTriple();
1439 if (triple.isOSDarwin() && triple.getOSMajorVersion() == unspecified)
1447 if (
GetTriple().getArch() == llvm::Triple::arm ||
1448 GetTriple().getArch() == llvm::Triple::thumb) {
1473 const llvm::Triple &triple =
GetTriple();
1474 llvm::StringRef arch_str = triple.getArchName();
1475 llvm::StringRef vendor_str = triple.getVendorName();
1476 llvm::StringRef os_str = triple.getOSName();
1477 llvm::StringRef environ_str = triple.getEnvironmentName();
1479 s << llvm::formatv(
"{0}-{1}-{2}", arch_str.empty() ?
"*" : arch_str,
1480 vendor_str.empty() ?
"*" : vendor_str,
1481 os_str.empty() ?
"*" : os_str);
1483 if (!environ_str.empty())
1484 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_xcoff_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 ArchDefinition g_xcoff_arch_def
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