aboutsummaryrefslogtreecommitdiff
path: root/tools/llvmc2/Core.h
blob: f82e0fa98ea85062753718c16eb5d190d129831d (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
//===--- Core.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.
//
//===----------------------------------------------------------------------===//
//
//  Core driver abstractions.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TOOLS_LLVMCC_CORE_H
#define LLVM_TOOLS_LLVMCC_CORE_H

#include "Utility.h"

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

#include <stdexcept>
#include <string>
#include <vector>

// Core functionality

namespace llvmcc {

  typedef std::vector<llvm::sys::Path> PathVector;
  typedef llvm::StringMap<std::string> LanguageMap;

  class Action {
    std::string Command_;
    std::vector<std::string> Args_;
  public:
    Action (std::string const& C,
            std::vector<std::string> const& A)
      : Command_(C), Args_(A)
    {}

    int Execute();
  };

  class Tool : public llvm::RefCountedBaseVPTR<Tool> {
  public:
    virtual Action GenerateAction (PathVector const& inFiles,
                                  llvm::sys::Path const& outFile) const = 0;

    virtual Action GenerateAction (llvm::sys::Path const& inFile,
                                  llvm::sys::Path const& outFile) const = 0;

    virtual std::string Name() const = 0;
    virtual std::string InputLanguage() const = 0;
    virtual std::string OutputLanguage() const = 0;
    virtual std::string OutputSuffix() const = 0;

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

    // Helper function that is called by the auto-generated code
    // Splits strings of the form ",-foo,-bar,-baz"
    // TOFIX: find a better name
    void UnpackValues (std::string const& from,
                       std::vector<std::string>& to) const;

    virtual ~Tool()
    {}
  };

  typedef std::vector<llvm::IntrusiveRefCntPtr<Tool> > ToolChain;
  typedef llvm::StringMap<ToolChain> ToolChainMap;

  struct CompilationGraph {
    ToolChainMap ToolChains;
    LanguageMap ExtsToLangs;

    int Build(llvm::sys::Path const& tempDir) const;
  };
}

#endif // LLVM_TOOLS_LLVMCC_CORE_H