Get rid of exceptions in llvmc.
[oota-llvm.git] / 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/System/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<Tool> {
37   public:
38
39     virtual ~Tool() {}
40
41     virtual int GenerateAction (Action& Out,
42                                 const PathVector& inFiles,
43                                 const bool HasChildren,
44                                 const llvm::sys::Path& TempDir,
45                                 const InputLanguagesSet& InLangs,
46                                 const LanguageMap& LangMap) const = 0;
47
48     virtual int GenerateAction (Action& Out,
49                                 const llvm::sys::Path& inFile,
50                                 const bool HasChildren,
51                                 const llvm::sys::Path& TempDir,
52                                 const InputLanguagesSet& InLangs,
53                                 const LanguageMap& LangMap) const = 0;
54
55     virtual const char*  Name() const = 0;
56     virtual const char** InputLanguages() const = 0;
57     virtual const char*  OutputLanguage() const = 0;
58
59     virtual bool IsJoin() const = 0;
60     virtual bool WorksOnEmpty() const = 0;
61
62   protected:
63     /// OutFileName - Generate the output file name.
64     llvm::sys::Path OutFilename(const llvm::sys::Path& In,
65                                 const llvm::sys::Path& TempDir,
66                                 bool StopCompilation,
67                                 const char* OutputSuffix) const;
68
69     StrVector SortArgs(ArgsVector& Args) const;
70   };
71
72   /// JoinTool - A Tool that has an associated input file list.
73   class JoinTool : public Tool {
74   public:
75     void AddToJoinList(const llvm::sys::Path& P) { JoinList_.push_back(P); }
76     void ClearJoinList() { JoinList_.clear(); }
77     bool JoinListEmpty() const { return JoinList_.empty(); }
78
79     int GenerateAction(Action& Out,
80                        const bool HasChildren,
81                        const llvm::sys::Path& TempDir,
82                        const InputLanguagesSet& InLangs,
83                        const LanguageMap& LangMap) const {
84       return GenerateAction(Out, JoinList_, HasChildren, TempDir, InLangs,
85                             LangMap);
86     }
87     // We shouldn't shadow base class's version of GenerateAction.
88     using Tool::GenerateAction;
89
90   private:
91     PathVector JoinList_;
92   };
93
94 }
95
96 #endif // LLVM_INCLUDE_COMPILER_DRIVER_TOOL_H