]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/include/llvm/CompilerDriver/Tool.h
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / include / llvm / CompilerDriver / Tool.h
1 //===--- Tool.h - The LLVM Compiler Driver ----------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open
6 // Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  Tool abstract base class - an interface to tool descriptions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_INCLUDE_COMPILER_DRIVER_TOOL_H
15 #define LLVM_INCLUDE_COMPILER_DRIVER_TOOL_H
16
17 #include "llvm/CompilerDriver/Action.h"
18
19 #include "llvm/ADT/IntrusiveRefCntPtr.h"
20 #include "llvm/ADT/StringSet.h"
21 #include "llvm/Support/Path.h"
22
23 #include <string>
24 #include <vector>
25 #include <utility>
26
27 namespace llvmc {
28
29   class LanguageMap;
30   typedef std::vector<std::pair<unsigned, std::string> > ArgsVector;
31   typedef std::vector<llvm::sys::Path> PathVector;
32   typedef std::vector<std::string> StrVector;
33   typedef llvm::StringSet<> InputLanguagesSet;
34
35   /// Tool - Represents a single tool.
36   class Tool : public llvm::RefCountedBaseVPTR {
37   public:
38
39     virtual ~Tool() {}
40
41     /// GenerateAction - Generate an Action given particular command-line
42     /// options. Returns non-zero value on error.
43     virtual int GenerateAction (Action& Out,
44                                 const PathVector& inFiles,
45                                 const bool HasChildren,
46                                 const llvm::sys::Path& TempDir,
47                                 const InputLanguagesSet& InLangs,
48                                 const LanguageMap& LangMap) const = 0;
49
50     /// GenerateAction - Generate an Action given particular command-line
51     /// options. Returns non-zero value on error.
52     virtual int GenerateAction (Action& Out,
53                                 const llvm::sys::Path& inFile,
54                                 const bool HasChildren,
55                                 const llvm::sys::Path& TempDir,
56                                 const InputLanguagesSet& InLangs,
57                                 const LanguageMap& LangMap) const = 0;
58
59     virtual const char*  Name() const = 0;
60     virtual const char** InputLanguages() const = 0;
61     virtual const char** OutputLanguages() const = 0;
62
63     virtual bool IsJoin() const = 0;
64     virtual bool WorksOnEmpty() const = 0;
65
66   protected:
67     /// OutFileName - Generate the output file name.
68     llvm::sys::Path OutFilename(const llvm::sys::Path& In,
69                                 const llvm::sys::Path& TempDir,
70                                 bool StopCompilation,
71                                 const char* OutputSuffix) const;
72
73     StrVector SortArgs(ArgsVector& Args) const;
74   };
75
76   /// JoinTool - A Tool that has an associated input file list.
77   class JoinTool : public Tool {
78   public:
79     void AddToJoinList(const llvm::sys::Path& P) { JoinList_.push_back(P); }
80     void ClearJoinList() { JoinList_.clear(); }
81     bool JoinListEmpty() const { return JoinList_.empty(); }
82
83     int GenerateAction(Action& Out,
84                        const bool HasChildren,
85                        const llvm::sys::Path& TempDir,
86                        const InputLanguagesSet& InLangs,
87                        const LanguageMap& LangMap) const {
88       return GenerateAction(Out, JoinList_, HasChildren, TempDir, InLangs,
89                             LangMap);
90     }
91     // We shouldn't shadow base class's version of GenerateAction.
92     using Tool::GenerateAction;
93
94   private:
95     PathVector JoinList_;
96   };
97
98 }
99
100 #endif // LLVM_INCLUDE_COMPILER_DRIVER_TOOL_H