ToolChain.h revision 00577ada44c889fbe311d61c51a8da89e65c7c9a
12ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar//===--- ToolChain.h - Collections of tools for one platform ----*- C++ -*-===// 22ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar// 32ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar// The LLVM Compiler Infrastructure 42ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar// 52ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar// This file is distributed under the University of Illinois Open Source 62ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar// License. See LICENSE.TXT for details. 72ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar// 82ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar//===----------------------------------------------------------------------===// 92ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 102ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar#ifndef CLANG_DRIVER_TOOLCHAIN_H_ 112ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar#define CLANG_DRIVER_TOOLCHAIN_H_ 122ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 134180011fb8cef06adec04d30486b1bf3b99aa8b8Daniel Dunbar#include "clang/Driver/Types.h" 140edefebc10fbc627d55d53936fc66178d1c08da1Daniel Dunbar#include "llvm/ADT/SmallVector.h" 15cb8ab23f7c800b041aeb6fc38c341d1aa0da86bfDaniel Dunbar#include "llvm/ADT/Triple.h" 162ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar#include "llvm/System/Path.h" 172ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar#include <string> 182ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 192ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbarnamespace clang { 202ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbarnamespace driver { 2100577ada44c889fbe311d61c51a8da89e65c7c9aDaniel Dunbar class ArgList; 222ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar class Compilation; 23f3cad36e59a41b5767fe662b5ac8911ee174b801Daniel Dunbar class DerivedArgList; 24ee788e70fcd0adf76103b17c78ac658d4ea30c9bDaniel Dunbar class Driver; 25fa0cda430f7324404ddd74f41a3b8f5f749d7ec1Daniel Dunbar class HostInfo; 26f3cad36e59a41b5767fe662b5ac8911ee174b801Daniel Dunbar class InputArgList; 272ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar class JobAction; 282ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar class Tool; 292ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 302ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar/// ToolChain - Access to tools for a single platform. 312ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbarclass ToolChain { 320edefebc10fbc627d55d53936fc66178d1c08da1Daniel Dunbarpublic: 330edefebc10fbc627d55d53936fc66178d1c08da1Daniel Dunbar typedef llvm::SmallVector<std::string, 4> path_list; 340edefebc10fbc627d55d53936fc66178d1c08da1Daniel Dunbar 350edefebc10fbc627d55d53936fc66178d1c08da1Daniel Dunbarprivate: 36fa0cda430f7324404ddd74f41a3b8f5f749d7ec1Daniel Dunbar const HostInfo &Host; 37cb8ab23f7c800b041aeb6fc38c341d1aa0da86bfDaniel Dunbar const llvm::Triple Triple; 382ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 390edefebc10fbc627d55d53936fc66178d1c08da1Daniel Dunbar /// The list of toolchain specific path prefixes to search for 400edefebc10fbc627d55d53936fc66178d1c08da1Daniel Dunbar /// files. 410edefebc10fbc627d55d53936fc66178d1c08da1Daniel Dunbar path_list FilePaths; 420edefebc10fbc627d55d53936fc66178d1c08da1Daniel Dunbar 430edefebc10fbc627d55d53936fc66178d1c08da1Daniel Dunbar /// The list of toolchain specific path prefixes to search for 440edefebc10fbc627d55d53936fc66178d1c08da1Daniel Dunbar /// programs. 450edefebc10fbc627d55d53936fc66178d1c08da1Daniel Dunbar path_list ProgramPaths; 460edefebc10fbc627d55d53936fc66178d1c08da1Daniel Dunbar 472ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbarprotected: 48cb8ab23f7c800b041aeb6fc38c341d1aa0da86bfDaniel Dunbar ToolChain(const HostInfo &Host, const llvm::Triple &_Triple); 492ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 502ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbarpublic: 512ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar virtual ~ToolChain(); 522ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 532ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar // Accessors 542ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 55ee788e70fcd0adf76103b17c78ac658d4ea30c9bDaniel Dunbar const Driver &getDriver() const; 5612cfe036d809173a25af0104844d4bb66a92252bDaniel Dunbar const llvm::Triple &getTriple() const { return Triple; } 5712cfe036d809173a25af0104844d4bb66a92252bDaniel Dunbar 58ba30bbe4e36a30a274da809a11a42f9cdc168e92Rafael Espindola llvm::Triple::ArchType getArch() const { return Triple.getArch(); } 59f22d1fd96d6056a2f271b0f7353b31f47547127bBenjamin Kramer llvm::StringRef getArchName() const { return Triple.getArchName(); } 60f22d1fd96d6056a2f271b0f7353b31f47547127bBenjamin Kramer llvm::StringRef getPlatform() const { return Triple.getVendorName(); } 61f22d1fd96d6056a2f271b0f7353b31f47547127bBenjamin Kramer llvm::StringRef getOS() const { return Triple.getOSName(); } 622ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 63cb8ab23f7c800b041aeb6fc38c341d1aa0da86bfDaniel Dunbar std::string getTripleString() const { 64cb8ab23f7c800b041aeb6fc38c341d1aa0da86bfDaniel Dunbar return Triple.getTriple(); 65cd8e4c44dd068956e9181381be3ee2d49a0fac52Daniel Dunbar } 66cd8e4c44dd068956e9181381be3ee2d49a0fac52Daniel Dunbar 67bbafc5c7645e41a52af688ef8f71a28b19fe4326Daniel Dunbar path_list &getFilePaths() { return FilePaths; } 68bbafc5c7645e41a52af688ef8f71a28b19fe4326Daniel Dunbar const path_list &getFilePaths() const { return FilePaths; } 690edefebc10fbc627d55d53936fc66178d1c08da1Daniel Dunbar 70bbafc5c7645e41a52af688ef8f71a28b19fe4326Daniel Dunbar path_list &getProgramPaths() { return ProgramPaths; } 71bbafc5c7645e41a52af688ef8f71a28b19fe4326Daniel Dunbar const path_list &getProgramPaths() const { return ProgramPaths; } 720edefebc10fbc627d55d53936fc66178d1c08da1Daniel Dunbar 732ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar // Tool access. 742ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 750dcb9a3705743ec972af37f48ead81a0939e3958Daniel Dunbar /// TranslateArgs - Create a new derived argument list for any argument 76279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar /// translations this ToolChain may wish to perform, or 0 if no tool chain 77279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar /// specific translations are needed. 780dcb9a3705743ec972af37f48ead81a0939e3958Daniel Dunbar /// 790dcb9a3705743ec972af37f48ead81a0939e3958Daniel Dunbar /// \param BoundArch - The bound architecture name, or 0. 80279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args, 81279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar const char *BoundArch) const { 82279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar return 0; 83279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar } 842ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 852ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar /// SelectTool - Choose a tool to use to handle the action \arg JA. 862ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const = 0; 872ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 882ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar // Helper methods 892ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 904a7e88978cf646ad10d654020cb00b3877069210Daniel Dunbar std::string GetFilePath(const char *Name) const; 914a7e88978cf646ad10d654020cb00b3877069210Daniel Dunbar std::string GetProgramPath(const char *Name, bool WantFile = false) const; 922ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 932ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar // Platform defaults information 942ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 954180011fb8cef06adec04d30486b1bf3b99aa8b8Daniel Dunbar /// LookupTypeForExtension - Return the default language type to use for the 964180011fb8cef06adec04d30486b1bf3b99aa8b8Daniel Dunbar /// given extension. 974180011fb8cef06adec04d30486b1bf3b99aa8b8Daniel Dunbar virtual types::ID LookupTypeForExtension(const char *Ext) const; 984180011fb8cef06adec04d30486b1bf3b99aa8b8Daniel Dunbar 999e5cc6b703b2d0013f13800c2ffbeb3cf85fcfadDaniel Dunbar /// IsBlocksDefault - Does this tool chain enable -fblocks by default. 1009e5cc6b703b2d0013f13800c2ffbeb3cf85fcfadDaniel Dunbar virtual bool IsBlocksDefault() const { return false; } 1019e5cc6b703b2d0013f13800c2ffbeb3cf85fcfadDaniel Dunbar 1028767cbc475ed96397b6f08617814eeb9cab121bdDaniel Dunbar /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as 1038767cbc475ed96397b6f08617814eeb9cab121bdDaniel Dunbar /// by default. 1048767cbc475ed96397b6f08617814eeb9cab121bdDaniel Dunbar virtual bool IsIntegratedAssemblerDefault() const { return false; } 1058767cbc475ed96397b6f08617814eeb9cab121bdDaniel Dunbar 1069e5cc6b703b2d0013f13800c2ffbeb3cf85fcfadDaniel Dunbar /// IsObjCNonFragileABIDefault - Does this tool chain set 1079e5cc6b703b2d0013f13800c2ffbeb3cf85fcfadDaniel Dunbar /// -fobjc-nonfragile-abi by default. 1089e5cc6b703b2d0013f13800c2ffbeb3cf85fcfadDaniel Dunbar virtual bool IsObjCNonFragileABIDefault() const { return false; } 1099e5cc6b703b2d0013f13800c2ffbeb3cf85fcfadDaniel Dunbar 110609508ce95732e7e7010f79c5207613eced7c9cbDaniel Dunbar /// IsObjCLegacyDispatchDefault - Does this tool chain set 111609508ce95732e7e7010f79c5207613eced7c9cbDaniel Dunbar /// -fobjc-legacy-dispatch by default (this is only used with the non-fragile 112609508ce95732e7e7010f79c5207613eced7c9cbDaniel Dunbar /// ABI). 113609508ce95732e7e7010f79c5207613eced7c9cbDaniel Dunbar virtual bool IsObjCLegacyDispatchDefault() const { return false; } 114609508ce95732e7e7010f79c5207613eced7c9cbDaniel Dunbar 115f643b9b338b797a824447207d7eab5f1187f4f34Daniel Dunbar /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the 116f643b9b338b797a824447207d7eab5f1187f4f34Daniel Dunbar /// mixed dispatch method be used? 117f643b9b338b797a824447207d7eab5f1187f4f34Daniel Dunbar virtual bool UseObjCMixedDispatch() const { return false; } 118f643b9b338b797a824447207d7eab5f1187f4f34Daniel Dunbar 1199e5cc6b703b2d0013f13800c2ffbeb3cf85fcfadDaniel Dunbar /// GetDefaultStackProtectorLevel - Get the default stack protector level for 1209e5cc6b703b2d0013f13800c2ffbeb3cf85fcfadDaniel Dunbar /// this tool chain (0=off, 1=on, 2=all). 1219e5cc6b703b2d0013f13800c2ffbeb3cf85fcfadDaniel Dunbar virtual unsigned GetDefaultStackProtectorLevel() const { return 0; } 1229e5cc6b703b2d0013f13800c2ffbeb3cf85fcfadDaniel Dunbar 1232ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables 1242ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar /// by default. 1252ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar virtual bool IsUnwindTablesDefault() const = 0; 1262ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 1272ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar /// GetDefaultRelocationModel - Return the LLVM name of the default 1282ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar /// relocation model for this tool chain. 1292ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar virtual const char *GetDefaultRelocationModel() const = 0; 1302ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 1312ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar /// GetForcedPicModel - Return the LLVM name of the forced PIC model 1322ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar /// for this tool chain, or 0 if this tool chain does not force a 1332ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar /// particular PIC mode. 1342ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar virtual const char *GetForcedPicModel() const = 0; 135f2d8b9f967a1ab53ee9fdbcc3ac0a4ee0a83a26eDaniel Dunbar 13643a9b3263cb0bcb050cc75c15b3e6a8951e6b97aDaniel Dunbar /// Does this tool chain support Objective-C garbage collection. 13743a9b3263cb0bcb050cc75c15b3e6a8951e6b97aDaniel Dunbar virtual bool SupportsObjCGC() const { return false; } 13843a9b3263cb0bcb050cc75c15b3e6a8951e6b97aDaniel Dunbar 139f2d8b9f967a1ab53ee9fdbcc3ac0a4ee0a83a26eDaniel Dunbar /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf 140f2d8b9f967a1ab53ee9fdbcc3ac0a4ee0a83a26eDaniel Dunbar /// compile unit information. 141f2d8b9f967a1ab53ee9fdbcc3ac0a4ee0a83a26eDaniel Dunbar virtual bool UseDwarfDebugFlags() const { return false; } 142b2987d159a88ab0ee2e40c884eb4d77b42ab89b6Daniel Dunbar 143b2987d159a88ab0ee2e40c884eb4d77b42ab89b6Daniel Dunbar /// UseSjLjExceptions - Does this tool chain use SjLj exceptions. 1448aa79947cbf8f0f3ac82cdd36a823ac1bb53cab4Benjamin Kramer virtual bool UseSjLjExceptions() const { return false; } 14500577ada44c889fbe311d61c51a8da89e65c7c9aDaniel Dunbar 14600577ada44c889fbe311d61c51a8da89e65c7c9aDaniel Dunbar /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking 14700577ada44c889fbe311d61c51a8da89e65c7c9aDaniel Dunbar /// command line arguments into account. 14800577ada44c889fbe311d61c51a8da89e65c7c9aDaniel Dunbar virtual std::string ComputeLLVMTriple(const ArgList &Args) const; 14900577ada44c889fbe311d61c51a8da89e65c7c9aDaniel Dunbar 15000577ada44c889fbe311d61c51a8da89e65c7c9aDaniel Dunbar /// ComputeEffectiveClangTriple - Return the Clang triple to use for this 15100577ada44c889fbe311d61c51a8da89e65c7c9aDaniel Dunbar /// target, which may take into account the command line arguments. For 15200577ada44c889fbe311d61c51a8da89e65c7c9aDaniel Dunbar /// example, on Darwin the -mmacosx-version-min= command line argument (which 15300577ada44c889fbe311d61c51a8da89e65c7c9aDaniel Dunbar /// sets the deployment target) determines the version in the triple passed to 15400577ada44c889fbe311d61c51a8da89e65c7c9aDaniel Dunbar /// Clang. 15500577ada44c889fbe311d61c51a8da89e65c7c9aDaniel Dunbar virtual std::string ComputeEffectiveClangTriple(const ArgList &Args) const; 1562ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar}; 1572ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 1582ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar} // end namespace driver 1592ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar} // end namespace clang 1602ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar 1612ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar#endif 162