aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/CompilerDriver/Tool.h
blob: 85d1690bcfedecb41073b2f3d457fea949811f08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//===--- Tool.h - The LLVM Compiler Driver ----------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open
// Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  Tool abstract base class - an interface to tool descriptions.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_INCLUDE_COMPILER_DRIVER_TOOL_H
#define LLVM_INCLUDE_COMPILER_DRIVER_TOOL_H

#include "llvm/CompilerDriver/Action.h"

#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/System/Path.h"

#include <string>
#include <vector>
#include <utility>

namespace llvmc {

  class LanguageMap;
  typedef std::vector<std::pair<unsigned, std::string> > ArgsVector;
  typedef std::vector<llvm::sys::Path> PathVector;
  typedef std::vector<std::string> StrVector;
  typedef llvm::StringSet<> InputLanguagesSet;

  /// Tool - Represents a single tool.
  class Tool : public llvm::RefCountedBaseVPTR<Tool> {
  public:

    virtual ~Tool() {}

    virtual Action GenerateAction (const PathVector& inFiles,
                                   bool  HasChildren,
                                   const llvm::sys::Path& TempDir,
                                   const InputLanguagesSet& InLangs,
                                   const LanguageMap& LangMap) const = 0;

    virtual Action GenerateAction (const llvm::sys::Path& inFile,
                                   bool  HasChildren,
                                   const llvm::sys::Path& TempDir,
                                   const InputLanguagesSet& InLangs,
                                   const LanguageMap& LangMap) const = 0;

    virtual const char*  Name() const = 0;
    virtual const char** InputLanguages() const = 0;
    virtual const char*  OutputLanguage() const = 0;

    virtual bool IsJoin() const = 0;
    virtual bool WorksOnEmpty() const = 0;

  protected:
    /// OutFileName - Generate the output file name.
    llvm::sys::Path OutFilename(const llvm::sys::Path& In,
                                const llvm::sys::Path& TempDir,
                                bool StopCompilation,
                                const char* OutputSuffix) const;

    StrVector SortArgs(ArgsVector& Args) const;
  };

  /// JoinTool - A Tool that has an associated input file list.
  class JoinTool : public Tool {
  public:
    void AddToJoinList(const llvm::sys::Path& P) { JoinList_.push_back(P); }
    void ClearJoinList() { JoinList_.clear(); }
    bool JoinListEmpty() const { return JoinList_.empty(); }

    Action GenerateAction(bool  HasChildren,
                          const llvm::sys::Path& TempDir,
                          const InputLanguagesSet& InLangs,
                          const LanguageMap& LangMap) const {
      return GenerateAction(JoinList_, HasChildren, TempDir, InLangs, LangMap);
    }
    // We shouldn't shadow base class's version of GenerateAction.
    using Tool::GenerateAction;

  private:
    PathVector JoinList_;
  };

}

#endif // LLVM_INCLUDE_COMPILER_DRIVER_TOOL_H