1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===-- llvm/ADT/Triple.h - Target triple helper class ----------*- C++ -*-===// 2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// The LLVM Compiler Infrastructure 4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source 6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details. 7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifndef LLVM_ADT_TRIPLE_H 11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define LLVM_ADT_TRIPLE_H 12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 1319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#include "llvm/ADT/Twine.h" 14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Some system headers or GCC predefined macros conflict with identifiers in 16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// this file. Undefine them here. 17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#undef mips 18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#undef sparc 19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace llvm { 21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// Triple - Helper class for working with target triples. 23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// 2419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/// Target triples are strings in the canonical form: 25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// ARCHITECTURE-VENDOR-OPERATING_SYSTEM 26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// or 27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT 28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// 29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// This class is used for clients which want to support arbitrary 30894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// target triples, but also want to implement certain special 31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// behavior for particular targets. This class isolates the mapping 32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// from the components of the target triple to well known IDs. 33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// 34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// At its core the Triple class is designed to be a wrapper for a triple 3519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/// string; the constructor does not change or normalize the triple string. 3619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/// Clients that need to handle the non-canonical triples that users often 3719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/// specify should use the normalize method. 38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// 3919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/// See autoconf/config.guess for a glimpse into what triples look like in 40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// practice. 41894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass Triple { 42894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanpublic: 43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman enum ArchType { 44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman UnknownArch, 4519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman alpha, // Alpha: alpha 47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman arm, // ARM; arm, armv.*, xscale 48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman bfin, // Blackfin: bfin 49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman cellspu, // CellSPU: spu, cellspu 50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman mips, // MIPS: mips, mipsallegrex 51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman mipsel, // MIPSEL: mipsel, mipsallegrexel, psp 5219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman mips64, // MIPS64: mips64 5319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman mips64el,// MIPS64EL: mips64el 54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman msp430, // MSP430: msp430 55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman ppc, // PPC: powerpc 56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman ppc64, // PPC64: powerpc64, ppu 57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman sparc, // Sparc: sparc 58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman sparcv9, // Sparcv9: Sparcv9 59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman systemz, // SystemZ: s390x 60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman tce, // TCE (http://tce.cs.tut.fi/): tce 61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman thumb, // Thumb: thumb, thumbv.* 62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman x86, // X86: i[3-9]86 63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman x86_64, // X86-64: amd64, x86_64 64894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman xcore, // XCore: xcore 65894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman mblaze, // MBlaze: mblaze 6619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman ptx32, // PTX: ptx (32-bit) 6719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman ptx64, // PTX: ptx (64-bit) 6819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman le32, // le32: generic little-endian 32-bit CPU (PNaCl / Emscripten) 6919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman amdil, // amdil: amd IL 70894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 71894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman InvalidArch 72894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman }; 73894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman enum VendorType { 74894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman UnknownVendor, 75894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 7619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman Apple, 7719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman PC, 7819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman SCEI 79894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman }; 80894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman enum OSType { 81894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman UnknownOS, 82894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 83894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman AuroraUX, 84894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Cygwin, 85894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Darwin, 86894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman DragonFly, 87894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman FreeBSD, 8819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman IOS, 8919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman KFreeBSD, 90894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Linux, 91894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Lv2, // PS3 9219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman MacOSX, 9319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman MinGW32, // i*86-pc-mingw32, *-w64-mingw32 94894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman NetBSD, 95894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman OpenBSD, 96894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Psp, 97894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Solaris, 98894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Win32, 99894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Haiku, 10019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman Minix, 10119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman RTEMS, 10219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman NativeClient 10319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman }; 10419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman enum EnvironmentType { 10519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman UnknownEnvironment, 10619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 10719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman GNU, 10819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman GNUEABI, 10919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman EABI, 11019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman MachO 111894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman }; 11219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 113894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanprivate: 114894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman std::string Data; 115894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 116894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// The parsed arch type (or InvalidArch if uninitialized). 117894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman mutable ArchType Arch; 118894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 119894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// The parsed vendor type. 120894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman mutable VendorType Vendor; 121894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 122894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// The parsed OS type. 123894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman mutable OSType OS; 124894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 12519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// The parsed Environment type. 12619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman mutable EnvironmentType Environment; 12719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 128894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman bool isInitialized() const { return Arch != InvalidArch; } 12919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static ArchType ParseArch(StringRef ArchName); 13019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static VendorType ParseVendor(StringRef VendorName); 13119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static OSType ParseOS(StringRef OSName); 13219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static EnvironmentType ParseEnvironment(StringRef EnvironmentName); 133894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void Parse() const; 134894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 135894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanpublic: 136894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @name Constructors 137894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @{ 13819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 139894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Triple() : Data(), Arch(InvalidArch) {} 14019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman explicit Triple(const Twine &Str) : Data(Str.str()), Arch(InvalidArch) {} 14119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr) 14219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()), 14319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman Arch(InvalidArch) { 14419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 14519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 14619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr, 14719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman const Twine &EnvironmentStr) 14819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') + 14919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman EnvironmentStr).str()), Arch(InvalidArch) { 150894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 151894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 152894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @} 15319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// @name Normalization 15419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// @{ 15519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 15619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// normalize - Turn an arbitrary machine specification into the canonical 15719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// triple form (or something sensible that the Triple class understands if 15819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// nothing better can reasonably be done). In particular, it handles the 15919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// common case in which otherwise valid components are in the wrong order. 16019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static std::string normalize(StringRef Str); 16119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 16219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// @} 163894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @name Typed Component Access 164894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @{ 16519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 166894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getArch - Get the parsed architecture type of this triple. 16719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman ArchType getArch() const { 16819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman if (!isInitialized()) Parse(); 169894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return Arch; 170894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 17119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 172894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getVendor - Get the parsed vendor type of this triple. 17319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman VendorType getVendor() const { 17419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman if (!isInitialized()) Parse(); 175894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return Vendor; 176894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 17719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 178894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getOS - Get the parsed operating system type of this triple. 17919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman OSType getOS() const { 18019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman if (!isInitialized()) Parse(); 181894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return OS; 182894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 183894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 184894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// hasEnvironment - Does this triple have the optional environment 185894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// (fourth) component? 186894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman bool hasEnvironment() const { 187894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return getEnvironmentName() != ""; 188894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 189894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 19019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// getEnvironment - Get the parsed environment type of this triple. 19119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman EnvironmentType getEnvironment() const { 19219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman if (!isInitialized()) Parse(); 19319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return Environment; 19419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 19519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 196894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @} 197894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @name Direct Component Access 198894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @{ 199894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 200894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman const std::string &str() const { return Data; } 201894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 202894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman const std::string &getTriple() const { return Data; } 203894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 204894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getArchName - Get the architecture (first) component of the 205894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// triple. 206894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman StringRef getArchName() const; 207894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 208894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getVendorName - Get the vendor (second) component of the triple. 209894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman StringRef getVendorName() const; 210894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 211894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getOSName - Get the operating system (third) component of the 212894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// triple. 213894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman StringRef getOSName() const; 214894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 215894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getEnvironmentName - Get the optional environment (fourth) 216894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// component of the triple, or "" if empty. 217894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman StringRef getEnvironmentName() const; 218894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 219894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getOSAndEnvironmentName - Get the operating system and optional 220894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// environment components as a single string (separated by a '-' 221894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// if the environment component is present). 222894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman StringRef getOSAndEnvironmentName() const; 223894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 22419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// getOSVersion - Parse the version number from the OS name component of the 22519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// triple, if present. 22619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// 22719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// For example, "fooos1.2.3" would return (1, 2, 3). 22819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// 22919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// If an entry is not defined, it will be returned as 0. 23019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman void getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const; 23119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 23219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// getOSMajorVersion - Return just the major version number, this is 233894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// specialized because it is a common query. 23419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman unsigned getOSMajorVersion() const { 23519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman unsigned Maj, Min, Micro; 23619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman getOSVersion(Maj, Min, Micro); 237894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return Maj; 238894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 23919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 24019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// isOSVersionLT - Helper function for doing comparisons against version 24119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// numbers included in the target triple. 24219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman bool isOSVersionLT(unsigned Major, unsigned Minor = 0, 24319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman unsigned Micro = 0) const { 24419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman unsigned LHS[3]; 24519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman getOSVersion(LHS[0], LHS[1], LHS[2]); 24619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 24719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman if (LHS[0] != Major) 24819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return LHS[0] < Major; 24919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman if (LHS[1] != Minor) 25019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return LHS[1] < Minor; 25119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman if (LHS[2] != Micro) 25219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return LHS[1] < Micro; 25319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 25419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return false; 25519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 25619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 25719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// isMacOSX - Is this a Mac OS X triple. For legacy reasons, we support both 25819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// "darwin" and "osx" as OS X triples. 25919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman bool isMacOSX() const { 26019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return getOS() == Triple::Darwin || getOS() == Triple::MacOSX; 26119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 26219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 26319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// isOSDarwin - Is this a "Darwin" OS (OS X or iOS). 26419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman bool isOSDarwin() const { 26519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return isMacOSX() || getOS() == Triple::IOS; 26619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 26719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 26819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// isOSWindows - Is this a "Windows" OS. 26919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman bool isOSWindows() const { 27019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return getOS() == Triple::Win32 || getOS() == Triple::Cygwin || 27119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman getOS() == Triple::MinGW32; 27219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 27319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 27419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// isMacOSXVersionLT - Comparison function for checking OS X version 27519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// compatibility, which handles supporting skewed version numbering schemes 27619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// used by the "darwin" triples. 27719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman unsigned isMacOSXVersionLT(unsigned Major, unsigned Minor = 0, 27819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman unsigned Micro = 0) const { 27919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman assert(isMacOSX() && "Not an OS X triple!"); 28019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 28119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman // If this is OS X, expect a sane version number. 28219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman if (getOS() == Triple::MacOSX) 28319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return isOSVersionLT(Major, Minor, Micro); 28419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 28519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman // Otherwise, compare to the "Darwin" number. 28619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman assert(Major == 10 && "Unexpected major version"); 28719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return isOSVersionLT(Minor + 4, Micro, 0); 28819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 28919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 290894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @} 291894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @name Mutators 292894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @{ 293894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 294894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// setArch - Set the architecture (first) component of the triple 295894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// to a known type. 296894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setArch(ArchType Kind); 297894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 298894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// setVendor - Set the vendor (second) component of the triple to a 299894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// known type. 300894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setVendor(VendorType Kind); 301894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 302894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// setOS - Set the operating system (third) component of the triple 303894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// to a known type. 304894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setOS(OSType Kind); 305894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 30619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// setEnvironment - Set the environment (fourth) component of the triple 30719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// to a known type. 30819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman void setEnvironment(EnvironmentType Kind); 30919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 310894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// setTriple - Set all components to the new triple \arg Str. 311894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setTriple(const Twine &Str); 312894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 313894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// setArchName - Set the architecture (first) component of the 314894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// triple by name. 315894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setArchName(StringRef Str); 316894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 317894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// setVendorName - Set the vendor (second) component of the triple 318894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// by name. 319894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setVendorName(StringRef Str); 320894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 321894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// setOSName - Set the operating system (third) component of the 322894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// triple by name. 323894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setOSName(StringRef Str); 324894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 325894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// setEnvironmentName - Set the optional environment (fourth) 326894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// component of the triple by name. 327894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setEnvironmentName(StringRef Str); 328894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 329894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// setOSAndEnvironmentName - Set the operating system and optional 330894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// environment components with a single string. 331894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setOSAndEnvironmentName(StringRef Str); 332894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 333894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getArchNameForAssembler - Get an architecture name that is understood by 334894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// the target assembler. 335894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman const char *getArchNameForAssembler(); 336894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 337894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @} 338894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @name Static helpers for IDs. 339894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @{ 340894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 341894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getArchTypeName - Get the canonical name for the \arg Kind 342894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// architecture. 343894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static const char *getArchTypeName(ArchType Kind); 344894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 345894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getArchTypePrefix - Get the "prefix" canonical name for the \arg Kind 346894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// architecture. This is the prefix used by the architecture specific 347894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// builtins, and is suitable for passing to \see 348894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// Intrinsic::getIntrinsicForGCCBuiltin(). 349894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// 350894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// \return - The architecture prefix, or 0 if none is defined. 351894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static const char *getArchTypePrefix(ArchType Kind); 352894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 353894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getVendorTypeName - Get the canonical name for the \arg Kind 354894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// vendor. 355894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static const char *getVendorTypeName(VendorType Kind); 356894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 35719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// getOSTypeName - Get the canonical name for the \arg Kind operating 35819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// system. 359894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static const char *getOSTypeName(OSType Kind); 360894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 36119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// getEnvironmentTypeName - Get the canonical name for the \arg Kind 36219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// environment. 36319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static const char *getEnvironmentTypeName(EnvironmentType Kind); 36419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 365894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @} 366894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @name Static helpers for converting alternate architecture names. 367894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @{ 368894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 369894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getArchTypeForLLVMName - The canonical type for the given LLVM 370894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// architecture name (e.g., "x86"). 371894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static ArchType getArchTypeForLLVMName(StringRef Str); 372894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 373894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getArchTypeForDarwinArchName - Get the architecture type for a "Darwin" 374894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// architecture name, for example as accepted by "gcc -arch" (see also 375894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// arch(3)). 376894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static ArchType getArchTypeForDarwinArchName(StringRef Str); 377894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 378894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// @} 379894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}; 380894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 381894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} // End llvm namespace 382894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 383894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 384894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif 385