2009-04-01 23:53:23 +02:00
|
|
|
//===-- llvm/ADT/Triple.h - Target triple helper class ----------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ADT_TRIPLE_H
|
|
|
|
#define LLVM_ADT_TRIPLE_H
|
|
|
|
|
2009-07-26 05:31:47 +02:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2009-04-01 23:53:23 +02:00
|
|
|
#include <string>
|
|
|
|
|
2009-08-26 07:00:16 +02:00
|
|
|
// Some system headers or GCC predefined macros conflict with identifiers in
|
|
|
|
// this file. Undefine them here.
|
|
|
|
#undef mips
|
|
|
|
#undef sparc
|
|
|
|
|
2009-04-01 23:53:23 +02:00
|
|
|
namespace llvm {
|
2009-07-26 05:31:47 +02:00
|
|
|
class StringRef;
|
|
|
|
class Twine;
|
2009-04-01 23:53:23 +02:00
|
|
|
|
|
|
|
/// Triple - Helper class for working with target triples.
|
|
|
|
///
|
2010-08-12 13:31:39 +02:00
|
|
|
/// Target triples are strings in the canonical form:
|
2009-04-01 23:53:23 +02:00
|
|
|
/// ARCHITECTURE-VENDOR-OPERATING_SYSTEM
|
|
|
|
/// or
|
|
|
|
/// ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
|
|
|
|
///
|
|
|
|
/// This class is used for clients which want to support arbitrary
|
|
|
|
/// target triples, but also want to implement certain special
|
|
|
|
/// behavior for particular targets. This class isolates the mapping
|
|
|
|
/// from the components of the target triple to well known IDs.
|
|
|
|
///
|
2009-08-18 21:26:55 +02:00
|
|
|
/// At its core the Triple class is designed to be a wrapper for a triple
|
2010-08-12 13:31:39 +02:00
|
|
|
/// string; the constructor does not change or normalize the triple string.
|
|
|
|
/// Clients that need to handle the non-canonical triples that users often
|
|
|
|
/// specify should use the normalize method.
|
2009-08-18 21:26:55 +02:00
|
|
|
///
|
2010-08-12 13:31:39 +02:00
|
|
|
/// See autoconf/config.guess for a glimpse into what triples look like in
|
2009-08-18 21:26:55 +02:00
|
|
|
/// practice.
|
2009-04-01 23:53:23 +02:00
|
|
|
class Triple {
|
|
|
|
public:
|
|
|
|
enum ArchType {
|
|
|
|
UnknownArch,
|
2010-11-13 05:17:15 +01:00
|
|
|
|
2009-08-02 21:41:20 +02:00
|
|
|
alpha, // Alpha: alpha
|
2009-08-18 06:51:26 +02:00
|
|
|
arm, // ARM; arm, armv.*, xscale
|
2009-08-02 21:41:20 +02:00
|
|
|
bfin, // Blackfin: bfin
|
|
|
|
cellspu, // CellSPU: spu, cellspu
|
|
|
|
mips, // MIPS: mips, mipsallegrex
|
|
|
|
mipsel, // MIPSEL: mipsel, mipsallegrexel, psp
|
2009-08-18 15:50:28 +02:00
|
|
|
msp430, // MSP430: msp430
|
2009-08-18 06:43:27 +02:00
|
|
|
pic16, // PIC16: pic16
|
2009-08-02 21:41:20 +02:00
|
|
|
ppc, // PPC: powerpc
|
2009-11-19 12:59:00 +01:00
|
|
|
ppc64, // PPC64: powerpc64, ppu
|
2009-08-02 21:41:20 +02:00
|
|
|
sparc, // Sparc: sparc
|
2010-02-04 07:34:01 +01:00
|
|
|
sparcv9, // Sparcv9: Sparcv9
|
2009-08-02 21:41:20 +02:00
|
|
|
systemz, // SystemZ: s390x
|
2009-08-19 22:46:03 +02:00
|
|
|
tce, // TCE (http://tce.cs.tut.fi/): tce
|
2009-08-02 21:41:20 +02:00
|
|
|
thumb, // Thumb: thumb, thumbv.*
|
|
|
|
x86, // X86: i[3-9]86
|
|
|
|
x86_64, // X86-64: amd64, x86_64
|
|
|
|
xcore, // XCore: xcore
|
2010-02-23 20:15:24 +01:00
|
|
|
mblaze, // MBlaze: mblaze
|
2010-09-07 20:14:24 +02:00
|
|
|
ptx, // PTX: ptx
|
2009-04-01 23:53:23 +02:00
|
|
|
|
|
|
|
InvalidArch
|
|
|
|
};
|
|
|
|
enum VendorType {
|
|
|
|
UnknownVendor,
|
|
|
|
|
2010-11-13 05:17:15 +01:00
|
|
|
Apple,
|
2009-04-01 23:53:23 +02:00
|
|
|
PC
|
|
|
|
};
|
|
|
|
enum OSType {
|
|
|
|
UnknownOS,
|
|
|
|
|
2009-06-19 16:40:01 +02:00
|
|
|
AuroraUX,
|
2009-07-26 06:23:03 +02:00
|
|
|
Cygwin,
|
2009-04-01 23:53:23 +02:00
|
|
|
Darwin,
|
2009-05-22 04:24:11 +02:00
|
|
|
DragonFly,
|
2009-04-01 23:53:23 +02:00
|
|
|
FreeBSD,
|
2009-06-29 15:36:13 +02:00
|
|
|
Linux,
|
2009-11-19 12:59:00 +01:00
|
|
|
Lv2, // PS3
|
2009-07-26 06:23:03 +02:00
|
|
|
MinGW32,
|
2009-08-12 08:32:10 +02:00
|
|
|
MinGW64,
|
2009-07-13 22:22:23 +02:00
|
|
|
NetBSD,
|
2009-07-26 06:23:03 +02:00
|
|
|
OpenBSD,
|
2009-11-15 11:18:17 +01:00
|
|
|
Psp,
|
2009-08-18 06:43:27 +02:00
|
|
|
Solaris,
|
2009-10-16 04:06:30 +02:00
|
|
|
Win32,
|
2010-07-07 17:52:27 +02:00
|
|
|
Haiku,
|
|
|
|
Minix
|
2009-04-01 23:53:23 +02:00
|
|
|
};
|
2010-09-16 10:25:48 +02:00
|
|
|
enum EnvironmentType {
|
|
|
|
UnknownEnvironment
|
|
|
|
};
|
2010-11-13 05:17:15 +01:00
|
|
|
|
2009-04-01 23:53:23 +02:00
|
|
|
private:
|
|
|
|
std::string Data;
|
|
|
|
|
|
|
|
/// The parsed arch type (or InvalidArch if uninitialized).
|
|
|
|
mutable ArchType Arch;
|
|
|
|
|
|
|
|
/// The parsed vendor type.
|
|
|
|
mutable VendorType Vendor;
|
|
|
|
|
|
|
|
/// The parsed OS type.
|
|
|
|
mutable OSType OS;
|
|
|
|
|
2010-09-16 10:25:48 +02:00
|
|
|
/// The parsed Environment type.
|
|
|
|
mutable EnvironmentType Environment;
|
|
|
|
|
2009-04-01 23:53:23 +02:00
|
|
|
bool isInitialized() const { return Arch != InvalidArch; }
|
2010-08-12 13:31:39 +02:00
|
|
|
static ArchType ParseArch(StringRef ArchName);
|
|
|
|
static VendorType ParseVendor(StringRef VendorName);
|
|
|
|
static OSType ParseOS(StringRef OSName);
|
2010-09-16 10:25:48 +02:00
|
|
|
static EnvironmentType ParseEnvironment(StringRef EnvironmentName);
|
2009-04-01 23:53:23 +02:00
|
|
|
void Parse() const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// @name Constructors
|
|
|
|
/// @{
|
2010-11-13 05:17:15 +01:00
|
|
|
|
2009-08-07 03:43:45 +02:00
|
|
|
Triple() : Data(), Arch(InvalidArch) {}
|
2009-09-09 01:32:51 +02:00
|
|
|
explicit Triple(StringRef Str) : Data(Str), Arch(InvalidArch) {}
|
|
|
|
explicit Triple(StringRef ArchStr, StringRef VendorStr, StringRef OSStr)
|
2009-05-22 04:24:11 +02:00
|
|
|
: Data(ArchStr), Arch(InvalidArch) {
|
|
|
|
Data += '-';
|
|
|
|
Data += VendorStr;
|
|
|
|
Data += '-';
|
|
|
|
Data += OSStr;
|
|
|
|
}
|
2009-04-01 23:53:23 +02:00
|
|
|
|
2010-09-16 10:25:48 +02:00
|
|
|
explicit Triple(StringRef ArchStr, StringRef VendorStr, StringRef OSStr,
|
|
|
|
StringRef EnvironmentStr)
|
|
|
|
: Data(ArchStr), Arch(InvalidArch) {
|
|
|
|
Data += '-';
|
|
|
|
Data += VendorStr;
|
|
|
|
Data += '-';
|
|
|
|
Data += OSStr;
|
|
|
|
Data += '-';
|
|
|
|
Data += EnvironmentStr;
|
|
|
|
}
|
|
|
|
|
2010-08-12 13:31:39 +02:00
|
|
|
/// @}
|
|
|
|
/// @name Normalization
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
/// normalize - Turn an arbitrary machine specification into the canonical
|
|
|
|
/// triple form (or something sensible that the Triple class understands if
|
|
|
|
/// nothing better can reasonably be done). In particular, it handles the
|
|
|
|
/// common case in which otherwise valid components are in the wrong order.
|
|
|
|
static std::string normalize(StringRef Str);
|
|
|
|
|
2009-04-01 23:53:23 +02:00
|
|
|
/// @}
|
|
|
|
/// @name Typed Component Access
|
|
|
|
/// @{
|
2010-11-13 05:17:15 +01:00
|
|
|
|
2009-04-01 23:53:23 +02:00
|
|
|
/// getArch - Get the parsed architecture type of this triple.
|
2010-11-13 05:17:15 +01:00
|
|
|
ArchType getArch() const {
|
|
|
|
if (!isInitialized()) Parse();
|
2009-04-01 23:53:23 +02:00
|
|
|
return Arch;
|
|
|
|
}
|
2010-11-13 05:17:15 +01:00
|
|
|
|
2009-04-01 23:53:23 +02:00
|
|
|
/// getVendor - Get the parsed vendor type of this triple.
|
2010-11-13 05:17:15 +01:00
|
|
|
VendorType getVendor() const {
|
|
|
|
if (!isInitialized()) Parse();
|
2009-04-01 23:53:23 +02:00
|
|
|
return Vendor;
|
|
|
|
}
|
2010-11-13 05:17:15 +01:00
|
|
|
|
2009-04-01 23:53:23 +02:00
|
|
|
/// getOS - Get the parsed operating system type of this triple.
|
2010-11-13 05:17:15 +01:00
|
|
|
OSType getOS() const {
|
|
|
|
if (!isInitialized()) Parse();
|
2009-04-01 23:53:23 +02:00
|
|
|
return OS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// hasEnvironment - Does this triple have the optional environment
|
|
|
|
/// (fourth) component?
|
|
|
|
bool hasEnvironment() const {
|
|
|
|
return getEnvironmentName() != "";
|
|
|
|
}
|
|
|
|
|
2010-09-16 10:25:48 +02:00
|
|
|
/// getEnvironment - Get the parsed environment type of this triple.
|
2010-11-13 05:17:15 +01:00
|
|
|
EnvironmentType getEnvironment() const {
|
|
|
|
if (!isInitialized()) Parse();
|
2010-09-16 10:25:48 +02:00
|
|
|
return Environment;
|
|
|
|
}
|
|
|
|
|
2009-04-01 23:53:23 +02:00
|
|
|
/// @}
|
|
|
|
/// @name Direct Component Access
|
|
|
|
/// @{
|
|
|
|
|
2009-11-11 01:43:14 +01:00
|
|
|
const std::string &str() const { return Data; }
|
|
|
|
|
2009-04-01 23:53:23 +02:00
|
|
|
const std::string &getTriple() const { return Data; }
|
|
|
|
|
|
|
|
/// getArchName - Get the architecture (first) component of the
|
|
|
|
/// triple.
|
2009-07-26 05:31:47 +02:00
|
|
|
StringRef getArchName() const;
|
2009-04-01 23:53:23 +02:00
|
|
|
|
|
|
|
/// getVendorName - Get the vendor (second) component of the triple.
|
2009-07-26 05:31:47 +02:00
|
|
|
StringRef getVendorName() const;
|
2009-04-01 23:53:23 +02:00
|
|
|
|
|
|
|
/// getOSName - Get the operating system (third) component of the
|
|
|
|
/// triple.
|
2009-07-26 05:31:47 +02:00
|
|
|
StringRef getOSName() const;
|
2009-04-01 23:53:23 +02:00
|
|
|
|
|
|
|
/// getEnvironmentName - Get the optional environment (fourth)
|
|
|
|
/// component of the triple, or "" if empty.
|
2009-07-26 05:31:47 +02:00
|
|
|
StringRef getEnvironmentName() const;
|
2009-04-01 23:53:23 +02:00
|
|
|
|
|
|
|
/// getOSAndEnvironmentName - Get the operating system and optional
|
|
|
|
/// environment components as a single string (separated by a '-'
|
|
|
|
/// if the environment component is present).
|
2009-07-26 05:31:47 +02:00
|
|
|
StringRef getOSAndEnvironmentName() const;
|
2009-04-01 23:53:23 +02:00
|
|
|
|
2010-11-13 05:17:15 +01:00
|
|
|
|
2009-08-12 08:19:40 +02:00
|
|
|
/// getDarwinNumber - Parse the 'darwin number' out of the specific target
|
|
|
|
/// triple. For example, if we have darwin8.5 return 8,5,0. If any entry is
|
|
|
|
/// not defined, return 0's. This requires that the triple have an OSType of
|
|
|
|
/// darwin before it is called.
|
|
|
|
void getDarwinNumber(unsigned &Maj, unsigned &Min, unsigned &Revision) const;
|
2010-11-13 05:17:15 +01:00
|
|
|
|
2009-08-12 08:19:40 +02:00
|
|
|
/// getDarwinMajorNumber - Return just the major version number, this is
|
|
|
|
/// specialized because it is a common query.
|
|
|
|
unsigned getDarwinMajorNumber() const {
|
|
|
|
unsigned Maj, Min, Rev;
|
|
|
|
getDarwinNumber(Maj, Min, Rev);
|
|
|
|
return Maj;
|
|
|
|
}
|
2010-11-13 05:17:15 +01:00
|
|
|
|
2009-04-01 23:53:23 +02:00
|
|
|
/// @}
|
|
|
|
/// @name Mutators
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
/// setArch - Set the architecture (first) component of the triple
|
|
|
|
/// to a known type.
|
|
|
|
void setArch(ArchType Kind);
|
|
|
|
|
|
|
|
/// setVendor - Set the vendor (second) component of the triple to a
|
|
|
|
/// known type.
|
|
|
|
void setVendor(VendorType Kind);
|
|
|
|
|
|
|
|
/// setOS - Set the operating system (third) component of the triple
|
|
|
|
/// to a known type.
|
|
|
|
void setOS(OSType Kind);
|
|
|
|
|
2010-09-16 10:25:48 +02:00
|
|
|
/// setEnvironment - Set the environment (fourth) component of the triple
|
|
|
|
/// to a known type.
|
|
|
|
void setEnvironment(EnvironmentType Kind);
|
|
|
|
|
2009-04-01 23:53:23 +02:00
|
|
|
/// setTriple - Set all components to the new triple \arg Str.
|
2009-07-26 05:31:47 +02:00
|
|
|
void setTriple(const Twine &Str);
|
2009-04-01 23:53:23 +02:00
|
|
|
|
|
|
|
/// setArchName - Set the architecture (first) component of the
|
|
|
|
/// triple by name.
|
2009-11-06 11:58:06 +01:00
|
|
|
void setArchName(StringRef Str);
|
2009-04-01 23:53:23 +02:00
|
|
|
|
|
|
|
/// setVendorName - Set the vendor (second) component of the triple
|
|
|
|
/// by name.
|
2009-11-06 11:58:06 +01:00
|
|
|
void setVendorName(StringRef Str);
|
2009-04-01 23:53:23 +02:00
|
|
|
|
|
|
|
/// setOSName - Set the operating system (third) component of the
|
|
|
|
/// triple by name.
|
2009-11-06 11:58:06 +01:00
|
|
|
void setOSName(StringRef Str);
|
2009-04-01 23:53:23 +02:00
|
|
|
|
|
|
|
/// setEnvironmentName - Set the optional environment (fourth)
|
|
|
|
/// component of the triple by name.
|
2009-11-06 11:58:06 +01:00
|
|
|
void setEnvironmentName(StringRef Str);
|
2009-04-01 23:53:23 +02:00
|
|
|
|
|
|
|
/// setOSAndEnvironmentName - Set the operating system and optional
|
|
|
|
/// environment components with a single string.
|
2009-11-06 11:58:06 +01:00
|
|
|
void setOSAndEnvironmentName(StringRef Str);
|
2009-04-01 23:53:23 +02:00
|
|
|
|
2010-07-13 07:50:08 +02:00
|
|
|
/// getArchNameForAssembler - Get an architecture name that is understood by
|
|
|
|
/// the target assembler.
|
2009-11-17 19:48:27 +01:00
|
|
|
const char *getArchNameForAssembler();
|
|
|
|
|
2009-04-01 23:53:23 +02:00
|
|
|
/// @}
|
|
|
|
/// @name Static helpers for IDs.
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
/// getArchTypeName - Get the canonical name for the \arg Kind
|
|
|
|
/// architecture.
|
|
|
|
static const char *getArchTypeName(ArchType Kind);
|
|
|
|
|
2009-08-24 11:53:06 +02:00
|
|
|
/// getArchTypePrefix - Get the "prefix" canonical name for the \arg Kind
|
|
|
|
/// architecture. This is the prefix used by the architecture specific
|
|
|
|
/// builtins, and is suitable for passing to \see
|
|
|
|
/// Intrinsic::getIntrinsicForGCCBuiltin().
|
|
|
|
///
|
|
|
|
/// \return - The architecture prefix, or 0 if none is defined.
|
|
|
|
static const char *getArchTypePrefix(ArchType Kind);
|
|
|
|
|
2009-04-01 23:53:23 +02:00
|
|
|
/// getVendorTypeName - Get the canonical name for the \arg Kind
|
|
|
|
/// vendor.
|
|
|
|
static const char *getVendorTypeName(VendorType Kind);
|
|
|
|
|
2010-09-16 10:25:48 +02:00
|
|
|
/// getOSTypeName - Get the canonical name for the \arg Kind operating
|
|
|
|
/// system.
|
2009-04-01 23:53:23 +02:00
|
|
|
static const char *getOSTypeName(OSType Kind);
|
|
|
|
|
2010-09-16 10:25:48 +02:00
|
|
|
/// getEnvironmentTypeName - Get the canonical name for the \arg Kind
|
|
|
|
/// environment.
|
|
|
|
static const char *getEnvironmentTypeName(EnvironmentType Kind);
|
|
|
|
|
2009-09-09 01:32:51 +02:00
|
|
|
/// @}
|
|
|
|
/// @name Static helpers for converting alternate architecture names.
|
|
|
|
/// @{
|
|
|
|
|
2009-08-03 06:03:51 +02:00
|
|
|
/// getArchTypeForLLVMName - The canonical type for the given LLVM
|
|
|
|
/// architecture name (e.g., "x86").
|
2009-11-06 11:58:06 +01:00
|
|
|
static ArchType getArchTypeForLLVMName(StringRef Str);
|
2009-08-03 06:03:51 +02:00
|
|
|
|
2009-09-09 01:32:51 +02:00
|
|
|
/// getArchTypeForDarwinArchName - Get the architecture type for a "Darwin"
|
|
|
|
/// architecture name, for example as accepted by "gcc -arch" (see also
|
|
|
|
/// arch(3)).
|
2009-11-06 11:58:06 +01:00
|
|
|
static ArchType getArchTypeForDarwinArchName(StringRef Str);
|
2009-09-09 01:32:51 +02:00
|
|
|
|
2009-04-01 23:53:23 +02:00
|
|
|
/// @}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|