The Ada front-end from the LLVM 2.2 release
[oota-llvm.git] / tools / llvmc2 / Core.h
1 //===--- Core.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 //  Core driver abstractions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TOOLS_LLVMCC_CORE_H
15 #define LLVM_TOOLS_LLVMCC_CORE_H
16
17 #include "Utility.h"
18
19 #include "llvm/ADT/IntrusiveRefCntPtr.h"
20 #include "llvm/ADT/StringMap.h"
21 #include "llvm/System/Path.h"
22
23 #include <stdexcept>
24 #include <string>
25 #include <vector>
26
27 // Core functionality
28
29 namespace llvmcc {
30
31   typedef std::vector<llvm::sys::Path> PathVector;
32   typedef llvm::StringMap<std::string> LanguageMap;
33
34   class Action {
35     std::string Command_;
36     std::vector<std::string> Args_;
37   public:
38     Action (std::string const& C,
39             std::vector<std::string> const& A)
40       : Command_(C), Args_(A)
41     {}
42
43     int Execute();
44   };
45
46   class Tool : public llvm::RefCountedBaseVPTR<Tool> {
47   public:
48     virtual Action GenerateAction (PathVector const& inFiles,
49                                   llvm::sys::Path const& outFile) const = 0;
50
51     virtual Action GenerateAction (llvm::sys::Path const& inFile,
52                                   llvm::sys::Path const& outFile) const = 0;
53
54     virtual std::string Name() const = 0;
55     virtual std::string InputLanguage() const = 0;
56     virtual std::string OutputLanguage() const = 0;
57     virtual std::string OutputSuffix() const = 0;
58
59     virtual bool IsLast() const = 0;
60     virtual bool IsJoin() const = 0;
61
62     // Helper function that is called by the auto-generated code
63     // Splits strings of the form ",-foo,-bar,-baz"
64     // TOFIX: find a better name
65     void UnpackValues (std::string const& from,
66                        std::vector<std::string>& to) const;
67
68     virtual ~Tool()
69     {}
70   };
71
72   typedef std::vector<llvm::IntrusiveRefCntPtr<Tool> > ToolChain;
73   typedef llvm::StringMap<ToolChain> ToolChainMap;
74
75   struct CompilationGraph {
76     ToolChainMap ToolChains;
77     LanguageMap ExtsToLangs;
78
79     int Build(llvm::sys::Path const& tempDir) const;
80   };
81 }
82
83 #endif // LLVM_TOOLS_LLVMCC_CORE_H