From: Mikhail Glushenkov Date: Mon, 22 Sep 2008 20:50:40 +0000 (+0000) Subject: Move llvmc2 header files under include/llvm/CompilerDriver X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4a1a77c1c9e0992735aa66b75c9e4c75c3b70561;p=oota-llvm.git Move llvmc2 header files under include/llvm/CompilerDriver git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56466 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CompilerDriver/Action.h b/include/llvm/CompilerDriver/Action.h new file mode 100644 index 00000000000..c3b31d4e558 --- /dev/null +++ b/include/llvm/CompilerDriver/Action.h @@ -0,0 +1,42 @@ +//===--- Action.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. +// +//===----------------------------------------------------------------------===// +// +// Action - encapsulates a single shell command. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TOOLS_LLVMC2_ACTION_H +#define LLVM_TOOLS_LLVMC2_ACTION_H + +#include +#include + +namespace llvmc { + + typedef std::vector StrVector; + + /// Action - A class that encapsulates a single shell command. + class Action { + /// Command_ - The actual command (for example, 'ls'). + std::string Command_; + /// Args_ - Command arguments. Stdout redirection ("> file") is allowed. + std::vector Args_; + public: + Action() {} + Action (const std::string& C, const StrVector& A) + : Command_(C), Args_(A) + {} + + /// Execute - Executes the represented action. + int Execute() const; + }; + +} + +#endif // LLVM_TOOLS_LLVMC2_ACTION_H diff --git a/include/llvm/CompilerDriver/CompilationGraph.h b/include/llvm/CompilerDriver/CompilationGraph.h new file mode 100644 index 00000000000..f3c31ab22c8 --- /dev/null +++ b/include/llvm/CompilerDriver/CompilationGraph.h @@ -0,0 +1,302 @@ +//===--- CompilationGraph.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. +// +//===----------------------------------------------------------------------===// +// +// Compilation graph - definition. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TOOLS_LLVMC2_COMPILATION_GRAPH_H +#define LLVM_TOOLS_LLVMC2_COMPILATION_GRAPH_H + +#include "llvm/CompilerDriver/Tool.h" + +#include "llvm/ADT/GraphTraits.h" +#include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "llvm/ADT/iterator.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringSet.h" +#include "llvm/System/Path.h" + +#include +#include + +namespace llvmc { + + class CompilationGraph; + typedef llvm::StringSet<> InputLanguagesSet; + + /// LanguageMap - Maps from extensions to language names. + class LanguageMap : public llvm::StringMap { + public: + + /// GetLanguage - Find the language name corresponding to a given file. + const std::string& GetLanguage(const llvm::sys::Path&) const; + }; + + /// Edge - Represents an edge of the compilation graph. + class Edge : public llvm::RefCountedBaseVPTR { + public: + Edge(const std::string& T) : ToolName_(T) {} + virtual ~Edge() {}; + + const std::string& ToolName() const { return ToolName_; } + virtual unsigned Weight(const InputLanguagesSet& InLangs) const = 0; + private: + std::string ToolName_; + }; + + /// SimpleEdge - An edge that has no properties. + class SimpleEdge : public Edge { + public: + SimpleEdge(const std::string& T) : Edge(T) {} + unsigned Weight(const InputLanguagesSet&) const { return 1; } + }; + + /// Node - A node (vertex) of the compilation graph. + struct Node { + // A Node holds a list of the outward edges. + typedef llvm::SmallVector, 3> container_type; + typedef container_type::iterator iterator; + typedef container_type::const_iterator const_iterator; + + Node() : OwningGraph(0), InEdges(0) {} + Node(CompilationGraph* G) : OwningGraph(G), InEdges(0) {} + Node(CompilationGraph* G, Tool* T) : + OwningGraph(G), ToolPtr(T), InEdges(0) {} + + bool HasChildren() const { return !OutEdges.empty(); } + const std::string Name() const + { return ToolPtr ? ToolPtr->Name() : "root"; } + + // Iteration. + iterator EdgesBegin() { return OutEdges.begin(); } + const_iterator EdgesBegin() const { return OutEdges.begin(); } + iterator EdgesEnd() { return OutEdges.end(); } + const_iterator EdgesEnd() const { return OutEdges.end(); } + + /// AddEdge - Add an outward edge. Takes ownership of the provided + /// Edge object. + void AddEdge(Edge* E) + { OutEdges.push_back(llvm::IntrusiveRefCntPtr(E)); } + + // Inward edge counter. Used to implement topological sort. + void IncrInEdges() { ++InEdges; } + void DecrInEdges() { --InEdges; } + bool HasNoInEdges() const { return InEdges == 0; } + + // Needed to implement NodeChildIterator/GraphTraits + CompilationGraph* OwningGraph; + // The corresponding Tool. + // WARNING: ToolPtr can be NULL (for the root node). + llvm::IntrusiveRefCntPtr ToolPtr; + // Links to children. + container_type OutEdges; + // Inward edge counter. Updated in + // CompilationGraph::insertEdge(). Used for topological sorting. + unsigned InEdges; + }; + + class NodesIterator; + + /// CompilationGraph - The compilation graph itself. + class CompilationGraph { + /// nodes_map_type - The main data structure. + typedef llvm::StringMap nodes_map_type; + /// tools_vector_type, tools_map_type - Data structures used to + /// map from language names to tools. (We can have several tools + /// associated with each language name, hence the need for a + /// vector.) + typedef + llvm::SmallVector, 3> tools_vector_type; + typedef llvm::StringMap tools_map_type; + + /// ToolsMap - Map from language names to lists of tool names. + tools_map_type ToolsMap; + /// NodesMap - Map from tool names to Tool objects. + nodes_map_type NodesMap; + + public: + + CompilationGraph(); + + /// insertNode - Insert a new node into the graph. Takes + /// ownership of the object. + 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); + + /// Build - Build target(s) from the input file set. Command-line + /// options are passed implicitly as global variables. + int Build(llvm::sys::Path const& TempDir, const LanguageMap& LangMap); + + /// 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; + + /// 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 a compilation-graph.dot file. + void writeGraph(); + + // GraphTraits support. + friend NodesIterator GraphBegin(CompilationGraph*); + friend NodesIterator GraphEnd(CompilationGraph*); + + private: + // 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; + + /// 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; + + /// FindToolChain - Find head of the toolchain corresponding to the given file. + const Node* FindToolChain(const llvm::sys::Path& In, + const std::string* ForceLanguage, + 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); + + /// TopologicalSort - Sort the nodes in topological order. + void TopologicalSort(std::vector& Out); + /// TopologicalSortFilterJoinNodes - Call TopologicalSort and + /// filter the resulting list to include only Join nodes. + void TopologicalSortFilterJoinNodes(std::vector& Out); + }; + + // GraphTraits support code. + + /// NodesIterator - Auxiliary class needed to implement GraphTraits + /// support. Can be generalised to something like value_iterator + /// for map-like containers. + class NodesIterator : public llvm::StringMap::iterator { + typedef llvm::StringMap::iterator super; + typedef NodesIterator ThisType; + typedef Node* pointer; + typedef Node& reference; + + public: + NodesIterator(super I) : super(I) {} + + inline reference operator*() const { + return super::operator->()->second; + } + inline pointer operator->() const { + return &super::operator->()->second; + } + }; + + inline NodesIterator GraphBegin(CompilationGraph* G) { + return NodesIterator(G->NodesMap.begin()); + } + + inline NodesIterator GraphEnd(CompilationGraph* G) { + return NodesIterator(G->NodesMap.end()); + } + + + /// NodeChildIterator - Another auxiliary class needed by GraphTraits. + class NodeChildIterator : public bidirectional_iterator { + typedef NodeChildIterator ThisType; + typedef Node::container_type::iterator iterator; + + CompilationGraph* OwningGraph; + iterator EdgeIter; + public: + typedef Node* pointer; + typedef Node& reference; + + NodeChildIterator(Node* N, iterator I) : + OwningGraph(N->OwningGraph), EdgeIter(I) {} + + const ThisType& operator=(const ThisType& I) { + assert(OwningGraph == I.OwningGraph); + EdgeIter = I.EdgeIter; + return *this; + } + + inline bool operator==(const ThisType& I) const + { return EdgeIter == I.EdgeIter; } + inline bool operator!=(const ThisType& I) const + { return EdgeIter != I.EdgeIter; } + + inline pointer operator*() const { + return &OwningGraph->getNode((*EdgeIter)->ToolName()); + } + inline pointer operator->() const { + return &OwningGraph->getNode((*EdgeIter)->ToolName()); + } + + ThisType& operator++() { ++EdgeIter; return *this; } // Preincrement + ThisType operator++(int) { // Postincrement + ThisType tmp = *this; + ++*this; + return tmp; + } + + inline ThisType& operator--() { --EdgeIter; return *this; } // Predecrement + inline ThisType operator--(int) { // Postdecrement + ThisType tmp = *this; + --*this; + return tmp; + } + + }; +} + +namespace llvm { + template <> + struct GraphTraits { + typedef llvmc::CompilationGraph GraphType; + typedef llvmc::Node NodeType; + typedef llvmc::NodeChildIterator ChildIteratorType; + + static NodeType* getEntryNode(GraphType* G) { + return &G->getNode("root"); + } + + static ChildIteratorType child_begin(NodeType* N) { + return ChildIteratorType(N, N->OutEdges.begin()); + } + static ChildIteratorType child_end(NodeType* N) { + return ChildIteratorType(N, N->OutEdges.end()); + } + + typedef llvmc::NodesIterator nodes_iterator; + static nodes_iterator nodes_begin(GraphType *G) { + return GraphBegin(G); + } + static nodes_iterator nodes_end(GraphType *G) { + return GraphEnd(G); + } + }; + +} + +#endif // LLVM_TOOLS_LLVMC2_COMPILATION_GRAPH_H diff --git a/include/llvm/CompilerDriver/Plugin.h b/include/llvm/CompilerDriver/Plugin.h new file mode 100644 index 00000000000..ba22450697b --- /dev/null +++ b/include/llvm/CompilerDriver/Plugin.h @@ -0,0 +1,56 @@ +//===--- 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 llvmc2. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TOOLS_LLVMC2_PLUGIN_H +#define LLVM_TOOLS_LLVMC2_PLUGIN_H + +namespace llvmc { + + class LanguageMap; + class CompilationGraph; + + /// BasePlugin - An abstract base class for all LLVMC plugins. + struct BasePlugin { + + /// 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; + }; + + // Helper class for RegisterPlugin. + class RegisterPluginImpl { + protected: + RegisterPluginImpl(BasePlugin*); + }; + + /// RegisterPlugin template - Used to register LLVMC plugins. + template + struct RegisterPlugin : RegisterPluginImpl { + RegisterPlugin() : RegisterPluginImpl (new T()) {} + }; + + /// PopulateLanguageMap - Fills in the language map by calling + /// PopulateLanguageMap methods of all plugins. + void PopulateLanguageMap(LanguageMap& langMap); + + /// PopulateCompilationGraph - Populates the compilation graph by + /// calling PopulateCompilationGraph methods of all plugins. + void PopulateCompilationGraph(CompilationGraph& tools); + +} + +#endif // LLVM_TOOLS_LLVMC2_PLUGIN_H diff --git a/include/llvm/CompilerDriver/Tool.h b/include/llvm/CompilerDriver/Tool.h new file mode 100644 index 00000000000..c422a439923 --- /dev/null +++ b/include/llvm/CompilerDriver/Tool.h @@ -0,0 +1,78 @@ +//===--- 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_TOOLS_LLVMC2_TOOL_H +#define LLVM_TOOLS_LLVMC2_TOOL_H + +#include "llvm/CompilerDriver/Action.h" + +#include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "llvm/ADT/StringSet.h" +#include "llvm/System/Path.h" + +#include +#include + +namespace llvmc { + + class LanguageMap; + typedef std::vector PathVector; + typedef llvm::StringSet<> InputLanguagesSet; + + /// Tool - A class + class Tool : public llvm::RefCountedBaseVPTR { + public: + + virtual ~Tool() {} + + virtual Action GenerateAction (const PathVector& inFiles, + const llvm::sys::Path& outFile, + const InputLanguagesSet& InLangs, + const LanguageMap& LangMap) const = 0; + + virtual Action GenerateAction (const llvm::sys::Path& inFile, + const llvm::sys::Path& outFile, + 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 const char* OutputSuffix() const = 0; + + virtual bool IsLast() const = 0; + virtual bool IsJoin() const = 0; + }; + + /// 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(const llvm::sys::Path& outFile, + const InputLanguagesSet& InLangs, + const LanguageMap& LangMap) const { + return GenerateAction(JoinList_, outFile, InLangs, LangMap); + } + // We shouldn't shadow base class's version of GenerateAction. + using Tool::GenerateAction; + + private: + PathVector JoinList_; + }; + +} + +#endif //LLVM_TOOLS_LLVMC2_TOOL_H diff --git a/tools/llvmc2/Action.cpp b/tools/llvmc2/Action.cpp index 08416263a1b..c0a1b849bcd 100644 --- a/tools/llvmc2/Action.cpp +++ b/tools/llvmc2/Action.cpp @@ -11,7 +11,7 @@ // //===----------------------------------------------------------------------===// -#include "Action.h" +#include "llvm/CompilerDriver/Action.h" #include "llvm/Support/CommandLine.h" #include "llvm/System/Program.h" diff --git a/tools/llvmc2/Action.h b/tools/llvmc2/Action.h deleted file mode 100644 index c3b31d4e558..00000000000 --- a/tools/llvmc2/Action.h +++ /dev/null @@ -1,42 +0,0 @@ -//===--- Action.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. -// -//===----------------------------------------------------------------------===// -// -// Action - encapsulates a single shell command. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_TOOLS_LLVMC2_ACTION_H -#define LLVM_TOOLS_LLVMC2_ACTION_H - -#include -#include - -namespace llvmc { - - typedef std::vector StrVector; - - /// Action - A class that encapsulates a single shell command. - class Action { - /// Command_ - The actual command (for example, 'ls'). - std::string Command_; - /// Args_ - Command arguments. Stdout redirection ("> file") is allowed. - std::vector Args_; - public: - Action() {} - Action (const std::string& C, const StrVector& A) - : Command_(C), Args_(A) - {} - - /// Execute - Executes the represented action. - int Execute() const; - }; - -} - -#endif // LLVM_TOOLS_LLVMC2_ACTION_H diff --git a/tools/llvmc2/CompilationGraph.cpp b/tools/llvmc2/CompilationGraph.cpp index 01953957045..2e83f44f67f 100644 --- a/tools/llvmc2/CompilationGraph.cpp +++ b/tools/llvmc2/CompilationGraph.cpp @@ -12,7 +12,7 @@ //===----------------------------------------------------------------------===// #include "Error.h" -#include "CompilationGraph.h" +#include "llvm/CompilerDriver/CompilationGraph.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/CommandLine.h" diff --git a/tools/llvmc2/CompilationGraph.h b/tools/llvmc2/CompilationGraph.h deleted file mode 100644 index 57758bfd9e0..00000000000 --- a/tools/llvmc2/CompilationGraph.h +++ /dev/null @@ -1,302 +0,0 @@ -//===--- CompilationGraph.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. -// -//===----------------------------------------------------------------------===// -// -// Compilation graph - definition. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_TOOLS_LLVMC2_COMPILATION_GRAPH_H -#define LLVM_TOOLS_LLVMC2_COMPILATION_GRAPH_H - -#include "Tool.h" - -#include "llvm/ADT/GraphTraits.h" -#include "llvm/ADT/IntrusiveRefCntPtr.h" -#include "llvm/ADT/iterator.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringMap.h" -#include "llvm/ADT/StringSet.h" -#include "llvm/System/Path.h" - -#include -#include - -namespace llvmc { - - class CompilationGraph; - typedef llvm::StringSet<> InputLanguagesSet; - - /// LanguageMap - Maps from extensions to language names. - class LanguageMap : public llvm::StringMap { - public: - - /// GetLanguage - Find the language name corresponding to a given file. - const std::string& GetLanguage(const llvm::sys::Path&) const; - }; - - /// Edge - Represents an edge of the compilation graph. - class Edge : public llvm::RefCountedBaseVPTR { - public: - Edge(const std::string& T) : ToolName_(T) {} - virtual ~Edge() {}; - - const std::string& ToolName() const { return ToolName_; } - virtual unsigned Weight(const InputLanguagesSet& InLangs) const = 0; - private: - std::string ToolName_; - }; - - /// SimpleEdge - An edge that has no properties. - class SimpleEdge : public Edge { - public: - SimpleEdge(const std::string& T) : Edge(T) {} - unsigned Weight(const InputLanguagesSet&) const { return 1; } - }; - - /// Node - A node (vertex) of the compilation graph. - struct Node { - // A Node holds a list of the outward edges. - typedef llvm::SmallVector, 3> container_type; - typedef container_type::iterator iterator; - typedef container_type::const_iterator const_iterator; - - Node() : OwningGraph(0), InEdges(0) {} - Node(CompilationGraph* G) : OwningGraph(G), InEdges(0) {} - Node(CompilationGraph* G, Tool* T) : - OwningGraph(G), ToolPtr(T), InEdges(0) {} - - bool HasChildren() const { return !OutEdges.empty(); } - const std::string Name() const - { return ToolPtr ? ToolPtr->Name() : "root"; } - - // Iteration. - iterator EdgesBegin() { return OutEdges.begin(); } - const_iterator EdgesBegin() const { return OutEdges.begin(); } - iterator EdgesEnd() { return OutEdges.end(); } - const_iterator EdgesEnd() const { return OutEdges.end(); } - - /// AddEdge - Add an outward edge. Takes ownership of the provided - /// Edge object. - void AddEdge(Edge* E) - { OutEdges.push_back(llvm::IntrusiveRefCntPtr(E)); } - - // Inward edge counter. Used to implement topological sort. - void IncrInEdges() { ++InEdges; } - void DecrInEdges() { --InEdges; } - bool HasNoInEdges() const { return InEdges == 0; } - - // Needed to implement NodeChildIterator/GraphTraits - CompilationGraph* OwningGraph; - // The corresponding Tool. - // WARNING: ToolPtr can be NULL (for the root node). - llvm::IntrusiveRefCntPtr ToolPtr; - // Links to children. - container_type OutEdges; - // Inward edge counter. Updated in - // CompilationGraph::insertEdge(). Used for topological sorting. - unsigned InEdges; - }; - - class NodesIterator; - - /// CompilationGraph - The compilation graph itself. - class CompilationGraph { - /// nodes_map_type - The main data structure. - typedef llvm::StringMap nodes_map_type; - /// tools_vector_type, tools_map_type - Data structures used to - /// map from language names to tools. (We can have several tools - /// associated with each language name, hence the need for a - /// vector.) - typedef - llvm::SmallVector, 3> tools_vector_type; - typedef llvm::StringMap tools_map_type; - - /// ToolsMap - Map from language names to lists of tool names. - tools_map_type ToolsMap; - /// NodesMap - Map from tool names to Tool objects. - nodes_map_type NodesMap; - - public: - - CompilationGraph(); - - /// insertNode - Insert a new node into the graph. Takes - /// ownership of the object. - 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); - - /// Build - Build target(s) from the input file set. Command-line - /// options are passed implicitly as global variables. - int Build(llvm::sys::Path const& TempDir, const LanguageMap& LangMap); - - /// 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; - - /// 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 a compilation-graph.dot file. - void writeGraph(); - - // GraphTraits support. - friend NodesIterator GraphBegin(CompilationGraph*); - friend NodesIterator GraphEnd(CompilationGraph*); - - private: - // 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; - - /// 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; - - /// FindToolChain - Find head of the toolchain corresponding to the given file. - const Node* FindToolChain(const llvm::sys::Path& In, - const std::string* ForceLanguage, - 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); - - /// TopologicalSort - Sort the nodes in topological order. - void TopologicalSort(std::vector& Out); - /// TopologicalSortFilterJoinNodes - Call TopologicalSort and - /// filter the resulting list to include only Join nodes. - void TopologicalSortFilterJoinNodes(std::vector& Out); - }; - - // GraphTraits support code. - - /// NodesIterator - Auxiliary class needed to implement GraphTraits - /// support. Can be generalised to something like value_iterator - /// for map-like containers. - class NodesIterator : public llvm::StringMap::iterator { - typedef llvm::StringMap::iterator super; - typedef NodesIterator ThisType; - typedef Node* pointer; - typedef Node& reference; - - public: - NodesIterator(super I) : super(I) {} - - inline reference operator*() const { - return super::operator->()->second; - } - inline pointer operator->() const { - return &super::operator->()->second; - } - }; - - inline NodesIterator GraphBegin(CompilationGraph* G) { - return NodesIterator(G->NodesMap.begin()); - } - - inline NodesIterator GraphEnd(CompilationGraph* G) { - return NodesIterator(G->NodesMap.end()); - } - - - /// NodeChildIterator - Another auxiliary class needed by GraphTraits. - class NodeChildIterator : public bidirectional_iterator { - typedef NodeChildIterator ThisType; - typedef Node::container_type::iterator iterator; - - CompilationGraph* OwningGraph; - iterator EdgeIter; - public: - typedef Node* pointer; - typedef Node& reference; - - NodeChildIterator(Node* N, iterator I) : - OwningGraph(N->OwningGraph), EdgeIter(I) {} - - const ThisType& operator=(const ThisType& I) { - assert(OwningGraph == I.OwningGraph); - EdgeIter = I.EdgeIter; - return *this; - } - - inline bool operator==(const ThisType& I) const - { return EdgeIter == I.EdgeIter; } - inline bool operator!=(const ThisType& I) const - { return EdgeIter != I.EdgeIter; } - - inline pointer operator*() const { - return &OwningGraph->getNode((*EdgeIter)->ToolName()); - } - inline pointer operator->() const { - return &OwningGraph->getNode((*EdgeIter)->ToolName()); - } - - ThisType& operator++() { ++EdgeIter; return *this; } // Preincrement - ThisType operator++(int) { // Postincrement - ThisType tmp = *this; - ++*this; - return tmp; - } - - inline ThisType& operator--() { --EdgeIter; return *this; } // Predecrement - inline ThisType operator--(int) { // Postdecrement - ThisType tmp = *this; - --*this; - return tmp; - } - - }; -} - -namespace llvm { - template <> - struct GraphTraits { - typedef llvmc::CompilationGraph GraphType; - typedef llvmc::Node NodeType; - typedef llvmc::NodeChildIterator ChildIteratorType; - - static NodeType* getEntryNode(GraphType* G) { - return &G->getNode("root"); - } - - static ChildIteratorType child_begin(NodeType* N) { - return ChildIteratorType(N, N->OutEdges.begin()); - } - static ChildIteratorType child_end(NodeType* N) { - return ChildIteratorType(N, N->OutEdges.end()); - } - - typedef llvmc::NodesIterator nodes_iterator; - static nodes_iterator nodes_begin(GraphType *G) { - return GraphBegin(G); - } - static nodes_iterator nodes_end(GraphType *G) { - return GraphEnd(G); - } - }; - -} - -#endif // LLVM_TOOLS_LLVMC2_COMPILATION_GRAPH_H diff --git a/tools/llvmc2/Plugin.cpp b/tools/llvmc2/Plugin.cpp index 70d99878ba9..cd94a013205 100644 --- a/tools/llvmc2/Plugin.cpp +++ b/tools/llvmc2/Plugin.cpp @@ -11,7 +11,7 @@ // //===----------------------------------------------------------------------===// -#include "Plugin.h" +#include "llvm/CompilerDriver/Plugin.h" #include diff --git a/tools/llvmc2/Plugin.h b/tools/llvmc2/Plugin.h deleted file mode 100644 index ba22450697b..00000000000 --- a/tools/llvmc2/Plugin.h +++ /dev/null @@ -1,56 +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 llvmc2. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_TOOLS_LLVMC2_PLUGIN_H -#define LLVM_TOOLS_LLVMC2_PLUGIN_H - -namespace llvmc { - - class LanguageMap; - class CompilationGraph; - - /// BasePlugin - An abstract base class for all LLVMC plugins. - struct BasePlugin { - - /// 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; - }; - - // Helper class for RegisterPlugin. - class RegisterPluginImpl { - protected: - RegisterPluginImpl(BasePlugin*); - }; - - /// RegisterPlugin template - Used to register LLVMC plugins. - template - struct RegisterPlugin : RegisterPluginImpl { - RegisterPlugin() : RegisterPluginImpl (new T()) {} - }; - - /// PopulateLanguageMap - Fills in the language map by calling - /// PopulateLanguageMap methods of all plugins. - void PopulateLanguageMap(LanguageMap& langMap); - - /// PopulateCompilationGraph - Populates the compilation graph by - /// calling PopulateCompilationGraph methods of all plugins. - void PopulateCompilationGraph(CompilationGraph& tools); - -} - -#endif // LLVM_TOOLS_LLVMC2_PLUGIN_H diff --git a/tools/llvmc2/Tool.h b/tools/llvmc2/Tool.h deleted file mode 100644 index 6f7cb8d051c..00000000000 --- a/tools/llvmc2/Tool.h +++ /dev/null @@ -1,78 +0,0 @@ -//===--- 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_TOOLS_LLVMC2_TOOL_H -#define LLVM_TOOLS_LLVMC2_TOOL_H - -#include "Action.h" - -#include "llvm/ADT/IntrusiveRefCntPtr.h" -#include "llvm/ADT/StringSet.h" -#include "llvm/System/Path.h" - -#include -#include - -namespace llvmc { - - class LanguageMap; - typedef std::vector PathVector; - typedef llvm::StringSet<> InputLanguagesSet; - - /// Tool - A class - class Tool : public llvm::RefCountedBaseVPTR { - public: - - virtual ~Tool() {} - - virtual Action GenerateAction (const PathVector& inFiles, - const llvm::sys::Path& outFile, - const InputLanguagesSet& InLangs, - const LanguageMap& LangMap) const = 0; - - virtual Action GenerateAction (const llvm::sys::Path& inFile, - const llvm::sys::Path& outFile, - 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 const char* OutputSuffix() const = 0; - - virtual bool IsLast() const = 0; - virtual bool IsJoin() const = 0; - }; - - /// 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(const llvm::sys::Path& outFile, - const InputLanguagesSet& InLangs, - const LanguageMap& LangMap) const { - return GenerateAction(JoinList_, outFile, InLangs, LangMap); - } - // We shouldn't shadow base class's version of GenerateAction. - using Tool::GenerateAction; - - private: - PathVector JoinList_; - }; - -} - -#endif //LLVM_TOOLS_LLVMC2_TOOL_H diff --git a/tools/llvmc2/llvmc.cpp b/tools/llvmc2/llvmc.cpp index bd5ea2b73f4..592a1333f3a 100644 --- a/tools/llvmc2/llvmc.cpp +++ b/tools/llvmc2/llvmc.cpp @@ -14,9 +14,10 @@ // //===----------------------------------------------------------------------===// -#include "CompilationGraph.h" #include "Error.h" -#include "Plugin.h" + +#include "llvm/CompilerDriver/CompilationGraph.h" +#include "llvm/CompilerDriver/Plugin.h" #include "llvm/System/Path.h" #include "llvm/Support/CommandLine.h" diff --git a/tools/llvmc2/plugins/Hello/Hello.cpp b/tools/llvmc2/plugins/Hello/Hello.cpp index 729d3c81667..a243dd86f7e 100644 --- a/tools/llvmc2/plugins/Hello/Hello.cpp +++ b/tools/llvmc2/plugins/Hello/Hello.cpp @@ -11,11 +11,8 @@ // //===----------------------------------------------------------------------===// -// TODO: Since llvmc2 has now gained support for plugins, its header -// files should be probably moved into LLVM include dir. - -#include "../../CompilationGraph.h" -#include "../../Plugin.h" +#include "llvm/CompilerDriver/CompilationGraph.h" +#include "llvm/CompilerDriver/Plugin.h" #include diff --git a/utils/TableGen/LLVMCConfigurationEmitter.cpp b/utils/TableGen/LLVMCConfigurationEmitter.cpp index 9bb3be3747e..43729033c39 100644 --- a/utils/TableGen/LLVMCConfigurationEmitter.cpp +++ b/utils/TableGen/LLVMCConfigurationEmitter.cpp @@ -1722,9 +1722,9 @@ void EmitRegisterPlugin(std::ostream& O) { /// EmitInclude - Emit necessary #include directives. void EmitIncludes(std::ostream& O) { - O << "#include \"CompilationGraph.h\"\n" - << "#include \"Plugin.h\"\n" - << "#include \"Tool.h\"\n\n" + O << "#include \"llvm/CompilerDriver/CompilationGraph.h\"\n" + << "#include \"llvm/CompilerDriver/Plugin.h\"\n" + << "#include \"llvm/CompilerDriver/Tool.h\"\n\n" << "#include \"llvm/ADT/StringExtras.h\"\n" << "#include \"llvm/Support/CommandLine.h\"\n\n"