diff options
author | dim <dim@FreeBSD.org> | 2010-09-17 15:48:55 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2010-09-17 15:48:55 +0000 |
commit | 5d5cc59cc77afe655b3707cb0e69e0827b444cad (patch) | |
tree | 36453626c792cccd91f783a38a169d610a6b9db9 /include/llvm/CompilerDriver | |
parent | 786a18553586229ad99ecb5ecde8a9d914c45e27 (diff) | |
download | FreeBSD-src-5d5cc59cc77afe655b3707cb0e69e0827b444cad.zip FreeBSD-src-5d5cc59cc77afe655b3707cb0e69e0827b444cad.tar.gz |
Vendor import of llvm r114020 (from the release_28 branch):
http://llvm.org/svn/llvm-project/llvm/branches/release_28@114020
Approved by: rpaulo (mentor)
Diffstat (limited to 'include/llvm/CompilerDriver')
-rw-r--r-- | include/llvm/CompilerDriver/Action.h | 16 | ||||
-rw-r--r-- | include/llvm/CompilerDriver/AutoGenerated.h | 40 | ||||
-rw-r--r-- | include/llvm/CompilerDriver/BuiltinOptions.h | 4 | ||||
-rw-r--r-- | include/llvm/CompilerDriver/Common.td | 41 | ||||
-rw-r--r-- | include/llvm/CompilerDriver/CompilationGraph.h | 95 | ||||
-rw-r--r-- | include/llvm/CompilerDriver/Error.h | 20 | ||||
-rw-r--r-- | include/llvm/CompilerDriver/ForceLinkage.h | 122 | ||||
-rw-r--r-- | include/llvm/CompilerDriver/ForceLinkageMacros.h | 29 | ||||
-rw-r--r-- | include/llvm/CompilerDriver/Main.h | 21 | ||||
-rw-r--r-- | include/llvm/CompilerDriver/Main.inc | 14 | ||||
-rw-r--r-- | include/llvm/CompilerDriver/Plugin.h | 81 | ||||
-rw-r--r-- | include/llvm/CompilerDriver/Tool.h | 40 |
12 files changed, 167 insertions, 356 deletions
diff --git a/include/llvm/CompilerDriver/Action.h b/include/llvm/CompilerDriver/Action.h index 7014139..f2b7965 100644 --- a/include/llvm/CompilerDriver/Action.h +++ b/include/llvm/CompilerDriver/Action.h @@ -34,12 +34,16 @@ namespace llvmc { std::string OutFile_; public: - Action (const std::string& C, const StrVector& A, - bool S, const std::string& O) - : Command_(C), Args_(A), StopCompilation_(S), OutFile_(O) - {} - - /// Execute - Executes the represented action. + void Construct (const std::string& C, const StrVector& A, + bool S, const std::string& O) { + Command_ = C; + Args_ = A; + StopCompilation_ = S; + OutFile_ = O; + } + bool IsConstructed () { return (Command_.size() != 0);} + + /// Execute - Executes the command. Returns -1 on error. int Execute () const; bool StopCompilation () const { return StopCompilation_; } const std::string& OutFile() { return OutFile_; } diff --git a/include/llvm/CompilerDriver/AutoGenerated.h b/include/llvm/CompilerDriver/AutoGenerated.h new file mode 100644 index 0000000..7b926c6 --- /dev/null +++ b/include/llvm/CompilerDriver/AutoGenerated.h @@ -0,0 +1,40 @@ +//===--- AutoGenerated.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. +// +//===----------------------------------------------------------------------===// +// +// Interface to the autogenerated driver code. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_INCLUDE_COMPILER_DRIVER_AUTOGENERATED_H +#define LLVM_INCLUDE_COMPILER_DRIVER_AUTOGENERATED_H + +namespace llvmc { + class LanguageMap; + class CompilationGraph; + + namespace autogenerated { + + int PreprocessOptions(); + int PopulateLanguageMap(LanguageMap& langMap); + int PopulateCompilationGraph(CompilationGraph& graph); + + inline int RunInitialization (LanguageMap& M, CompilationGraph& G) { + if (int ret = PreprocessOptions()) + return ret; + if (int ret = PopulateLanguageMap(M)) + return ret; + if (int ret = PopulateCompilationGraph(G)) + return ret; + + return 0; + } + } +} + +#endif // LLVM_INCLUDE_COMPILER_DRIVER_AUTOGENERATED_H diff --git a/include/llvm/CompilerDriver/BuiltinOptions.h b/include/llvm/CompilerDriver/BuiltinOptions.h index 0c1bbe2..7b9c15c 100644 --- a/include/llvm/CompilerDriver/BuiltinOptions.h +++ b/include/llvm/CompilerDriver/BuiltinOptions.h @@ -18,6 +18,8 @@ #include <string> +namespace llvmc { + namespace SaveTempsEnum { enum Values { Cwd, Obj, Unset }; } extern llvm::cl::list<std::string> InputFilenames; @@ -32,4 +34,6 @@ extern llvm::cl::opt<bool> ViewGraph; extern llvm::cl::opt<bool> WriteGraph; extern llvm::cl::opt<SaveTempsEnum::Values> SaveTemps; +} // End namespace llvmc. + #endif // LLVM_INCLUDE_COMPILER_DRIVER_BUILTIN_OPTIONS_H diff --git a/include/llvm/CompilerDriver/Common.td b/include/llvm/CompilerDriver/Common.td index 31a627d..84e8783 100644 --- a/include/llvm/CompilerDriver/Common.td +++ b/include/llvm/CompilerDriver/Common.td @@ -32,6 +32,7 @@ def actions; def alias_option; def switch_option; +def switch_list_option; def parameter_option; def parameter_list_option; def prefix_option; @@ -39,7 +40,6 @@ def prefix_list_option; // Possible option properties. -def extern; def help; def hidden; def init; @@ -93,17 +93,8 @@ def error; def set_option; def unset_option; -// Increase/decrease the edge weight. +// Increase the edge weight. def inc_weight; -def dec_weight; - -// Empty DAG marker. -def empty_dag_marker; - -// Used to specify plugin priority. -class PluginPriority<int p> { - int priority = p; -} // Option list - a single place to specify options. class OptionList<list<dag> l> { @@ -117,31 +108,17 @@ class OptionPreprocessor<dag d> { // Map from suffixes to language names -class LangToSuffixes<string str, list<string> lst> { - string lang = str; - list<string> suffixes = lst; -} +def lang_to_suffixes; -class LanguageMap<list<LangToSuffixes> lst> { - list<LangToSuffixes> map = lst; +class LanguageMap<list<dag> l> { + list<dag> map = l; } // Compilation graph -class EdgeBase<string t1, string t2, dag d> { - string a = t1; - string b = t2; - dag weight = d; -} - -class Edge<string t1, string t2> : EdgeBase<t1, t2, (empty_dag_marker)>; - -// Edge and SimpleEdge are synonyms. -class SimpleEdge<string t1, string t2> : EdgeBase<t1, t2, (empty_dag_marker)>; - -// Optionally enabled edge. -class OptionalEdge<string t1, string t2, dag props> : EdgeBase<t1, t2, props>; +def edge; +def optional_edge; -class CompilationGraph<list<EdgeBase> lst> { - list<EdgeBase> edges = lst; +class CompilationGraph<list<dag> l> { + list<dag> edges = l; } diff --git a/include/llvm/CompilerDriver/CompilationGraph.h b/include/llvm/CompilerDriver/CompilationGraph.h index ba6ff47..619c904 100644 --- a/include/llvm/CompilerDriver/CompilationGraph.h +++ b/include/llvm/CompilerDriver/CompilationGraph.h @@ -36,7 +36,7 @@ namespace llvmc { public: /// GetLanguage - Find the language name corresponding to a given file. - const std::string& GetLanguage(const llvm::sys::Path&) const; + const std::string* GetLanguage(const llvm::sys::Path&) const; }; /// Edge - Represents an edge of the compilation graph. @@ -46,7 +46,7 @@ namespace llvmc { virtual ~Edge() {} const std::string& ToolName() const { return ToolName_; } - virtual unsigned Weight(const InputLanguagesSet& InLangs) const = 0; + virtual int Weight(const InputLanguagesSet& InLangs) const = 0; private: std::string ToolName_; }; @@ -55,7 +55,7 @@ namespace llvmc { class SimpleEdge : public Edge { public: SimpleEdge(const std::string& T) : Edge(T) {} - unsigned Weight(const InputLanguagesSet&) const { return 1; } + int Weight(const InputLanguagesSet&) const { return 1; } }; /// Node - A node (vertex) of the compilation graph. @@ -132,32 +132,32 @@ namespace llvmc { void insertNode(Tool* T); /// insertEdge - Insert a new edge into the graph. Takes ownership - /// of the Edge object. - void insertEdge(const std::string& A, Edge* E); + /// of the Edge object. Returns non-zero value on error. + int insertEdge(const std::string& A, Edge* E); - /// Build - Build target(s) from the input file set. Command-line - /// options are passed implicitly as global variables. + /// Build - Build target(s) from the input file set. Command-line options + /// are passed implicitly as global variables. Returns non-zero value on + /// error (usually the failed program's exit code). int Build(llvm::sys::Path const& TempDir, const LanguageMap& LangMap); - /// Check - Check the compilation graph for common errors like - /// cycles, input/output language mismatch and multiple default - /// edges. Prints error messages and in case it finds any errors. + /// Check - Check the compilation graph for common errors like cycles, + /// input/output language mismatch and multiple default edges. Prints error + /// messages and in case it finds any errors. int Check(); - /// getNode - Return a reference to the node correponding to the - /// given tool name. Throws std::runtime_error. - Node& getNode(const std::string& ToolName); - const Node& getNode(const std::string& ToolName) const; + /// getNode - Return a reference to the node corresponding to the given tool + /// name. Returns 0 on error. + Node* getNode(const std::string& ToolName); + const Node* getNode(const std::string& ToolName) const; - /// viewGraph - This function is meant for use from the debugger. - /// You can just say 'call G->viewGraph()' and a ghostview window - /// should pop up from the program, displaying the compilation - /// graph. This depends on there being a 'dot' and 'gv' program - /// in your path. + /// viewGraph - This function is meant for use from the debugger. You can + /// just say 'call G->viewGraph()' and a ghostview window should pop up from + /// the program, displaying the compilation graph. This depends on there + /// being a 'dot' and 'gv' program in your path. void viewGraph(); /// writeGraph - Write Graphviz .dot source file to the current direcotry. - void writeGraph(const std::string& OutputFilename); + int writeGraph(const std::string& OutputFilename); // GraphTraits support. friend NodesIterator GraphBegin(CompilationGraph*); @@ -167,16 +167,15 @@ namespace llvmc { // Helper functions. /// getToolsVector - Return a reference to the list of tool names - /// corresponding to the given language name. Throws - /// std::runtime_error. - const tools_vector_type& getToolsVector(const std::string& LangName) const; + /// corresponding to the given language name. Returns 0 on error. + const tools_vector_type* getToolsVector(const std::string& LangName) const; - /// PassThroughGraph - Pass the input file through the toolchain - /// starting at StartNode. - void PassThroughGraph (const llvm::sys::Path& In, const Node* StartNode, - const InputLanguagesSet& InLangs, - const llvm::sys::Path& TempDir, - const LanguageMap& LangMap) const; + /// PassThroughGraph - Pass the input file through the toolchain starting at + /// StartNode. + int PassThroughGraph (const llvm::sys::Path& In, const Node* StartNode, + const InputLanguagesSet& InLangs, + const llvm::sys::Path& TempDir, + const LanguageMap& LangMap) const; /// FindToolChain - Find head of the toolchain corresponding to /// the given file. @@ -185,26 +184,32 @@ namespace llvmc { InputLanguagesSet& InLangs, const LanguageMap& LangMap) const; - /// BuildInitial - Traverse the initial parts of the toolchains. - void BuildInitial(InputLanguagesSet& InLangs, - const llvm::sys::Path& TempDir, - const LanguageMap& LangMap); + /// BuildInitial - Traverse the initial parts of the toolchains. Returns + /// non-zero value on error. + int BuildInitial(InputLanguagesSet& InLangs, + const llvm::sys::Path& TempDir, + const LanguageMap& LangMap); - /// TopologicalSort - Sort the nodes in topological order. - void TopologicalSort(std::vector<const Node*>& Out); - /// TopologicalSortFilterJoinNodes - Call TopologicalSort and - /// filter the resulting list to include only Join nodes. - void TopologicalSortFilterJoinNodes(std::vector<const Node*>& Out); + /// TopologicalSort - Sort the nodes in topological order. Returns non-zero + /// value on error. + int TopologicalSort(std::vector<const Node*>& Out); + /// TopologicalSortFilterJoinNodes - Call TopologicalSort and filter the + /// resulting list to include only Join nodes. Returns non-zero value on + /// error. + int TopologicalSortFilterJoinNodes(std::vector<const Node*>& Out); // Functions used to implement Check(). - /// CheckLanguageNames - Check that output/input language names - /// match for all nodes. + /// CheckLanguageNames - Check that output/input language names match for + /// all nodes. Returns non-zero value on error (number of errors + /// encountered). int CheckLanguageNames() const; - /// CheckMultipleDefaultEdges - check that there are no multiple - /// default default edges. + /// CheckMultipleDefaultEdges - check that there are no multiple default + /// default edges. Returns non-zero value on error (number of errors + /// encountered). int CheckMultipleDefaultEdges() const; - /// CheckCycles - Check that there are no cycles in the graph. + /// CheckCycles - Check that there are no cycles in the graph. Returns + /// non-zero value on error (number of errors encountered). int CheckCycles(); }; @@ -270,7 +275,7 @@ namespace llvmc { } inline pointer operator*() const { - return &OwningGraph->getNode((*EdgeIter)->ToolName()); + return OwningGraph->getNode((*EdgeIter)->ToolName()); } inline pointer operator->() const { return this->operator*(); @@ -301,7 +306,7 @@ namespace llvm { typedef llvmc::NodeChildIterator ChildIteratorType; static NodeType* getEntryNode(GraphType* G) { - return &G->getNode("root"); + return G->getNode("root"); } static ChildIteratorType child_begin(NodeType* N) { diff --git a/include/llvm/CompilerDriver/Error.h b/include/llvm/CompilerDriver/Error.h index fa678cf..013094e 100644 --- a/include/llvm/CompilerDriver/Error.h +++ b/include/llvm/CompilerDriver/Error.h @@ -7,28 +7,22 @@ // //===----------------------------------------------------------------------===// // -// Exception classes for llvmc. +// Error handling. // //===----------------------------------------------------------------------===// #ifndef LLVM_INCLUDE_COMPILER_DRIVER_ERROR_H #define LLVM_INCLUDE_COMPILER_DRIVER_ERROR_H -#include <stdexcept> +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/raw_ostream.h" namespace llvmc { - /// error_code - This gets thrown during the compilation process if a tool - /// invocation returns a non-zero exit code. - class error_code: public std::runtime_error { - int Code_; - public: - error_code (int c) - : std::runtime_error("Tool returned error code"), Code_(c) - {} - - int code() const { return Code_; } - }; + inline void PrintError(llvm::StringRef Err) { + extern const char* ProgramName; + llvm::errs() << ProgramName << ": " << Err << '\n'; + } } diff --git a/include/llvm/CompilerDriver/ForceLinkage.h b/include/llvm/CompilerDriver/ForceLinkage.h deleted file mode 100644 index 830c04e..0000000 --- a/include/llvm/CompilerDriver/ForceLinkage.h +++ /dev/null @@ -1,122 +0,0 @@ -//===--- ForceLinkage.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. -// -//===----------------------------------------------------------------------===// -// -// A bit of preprocessor magic to force references to static libraries. Needed -// because plugin initialization is done via static variables. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_H -#define LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_H - -#include "llvm/CompilerDriver/ForceLinkageMacros.h" - -namespace llvmc { - -// Declare all ForceLinkage$(PluginName) functions. - -#ifdef LLVMC_BUILTIN_PLUGIN_1 - LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_1); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_2 - LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_2); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_3 - LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_3); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_4 - LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_4); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_5 - LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_5); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_6 - LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_6); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_7 - LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_7); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_8 - LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_8); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_9 - LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_9); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_10 - LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_10); -#endif - -namespace force_linkage { - - struct LinkageForcer { - - LinkageForcer() { - -// Call all ForceLinkage$(PluginName) functions. -#ifdef LLVMC_BUILTIN_PLUGIN_1 - LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_1); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_2 - LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_2); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_3 - LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_3); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_4 - LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_4); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_5 - LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_5); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_6 - LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_6); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_7 - LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_7); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_8 - LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_8); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_9 - LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_9); -#endif - -#ifdef LLVMC_BUILTIN_PLUGIN_10 - LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_10); -#endif - - } - }; -} // End namespace force_linkage. - -// The only externally used bit. -void ForceLinkage() { - force_linkage::LinkageForcer dummy; -} - -} // End namespace llvmc. - -#endif // LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_H diff --git a/include/llvm/CompilerDriver/ForceLinkageMacros.h b/include/llvm/CompilerDriver/ForceLinkageMacros.h deleted file mode 100644 index 8862b00..0000000 --- a/include/llvm/CompilerDriver/ForceLinkageMacros.h +++ /dev/null @@ -1,29 +0,0 @@ -//===--- ForceLinkageMacros.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. -// -//===----------------------------------------------------------------------===// -// -// Preprocessor magic that forces references to static libraries - common -// macros used by both driver and plugins. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_MACROS_H -#define LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_MACROS_H - -#define LLVMC_FORCE_LINKAGE_PREFIX(PluginName) ForceLinkage ## PluginName - -#define LLVMC_FORCE_LINKAGE_FUN(PluginName) \ - LLVMC_FORCE_LINKAGE_PREFIX(PluginName) - -#define LLVMC_FORCE_LINKAGE_DECL(PluginName) \ - void LLVMC_FORCE_LINKAGE_FUN(PluginName) () - -#define LLVMC_FORCE_LINKAGE_CALL(PluginName) \ - LLVMC_FORCE_LINKAGE_FUN(PluginName) () - -#endif // LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_MACROS_H diff --git a/include/llvm/CompilerDriver/Main.h b/include/llvm/CompilerDriver/Main.h new file mode 100644 index 0000000..d136a5d --- /dev/null +++ b/include/llvm/CompilerDriver/Main.h @@ -0,0 +1,21 @@ +//===--- Main.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. +// +//===----------------------------------------------------------------------===// +// +// Entry point for the driver executable. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_INCLUDE_COMPILER_DRIVER_MAIN_H +#define LLVM_INCLUDE_COMPILER_DRIVER_MAIN_H + +namespace llvmc { + int Main(int argc, char** argv); +} + +#endif // LLVM_INCLUDE_COMPILER_DRIVER_MAIN_H diff --git a/include/llvm/CompilerDriver/Main.inc b/include/llvm/CompilerDriver/Main.inc index 71bb8cb..4164043 100644 --- a/include/llvm/CompilerDriver/Main.inc +++ b/include/llvm/CompilerDriver/Main.inc @@ -7,26 +7,16 @@ // //===----------------------------------------------------------------------===// // -// This tool provides a single point of access to the LLVM -// compilation tools. It has many options. To discover the options -// supported please refer to the tools' manual page or run the tool -// with the -help option. -// -// This file provides the default entry point for the driver executable. +// Default main() for the driver executable. // //===----------------------------------------------------------------------===// #ifndef LLVM_INCLUDE_COMPILER_DRIVER_MAIN_INC #define LLVM_INCLUDE_COMPILER_DRIVER_MAIN_INC -#include "llvm/CompilerDriver/ForceLinkage.h" - -namespace llvmc { - int Main(int argc, char** argv); -} +#include "llvm/CompilerDriver/Main.h" int main(int argc, char** argv) { - llvmc::ForceLinkage(); return llvmc::Main(argc, argv); } diff --git a/include/llvm/CompilerDriver/Plugin.h b/include/llvm/CompilerDriver/Plugin.h deleted file mode 100644 index e9a2048..0000000 --- a/include/llvm/CompilerDriver/Plugin.h +++ /dev/null @@ -1,81 +0,0 @@ -//===--- Plugin.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. -// -//===----------------------------------------------------------------------===// -// -// Plugin support for llvmc. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_INCLUDE_COMPILER_DRIVER_PLUGIN_H -#define LLVM_INCLUDE_COMPILER_DRIVER_PLUGIN_H - -#include "llvm/Support/Registry.h" - -namespace llvmc { - - class LanguageMap; - class CompilationGraph; - - /// BasePlugin - An abstract base class for all LLVMC plugins. - struct BasePlugin { - - /// Priority - Plugin priority, useful for handling dependencies - /// between plugins. Plugins with lower priorities are loaded - /// first. - virtual int Priority() const { return 0; } - - /// PreprocessOptions - The auto-generated function that performs various - /// consistency checks on options (like ensuring that -O2 and -O3 are not - /// used together). - virtual void PreprocessOptions() const = 0; - - /// PopulateLanguageMap - The auto-generated function that fills in - /// the language map (map from file extensions to language names). - virtual void PopulateLanguageMap(LanguageMap&) const = 0; - - /// PopulateCompilationGraph - The auto-generated function that - /// populates the compilation graph with nodes and edges. - virtual void PopulateCompilationGraph(CompilationGraph&) const = 0; - - /// Needed to avoid a compiler warning. - virtual ~BasePlugin() {} - }; - - typedef llvm::Registry<BasePlugin> PluginRegistry; - - template <class P> - struct RegisterPlugin - : public PluginRegistry::Add<P> { - typedef PluginRegistry::Add<P> Base; - - RegisterPlugin(const char* Name = "Nameless", - const char* Desc = "Auto-generated plugin") - : Base(Name, Desc) {} - }; - - - /// PluginLoader - Helper class used by the main program for - /// lifetime management. - struct PluginLoader { - PluginLoader(); - ~PluginLoader(); - - /// RunInitialization - Calls PreprocessOptions, PopulateLanguageMap and - /// PopulateCompilationGraph methods of all plugins. This populates the - /// global language map and the compilation graph. - void RunInitialization(LanguageMap& langMap, CompilationGraph& graph) const; - - private: - // noncopyable - PluginLoader(const PluginLoader& other); - const PluginLoader& operator=(const PluginLoader& other); - }; - -} - -#endif // LLVM_INCLUDE_COMPILER_DRIVER_PLUGIN_H diff --git a/include/llvm/CompilerDriver/Tool.h b/include/llvm/CompilerDriver/Tool.h index 85d1690..45ef50d 100644 --- a/include/llvm/CompilerDriver/Tool.h +++ b/include/llvm/CompilerDriver/Tool.h @@ -38,17 +38,23 @@ namespace llvmc { 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; + /// GenerateAction - Generate an Action given particular command-line + /// options. Returns non-zero value on error. + virtual int GenerateAction (Action& Out, + const PathVector& inFiles, + const bool HasChildren, + const llvm::sys::Path& TempDir, + const InputLanguagesSet& InLangs, + const LanguageMap& LangMap) const = 0; + + /// GenerateAction - Generate an Action given particular command-line + /// options. Returns non-zero value on error. + virtual int GenerateAction (Action& Out, + const llvm::sys::Path& inFile, + const 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; @@ -74,11 +80,13 @@ namespace llvmc { 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); + int GenerateAction(Action& Out, + const bool HasChildren, + const llvm::sys::Path& TempDir, + const InputLanguagesSet& InLangs, + const LanguageMap& LangMap) const { + return GenerateAction(Out, JoinList_, HasChildren, TempDir, InLangs, + LangMap); } // We shouldn't shadow base class's version of GenerateAction. using Tool::GenerateAction; |