mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-18 07:52:35 +00:00
Switch the llvm::Triple class to immediately parse the triple string on
construction. Simplify its interface, implementation, and users accordingly as there is no longer an 'uninitialized' state to check for. Also, fixes a bug lurking in the interface as there was one method that didn't correctly check for initialization. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151024 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4b04578d65
commit
124e51c0d2
@ -64,9 +64,7 @@ public:
|
|||||||
ptx32, // PTX: ptx (32-bit)
|
ptx32, // PTX: ptx (32-bit)
|
||||||
ptx64, // PTX: ptx (64-bit)
|
ptx64, // PTX: ptx (64-bit)
|
||||||
le32, // le32: generic little-endian 32-bit CPU (PNaCl / Emscripten)
|
le32, // le32: generic little-endian 32-bit CPU (PNaCl / Emscripten)
|
||||||
amdil, // amdil: amd IL
|
amdil // amdil: amd IL
|
||||||
|
|
||||||
InvalidArch
|
|
||||||
};
|
};
|
||||||
enum VendorType {
|
enum VendorType {
|
||||||
UnknownVendor,
|
UnknownVendor,
|
||||||
@ -113,31 +111,29 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::string Data;
|
std::string Data;
|
||||||
|
|
||||||
/// The parsed arch type (or InvalidArch if uninitialized).
|
/// The parsed arch type.
|
||||||
mutable ArchType Arch;
|
ArchType Arch;
|
||||||
|
|
||||||
/// The parsed vendor type.
|
/// The parsed vendor type.
|
||||||
mutable VendorType Vendor;
|
VendorType Vendor;
|
||||||
|
|
||||||
/// The parsed OS type.
|
/// The parsed OS type.
|
||||||
mutable OSType OS;
|
OSType OS;
|
||||||
|
|
||||||
/// The parsed Environment type.
|
/// The parsed Environment type.
|
||||||
mutable EnvironmentType Environment;
|
EnvironmentType Environment;
|
||||||
|
|
||||||
bool isInitialized() const { return Arch != InvalidArch; }
|
|
||||||
static ArchType ParseArch(StringRef ArchName);
|
static ArchType ParseArch(StringRef ArchName);
|
||||||
static VendorType ParseVendor(StringRef VendorName);
|
static VendorType ParseVendor(StringRef VendorName);
|
||||||
static OSType ParseOS(StringRef OSName);
|
static OSType ParseOS(StringRef OSName);
|
||||||
static EnvironmentType ParseEnvironment(StringRef EnvironmentName);
|
static EnvironmentType ParseEnvironment(StringRef EnvironmentName);
|
||||||
void Parse() const;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// @name Constructors
|
/// @name Constructors
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
/// \brief Default constructor produces an empty, invalid triple.
|
/// \brief Default constructor produces an empty, invalid triple.
|
||||||
Triple() : Data(), Arch(InvalidArch) {}
|
Triple() : Data(), Arch(), Vendor(), OS(), Environment() {}
|
||||||
|
|
||||||
explicit Triple(const Twine &Str);
|
explicit Triple(const Twine &Str);
|
||||||
Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr);
|
Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr);
|
||||||
@ -159,22 +155,13 @@ public:
|
|||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
/// getArch - Get the parsed architecture type of this triple.
|
/// getArch - Get the parsed architecture type of this triple.
|
||||||
ArchType getArch() const {
|
ArchType getArch() const { return Arch; }
|
||||||
if (!isInitialized()) Parse();
|
|
||||||
return Arch;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// getVendor - Get the parsed vendor type of this triple.
|
/// getVendor - Get the parsed vendor type of this triple.
|
||||||
VendorType getVendor() const {
|
VendorType getVendor() const { return Vendor; }
|
||||||
if (!isInitialized()) Parse();
|
|
||||||
return Vendor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// getOS - Get the parsed operating system type of this triple.
|
/// getOS - Get the parsed operating system type of this triple.
|
||||||
OSType getOS() const {
|
OSType getOS() const { return OS; }
|
||||||
if (!isInitialized()) Parse();
|
|
||||||
return OS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// hasEnvironment - Does this triple have the optional environment
|
/// hasEnvironment - Does this triple have the optional environment
|
||||||
/// (fourth) component?
|
/// (fourth) component?
|
||||||
@ -183,10 +170,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// getEnvironment - Get the parsed environment type of this triple.
|
/// getEnvironment - Get the parsed environment type of this triple.
|
||||||
EnvironmentType getEnvironment() const {
|
EnvironmentType getEnvironment() const { return Environment; }
|
||||||
if (!isInitialized()) Parse();
|
|
||||||
return Environment;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// getOSVersion - Parse the version number from the OS name component of the
|
/// getOSVersion - Parse the version number from the OS name component of the
|
||||||
/// triple, if present.
|
/// triple, if present.
|
||||||
|
@ -786,7 +786,7 @@ namespace llvm {
|
|||||||
/// extern "C" void LLVMInitializeFooTargetInfo() {
|
/// extern "C" void LLVMInitializeFooTargetInfo() {
|
||||||
/// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
|
/// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
|
||||||
/// }
|
/// }
|
||||||
template<Triple::ArchType TargetArchType = Triple::InvalidArch,
|
template<Triple::ArchType TargetArchType = Triple::UnknownArch,
|
||||||
bool HasJIT = false>
|
bool HasJIT = false>
|
||||||
struct RegisterTarget {
|
struct RegisterTarget {
|
||||||
RegisterTarget(Target &T, const char *Name, const char *Desc) {
|
RegisterTarget(Target &T, const char *Name, const char *Desc) {
|
||||||
|
@ -47,8 +47,7 @@ static struct TripleMap triplemap[] = {
|
|||||||
{ Triple::x86, "i386-unknown-unknown" },
|
{ Triple::x86, "i386-unknown-unknown" },
|
||||||
{ Triple::x86_64, "x86_64-unknown-unknown" },
|
{ Triple::x86_64, "x86_64-unknown-unknown" },
|
||||||
{ Triple::arm, "arm-unknown-unknown" },
|
{ Triple::arm, "arm-unknown-unknown" },
|
||||||
{ Triple::thumb, "thumb-unknown-unknown" },
|
{ Triple::thumb, "thumb-unknown-unknown" }
|
||||||
{ Triple::InvalidArch, NULL, }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// infoFromArch - Returns the TripleMap corresponding to a given architecture,
|
/// infoFromArch - Returns the TripleMap corresponding to a given architecture,
|
||||||
@ -128,8 +127,6 @@ EDDisassembler::EDDisassembler(CPUKey &key) :
|
|||||||
ErrorStream(nulls()),
|
ErrorStream(nulls()),
|
||||||
Key(key),
|
Key(key),
|
||||||
TgtTriple(key.Triple.c_str()) {
|
TgtTriple(key.Triple.c_str()) {
|
||||||
if (TgtTriple.getArch() == Triple::InvalidArch)
|
|
||||||
return;
|
|
||||||
|
|
||||||
LLVMSyntaxVariant = getLLVMSyntaxVariant(TgtTriple.getArch(), key.Syntax);
|
LLVMSyntaxVariant = getLLVMSyntaxVariant(TgtTriple.getArch(), key.Syntax);
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ using namespace llvm;
|
|||||||
|
|
||||||
const char *Triple::getArchTypeName(ArchType Kind) {
|
const char *Triple::getArchTypeName(ArchType Kind) {
|
||||||
switch (Kind) {
|
switch (Kind) {
|
||||||
case InvalidArch: return "<invalid>";
|
|
||||||
case UnknownArch: return "unknown";
|
case UnknownArch: return "unknown";
|
||||||
|
|
||||||
case arm: return "arm";
|
case arm: return "arm";
|
||||||
@ -291,24 +290,19 @@ Triple::EnvironmentType Triple::ParseEnvironment(StringRef EnvironmentName) {
|
|||||||
.Default(UnknownEnvironment);
|
.Default(UnknownEnvironment);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Triple::Parse() const {
|
|
||||||
assert(!isInitialized() && "Invalid parse call.");
|
|
||||||
|
|
||||||
Arch = ParseArch(getArchName());
|
|
||||||
Vendor = ParseVendor(getVendorName());
|
|
||||||
OS = ParseOS(getOSName());
|
|
||||||
Environment = ParseEnvironment(getEnvironmentName());
|
|
||||||
|
|
||||||
assert(isInitialized() && "Failed to initialize!");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Construct a triple from the string representation provided.
|
/// \brief Construct a triple from the string representation provided.
|
||||||
///
|
///
|
||||||
/// This doesn't actually parse the string representation eagerly. Instead it
|
/// This doesn't actually parse the string representation eagerly. Instead it
|
||||||
/// stores it, and tracks the fact that it hasn't been parsed. The first time
|
/// stores it, and tracks the fact that it hasn't been parsed. The first time
|
||||||
/// any of the structural queries are made, the string is parsed and the
|
/// any of the structural queries are made, the string is parsed and the
|
||||||
/// results cached in various members.
|
/// results cached in various members.
|
||||||
Triple::Triple(const Twine &Str) : Data(Str.str()), Arch(InvalidArch) {}
|
Triple::Triple(const Twine &Str)
|
||||||
|
: Data(Str.str()),
|
||||||
|
Arch(ParseArch(getArchName())),
|
||||||
|
Vendor(ParseVendor(getVendorName())),
|
||||||
|
OS(ParseOS(getOSName())),
|
||||||
|
Environment(ParseEnvironment(getEnvironmentName())) {
|
||||||
|
}
|
||||||
|
|
||||||
/// \brief Construct a triple from string representations of the architecture,
|
/// \brief Construct a triple from string representations of the architecture,
|
||||||
/// vendor, and OS.
|
/// vendor, and OS.
|
||||||
@ -318,7 +312,10 @@ Triple::Triple(const Twine &Str) : Data(Str.str()), Arch(InvalidArch) {}
|
|||||||
/// string, and lazily parses it on use.
|
/// string, and lazily parses it on use.
|
||||||
Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
|
Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
|
||||||
: Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
|
: Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
|
||||||
Arch(InvalidArch) {
|
Arch(ParseArch(ArchStr.str())),
|
||||||
|
Vendor(ParseVendor(VendorStr.str())),
|
||||||
|
OS(ParseOS(OSStr.str())),
|
||||||
|
Environment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Construct a triple from string representations of the architecture,
|
/// \brief Construct a triple from string representations of the architecture,
|
||||||
@ -331,7 +328,10 @@ Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
|
|||||||
const Twine &EnvironmentStr)
|
const Twine &EnvironmentStr)
|
||||||
: Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
|
: Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
|
||||||
EnvironmentStr).str()),
|
EnvironmentStr).str()),
|
||||||
Arch(InvalidArch) {
|
Arch(ParseArch(ArchStr.str())),
|
||||||
|
Vendor(ParseVendor(VendorStr.str())),
|
||||||
|
OS(ParseOS(OSStr.str())),
|
||||||
|
Environment(ParseEnvironment(EnvironmentStr.str())) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Triple::normalize(StringRef Str) {
|
std::string Triple::normalize(StringRef Str) {
|
||||||
@ -577,8 +577,7 @@ bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Triple::setTriple(const Twine &Str) {
|
void Triple::setTriple(const Twine &Str) {
|
||||||
Data = Str.str();
|
*this = Triple(Str);
|
||||||
Arch = InvalidArch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Triple::setArch(ArchType Kind) {
|
void Triple::setArch(ArchType Kind) {
|
||||||
@ -632,7 +631,6 @@ void Triple::setOSAndEnvironmentName(StringRef Str) {
|
|||||||
static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
|
static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
|
||||||
switch (Arch) {
|
switch (Arch) {
|
||||||
case llvm::Triple::UnknownArch:
|
case llvm::Triple::UnknownArch:
|
||||||
case llvm::Triple::InvalidArch:
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case llvm::Triple::msp430:
|
case llvm::Triple::msp430:
|
||||||
@ -682,7 +680,6 @@ Triple Triple::get32BitArchVariant() const {
|
|||||||
Triple T(*this);
|
Triple T(*this);
|
||||||
switch (getArch()) {
|
switch (getArch()) {
|
||||||
case Triple::UnknownArch:
|
case Triple::UnknownArch:
|
||||||
case Triple::InvalidArch:
|
|
||||||
case Triple::msp430:
|
case Triple::msp430:
|
||||||
T.setArch(UnknownArch);
|
T.setArch(UnknownArch);
|
||||||
break;
|
break;
|
||||||
@ -718,7 +715,6 @@ Triple Triple::get32BitArchVariant() const {
|
|||||||
Triple Triple::get64BitArchVariant() const {
|
Triple Triple::get64BitArchVariant() const {
|
||||||
Triple T(*this);
|
Triple T(*this);
|
||||||
switch (getArch()) {
|
switch (getArch()) {
|
||||||
case Triple::InvalidArch:
|
|
||||||
case Triple::UnknownArch:
|
case Triple::UnknownArch:
|
||||||
case Triple::amdil:
|
case Triple::amdil:
|
||||||
case Triple::arm:
|
case Triple::arm:
|
||||||
|
@ -154,7 +154,7 @@ TEST(TripleTest, Normalization) {
|
|||||||
// Check that normalizing a permutated set of valid components returns a
|
// Check that normalizing a permutated set of valid components returns a
|
||||||
// triple with the unpermuted components.
|
// triple with the unpermuted components.
|
||||||
StringRef C[4];
|
StringRef C[4];
|
||||||
for (int Arch = 1+Triple::UnknownArch; Arch < Triple::InvalidArch; ++Arch) {
|
for (int Arch = 1+Triple::UnknownArch; Arch <= Triple::amdil; ++Arch) {
|
||||||
C[0] = Triple::getArchTypeName(Triple::ArchType(Arch));
|
C[0] = Triple::getArchTypeName(Triple::ArchType(Arch));
|
||||||
for (int Vendor = 1+Triple::UnknownVendor; Vendor <= Triple::PC;
|
for (int Vendor = 1+Triple::UnknownVendor; Vendor <= Triple::PC;
|
||||||
++Vendor) {
|
++Vendor) {
|
||||||
@ -273,11 +273,6 @@ TEST(TripleTest, BitWidthPredicates) {
|
|||||||
EXPECT_FALSE(T.isArch32Bit());
|
EXPECT_FALSE(T.isArch32Bit());
|
||||||
EXPECT_FALSE(T.isArch64Bit());
|
EXPECT_FALSE(T.isArch64Bit());
|
||||||
|
|
||||||
T.setArch(Triple::InvalidArch);
|
|
||||||
EXPECT_FALSE(T.isArch16Bit());
|
|
||||||
EXPECT_FALSE(T.isArch32Bit());
|
|
||||||
EXPECT_FALSE(T.isArch64Bit());
|
|
||||||
|
|
||||||
T.setArch(Triple::arm);
|
T.setArch(Triple::arm);
|
||||||
EXPECT_FALSE(T.isArch16Bit());
|
EXPECT_FALSE(T.isArch16Bit());
|
||||||
EXPECT_TRUE(T.isArch32Bit());
|
EXPECT_TRUE(T.isArch32Bit());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user