mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 17:32:19 +00:00
Update Triple to use StringRef/Twine based APIs.
- This is now shorter, simpler, safer, and more efficient, what a deal. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77119 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d61918fc68
commit
a14d225ef4
@ -10,9 +10,12 @@
|
|||||||
#ifndef LLVM_ADT_TRIPLE_H
|
#ifndef LLVM_ADT_TRIPLE_H
|
||||||
#define LLVM_ADT_TRIPLE_H
|
#define LLVM_ADT_TRIPLE_H
|
||||||
|
|
||||||
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
class StringRef;
|
||||||
|
class Twine;
|
||||||
|
|
||||||
/// Triple - Helper class for working with target triples.
|
/// Triple - Helper class for working with target triples.
|
||||||
///
|
///
|
||||||
@ -121,28 +124,25 @@ public:
|
|||||||
|
|
||||||
const std::string &getTriple() const { return Data; }
|
const std::string &getTriple() const { return Data; }
|
||||||
|
|
||||||
// FIXME: Invent a lightweight string representation for these to
|
|
||||||
// use.
|
|
||||||
|
|
||||||
/// getArchName - Get the architecture (first) component of the
|
/// getArchName - Get the architecture (first) component of the
|
||||||
/// triple.
|
/// triple.
|
||||||
std::string getArchName() const;
|
StringRef getArchName() const;
|
||||||
|
|
||||||
/// getVendorName - Get the vendor (second) component of the triple.
|
/// getVendorName - Get the vendor (second) component of the triple.
|
||||||
std::string getVendorName() const;
|
StringRef getVendorName() const;
|
||||||
|
|
||||||
/// getOSName - Get the operating system (third) component of the
|
/// getOSName - Get the operating system (third) component of the
|
||||||
/// triple.
|
/// triple.
|
||||||
std::string getOSName() const;
|
StringRef getOSName() const;
|
||||||
|
|
||||||
/// getEnvironmentName - Get the optional environment (fourth)
|
/// getEnvironmentName - Get the optional environment (fourth)
|
||||||
/// component of the triple, or "" if empty.
|
/// component of the triple, or "" if empty.
|
||||||
std::string getEnvironmentName() const;
|
StringRef getEnvironmentName() const;
|
||||||
|
|
||||||
/// getOSAndEnvironmentName - Get the operating system and optional
|
/// getOSAndEnvironmentName - Get the operating system and optional
|
||||||
/// environment components as a single string (separated by a '-'
|
/// environment components as a single string (separated by a '-'
|
||||||
/// if the environment component is present).
|
/// if the environment component is present).
|
||||||
std::string getOSAndEnvironmentName() const;
|
StringRef getOSAndEnvironmentName() const;
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
/// @name Mutators
|
/// @name Mutators
|
||||||
@ -161,27 +161,27 @@ public:
|
|||||||
void setOS(OSType Kind);
|
void setOS(OSType Kind);
|
||||||
|
|
||||||
/// setTriple - Set all components to the new triple \arg Str.
|
/// setTriple - Set all components to the new triple \arg Str.
|
||||||
void setTriple(const std::string &Str);
|
void setTriple(const Twine &Str);
|
||||||
|
|
||||||
/// setArchName - Set the architecture (first) component of the
|
/// setArchName - Set the architecture (first) component of the
|
||||||
/// triple by name.
|
/// triple by name.
|
||||||
void setArchName(const std::string &Str);
|
void setArchName(const StringRef &Str);
|
||||||
|
|
||||||
/// setVendorName - Set the vendor (second) component of the triple
|
/// setVendorName - Set the vendor (second) component of the triple
|
||||||
/// by name.
|
/// by name.
|
||||||
void setVendorName(const std::string &Str);
|
void setVendorName(const StringRef &Str);
|
||||||
|
|
||||||
/// setOSName - Set the operating system (third) component of the
|
/// setOSName - Set the operating system (third) component of the
|
||||||
/// triple by name.
|
/// triple by name.
|
||||||
void setOSName(const std::string &Str);
|
void setOSName(const StringRef &Str);
|
||||||
|
|
||||||
/// setEnvironmentName - Set the optional environment (fourth)
|
/// setEnvironmentName - Set the optional environment (fourth)
|
||||||
/// component of the triple by name.
|
/// component of the triple by name.
|
||||||
void setEnvironmentName(const std::string &Str);
|
void setEnvironmentName(const StringRef &Str);
|
||||||
|
|
||||||
/// setOSAndEnvironmentName - Set the operating system and optional
|
/// setOSAndEnvironmentName - Set the operating system and optional
|
||||||
/// environment components with a single string.
|
/// environment components with a single string.
|
||||||
void setOSAndEnvironmentName(const std::string &Str);
|
void setOSAndEnvironmentName(const StringRef &Str);
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
/// @name Static helpers for IDs.
|
/// @name Static helpers for IDs.
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/ADT/Triple.h"
|
#include "llvm/ADT/Triple.h"
|
||||||
|
|
||||||
|
#include "llvm/ADT/Twine.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@ -60,7 +62,7 @@ const char *Triple::getOSTypeName(OSType Kind) {
|
|||||||
void Triple::Parse() const {
|
void Triple::Parse() const {
|
||||||
assert(!isInitialized() && "Invalid parse call.");
|
assert(!isInitialized() && "Invalid parse call.");
|
||||||
|
|
||||||
std::string ArchName = getArchName();
|
StringRef ArchName = getArchName();
|
||||||
if (ArchName.size() == 4 && ArchName[0] == 'i' &&
|
if (ArchName.size() == 4 && ArchName[0] == 'i' &&
|
||||||
ArchName[2] == '8' && ArchName[3] == '6')
|
ArchName[2] == '8' && ArchName[3] == '6')
|
||||||
Arch = x86;
|
Arch = x86;
|
||||||
@ -73,7 +75,7 @@ void Triple::Parse() const {
|
|||||||
else
|
else
|
||||||
Arch = UnknownArch;
|
Arch = UnknownArch;
|
||||||
|
|
||||||
std::string VendorName = getVendorName();
|
StringRef VendorName = getVendorName();
|
||||||
if (VendorName == "apple")
|
if (VendorName == "apple")
|
||||||
Vendor = Apple;
|
Vendor = Apple;
|
||||||
else if (VendorName == "pc")
|
else if (VendorName == "pc")
|
||||||
@ -81,20 +83,20 @@ void Triple::Parse() const {
|
|||||||
else
|
else
|
||||||
Vendor = UnknownVendor;
|
Vendor = UnknownVendor;
|
||||||
|
|
||||||
std::string OSName = getOSName();
|
StringRef OSName = getOSName();
|
||||||
if (memcmp(&OSName[0], "auroraux", 8) == 0)
|
if (OSName.startswith("auroraux"))
|
||||||
OS = AuroraUX;
|
OS = AuroraUX;
|
||||||
else if (memcmp(&OSName[0], "darwin", 6) == 0)
|
else if (OSName.startswith("darwin"))
|
||||||
OS = Darwin;
|
OS = Darwin;
|
||||||
else if (memcmp(&OSName[0], "dragonfly", 9) == 0)
|
else if (OSName.startswith("dragonfly"))
|
||||||
OS = DragonFly;
|
OS = DragonFly;
|
||||||
else if (memcmp(&OSName[0], "freebsd", 7) == 0)
|
else if (OSName.startswith("freebsd"))
|
||||||
OS = FreeBSD;
|
OS = FreeBSD;
|
||||||
else if (memcmp(&OSName[0], "linux", 5) == 0)
|
else if (OSName.startswith("linux"))
|
||||||
OS = Linux;
|
OS = Linux;
|
||||||
else if (memcmp(&OSName[0], "netbsd", 6) == 0)
|
else if (OSName.startswith("netbsd"))
|
||||||
OS = NetBSD;
|
OS = NetBSD;
|
||||||
else if (memcmp(&OSName[0], "openbsd", 7) == 0)
|
else if (OSName.startswith("openbsd"))
|
||||||
OS = OpenBSD;
|
OS = OpenBSD;
|
||||||
else
|
else
|
||||||
OS = UnknownOS;
|
OS = UnknownOS;
|
||||||
@ -102,59 +104,34 @@ void Triple::Parse() const {
|
|||||||
assert(isInitialized() && "Failed to initialize!");
|
assert(isInitialized() && "Failed to initialize!");
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string extract(const std::string &A,
|
StringRef Triple::getArchName() const {
|
||||||
std::string::size_type begin,
|
return StringRef(Data).split('-').first; // Isolate first component
|
||||||
std::string::size_type end) {
|
|
||||||
if (begin == std::string::npos)
|
|
||||||
return "";
|
|
||||||
if (end == std::string::npos)
|
|
||||||
return A.substr(begin);
|
|
||||||
return A.substr(begin, end - begin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string extract1(const std::string &A,
|
StringRef Triple::getVendorName() const {
|
||||||
std::string::size_type begin,
|
StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
|
||||||
std::string::size_type end) {
|
return Tmp.split('-').first; // Isolate second component
|
||||||
if (begin == std::string::npos || begin == end)
|
|
||||||
return "";
|
|
||||||
return extract(A, begin + 1, end);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Triple::getArchName() const {
|
StringRef Triple::getOSName() const {
|
||||||
std::string Tmp = Data;
|
StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
|
||||||
return extract(Tmp, 0, Tmp.find('-'));
|
Tmp = Tmp.split('-').second; // Strip second component
|
||||||
|
return Tmp.split('-').first; // Isolate third component
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Triple::getVendorName() const {
|
StringRef Triple::getEnvironmentName() const {
|
||||||
std::string Tmp = Data;
|
StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
|
||||||
Tmp = extract1(Tmp, Tmp.find('-'), std::string::npos);
|
Tmp = Tmp.split('-').second; // Strip second component
|
||||||
return extract(Tmp, 0, Tmp.find('-'));
|
return Tmp.split('-').second; // Strip third component
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Triple::getOSName() const {
|
StringRef Triple::getOSAndEnvironmentName() const {
|
||||||
std::string Tmp = Data;
|
StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
|
||||||
Tmp = extract1(Tmp, Tmp.find('-'), std::string::npos);
|
return Tmp.split('-').second; // Strip second component
|
||||||
Tmp = extract1(Tmp, Tmp.find('-'), std::string::npos);
|
|
||||||
return extract(Tmp, 0, Tmp.find('-'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Triple::getEnvironmentName() const {
|
void Triple::setTriple(const Twine &Str) {
|
||||||
std::string Tmp = Data;
|
Data = Str.str();
|
||||||
Tmp = extract1(Tmp, Tmp.find('-'), std::string::npos);
|
|
||||||
Tmp = extract1(Tmp, Tmp.find('-'), std::string::npos);
|
|
||||||
Tmp = extract1(Tmp, Tmp.find('-'), std::string::npos);
|
|
||||||
return extract(Tmp, 0, std::string::npos);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Triple::getOSAndEnvironmentName() const {
|
|
||||||
std::string Tmp = Data;
|
|
||||||
Tmp = extract1(Tmp, Tmp.find('-'), std::string::npos);
|
|
||||||
Tmp = extract1(Tmp, Tmp.find('-'), std::string::npos);
|
|
||||||
return extract(Tmp, 0, std::string::npos);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Triple::setTriple(const std::string &Str) {
|
|
||||||
Data = Str;
|
|
||||||
Arch = InvalidArch;
|
Arch = InvalidArch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,15 +147,15 @@ void Triple::setOS(OSType Kind) {
|
|||||||
setOSName(getOSTypeName(Kind));
|
setOSName(getOSTypeName(Kind));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Triple::setArchName(const std::string &Str) {
|
void Triple::setArchName(const StringRef &Str) {
|
||||||
setTriple(Str + "-" + getVendorName() + "-" + getOSAndEnvironmentName());
|
setTriple(Str + "-" + getVendorName() + "-" + getOSAndEnvironmentName());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Triple::setVendorName(const std::string &Str) {
|
void Triple::setVendorName(const StringRef &Str) {
|
||||||
setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
|
setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Triple::setOSName(const std::string &Str) {
|
void Triple::setOSName(const StringRef &Str) {
|
||||||
if (hasEnvironment())
|
if (hasEnvironment())
|
||||||
setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
|
setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
|
||||||
"-" + getEnvironmentName());
|
"-" + getEnvironmentName());
|
||||||
@ -186,11 +163,11 @@ void Triple::setOSName(const std::string &Str) {
|
|||||||
setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
|
setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Triple::setEnvironmentName(const std::string &Str) {
|
void Triple::setEnvironmentName(const StringRef &Str) {
|
||||||
setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
|
setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
|
||||||
"-" + Str);
|
"-" + Str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Triple::setOSAndEnvironmentName(const std::string &Str) {
|
void Triple::setOSAndEnvironmentName(const StringRef &Str) {
|
||||||
setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
|
setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
|
||||||
}
|
}
|
||||||
|
@ -18,58 +18,58 @@ TEST(TripleTest, BasicParsing) {
|
|||||||
Triple T;
|
Triple T;
|
||||||
|
|
||||||
T = Triple("");
|
T = Triple("");
|
||||||
EXPECT_EQ("", T.getArchName());
|
EXPECT_EQ("", T.getArchName().str());
|
||||||
EXPECT_EQ("", T.getVendorName());
|
EXPECT_EQ("", T.getVendorName().str());
|
||||||
EXPECT_EQ("", T.getOSName());
|
EXPECT_EQ("", T.getOSName().str());
|
||||||
EXPECT_EQ("", T.getEnvironmentName());
|
EXPECT_EQ("", T.getEnvironmentName().str());
|
||||||
|
|
||||||
T = Triple("-");
|
T = Triple("-");
|
||||||
EXPECT_EQ("", T.getArchName());
|
EXPECT_EQ("", T.getArchName().str());
|
||||||
EXPECT_EQ("", T.getVendorName());
|
EXPECT_EQ("", T.getVendorName().str());
|
||||||
EXPECT_EQ("", T.getOSName());
|
EXPECT_EQ("", T.getOSName().str());
|
||||||
EXPECT_EQ("", T.getEnvironmentName());
|
EXPECT_EQ("", T.getEnvironmentName().str());
|
||||||
|
|
||||||
T = Triple("--");
|
T = Triple("--");
|
||||||
EXPECT_EQ("", T.getArchName());
|
EXPECT_EQ("", T.getArchName().str());
|
||||||
EXPECT_EQ("", T.getVendorName());
|
EXPECT_EQ("", T.getVendorName().str());
|
||||||
EXPECT_EQ("", T.getOSName());
|
EXPECT_EQ("", T.getOSName().str());
|
||||||
EXPECT_EQ("", T.getEnvironmentName());
|
EXPECT_EQ("", T.getEnvironmentName().str());
|
||||||
|
|
||||||
T = Triple("---");
|
T = Triple("---");
|
||||||
EXPECT_EQ("", T.getArchName());
|
EXPECT_EQ("", T.getArchName().str());
|
||||||
EXPECT_EQ("", T.getVendorName());
|
EXPECT_EQ("", T.getVendorName().str());
|
||||||
EXPECT_EQ("", T.getOSName());
|
EXPECT_EQ("", T.getOSName().str());
|
||||||
EXPECT_EQ("", T.getEnvironmentName());
|
EXPECT_EQ("", T.getEnvironmentName().str());
|
||||||
|
|
||||||
T = Triple("----");
|
T = Triple("----");
|
||||||
EXPECT_EQ("", T.getArchName());
|
EXPECT_EQ("", T.getArchName().str());
|
||||||
EXPECT_EQ("", T.getVendorName());
|
EXPECT_EQ("", T.getVendorName().str());
|
||||||
EXPECT_EQ("", T.getOSName());
|
EXPECT_EQ("", T.getOSName().str());
|
||||||
EXPECT_EQ("-", T.getEnvironmentName());
|
EXPECT_EQ("-", T.getEnvironmentName().str());
|
||||||
|
|
||||||
T = Triple("a");
|
T = Triple("a");
|
||||||
EXPECT_EQ("a", T.getArchName());
|
EXPECT_EQ("a", T.getArchName().str());
|
||||||
EXPECT_EQ("", T.getVendorName());
|
EXPECT_EQ("", T.getVendorName().str());
|
||||||
EXPECT_EQ("", T.getOSName());
|
EXPECT_EQ("", T.getOSName().str());
|
||||||
EXPECT_EQ("", T.getEnvironmentName());
|
EXPECT_EQ("", T.getEnvironmentName().str());
|
||||||
|
|
||||||
T = Triple("a-b");
|
T = Triple("a-b");
|
||||||
EXPECT_EQ("a", T.getArchName());
|
EXPECT_EQ("a", T.getArchName().str());
|
||||||
EXPECT_EQ("b", T.getVendorName());
|
EXPECT_EQ("b", T.getVendorName().str());
|
||||||
EXPECT_EQ("", T.getOSName());
|
EXPECT_EQ("", T.getOSName().str());
|
||||||
EXPECT_EQ("", T.getEnvironmentName());
|
EXPECT_EQ("", T.getEnvironmentName().str());
|
||||||
|
|
||||||
T = Triple("a-b-c");
|
T = Triple("a-b-c");
|
||||||
EXPECT_EQ("a", T.getArchName());
|
EXPECT_EQ("a", T.getArchName().str());
|
||||||
EXPECT_EQ("b", T.getVendorName());
|
EXPECT_EQ("b", T.getVendorName().str());
|
||||||
EXPECT_EQ("c", T.getOSName());
|
EXPECT_EQ("c", T.getOSName().str());
|
||||||
EXPECT_EQ("", T.getEnvironmentName());
|
EXPECT_EQ("", T.getEnvironmentName().str());
|
||||||
|
|
||||||
T = Triple("a-b-c-d");
|
T = Triple("a-b-c-d");
|
||||||
EXPECT_EQ("a", T.getArchName());
|
EXPECT_EQ("a", T.getArchName().str());
|
||||||
EXPECT_EQ("b", T.getVendorName());
|
EXPECT_EQ("b", T.getVendorName().str());
|
||||||
EXPECT_EQ("c", T.getOSName());
|
EXPECT_EQ("c", T.getOSName().str());
|
||||||
EXPECT_EQ("d", T.getEnvironmentName());
|
EXPECT_EQ("d", T.getEnvironmentName().str());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TripleTest, ParsedIDs) {
|
TEST(TripleTest, ParsedIDs) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user