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);
258 "make sure we have one core definition for each core");
285#define CPU_ANY (UINT32_MAX)
292#define SUBTYPE_MASK 0x00FFFFFFu
372 0xFFFFFFFFu, 0xFFFFFFFFu},
374 0xFFFFFFFFu, 0xFFFFFFFFu},
376 0xFFFFFFFFu, 0xFFFFFFFFu},
378 0xFFFFFFFFu, 0xFFFFFFFFu},
384 0xFFFFFFFFu, 0xFFFFFFFFu},
386 0xFFFFFFFFu, 0xFFFFFFFFu},
388 0xFFFFFFFFu, 0xFFFFFFFFu},
392 0xFFFFFFFFu, 0xFFFFFFFFu},
394 0xFFFFFFFFu, 0xFFFFFFFFu},
406 0xFFFFFFFFu, 0xFFFFFFFFu},
418 0xFFFFFFFFu, 0xFFFFFFFFu},
422 0xFFFFFFFFu, 0xFFFFFFFFu},
472 0xFFFFFFFFu, 0xFFFFFFFFu},
494 if (def->type == arch_type)
503 if (name.equals_insensitive(def.name))
523 if (entries[i].cpu == (cpu & entries[i].cpu_mask))
524 if (entries[i].sub == (sub & entries[i].sub_mask))
537 if (entries[i].core == core)
576 return core_def->
name;
608 if (elf_abi ==
"n64")
610 else if (elf_abi ==
"n32")
612 else if (elf_abi ==
"o32")
668 cpu = llvm::ARM::getARMCPUForArch(
GetTriple(),
"").str();
678 return arch_def->
cpu;
690 return arch_def->
sub;
709 return llvm::Triple::UnknownArch;
715 if (core_def->
machine == llvm::Triple::mips64 ||
716 core_def->
machine == llvm::Triple::mips64el) {
738 case llvm::Triple::aarch64:
739 case llvm::Triple::aarch64_32:
740 case llvm::Triple::aarch64_be:
741 case llvm::Triple::arm:
742 case llvm::Triple::armeb:
743 case llvm::Triple::thumb:
744 case llvm::Triple::thumbeb:
747 case llvm::Triple::ppc:
748 case llvm::Triple::ppc64:
751 case llvm::Triple::ppc64le:
752 case llvm::Triple::systemz:
753 case llvm::Triple::xcore:
754 case llvm::Triple::arc:
777 if (triple_str.empty())
780 size_t pos = triple_str.find_first_of(
"-.");
781 if (pos == llvm::StringRef::npos)
784 llvm::StringRef cpu_str = triple_str.substr(0, pos);
785 llvm::StringRef remainder = triple_str.substr(pos + 1);
786 if (cpu_str.empty() || remainder.empty())
789 llvm::StringRef sub_str;
790 llvm::StringRef vendor;
792 std::tie(sub_str, remainder) = remainder.split(
'-');
793 std::tie(vendor, os) = remainder.split(
'-');
797 if (cpu_str.getAsInteger(10, cpu) || sub_str.getAsInteger(10, sub))
802 if (!vendor.empty() && !os.empty()) {
811 if (triple.empty()) {
819 SetTriple(llvm::Triple(llvm::Triple::normalize(triple)));
824 return !normalized_triple.getArchName().empty() &&
825 normalized_triple.getOSName().empty() &&
826 normalized_triple.getVendorName().empty() &&
827 normalized_triple.getEnvironmentName().empty();
832 if ((
GetTriple().getOS() == llvm::Triple::MacOSX ||
833 GetTriple().getOS() == llvm::Triple::UnknownOS) &&
834 other.
GetTriple().getOS() == llvm::Triple::IOS &&
835 other.
GetTriple().getEnvironment() == llvm::Triple::MacABI) {
844 if (
GetTriple().getArch() == llvm::Triple::UnknownArch) {
860 if (
GetTriple().getArch() == llvm::Triple::arm &&
861 other.
GetTriple().getArch() == llvm::Triple::arm &&
873 uint32_t sub, uint32_t os) {
875 bool update_triple =
true;
880 if (arch_def_entry) {
884 update_triple =
false;
890 m_triple.setVendor(llvm::Triple::Apple);
902 case llvm::ELF::ELFOSABI_AIX:
903 m_triple.setOS(llvm::Triple::OSType::AIX);
905 case llvm::ELF::ELFOSABI_FREEBSD:
906 m_triple.setOS(llvm::Triple::OSType::FreeBSD);
908 case llvm::ELF::ELFOSABI_GNU:
909 m_triple.setOS(llvm::Triple::OSType::Linux);
911 case llvm::ELF::ELFOSABI_NETBSD:
912 m_triple.setOS(llvm::Triple::OSType::NetBSD);
914 case llvm::ELF::ELFOSABI_OPENBSD:
915 m_triple.setOS(llvm::Triple::OSType::OpenBSD);
917 case llvm::ELF::ELFOSABI_SOLARIS:
918 m_triple.setOS(llvm::Triple::OSType::Solaris);
920 case llvm::ELF::ELFOSABI_STANDALONE:
921 m_triple.setOS(llvm::Triple::OSType::UnknownOS);
924 }
else if (arch_type ==
eArchTypeCOFF && os == llvm::Triple::Win32) {
925 m_triple.setVendor(llvm::Triple::PC);
926 m_triple.setOS(llvm::Triple::Win32);
927 }
else if (arch_type ==
eArchTypeXCOFF && os == llvm::Triple::AIX) {
928 m_triple.setVendor(llvm::Triple::IBM);
931 m_triple.setVendor(llvm::Triple::UnknownVendor);
932 m_triple.setOS(llvm::Triple::UnknownOS);
936 if (
m_triple.getArch() == llvm::Triple::UnknownArch)
942 "Unable to find a core definition for cpu 0x%" PRIx32
966 llvm::Triple::EnvironmentType rhs) {
973 if (lhs == llvm::Triple::Simulator || rhs == llvm::Triple::Simulator)
977 if (lhs == llvm::Triple::UnknownEnvironment ||
978 rhs == llvm::Triple::UnknownEnvironment)
985 if ((lhs == llvm::Triple::Android && rhs == llvm::Triple::EABI) ||
986 (rhs == llvm::Triple::Android && lhs == llvm::Triple::EABI) ||
987 (lhs == llvm::Triple::GNUEABI && rhs == llvm::Triple::EABI) ||
988 (rhs == llvm::Triple::GNUEABI && lhs == llvm::Triple::EABI) ||
989 (lhs == llvm::Triple::GNUEABIHF && rhs == llvm::Triple::EABIHF) ||
990 (rhs == llvm::Triple::GNUEABIHF && lhs == llvm::Triple::EABIHF))
1001 const llvm::Triple &lhs_triple =
GetTriple();
1002 const llvm::Triple &rhs_triple = rhs.
GetTriple();
1004 const llvm::Triple::VendorType lhs_triple_vendor = lhs_triple.getVendor();
1005 const llvm::Triple::VendorType rhs_triple_vendor = rhs_triple.getVendor();
1007 const llvm::Triple::OSType lhs_triple_os = lhs_triple.getOS();
1008 const llvm::Triple::OSType rhs_triple_os = rhs_triple.getOS();
1010 bool both_windows = lhs_triple.isOSWindows() && rhs_triple.isOSWindows();
1014 if ((lhs_triple_vendor != rhs_triple_vendor) &&
1020 if (rhs_vendor_specified && lhs_vendor_specified)
1024 if (lhs_triple_vendor != llvm::Triple::UnknownVendor &&
1025 rhs_triple_vendor != llvm::Triple::UnknownVendor)
1029 const llvm::Triple::EnvironmentType lhs_triple_env =
1030 lhs_triple.getEnvironment();
1031 const llvm::Triple::EnvironmentType rhs_triple_env =
1032 rhs_triple.getEnvironment();
1036 if ((lhs_triple_os == llvm::Triple::IOS &&
1037 lhs_triple_env == llvm::Triple::MacABI &&
1038 rhs_triple_os == llvm::Triple::MacOSX) ||
1039 (lhs_triple_os == llvm::Triple::MacOSX &&
1040 rhs_triple_os == llvm::Triple::IOS &&
1041 rhs_triple_env == llvm::Triple::MacABI))
1046 if (lhs_triple_os == llvm::Triple::IOS &&
1047 rhs_triple_os == llvm::Triple::IOS &&
1048 (lhs_triple_env == llvm::Triple::MacABI ||
1049 rhs_triple_env == llvm::Triple::MacABI) &&
1050 lhs_triple_env != rhs_triple_env)
1053 if (lhs_triple_os != rhs_triple_os) {
1057 if (lhs_os_specified && rhs_os_specified)
1062 ((!lhs_os_specified && !lhs_triple.hasEnvironment()) ||
1063 (!rhs_os_specified && !rhs_triple.hasEnvironment())))
1074 llvm::StringRef arch_name(
m_triple.getArchName());
1094 m_triple = llvm::Triple(core_def->
name,
"unknown",
"unknown");
1107 bool try_inverse,
bool enforce_exact_match) {
1116 if (enforce_exact_match)
1169 if (!enforce_exact_match) {
1187 if (!enforce_exact_match) {
1205 if (!enforce_exact_match) {
1214 try_inverse =
false;
1223 if (!enforce_exact_match) {
1228 try_inverse =
false;
1234 if (!enforce_exact_match) {
1235 try_inverse =
false;
1242 if (!enforce_exact_match) {
1249 try_inverse =
false;
1254 if (!enforce_exact_match) {
1261 try_inverse =
false;
1265 if (!enforce_exact_match) {
1272 try_inverse =
false;
1277 if (!enforce_exact_match) {
1284 try_inverse =
false;
1289 if (!enforce_exact_match) {
1292 try_inverse =
false;
1297 if (!enforce_exact_match) {
1301 try_inverse =
false;
1306 if (!enforce_exact_match) {
1315 if (!enforce_exact_match) {
1322 try_inverse =
false;
1327 if (!enforce_exact_match) {
1334 try_inverse =
false;
1341 if (!enforce_exact_match) {
1346 try_inverse =
false;
1353 if (!enforce_exact_match) {
1358 try_inverse =
false;
1365 if (!enforce_exact_match) {
1374 if (!enforce_exact_match) {
1381 if (!enforce_exact_match) {
1388 if (!enforce_exact_match) {
1396 if (!enforce_exact_match) {
1405 if (!enforce_exact_match) {
1419 return cores_match(core2, core1,
false, enforce_exact_match);
1426 return lhs_core < rhs_core;
1441 const unsigned unspecified = 0;
1442 const llvm::Triple &triple =
GetTriple();
1443 if (triple.isOSDarwin() && triple.getOSMajorVersion() == unspecified)
1451 if (
GetTriple().getArch() == llvm::Triple::arm ||
1452 GetTriple().getArch() == llvm::Triple::thumb) {
1477 const llvm::Triple &triple =
GetTriple();
1478 llvm::StringRef arch_str = triple.getArchName();
1479 llvm::StringRef vendor_str = triple.getVendorName();
1480 llvm::StringRef os_str = triple.getOSName();
1481 llvm::StringRef environ_str = triple.getEnvironmentName();
1483 s << llvm::formatv(
"{0}-{1}-{2}", arch_str.empty() ?
"*" : arch_str,
1484 vendor_str.empty() ?
"*" : vendor_str,
1485 os_str.empty() ?
"*" : os_str);
1487 if (!environ_str.empty())
1488 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