blob: b879c18c3f928d4869541661d08f1fab660f8d61 [file] [log] [blame]
Daniel Dunbar83b08eb2009-03-17 21:38:00 +00001//===--- ToolChains.h - ToolChain Implementations ---------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef CLANG_LIB_DRIVER_TOOLCHAINS_H_
11#define CLANG_LIB_DRIVER_TOOLCHAINS_H_
12
Daniel Dunbar670b7f42009-03-17 22:07:31 +000013#include "clang/Driver/Action.h"
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000014#include "clang/Driver/ToolChain.h"
15
Daniel Dunbar670b7f42009-03-17 22:07:31 +000016#include "llvm/ADT/DenseMap.h"
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000017#include "llvm/Support/Compiler.h"
18
Daniel Dunbar670b7f42009-03-17 22:07:31 +000019#include "Tools.h"
20
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000021namespace clang {
22namespace driver {
Daniel Dunbar985b8252009-03-17 22:18:43 +000023namespace toolchains {
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000024
Daniel Dunbar670b7f42009-03-17 22:07:31 +000025 /// Generic_GCC - A tool chain using the 'gcc' command to perform
26 /// all subcommands; this relies on gcc translating the majority of
27 /// command line options.
Daniel Dunbar985b8252009-03-17 22:18:43 +000028class VISIBILITY_HIDDEN Generic_GCC : public ToolChain {
Daniel Dunbar670b7f42009-03-17 22:07:31 +000029 mutable llvm::DenseMap<unsigned, Tool*> Tools;
30
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000031public:
32 Generic_GCC(const HostInfo &Host, const char *Arch, const char *Platform,
Daniel Dunbar670b7f42009-03-17 22:07:31 +000033 const char *OS) : ToolChain(Host, Arch, Platform, OS) {}
Daniel Dunbar7e4534d2009-03-18 01:09:40 +000034 ~Generic_GCC() {
35 // Free tool implementations.
36 for (llvm::DenseMap<unsigned, Tool*>::iterator
37 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
38 delete it->second;
39 }
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000040
41 virtual ArgList *TranslateArgs(ArgList &Args) const { return &Args; }
42
43 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const {
Daniel Dunbar670b7f42009-03-17 22:07:31 +000044 Action::ActionClass Key;
45 if (ShouldUseClangCompiler(C, JA))
46 Key = Action::AnalyzeJobClass;
47 else
48 Key = JA.getKind();
49
50 Tool *&T = Tools[Key];
51 if (!T) {
52 switch (Key) {
53 default:
54 assert(0 && "Invalid tool kind.");
55 case Action::PreprocessJobClass:
Daniel Dunbar31b1e542009-03-17 22:45:24 +000056 T = new tools::gcc::Preprocess(*this); break;
Daniel Dunbar670b7f42009-03-17 22:07:31 +000057 case Action::PrecompileJobClass:
Daniel Dunbar31b1e542009-03-17 22:45:24 +000058 T = new tools::gcc::Precompile(*this); break;
Daniel Dunbar670b7f42009-03-17 22:07:31 +000059 case Action::AnalyzeJobClass:
60 T = new tools::Clang(*this); break;
61 case Action::CompileJobClass:
Daniel Dunbar31b1e542009-03-17 22:45:24 +000062 T = new tools::gcc::Compile(*this); break;
Daniel Dunbar670b7f42009-03-17 22:07:31 +000063 case Action::AssembleJobClass:
Daniel Dunbar31b1e542009-03-17 22:45:24 +000064 T = new tools::gcc::Assemble(*this); break;
Daniel Dunbar670b7f42009-03-17 22:07:31 +000065 case Action::LinkJobClass:
Daniel Dunbar31b1e542009-03-17 22:45:24 +000066 T = new tools::gcc::Link(*this); break;
Daniel Dunbar670b7f42009-03-17 22:07:31 +000067 }
68 }
69
70 return *T;
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000071 }
72
73 virtual bool IsMathErrnoDefault() const { return true; }
74
75 virtual bool IsUnwindTablesDefault() const {
76 // FIXME: Gross; we should probably have some separate target definition,
77 // possibly even reusing the one in clang.
78 return getArchName() == "x86_64";
79 }
80
81 virtual const char *GetDefaultRelocationModel() const {
82 return "static";
83 }
84
85 virtual const char *GetForcedPicModel() const {
86 return 0;
87 }
88};
89
90} // end namespace toolchains
91} // end namespace driver
92} // end namespace clang
93
94#endif