123e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar//===-- llvm/ADT/Triple.h - Target triple helper class ----------*- C++ -*-===//
223e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar//
323e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar//                     The LLVM Compiler Infrastructure
423e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar//
523e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar// This file is distributed under the University of Illinois Open Source
623e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar// License. See LICENSE.TXT for details.
723e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar//
823e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar//===----------------------------------------------------------------------===//
923e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
1023e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar#ifndef LLVM_ADT_TRIPLE_H
1123e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar#define LLVM_ADT_TRIPLE_H
1223e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
13b7fbcc9696e38ca26c7eb67077c04b51c846c9cbChris Lattner#include "llvm/ADT/Twine.h"
1423e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
15be1f788676ff6a71bc0324ac38af7626fdcf92b2Chris Lattner// Some system headers or GCC predefined macros conflict with identifiers in
16be1f788676ff6a71bc0324ac38af7626fdcf92b2Chris Lattner// this file.  Undefine them here.
172558c2bfbaa4bfd49ee8e06be78a0ccb0f3ff0e7Joerg Sonnenberger#undef NetBSD
18be1f788676ff6a71bc0324ac38af7626fdcf92b2Chris Lattner#undef mips
19be1f788676ff6a71bc0324ac38af7626fdcf92b2Chris Lattner#undef sparc
20be1f788676ff6a71bc0324ac38af7626fdcf92b2Chris Lattner
2123e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbarnamespace llvm {
2223e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
236f43379e23e96442a6d3a747ce921cacebcfe9acRichard Smith/// Triple - Helper class for working with autoconf configuration names. For
246f43379e23e96442a6d3a747ce921cacebcfe9acRichard Smith/// historical reasons, we also call these 'triples' (they used to contain
256f43379e23e96442a6d3a747ce921cacebcfe9acRichard Smith/// exactly three fields).
2623e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar///
276f43379e23e96442a6d3a747ce921cacebcfe9acRichard Smith/// Configuration names are strings in the canonical form:
2823e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar///   ARCHITECTURE-VENDOR-OPERATING_SYSTEM
2923e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar/// or
3023e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar///   ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
3123e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar///
3223e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar/// This class is used for clients which want to support arbitrary
336f43379e23e96442a6d3a747ce921cacebcfe9acRichard Smith/// configuration names, but also want to implement certain special
346f43379e23e96442a6d3a747ce921cacebcfe9acRichard Smith/// behavior for particular configurations. This class isolates the mapping
356f43379e23e96442a6d3a747ce921cacebcfe9acRichard Smith/// from the components of the configuration name to well known IDs.
3623e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar///
37651aa689cc37d5932fac0e096aa8b536f282aa21Daniel Dunbar/// At its core the Triple class is designed to be a wrapper for a triple
38335db223926931db204bf54d4accac6677b8e6b1Duncan Sands/// string; the constructor does not change or normalize the triple string.
39335db223926931db204bf54d4accac6677b8e6b1Duncan Sands/// Clients that need to handle the non-canonical triples that users often
40335db223926931db204bf54d4accac6677b8e6b1Duncan Sands/// specify should use the normalize method.
41651aa689cc37d5932fac0e096aa8b536f282aa21Daniel Dunbar///
426f43379e23e96442a6d3a747ce921cacebcfe9acRichard Smith/// See autoconf/config.guess for a glimpse into what configuration names
436f43379e23e96442a6d3a747ce921cacebcfe9acRichard Smith/// look like in practice.
4423e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbarclass Triple {
4523e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbarpublic:
4623e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  enum ArchType {
4723e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar    UnknownArch,
48ce8ca9ab0cc42be4f2ff5ed5d349eac5c90f9b04Jim Grosbach
4936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    arm,        // ARM (little endian): arm, armv.*, xscale
5036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    armeb,      // ARM (big endian): armeb
51dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    arm64,      // ARM64 (little endian): arm64
52dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    arm64_be,   // ARM64 (big endian): arm64_be
5336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    aarch64,    // AArch64 (little endian): aarch64
5436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    aarch64_be, // AArch64 (big endian): aarch64_be
5536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    hexagon,    // Hexagon: hexagon
5636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    mips,       // MIPS: mips, mipsallegrex
5736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    mipsel,     // MIPSEL: mipsel, mipsallegrexel
5836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    mips64,     // MIPS64: mips64
5936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    mips64el,   // MIPS64EL: mips64el
6036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    msp430,     // MSP430: msp430
6136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    ppc,        // PPC: powerpc
6236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    ppc64,      // PPC64: powerpc64, ppu
6336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    ppc64le,    // PPC64LE: powerpc64le
6436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    r600,       // R600: AMD GPUs HD2XXX - HD6XXX
6536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    sparc,      // Sparc: sparc
6636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    sparcv9,    // Sparcv9: Sparcv9
6736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    systemz,    // SystemZ: s390x
6836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    tce,        // TCE (http://tce.cs.tut.fi/): tce
6936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    thumb,      // Thumb (little endian): thumb, thumbv.*
7036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    thumbeb,    // Thumb (big endian): thumbeb
7136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    x86,        // X86: i[3-9]86
7236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    x86_64,     // X86-64: amd64, x86_64
7336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    xcore,      // XCore: xcore
7436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    nvptx,      // NVPTX: 32-bit
7536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    nvptx64,    // NVPTX: 64-bit
7636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    le32,       // le32: generic little-endian 32-bit CPU (PNaCl / Emscripten)
7736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    amdil,      // amdil: amd IL
7836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    spir,       // SPIR: standard portable IR for OpenCL 32-bit version
79cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    spir64,     // SPIR: standard portable IR for OpenCL 64-bit version
80cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    kalimba     // Kalimba: generic kalimba
8123e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  };
8223e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  enum VendorType {
8323e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar    UnknownVendor,
8423e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
85ce8ca9ab0cc42be4f2ff5ed5d349eac5c90f9b04Jim Grosbach    Apple,
866046cffbaf584b5d6bd7baf827794a5f91a07a9bJohn Thompson    PC,
87a47406c442a81aaf368b6e1a9b31d1730975a717Hal Finkel    SCEI,
88a47406c442a81aaf368b6e1a9b31d1730975a717Hal Finkel    BGP,
89d939cd68f40e6fa0ccd6bee6391374b66abd71a1Hal Finkel    BGQ,
902e522d05278a69cf75b41dcd4b358e46b5350425Duncan Sands    Freescale,
910ff4287fe2245f417ed78fa535fce360b8b8df23Justin Holewinski    IBM,
92cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    ImaginationTechnologies,
93cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    NVIDIA,
94cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    CSR
9523e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  };
9623e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  enum OSType {
9723e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar    UnknownOS,
9823e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
99852cd112edef55ff6fe334eeaeff153209f85666Duncan Sands    AuroraUX,
1006337f15b5a73c3eeb644d59cf34d37d4a278f5f7Daniel Dunbar    Cygwin,
10123e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar    Darwin,
1027eaf057e54e9b5f0469057c71d81dcfee90d9e12Daniel Dunbar    DragonFly,
10323e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar    FreeBSD,
1040dde4c00ee3b3514fcbabb7bca6b1f1189c4c5b9Daniel Dunbar    IOS,
105652b48bf231521642c53221a7d10a0acf2030f48Duncan Sands    KFreeBSD,
106cd1267d2d68f03026aed21e22f7e28efd510ec5fDuncan Sands    Linux,
107cc9fa81fe1675b29fa813945c52abee692229143Edward O'Callaghan    Lv2,        // PS3
1081af394766fe4e725d5af2fe82c2ad9cfcbc7dd34Daniel Dunbar    MacOSX,
1096904f05e607b6bbdfa96a2ebb628ebf3a1f21455NAKAMURA Takumi    MinGW32,    // i*86-pc-mingw32, *-w64-mingw32
110b8ac841c9a275cc8d4e1a92dd06cc99323e35fa2Chris Lattner    NetBSD,
1116337f15b5a73c3eeb644d59cf34d37d4a278f5f7Daniel Dunbar    OpenBSD,
112fdb0b7b555aaea054f85f654275fce56e5d7d1d3Daniel Dunbar    Solaris,
113a43fc3452b4c5a853054b6b671eacbdd05039130Chris Lattner    Win32,
11429269d03af6dc3feb69d0230831a059f39c03700Chris Lattner    Haiku,
1156ced1d12dd7ee18d65a6df6e66c9662753a5876dDouglas Gregor    Minix,
116fb23462889ff2dcd016a4b4169ebce94a878218eIvan Krasin    RTEMS,
1178181827d1b04f7bc6939ab099acc09ef2b247061Eli Bendersky    NaCl,       // Native Client
118f659c0de6c7a4684a2a30c344ce6827ea87032d8Eli Bendersky    CNK,        // BG/P Compute-Node Kernel
1192e522d05278a69cf75b41dcd4b358e46b5350425Duncan Sands    Bitrig,
1200ff4287fe2245f417ed78fa535fce360b8b8df23Justin Holewinski    AIX,
1210ff4287fe2245f417ed78fa535fce360b8b8df23Justin Holewinski    CUDA,       // NVIDIA CUDA
1220ff4287fe2245f417ed78fa535fce360b8b8df23Justin Holewinski    NVCL        // NVIDIA OpenCL
12323e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  };
1245754a4525625a67a6c9b4f63512ea9db6997bf05Duncan Sands  enum EnvironmentType {
125859f8183639346378ed29d1e04a4b070ebc7e97fRenato Golin    UnknownEnvironment,
126859f8183639346378ed29d1e04a4b070ebc7e97fRenato Golin
127859f8183639346378ed29d1e04a4b070ebc7e97fRenato Golin    GNU,
128859f8183639346378ed29d1e04a4b070ebc7e97fRenato Golin    GNUEABI,
1298887a0f34152b63a84e759b76694d6928d01b4eeRafael Espindola    GNUEABIHF,
1309dd2a3b1f2c253e20262535bb89b1ab6cc680eceEli Bendersky    GNUX32,
13136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    CODE16,
1322bffee2ee725047137d2523e31db9ecc7b246cbbEvan Cheng    EABI,
13336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    EABIHF,
1347bbd6e366b39157445cc921024a987e61ea68c00Andrew Kaylor    Android,
13536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
13636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    MSVC,
13736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    Itanium,
13836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    Cygnus,
13936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  };
14036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  enum ObjectFormatType {
14136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    UnknownObjectFormat,
14236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
14336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    COFF,
14436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    ELF,
14536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    MachO,
1465754a4525625a67a6c9b4f63512ea9db6997bf05Duncan Sands  };
147ce8ca9ab0cc42be4f2ff5ed5d349eac5c90f9b04Jim Grosbach
14823e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbarprivate:
14923e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  std::string Data;
15023e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
151124e51c0d2b521b0fb3aaaf2443403cd451b7857Chandler Carruth  /// The parsed arch type.
152124e51c0d2b521b0fb3aaaf2443403cd451b7857Chandler Carruth  ArchType Arch;
15323e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
15423e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// The parsed vendor type.
155124e51c0d2b521b0fb3aaaf2443403cd451b7857Chandler Carruth  VendorType Vendor;
15623e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
15723e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// The parsed OS type.
158124e51c0d2b521b0fb3aaaf2443403cd451b7857Chandler Carruth  OSType OS;
15923e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
1605754a4525625a67a6c9b4f63512ea9db6997bf05Duncan Sands  /// The parsed Environment type.
161124e51c0d2b521b0fb3aaaf2443403cd451b7857Chandler Carruth  EnvironmentType Environment;
1625754a4525625a67a6c9b4f63512ea9db6997bf05Duncan Sands
16336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// The object format type.
16436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  ObjectFormatType ObjectFormat;
16536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
16623e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbarpublic:
16723e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// @name Constructors
16823e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// @{
169ce8ca9ab0cc42be4f2ff5ed5d349eac5c90f9b04Jim Grosbach
1700523f41841d0860b2e175a4b20d1ecefd7295c4aChandler Carruth  /// \brief Default constructor is the same as an empty string and leaves all
1710523f41841d0860b2e175a4b20d1ecefd7295c4aChandler Carruth  /// triple fields unknown.
17236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Triple() : Data(), Arch(), Vendor(), OS(), Environment(), ObjectFormat() {}
17323e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
174cceb8f44a0ca3a9c57ab3a7f4947b2abda531cefChandler Carruth  explicit Triple(const Twine &Str);
175cceb8f44a0ca3a9c57ab3a7f4947b2abda531cefChandler Carruth  Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr);
176b7fbcc9696e38ca26c7eb67077c04b51c846c9cbChris Lattner  Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
177cceb8f44a0ca3a9c57ab3a7f4947b2abda531cefChandler Carruth         const Twine &EnvironmentStr);
1785754a4525625a67a6c9b4f63512ea9db6997bf05Duncan Sands
17923e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// @}
180335db223926931db204bf54d4accac6677b8e6b1Duncan Sands  /// @name Normalization
181335db223926931db204bf54d4accac6677b8e6b1Duncan Sands  /// @{
182335db223926931db204bf54d4accac6677b8e6b1Duncan Sands
183335db223926931db204bf54d4accac6677b8e6b1Duncan Sands  /// normalize - Turn an arbitrary machine specification into the canonical
184335db223926931db204bf54d4accac6677b8e6b1Duncan Sands  /// triple form (or something sensible that the Triple class understands if
185335db223926931db204bf54d4accac6677b8e6b1Duncan Sands  /// nothing better can reasonably be done).  In particular, it handles the
186335db223926931db204bf54d4accac6677b8e6b1Duncan Sands  /// common case in which otherwise valid components are in the wrong order.
187335db223926931db204bf54d4accac6677b8e6b1Duncan Sands  static std::string normalize(StringRef Str);
188335db223926931db204bf54d4accac6677b8e6b1Duncan Sands
189335db223926931db204bf54d4accac6677b8e6b1Duncan Sands  /// @}
19023e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// @name Typed Component Access
19123e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// @{
192ce8ca9ab0cc42be4f2ff5ed5d349eac5c90f9b04Jim Grosbach
19323e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// getArch - Get the parsed architecture type of this triple.
194124e51c0d2b521b0fb3aaaf2443403cd451b7857Chandler Carruth  ArchType getArch() const { return Arch; }
195ce8ca9ab0cc42be4f2ff5ed5d349eac5c90f9b04Jim Grosbach
19623e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// getVendor - Get the parsed vendor type of this triple.
197124e51c0d2b521b0fb3aaaf2443403cd451b7857Chandler Carruth  VendorType getVendor() const { return Vendor; }
198ce8ca9ab0cc42be4f2ff5ed5d349eac5c90f9b04Jim Grosbach
19923e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// getOS - Get the parsed operating system type of this triple.
200124e51c0d2b521b0fb3aaaf2443403cd451b7857Chandler Carruth  OSType getOS() const { return OS; }
20123e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
20223e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// hasEnvironment - Does this triple have the optional environment
20323e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// (fourth) component?
20423e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  bool hasEnvironment() const {
20523e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar    return getEnvironmentName() != "";
20623e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  }
20723e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
2085754a4525625a67a6c9b4f63512ea9db6997bf05Duncan Sands  /// getEnvironment - Get the parsed environment type of this triple.
209124e51c0d2b521b0fb3aaaf2443403cd451b7857Chandler Carruth  EnvironmentType getEnvironment() const { return Environment; }
2105754a4525625a67a6c9b4f63512ea9db6997bf05Duncan Sands
21136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// getFormat - Get the object format for this triple.
21236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  ObjectFormatType getObjectFormat() const { return ObjectFormat; }
21336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
214f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth  /// getOSVersion - Parse the version number from the OS name component of the
215f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth  /// triple, if present.
216f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth  ///
217f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth  /// For example, "fooos1.2.3" would return (1, 2, 3).
218f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth  ///
219f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth  /// If an entry is not defined, it will be returned as 0.
220f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth  void getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const;
221f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth
222f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth  /// getOSMajorVersion - Return just the major version number, this is
223f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth  /// specialized because it is a common query.
224f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth  unsigned getOSMajorVersion() const {
225f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth    unsigned Maj, Min, Micro;
226f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth    getOSVersion(Maj, Min, Micro);
227f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth    return Maj;
228f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth  }
229f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth
230bda59fdd71033a8ddfa30ec4b514753017f3da5cBob Wilson  /// getMacOSXVersion - Parse the version number as with getOSVersion and then
231bda59fdd71033a8ddfa30ec4b514753017f3da5cBob Wilson  /// translate generic "darwin" versions to the corresponding OS X versions.
232bda59fdd71033a8ddfa30ec4b514753017f3da5cBob Wilson  /// This may also be called with IOS triples but the OS X version number is
233bda59fdd71033a8ddfa30ec4b514753017f3da5cBob Wilson  /// just set to a constant 10.4.0 in that case.  Returns true if successful.
234bda59fdd71033a8ddfa30ec4b514753017f3da5cBob Wilson  bool getMacOSXVersion(unsigned &Major, unsigned &Minor,
235bda59fdd71033a8ddfa30ec4b514753017f3da5cBob Wilson                        unsigned &Micro) const;
236bda59fdd71033a8ddfa30ec4b514753017f3da5cBob Wilson
237ecee47eab409f6a6fada7ace3d9bee0a0146ac3fChad Rosier  /// getiOSVersion - Parse the version number as with getOSVersion.  This should
238ecee47eab409f6a6fada7ace3d9bee0a0146ac3fChad Rosier  /// only be called with IOS triples.
239ecee47eab409f6a6fada7ace3d9bee0a0146ac3fChad Rosier  void getiOSVersion(unsigned &Major, unsigned &Minor,
240ecee47eab409f6a6fada7ace3d9bee0a0146ac3fChad Rosier                     unsigned &Micro) const;
241ecee47eab409f6a6fada7ace3d9bee0a0146ac3fChad Rosier
24223e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// @}
24323e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// @name Direct Component Access
24423e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// @{
24523e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
2463691393b86c6849525dcdfb096d9da816ac1545eDaniel Dunbar  const std::string &str() const { return Data; }
2473691393b86c6849525dcdfb096d9da816ac1545eDaniel Dunbar
24823e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  const std::string &getTriple() const { return Data; }
24923e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
25023e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// getArchName - Get the architecture (first) component of the
25123e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// triple.
252a14d225ef4d3d8bd8ec9ec913246d1fb47d2edc1Daniel Dunbar  StringRef getArchName() const;
25323e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
25423e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// getVendorName - Get the vendor (second) component of the triple.
255a14d225ef4d3d8bd8ec9ec913246d1fb47d2edc1Daniel Dunbar  StringRef getVendorName() const;
25623e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
25723e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// getOSName - Get the operating system (third) component of the
25823e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// triple.
259a14d225ef4d3d8bd8ec9ec913246d1fb47d2edc1Daniel Dunbar  StringRef getOSName() const;
26023e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
26123e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// getEnvironmentName - Get the optional environment (fourth)
26223e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// component of the triple, or "" if empty.
263a14d225ef4d3d8bd8ec9ec913246d1fb47d2edc1Daniel Dunbar  StringRef getEnvironmentName() const;
26423e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
26523e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// getOSAndEnvironmentName - Get the operating system and optional
26623e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// environment components as a single string (separated by a '-'
26723e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// if the environment component is present).
268a14d225ef4d3d8bd8ec9ec913246d1fb47d2edc1Daniel Dunbar  StringRef getOSAndEnvironmentName() const;
26923e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
270f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth  /// @}
271f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth  /// @name Convenience Predicates
272f95b2dafc9a6ae88c6085aceeaf7a34af09df93bChandler Carruth  /// @{
273ce8ca9ab0cc42be4f2ff5ed5d349eac5c90f9b04Jim Grosbach
2746f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth  /// \brief Test whether the architecture is 64-bit
2756f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth  ///
2766f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth  /// Note that this tests for 64-bit pointer width, and nothing else. Note
2776f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth  /// that we intentionally expose only three predicates, 64-bit, 32-bit, and
2786f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth  /// 16-bit. The inner details of pointer width for particular architectures
2796f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth  /// is not summed up in the triple, and so only a coarse grained predicate
2806f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth  /// system is provided.
2816f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth  bool isArch64Bit() const;
2826f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth
2836f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth  /// \brief Test whether the architecture is 32-bit
2846f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth  ///
2856f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth  /// Note that this tests for 32-bit pointer width, and nothing else.
2866f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth  bool isArch32Bit() const;
2876f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth
2886f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth  /// \brief Test whether the architecture is 16-bit
2896f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth  ///
2906f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth  /// Note that this tests for 16-bit pointer width, and nothing else.
2916f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth  bool isArch16Bit() const;
2926f72ac4799a1a20c07cd96cc994dd6394ebff9a2Chandler Carruth
293e1fe09f6826f158def69cff89f3ce4e67e199bb5Daniel Dunbar  /// isOSVersionLT - Helper function for doing comparisons against version
294e1fe09f6826f158def69cff89f3ce4e67e199bb5Daniel Dunbar  /// numbers included in the target triple.
2954860fe0ad0447f8545bdbc1b327e82cb1ba41a51Daniel Dunbar  bool isOSVersionLT(unsigned Major, unsigned Minor = 0,
2964860fe0ad0447f8545bdbc1b327e82cb1ba41a51Daniel Dunbar                     unsigned Micro = 0) const {
2978974153870928527826ea5bad3359377b66666ccDaniel Dunbar    unsigned LHS[3];
2988974153870928527826ea5bad3359377b66666ccDaniel Dunbar    getOSVersion(LHS[0], LHS[1], LHS[2]);
2998974153870928527826ea5bad3359377b66666ccDaniel Dunbar
3008974153870928527826ea5bad3359377b66666ccDaniel Dunbar    if (LHS[0] != Major)
3018974153870928527826ea5bad3359377b66666ccDaniel Dunbar      return LHS[0] < Major;
3028974153870928527826ea5bad3359377b66666ccDaniel Dunbar    if (LHS[1] != Minor)
3038974153870928527826ea5bad3359377b66666ccDaniel Dunbar      return LHS[1] < Minor;
3048974153870928527826ea5bad3359377b66666ccDaniel Dunbar    if (LHS[2] != Micro)
3058974153870928527826ea5bad3359377b66666ccDaniel Dunbar      return LHS[1] < Micro;
3068974153870928527826ea5bad3359377b66666ccDaniel Dunbar
3078974153870928527826ea5bad3359377b66666ccDaniel Dunbar    return false;
3088974153870928527826ea5bad3359377b66666ccDaniel Dunbar  }
3098974153870928527826ea5bad3359377b66666ccDaniel Dunbar
31069f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth  /// isMacOSXVersionLT - Comparison function for checking OS X version
31169f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth  /// compatibility, which handles supporting skewed version numbering schemes
31269f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth  /// used by the "darwin" triples.
31369f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth  unsigned isMacOSXVersionLT(unsigned Major, unsigned Minor = 0,
314aa7507d68dcc04f3118a05b5dff4123ded03253eBill Wendling                             unsigned Micro = 0) const {
31569f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth    assert(isMacOSX() && "Not an OS X triple!");
31669f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth
31769f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth    // If this is OS X, expect a sane version number.
31869f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth    if (getOS() == Triple::MacOSX)
31969f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth      return isOSVersionLT(Major, Minor, Micro);
32069f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth
32169f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth    // Otherwise, compare to the "Darwin" number.
32269f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth    assert(Major == 10 && "Unexpected major version");
32369f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth    return isOSVersionLT(Minor + 4, Micro, 0);
32469f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth  }
32569f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth
326558692fd0a31d4d3ae4fd09a3a02f80da2e44e5cDaniel Dunbar  /// isMacOSX - Is this a Mac OS X triple. For legacy reasons, we support both
3274860fe0ad0447f8545bdbc1b327e82cb1ba41a51Daniel Dunbar  /// "darwin" and "osx" as OS X triples.
328558692fd0a31d4d3ae4fd09a3a02f80da2e44e5cDaniel Dunbar  bool isMacOSX() const {
329398a5ca9cdf6256775904d957d6c40b63d45636cDaniel Dunbar    return getOS() == Triple::Darwin || getOS() == Triple::MacOSX;
3304860fe0ad0447f8545bdbc1b327e82cb1ba41a51Daniel Dunbar  }
3314860fe0ad0447f8545bdbc1b327e82cb1ba41a51Daniel Dunbar
332e502bba8c6dde1d95cc350c7935a1aea0b41465fMichael Gottesman  /// Is this an iOS triple.
333e502bba8c6dde1d95cc350c7935a1aea0b41465fMichael Gottesman  bool isiOS() const {
334e502bba8c6dde1d95cc350c7935a1aea0b41465fMichael Gottesman    return getOS() == Triple::IOS;
335e502bba8c6dde1d95cc350c7935a1aea0b41465fMichael Gottesman  }
336e502bba8c6dde1d95cc350c7935a1aea0b41465fMichael Gottesman
337e1fe09f6826f158def69cff89f3ce4e67e199bb5Daniel Dunbar  /// isOSDarwin - Is this a "Darwin" OS (OS X or iOS).
338e1fe09f6826f158def69cff89f3ce4e67e199bb5Daniel Dunbar  bool isOSDarwin() const {
339e502bba8c6dde1d95cc350c7935a1aea0b41465fMichael Gottesman    return isMacOSX() || isiOS();
340e1fe09f6826f158def69cff89f3ce4e67e199bb5Daniel Dunbar  }
341e1fe09f6826f158def69cff89f3ce4e67e199bb5Daniel Dunbar
342dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  bool isOSFreeBSD() const {
343dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    return getOS() == Triple::FreeBSD;
344dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  }
345dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines
34636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool isWindowsMSVCEnvironment() const {
34736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return getOS() == Triple::Win32 &&
34836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines           (getEnvironment() == Triple::UnknownEnvironment ||
34936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines            getEnvironment() == Triple::MSVC);
35036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
35136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
35236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool isKnownWindowsMSVCEnvironment() const {
35336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return getOS() == Triple::Win32 && getEnvironment() == Triple::MSVC;
35436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
35536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
356cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  bool isWindowsItaniumEnvironment() const {
357cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    return getOS() == Triple::Win32 && getEnvironment() == Triple::Itanium;
358cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  }
359cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines
36036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool isWindowsCygwinEnvironment() const {
36136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return getOS() == Triple::Cygwin ||
36236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines           (getOS() == Triple::Win32 && getEnvironment() == Triple::Cygnus);
36336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
36436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
36536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool isWindowsGNUEnvironment() const {
36636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return getOS() == Triple::MinGW32 ||
36736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines           (getOS() == Triple::Win32 && getEnvironment() == Triple::GNU);
36836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
36936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
37069f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth  /// \brief Tests for either Cygwin or MinGW OS
37169f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth  bool isOSCygMing() const {
37236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return isWindowsCygwinEnvironment() || isWindowsGNUEnvironment();
37369f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth  }
37469f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth
37579ef34d1802eeea48aa4e9346abecbf8ceb2e8ebDavid Majnemer  /// \brief Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
37679ef34d1802eeea48aa4e9346abecbf8ceb2e8ebDavid Majnemer  bool isOSMSVCRT() const {
377dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    return isWindowsMSVCEnvironment() || isWindowsGNUEnvironment();
37879ef34d1802eeea48aa4e9346abecbf8ceb2e8ebDavid Majnemer  }
37979ef34d1802eeea48aa4e9346abecbf8ceb2e8ebDavid Majnemer
380441c557708b5dbe91f1799baf790ad418c23ea70Cameron Esfahani  /// \brief Tests whether the OS is Windows.
381e1fe09f6826f158def69cff89f3ce4e67e199bb5Daniel Dunbar  bool isOSWindows() const {
38269f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth    return getOS() == Triple::Win32 || isOSCygMing();
383e1fe09f6826f158def69cff89f3ce4e67e199bb5Daniel Dunbar  }
384e1fe09f6826f158def69cff89f3ce4e67e199bb5Daniel Dunbar
385105fdbb1312bac8c46ba2e28e9d6a70c0af151c8Eli Bendersky  /// \brief Tests whether the OS is NaCl (Native Client)
386105fdbb1312bac8c46ba2e28e9d6a70c0af151c8Eli Bendersky  bool isOSNaCl() const {
387105fdbb1312bac8c46ba2e28e9d6a70c0af151c8Eli Bendersky    return getOS() == Triple::NaCl;
388105fdbb1312bac8c46ba2e28e9d6a70c0af151c8Eli Bendersky  }
389105fdbb1312bac8c46ba2e28e9d6a70c0af151c8Eli Bendersky
390441c557708b5dbe91f1799baf790ad418c23ea70Cameron Esfahani  /// \brief Tests whether the OS is Linux.
391441c557708b5dbe91f1799baf790ad418c23ea70Cameron Esfahani  bool isOSLinux() const {
392441c557708b5dbe91f1799baf790ad418c23ea70Cameron Esfahani    return getOS() == Triple::Linux;
393441c557708b5dbe91f1799baf790ad418c23ea70Cameron Esfahani  }
394441c557708b5dbe91f1799baf790ad418c23ea70Cameron Esfahani
39569f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth  /// \brief Tests whether the OS uses the ELF binary format.
39669f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth  bool isOSBinFormatELF() const {
39736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return getObjectFormat() == Triple::ELF;
39869f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth  }
3994860fe0ad0447f8545bdbc1b327e82cb1ba41a51Daniel Dunbar
40069f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth  /// \brief Tests whether the OS uses the COFF binary format.
40169f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth  bool isOSBinFormatCOFF() const {
40236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return getObjectFormat() == Triple::COFF;
40369f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth  }
4044860fe0ad0447f8545bdbc1b327e82cb1ba41a51Daniel Dunbar
40569f44692bf5fea1d908fc06487e173837d06ea58Chandler Carruth  /// \brief Tests whether the environment is MachO.
40636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool isOSBinFormatMachO() const {
40736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return getObjectFormat() == Triple::MachO;
4084860fe0ad0447f8545bdbc1b327e82cb1ba41a51Daniel Dunbar  }
4094d59ff95d8f28089dce9997a38a334c18f50a641Eric Christopher
41023e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// @}
41123e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// @name Mutators
41223e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// @{
41323e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
41423e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// setArch - Set the architecture (first) component of the triple
41523e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// to a known type.
41623e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  void setArch(ArchType Kind);
41723e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
41823e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// setVendor - Set the vendor (second) component of the triple to a
41923e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// known type.
42023e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  void setVendor(VendorType Kind);
42123e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
42223e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// setOS - Set the operating system (third) component of the triple
42323e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// to a known type.
42423e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  void setOS(OSType Kind);
42523e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
4265754a4525625a67a6c9b4f63512ea9db6997bf05Duncan Sands  /// setEnvironment - Set the environment (fourth) component of the triple
4275754a4525625a67a6c9b4f63512ea9db6997bf05Duncan Sands  /// to a known type.
4285754a4525625a67a6c9b4f63512ea9db6997bf05Duncan Sands  void setEnvironment(EnvironmentType Kind);
4295754a4525625a67a6c9b4f63512ea9db6997bf05Duncan Sands
43036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// setObjectFormat - Set the object file format
43136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  void setObjectFormat(ObjectFormatType Kind);
43236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
4332d9eb72178af8e79dc6432cd1b7d29bde16da1b9Dmitri Gribenko  /// setTriple - Set all components to the new triple \p Str.
434a14d225ef4d3d8bd8ec9ec913246d1fb47d2edc1Daniel Dunbar  void setTriple(const Twine &Str);
43523e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
43623e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// setArchName - Set the architecture (first) component of the
43723e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// triple by name.
4382928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar  void setArchName(StringRef Str);
43923e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
44023e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// setVendorName - Set the vendor (second) component of the triple
44123e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// by name.
4422928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar  void setVendorName(StringRef Str);
44323e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
44423e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// setOSName - Set the operating system (third) component of the
44523e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// triple by name.
4462928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar  void setOSName(StringRef Str);
44723e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
44823e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// setEnvironmentName - Set the optional environment (fourth)
44923e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// component of the triple by name.
4502928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar  void setEnvironmentName(StringRef Str);
45123e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
45223e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// setOSAndEnvironmentName - Set the operating system and optional
45323e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// environment components with a single string.
4542928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar  void setOSAndEnvironmentName(StringRef Str);
45523e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
4560764e39a921ae424e2ac8c7ba114b67040eba8f6Eric Christopher  /// getArchNameForAssembler - Get an architecture name that is understood by
4570764e39a921ae424e2ac8c7ba114b67040eba8f6Eric Christopher  /// the target assembler.
45851cdac02c4125b8545728eb30ab5f54e437d6377Viktor Kutuzov  const char *getArchNameForAssembler();
45951cdac02c4125b8545728eb30ab5f54e437d6377Viktor Kutuzov
46023e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// @}
4617d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth  /// @name Helpers to build variants of a particular triple.
4627d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth  /// @{
4637d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth
4647d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth  /// \brief Form a triple with a 32-bit variant of the current architecture.
4657d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth  ///
4667d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth  /// This can be used to move across "families" of architectures where useful.
4677d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth  ///
4687d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth  /// \returns A new triple with a 32-bit architecture or an unknown
4697d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth  ///          architecture if no such variant can be found.
4707d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth  llvm::Triple get32BitArchVariant() const;
4717d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth
4727d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth  /// \brief Form a triple with a 64-bit variant of the current architecture.
4737d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth  ///
4747d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth  /// This can be used to move across "families" of architectures where useful.
4757d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth  ///
4767d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth  /// \returns A new triple with a 64-bit architecture or an unknown
4777d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth  ///          architecture if no such variant can be found.
4787d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth  llvm::Triple get64BitArchVariant() const;
4797d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth
4807d5a289f2d7d75c29df4c17856ab54dd28dec508Chandler Carruth  /// @}
48123e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// @name Static helpers for IDs.
48223e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// @{
48323e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
4842d9eb72178af8e79dc6432cd1b7d29bde16da1b9Dmitri Gribenko  /// getArchTypeName - Get the canonical name for the \p Kind architecture.
48523e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  static const char *getArchTypeName(ArchType Kind);
48623e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
4872d9eb72178af8e79dc6432cd1b7d29bde16da1b9Dmitri Gribenko  /// getArchTypePrefix - Get the "prefix" canonical name for the \p Kind
488688b55b436b4a3a036f0827dc484b5f219ace1a3Daniel Dunbar  /// architecture. This is the prefix used by the architecture specific
489688b55b436b4a3a036f0827dc484b5f219ace1a3Daniel Dunbar  /// builtins, and is suitable for passing to \see
490688b55b436b4a3a036f0827dc484b5f219ace1a3Daniel Dunbar  /// Intrinsic::getIntrinsicForGCCBuiltin().
491688b55b436b4a3a036f0827dc484b5f219ace1a3Daniel Dunbar  ///
492688b55b436b4a3a036f0827dc484b5f219ace1a3Daniel Dunbar  /// \return - The architecture prefix, or 0 if none is defined.
493688b55b436b4a3a036f0827dc484b5f219ace1a3Daniel Dunbar  static const char *getArchTypePrefix(ArchType Kind);
494688b55b436b4a3a036f0827dc484b5f219ace1a3Daniel Dunbar
4952d9eb72178af8e79dc6432cd1b7d29bde16da1b9Dmitri Gribenko  /// getVendorTypeName - Get the canonical name for the \p Kind vendor.
49623e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  static const char *getVendorTypeName(VendorType Kind);
49723e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
4982d9eb72178af8e79dc6432cd1b7d29bde16da1b9Dmitri Gribenko  /// getOSTypeName - Get the canonical name for the \p Kind operating system.
49923e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  static const char *getOSTypeName(OSType Kind);
50023e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
5012d9eb72178af8e79dc6432cd1b7d29bde16da1b9Dmitri Gribenko  /// getEnvironmentTypeName - Get the canonical name for the \p Kind
5025754a4525625a67a6c9b4f63512ea9db6997bf05Duncan Sands  /// environment.
5035754a4525625a67a6c9b4f63512ea9db6997bf05Duncan Sands  static const char *getEnvironmentTypeName(EnvironmentType Kind);
5045754a4525625a67a6c9b4f63512ea9db6997bf05Duncan Sands
505baf9b562309ae0f82774a6a3b4ffb9417a43a032Daniel Dunbar  /// @}
506baf9b562309ae0f82774a6a3b4ffb9417a43a032Daniel Dunbar  /// @name Static helpers for converting alternate architecture names.
507baf9b562309ae0f82774a6a3b4ffb9417a43a032Daniel Dunbar  /// @{
508baf9b562309ae0f82774a6a3b4ffb9417a43a032Daniel Dunbar
5093c2d4bf97fa96fe171883cd80e4ea93fc43563e6Daniel Dunbar  /// getArchTypeForLLVMName - The canonical type for the given LLVM
5103c2d4bf97fa96fe171883cd80e4ea93fc43563e6Daniel Dunbar  /// architecture name (e.g., "x86").
5112928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar  static ArchType getArchTypeForLLVMName(StringRef Str);
5123c2d4bf97fa96fe171883cd80e4ea93fc43563e6Daniel Dunbar
51323e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar  /// @}
51423e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar};
51523e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
51623e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar} // End llvm namespace
51723e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
51823e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar
51923e97b05da7b31ed97e5ccc6330670da0173ca2eDaniel Dunbar#endif
520