Get rid of exceptions in llvmc.

llvmc can be now compiled with llvm-gcc on Windows.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109215 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Mikhail Glushenkov
2010-07-23 03:42:55 +00:00
parent a23650bc01
commit b374d4fd82
13 changed files with 361 additions and 258 deletions

View File

@ -203,7 +203,6 @@ ifdef LLVMC_PLUGIN
LIBRARYNAME := $(patsubst %,plugin_llvmc_%,$(LLVMC_PLUGIN)) LIBRARYNAME := $(patsubst %,plugin_llvmc_%,$(LLVMC_PLUGIN))
CPP.Flags += -DLLVMC_PLUGIN_NAME=$(LLVMC_PLUGIN) CPP.Flags += -DLLVMC_PLUGIN_NAME=$(LLVMC_PLUGIN)
REQUIRES_EH := 1
ifeq ($(ENABLE_LLVMC_DYNAMIC),1) ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
LD.Flags += -lCompilerDriver LD.Flags += -lCompilerDriver
@ -226,8 +225,6 @@ ifdef LLVMC_BASED_DRIVER
TOOLNAME = $(LLVMC_BASED_DRIVER) TOOLNAME = $(LLVMC_BASED_DRIVER)
REQUIRES_EH := 1
ifeq ($(ENABLE_LLVMC_DYNAMIC),1) ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
LD.Flags += -lCompilerDriver LD.Flags += -lCompilerDriver
else else

View File

@ -34,10 +34,14 @@ namespace llvmc {
std::string OutFile_; std::string OutFile_;
public: public:
Action (const std::string& C, const StrVector& A, void Construct (const std::string& C, const StrVector& A,
bool S, const std::string& O) bool S, const std::string& O) {
: Command_(C), Args_(A), StopCompilation_(S), OutFile_(O) Command_ = C;
{} Args_ = A;
StopCompilation_ = S;
OutFile_ = O;
}
bool IsConstructed () { return (Command_.size() != 0);}
/// Execute - Executes the represented action. /// Execute - Executes the represented action.
int Execute () const; int Execute () const;

View File

@ -36,7 +36,7 @@ namespace llvmc {
public: public:
/// GetLanguage - Find the language name corresponding to a given file. /// 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. /// Edge - Represents an edge of the compilation graph.
@ -133,7 +133,7 @@ namespace llvmc {
/// insertEdge - Insert a new edge into the graph. Takes ownership /// insertEdge - Insert a new edge into the graph. Takes ownership
/// of the Edge object. /// of the Edge object.
void insertEdge(const std::string& A, Edge* E); int insertEdge(const std::string& A, Edge* E);
/// Build - Build target(s) from the input file set. Command-line /// Build - Build target(s) from the input file set. Command-line
/// options are passed implicitly as global variables. /// options are passed implicitly as global variables.
@ -146,8 +146,8 @@ namespace llvmc {
/// getNode - Return a reference to the node correponding to the /// getNode - Return a reference to the node correponding to the
/// given tool name. Throws std::runtime_error. /// given tool name. Throws std::runtime_error.
Node& getNode(const std::string& ToolName); Node* getNode(const std::string& ToolName);
const Node& getNode(const std::string& ToolName) const; const Node* getNode(const std::string& ToolName) const;
/// viewGraph - This function is meant for use from the debugger. /// viewGraph - This function is meant for use from the debugger.
/// You can just say 'call G->viewGraph()' and a ghostview window /// You can just say 'call G->viewGraph()' and a ghostview window
@ -157,7 +157,7 @@ namespace llvmc {
void viewGraph(); void viewGraph();
/// writeGraph - Write Graphviz .dot source file to the current direcotry. /// writeGraph - Write Graphviz .dot source file to the current direcotry.
void writeGraph(const std::string& OutputFilename); int writeGraph(const std::string& OutputFilename);
// GraphTraits support. // GraphTraits support.
friend NodesIterator GraphBegin(CompilationGraph*); friend NodesIterator GraphBegin(CompilationGraph*);
@ -169,11 +169,11 @@ namespace llvmc {
/// getToolsVector - Return a reference to the list of tool names /// getToolsVector - Return a reference to the list of tool names
/// corresponding to the given language name. Throws /// corresponding to the given language name. Throws
/// std::runtime_error. /// std::runtime_error.
const tools_vector_type& getToolsVector(const std::string& LangName) const; const tools_vector_type* getToolsVector(const std::string& LangName) const;
/// PassThroughGraph - Pass the input file through the toolchain /// PassThroughGraph - Pass the input file through the toolchain
/// starting at StartNode. /// starting at StartNode.
void PassThroughGraph (const llvm::sys::Path& In, const Node* StartNode, int PassThroughGraph (const llvm::sys::Path& In, const Node* StartNode,
const InputLanguagesSet& InLangs, const InputLanguagesSet& InLangs,
const llvm::sys::Path& TempDir, const llvm::sys::Path& TempDir,
const LanguageMap& LangMap) const; const LanguageMap& LangMap) const;
@ -186,15 +186,15 @@ namespace llvmc {
const LanguageMap& LangMap) const; const LanguageMap& LangMap) const;
/// BuildInitial - Traverse the initial parts of the toolchains. /// BuildInitial - Traverse the initial parts of the toolchains.
void BuildInitial(InputLanguagesSet& InLangs, int BuildInitial(InputLanguagesSet& InLangs,
const llvm::sys::Path& TempDir, const llvm::sys::Path& TempDir,
const LanguageMap& LangMap); const LanguageMap& LangMap);
/// TopologicalSort - Sort the nodes in topological order. /// TopologicalSort - Sort the nodes in topological order.
void TopologicalSort(std::vector<const Node*>& Out); int TopologicalSort(std::vector<const Node*>& Out);
/// TopologicalSortFilterJoinNodes - Call TopologicalSort and /// TopologicalSortFilterJoinNodes - Call TopologicalSort and
/// filter the resulting list to include only Join nodes. /// filter the resulting list to include only Join nodes.
void TopologicalSortFilterJoinNodes(std::vector<const Node*>& Out); int TopologicalSortFilterJoinNodes(std::vector<const Node*>& Out);
// Functions used to implement Check(). // Functions used to implement Check().
@ -270,7 +270,7 @@ namespace llvmc {
} }
inline pointer operator*() const { inline pointer operator*() const {
return &OwningGraph->getNode((*EdgeIter)->ToolName()); return OwningGraph->getNode((*EdgeIter)->ToolName());
} }
inline pointer operator->() const { inline pointer operator->() const {
return this->operator*(); return this->operator*();
@ -301,7 +301,7 @@ namespace llvm {
typedef llvmc::NodeChildIterator ChildIteratorType; typedef llvmc::NodeChildIterator ChildIteratorType;
static NodeType* getEntryNode(GraphType* G) { static NodeType* getEntryNode(GraphType* G) {
return &G->getNode("root"); return G->getNode("root");
} }
static ChildIteratorType child_begin(NodeType* N) { static ChildIteratorType child_begin(NodeType* N) {

View File

@ -7,29 +7,27 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// //
// Exception classes for llvmc. // Error handling.
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#ifndef LLVM_INCLUDE_COMPILER_DRIVER_ERROR_H #ifndef LLVM_INCLUDE_COMPILER_DRIVER_ERROR_H
#define LLVM_INCLUDE_COMPILER_DRIVER_ERROR_H #define LLVM_INCLUDE_COMPILER_DRIVER_ERROR_H
#include <stdexcept> #include "llvm/Support/raw_ostream.h"
#include <string>
namespace llvmc { namespace llvmc {
/// error_code - This gets thrown during the compilation process if a tool inline void PrintError(const char* Err) {
/// invocation returns a non-zero exit code. extern const char* ProgramName;
class error_code: public std::runtime_error { llvm::errs() << ProgramName << ": " << Err << '\n';
int Code_; }
public:
error_code (int c)
: std::runtime_error("Tool returned error code"), Code_(c)
{}
int code() const { return Code_; }
};
inline void PrintError(const std::string& Err) {
PrintError(Err.c_str());
}
} }
#endif // LLVM_INCLUDE_COMPILER_DRIVER_ERROR_H #endif // LLVM_INCLUDE_COMPILER_DRIVER_ERROR_H

View File

@ -32,15 +32,15 @@ namespace llvmc {
/// PreprocessOptions - The auto-generated function that performs various /// PreprocessOptions - The auto-generated function that performs various
/// consistency checks on options (like ensuring that -O2 and -O3 are not /// consistency checks on options (like ensuring that -O2 and -O3 are not
/// used together). /// used together).
virtual void PreprocessOptions() const = 0; virtual int PreprocessOptions() const = 0;
/// PopulateLanguageMap - The auto-generated function that fills in /// PopulateLanguageMap - The auto-generated function that fills in
/// the language map (map from file extensions to language names). /// the language map (map from file extensions to language names).
virtual void PopulateLanguageMap(LanguageMap&) const = 0; virtual int PopulateLanguageMap(LanguageMap&) const = 0;
/// PopulateCompilationGraph - The auto-generated function that /// PopulateCompilationGraph - The auto-generated function that
/// populates the compilation graph with nodes and edges. /// populates the compilation graph with nodes and edges.
virtual void PopulateCompilationGraph(CompilationGraph&) const = 0; virtual int PopulateCompilationGraph(CompilationGraph&) const = 0;
/// Needed to avoid a compiler warning. /// Needed to avoid a compiler warning.
virtual ~BasePlugin() {} virtual ~BasePlugin() {}
@ -68,7 +68,7 @@ namespace llvmc {
/// RunInitialization - Calls PreprocessOptions, PopulateLanguageMap and /// RunInitialization - Calls PreprocessOptions, PopulateLanguageMap and
/// PopulateCompilationGraph methods of all plugins. This populates the /// PopulateCompilationGraph methods of all plugins. This populates the
/// global language map and the compilation graph. /// global language map and the compilation graph.
void RunInitialization(LanguageMap& langMap, CompilationGraph& graph) const; int RunInitialization(LanguageMap& langMap, CompilationGraph& graph) const;
private: private:
// noncopyable // noncopyable

View File

@ -38,14 +38,16 @@ namespace llvmc {
virtual ~Tool() {} virtual ~Tool() {}
virtual Action GenerateAction (const PathVector& inFiles, virtual int GenerateAction (Action& Out,
bool HasChildren, const PathVector& inFiles,
const bool HasChildren,
const llvm::sys::Path& TempDir, const llvm::sys::Path& TempDir,
const InputLanguagesSet& InLangs, const InputLanguagesSet& InLangs,
const LanguageMap& LangMap) const = 0; const LanguageMap& LangMap) const = 0;
virtual Action GenerateAction (const llvm::sys::Path& inFile, virtual int GenerateAction (Action& Out,
bool HasChildren, const llvm::sys::Path& inFile,
const bool HasChildren,
const llvm::sys::Path& TempDir, const llvm::sys::Path& TempDir,
const InputLanguagesSet& InLangs, const InputLanguagesSet& InLangs,
const LanguageMap& LangMap) const = 0; const LanguageMap& LangMap) const = 0;
@ -74,11 +76,13 @@ namespace llvmc {
void ClearJoinList() { JoinList_.clear(); } void ClearJoinList() { JoinList_.clear(); }
bool JoinListEmpty() const { return JoinList_.empty(); } bool JoinListEmpty() const { return JoinList_.empty(); }
Action GenerateAction(bool HasChildren, int GenerateAction(Action& Out,
const bool HasChildren,
const llvm::sys::Path& TempDir, const llvm::sys::Path& TempDir,
const InputLanguagesSet& InLangs, const InputLanguagesSet& InLangs,
const LanguageMap& LangMap) const { const LanguageMap& LangMap) const {
return GenerateAction(JoinList_, HasChildren, TempDir, InLangs, LangMap); return GenerateAction(Out, JoinList_, HasChildren, TempDir, InLangs,
LangMap);
} }
// We shouldn't shadow base class's version of GenerateAction. // We shouldn't shadow base class's version of GenerateAction.
using Tool::GenerateAction; using Tool::GenerateAction;

View File

@ -13,6 +13,7 @@
#include "llvm/CompilerDriver/Action.h" #include "llvm/CompilerDriver/Action.h"
#include "llvm/CompilerDriver/BuiltinOptions.h" #include "llvm/CompilerDriver/BuiltinOptions.h"
#include "llvm/CompilerDriver/Error.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include "llvm/Support/SystemUtils.h" #include "llvm/Support/SystemUtils.h"
@ -58,11 +59,15 @@ namespace {
if (prog.isEmpty()) { if (prog.isEmpty()) {
prog = FindExecutable(name, ProgramName, (void *)(intptr_t)&Main); prog = FindExecutable(name, ProgramName, (void *)(intptr_t)&Main);
if (prog.isEmpty()) if (prog.isEmpty()) {
throw std::runtime_error("Can't find program '" + name + "'"); PrintError("Can't find program '" + name + "'");
return -1;
}
}
if (!prog.canExecute()) {
PrintError("Program '" + name + "' is not executable.");
return -1;
} }
if (!prog.canExecute())
throw std::runtime_error("Program '" + name + "' is not executable.");
// Build the command line vector and the redirects array. // Build the command line vector and the redirects array.
const sys::Path* redirects[3] = {0,0,0}; const sys::Path* redirects[3] = {0,0,0};

View File

@ -25,21 +25,22 @@
#include <iterator> #include <iterator>
#include <limits> #include <limits>
#include <queue> #include <queue>
#include <stdexcept>
using namespace llvm; using namespace llvm;
using namespace llvmc; using namespace llvmc;
namespace llvmc { namespace llvmc {
const std::string& LanguageMap::GetLanguage(const sys::Path& File) const { const std::string* LanguageMap::GetLanguage(const sys::Path& File) const {
StringRef suf = File.getSuffix(); StringRef suf = File.getSuffix();
LanguageMap::const_iterator Lang = LanguageMap::const_iterator Lang =
this->find(suf.empty() ? "*empty*" : suf); this->find(suf.empty() ? "*empty*" : suf);
if (Lang == this->end()) if (Lang == this->end()) {
throw std::runtime_error("File '" + File.str() + PrintError("File '" + File.str() + "' has unknown suffix '"
"' has unknown suffix '" + suf.str() + '\''); + suf.str() + '\'');
return Lang->second; return 0;
}
return &Lang->second;
} }
} }
@ -67,14 +68,16 @@ namespace {
} }
} }
if (!SingleMax) if (!SingleMax) {
throw std::runtime_error("Node " + NodeName + PrintError("Node " + NodeName + ": multiple maximal outward edges found!"
": multiple maximal outward edges found!"
" Most probably a specification error."); " Most probably a specification error.");
if (!MaxEdge) return 0;
throw std::runtime_error("Node " + NodeName + }
": no maximal outward edge found!" if (!MaxEdge) {
PrintError("Node " + NodeName + ": no maximal outward edge found!"
" Most probably a specification error."); " Most probably a specification error.");
return 0;
}
return MaxEdge; return MaxEdge;
} }
@ -98,29 +101,34 @@ CompilationGraph::CompilationGraph() {
NodesMap["root"] = Node(this); NodesMap["root"] = Node(this);
} }
Node& CompilationGraph::getNode(const std::string& ToolName) { Node* CompilationGraph::getNode(const std::string& ToolName) {
nodes_map_type::iterator I = NodesMap.find(ToolName); nodes_map_type::iterator I = NodesMap.find(ToolName);
if (I == NodesMap.end()) if (I == NodesMap.end()) {
throw std::runtime_error("Node " + ToolName + " is not in the graph"); PrintError("Node " + ToolName + " is not in the graph");
return I->second; return 0;
}
return &I->second;
} }
const Node& CompilationGraph::getNode(const std::string& ToolName) const { const Node* CompilationGraph::getNode(const std::string& ToolName) const {
nodes_map_type::const_iterator I = NodesMap.find(ToolName); nodes_map_type::const_iterator I = NodesMap.find(ToolName);
if (I == NodesMap.end()) if (I == NodesMap.end()) {
throw std::runtime_error("Node " + ToolName + " is not in the graph!"); PrintError("Node " + ToolName + " is not in the graph!");
return I->second; return 0;
}
return &I->second;
} }
// Find the tools list corresponding to the given language name. // Find the tools list corresponding to the given language name.
const CompilationGraph::tools_vector_type& const CompilationGraph::tools_vector_type*
CompilationGraph::getToolsVector(const std::string& LangName) const CompilationGraph::getToolsVector(const std::string& LangName) const
{ {
tools_map_type::const_iterator I = ToolsMap.find(LangName); tools_map_type::const_iterator I = ToolsMap.find(LangName);
if (I == ToolsMap.end()) if (I == ToolsMap.end()) {
throw std::runtime_error("No tool corresponding to the language " PrintError("No tool corresponding to the language " + LangName + " found");
+ LangName + " found"); return 0;
return I->second; }
return &I->second;
} }
void CompilationGraph::insertNode(Tool* V) { void CompilationGraph::insertNode(Tool* V) {
@ -128,25 +136,33 @@ void CompilationGraph::insertNode(Tool* V) {
NodesMap[V->Name()] = Node(this, V); NodesMap[V->Name()] = Node(this, V);
} }
void CompilationGraph::insertEdge(const std::string& A, Edge* Edg) { int CompilationGraph::insertEdge(const std::string& A, Edge* Edg) {
Node& B = getNode(Edg->ToolName()); Node* B = getNode(Edg->ToolName());
if (B == 0)
return -1;
if (A == "root") { if (A == "root") {
const char** InLangs = B.ToolPtr->InputLanguages(); const char** InLangs = B->ToolPtr->InputLanguages();
for (;*InLangs; ++InLangs) for (;*InLangs; ++InLangs)
ToolsMap[*InLangs].push_back(IntrusiveRefCntPtr<Edge>(Edg)); ToolsMap[*InLangs].push_back(IntrusiveRefCntPtr<Edge>(Edg));
NodesMap["root"].AddEdge(Edg); NodesMap["root"].AddEdge(Edg);
} }
else { else {
Node& N = getNode(A); Node* N = getNode(A);
N.AddEdge(Edg); if (N == 0)
return -1;
N->AddEdge(Edg);
} }
// Increase the inward edge counter. // Increase the inward edge counter.
B.IncrInEdges(); B->IncrInEdges();
return 0;
} }
// Pass input file through the chain until we bump into a Join node or // Pass input file through the chain until we bump into a Join node or
// a node that says that it is the last. // a node that says that it is the last.
void CompilationGraph::PassThroughGraph (const sys::Path& InFile, int CompilationGraph::PassThroughGraph (const sys::Path& InFile,
const Node* StartNode, const Node* StartNode,
const InputLanguagesSet& InLangs, const InputLanguagesSet& InLangs,
const sys::Path& TempDir, const sys::Path& TempDir,
@ -158,25 +174,35 @@ void CompilationGraph::PassThroughGraph (const sys::Path& InFile,
Tool* CurTool = CurNode->ToolPtr.getPtr(); Tool* CurTool = CurNode->ToolPtr.getPtr();
if (CurTool->IsJoin()) { if (CurTool->IsJoin()) {
JoinTool& JT = dynamic_cast<JoinTool&>(*CurTool); JoinTool& JT = static_cast<JoinTool&>(*CurTool);
JT.AddToJoinList(In); JT.AddToJoinList(In);
break; break;
} }
Action CurAction = CurTool->GenerateAction(In, CurNode->HasChildren(), Action CurAction;
TempDir, InLangs, LangMap); if (int ret = CurTool->GenerateAction(CurAction, In, CurNode->HasChildren(),
TempDir, InLangs, LangMap)) {
return ret;
}
if (int ret = CurAction.Execute()) if (int ret = CurAction.Execute())
throw error_code(ret); return ret;
if (CurAction.StopCompilation()) if (CurAction.StopCompilation())
return; return 0;
const Edge* Edg = ChooseEdge(CurNode->OutEdges, InLangs, CurNode->Name());
if (Edg == 0)
return -1;
CurNode = getNode(Edg->ToolName());
if (CurNode == 0)
return -1;
CurNode = &getNode(ChooseEdge(CurNode->OutEdges,
InLangs,
CurNode->Name())->ToolName());
In = CurAction.OutFile(); In = CurAction.OutFile();
} }
return 0;
} }
// Find the head of the toolchain corresponding to the given file. // Find the head of the toolchain corresponding to the given file.
@ -186,24 +212,37 @@ FindToolChain(const sys::Path& In, const std::string* ForceLanguage,
InputLanguagesSet& InLangs, const LanguageMap& LangMap) const { InputLanguagesSet& InLangs, const LanguageMap& LangMap) const {
// Determine the input language. // Determine the input language.
const std::string& InLanguage = const std::string* InLang = LangMap.GetLanguage(In);
ForceLanguage ? *ForceLanguage : LangMap.GetLanguage(In); if (InLang == 0)
return 0;
const std::string& InLanguage = (ForceLanguage ? *ForceLanguage : *InLang);
// Add the current input language to the input language set. // Add the current input language to the input language set.
InLangs.insert(InLanguage); InLangs.insert(InLanguage);
// Find the toolchain for the input language. // Find the toolchain for the input language.
const tools_vector_type& TV = getToolsVector(InLanguage); const tools_vector_type* pTV = getToolsVector(InLanguage);
if (TV.empty()) if (pTV == 0)
throw std::runtime_error("No toolchain corresponding to language " return 0;
const tools_vector_type& TV = *pTV;
if (TV.empty()) {
PrintError("No toolchain corresponding to language "
+ InLanguage + " found"); + InLanguage + " found");
return &getNode(ChooseEdge(TV, InLangs)->ToolName()); return 0;
}
const Edge* Edg = ChooseEdge(TV, InLangs);
if (Edg == 0)
return 0;
return getNode(Edg->ToolName());
} }
// Helper function used by Build(). // Helper function used by Build().
// Traverses initial portions of the toolchains (up to the first Join node). // Traverses initial portions of the toolchains (up to the first Join node).
// This function is also responsible for handling the -x option. // This function is also responsible for handling the -x option.
void CompilationGraph::BuildInitial (InputLanguagesSet& InLangs, int CompilationGraph::BuildInitial (InputLanguagesSet& InLangs,
const sys::Path& TempDir, const sys::Path& TempDir,
const LanguageMap& LangMap) { const LanguageMap& LangMap) {
// This is related to -x option handling. // This is related to -x option handling.
@ -255,15 +294,25 @@ void CompilationGraph::BuildInitial (InputLanguagesSet& InLangs,
// Find the toolchain corresponding to this file. // Find the toolchain corresponding to this file.
const Node* N = FindToolChain(In, xLanguage, InLangs, LangMap); const Node* N = FindToolChain(In, xLanguage, InLangs, LangMap);
if (N == 0)
return -1;
// Pass file through the chain starting at head. // Pass file through the chain starting at head.
PassThroughGraph(In, N, InLangs, TempDir, LangMap); if (int ret = PassThroughGraph(In, N, InLangs, TempDir, LangMap))
return ret;
} }
return 0;
} }
// Sort the nodes in topological order. // Sort the nodes in topological order.
void CompilationGraph::TopologicalSort(std::vector<const Node*>& Out) { int CompilationGraph::TopologicalSort(std::vector<const Node*>& Out) {
std::queue<const Node*> Q; std::queue<const Node*> Q;
Q.push(&getNode("root"));
Node* Root = getNode("root");
if (Root == 0)
return -1;
Q.push(Root);
while (!Q.empty()) { while (!Q.empty()) {
const Node* A = Q.front(); const Node* A = Q.front();
@ -271,12 +320,17 @@ void CompilationGraph::TopologicalSort(std::vector<const Node*>& Out) {
Out.push_back(A); Out.push_back(A);
for (Node::const_iterator EB = A->EdgesBegin(), EE = A->EdgesEnd(); for (Node::const_iterator EB = A->EdgesBegin(), EE = A->EdgesEnd();
EB != EE; ++EB) { EB != EE; ++EB) {
Node* B = &getNode((*EB)->ToolName()); Node* B = getNode((*EB)->ToolName());
if (B == 0)
return -1;
B->DecrInEdges(); B->DecrInEdges();
if (B->HasNoInEdges()) if (B->HasNoInEdges())
Q.push(B); Q.push(B);
} }
} }
return 0;
} }
namespace { namespace {
@ -287,49 +341,64 @@ namespace {
// Call TopologicalSort and filter the resulting list to include // Call TopologicalSort and filter the resulting list to include
// only Join nodes. // only Join nodes.
void CompilationGraph:: int CompilationGraph::
TopologicalSortFilterJoinNodes(std::vector<const Node*>& Out) { TopologicalSortFilterJoinNodes(std::vector<const Node*>& Out) {
std::vector<const Node*> TopSorted; std::vector<const Node*> TopSorted;
TopologicalSort(TopSorted); if (int ret = TopologicalSort(TopSorted))
return ret;
std::remove_copy_if(TopSorted.begin(), TopSorted.end(), std::remove_copy_if(TopSorted.begin(), TopSorted.end(),
std::back_inserter(Out), NotJoinNode); std::back_inserter(Out), NotJoinNode);
return 0;
} }
int CompilationGraph::Build (const sys::Path& TempDir, int CompilationGraph::Build (const sys::Path& TempDir,
const LanguageMap& LangMap) { const LanguageMap& LangMap) {
InputLanguagesSet InLangs; InputLanguagesSet InLangs;
// Traverse initial parts of the toolchains and fill in InLangs. // Traverse initial parts of the toolchains and fill in InLangs.
BuildInitial(InLangs, TempDir, LangMap); if (int ret = BuildInitial(InLangs, TempDir, LangMap))
return ret;
std::vector<const Node*> JTV; std::vector<const Node*> JTV;
TopologicalSortFilterJoinNodes(JTV); if (int ret = TopologicalSortFilterJoinNodes(JTV))
return ret;
// For all join nodes in topological order: // For all join nodes in topological order:
for (std::vector<const Node*>::iterator B = JTV.begin(), E = JTV.end(); for (std::vector<const Node*>::iterator B = JTV.begin(), E = JTV.end();
B != E; ++B) { B != E; ++B) {
const Node* CurNode = *B; const Node* CurNode = *B;
JoinTool* JT = &dynamic_cast<JoinTool&>(*CurNode->ToolPtr.getPtr()); JoinTool* JT = &static_cast<JoinTool&>(*CurNode->ToolPtr.getPtr());
// Are there any files in the join list? // Are there any files in the join list?
if (JT->JoinListEmpty() && !(JT->WorksOnEmpty() && InputFilenames.empty())) if (JT->JoinListEmpty() && !(JT->WorksOnEmpty() && InputFilenames.empty()))
continue; continue;
Action CurAction = JT->GenerateAction(CurNode->HasChildren(), Action CurAction;
TempDir, InLangs, LangMap); if (int ret = JT->GenerateAction(CurAction, CurNode->HasChildren(),
TempDir, InLangs, LangMap)) {
return ret;
}
if (int ret = CurAction.Execute()) if (int ret = CurAction.Execute())
throw error_code(ret); return ret;
if (CurAction.StopCompilation()) if (CurAction.StopCompilation())
return 0; return 0;
const Node* NextNode = &getNode(ChooseEdge(CurNode->OutEdges, InLangs, const Edge* Edg = ChooseEdge(CurNode->OutEdges, InLangs, CurNode->Name());
CurNode->Name())->ToolName()); if (Edg == 0)
PassThroughGraph(sys::Path(CurAction.OutFile()), NextNode, return -1;
InLangs, TempDir, LangMap);
const Node* NextNode = getNode(Edg->ToolName());
if (NextNode == 0)
return -1;
if (int ret = PassThroughGraph(sys::Path(CurAction.OutFile()), NextNode,
InLangs, TempDir, LangMap)) {
return ret;
}
} }
return 0; return 0;
@ -337,6 +406,7 @@ int CompilationGraph::Build (const sys::Path& TempDir,
int CompilationGraph::CheckLanguageNames() const { int CompilationGraph::CheckLanguageNames() const {
int ret = 0; int ret = 0;
// Check that names for output and input languages on all edges do match. // Check that names for output and input languages on all edges do match.
for (const_nodes_iterator B = this->NodesMap.begin(), for (const_nodes_iterator B = this->NodesMap.begin(),
E = this->NodesMap.end(); B != E; ++B) { E = this->NodesMap.end(); B != E; ++B) {
@ -345,9 +415,11 @@ int CompilationGraph::CheckLanguageNames() const {
if (N1.ToolPtr) { if (N1.ToolPtr) {
for (Node::const_iterator EB = N1.EdgesBegin(), EE = N1.EdgesEnd(); for (Node::const_iterator EB = N1.EdgesBegin(), EE = N1.EdgesEnd();
EB != EE; ++EB) { EB != EE; ++EB) {
const Node& N2 = this->getNode((*EB)->ToolName()); const Node* N2 = this->getNode((*EB)->ToolName());
if (N2 == 0)
return -1;
if (!N2.ToolPtr) { if (!N2->ToolPtr) {
++ret; ++ret;
errs() << "Error: there is an edge from '" << N1.ToolPtr->Name() errs() << "Error: there is an edge from '" << N1.ToolPtr->Name()
<< "' back to the root!\n\n"; << "' back to the root!\n\n";
@ -355,7 +427,7 @@ int CompilationGraph::CheckLanguageNames() const {
} }
const char* OutLang = N1.ToolPtr->OutputLanguage(); const char* OutLang = N1.ToolPtr->OutputLanguage();
const char** InLangs = N2.ToolPtr->InputLanguages(); const char** InLangs = N2->ToolPtr->InputLanguages();
bool eq = false; bool eq = false;
for (;*InLangs; ++InLangs) { for (;*InLangs; ++InLangs) {
if (std::strcmp(OutLang, *InLangs) == 0) { if (std::strcmp(OutLang, *InLangs) == 0) {
@ -367,11 +439,11 @@ int CompilationGraph::CheckLanguageNames() const {
if (!eq) { if (!eq) {
++ret; ++ret;
errs() << "Error: Output->input language mismatch in the edge '" errs() << "Error: Output->input language mismatch in the edge '"
<< N1.ToolPtr->Name() << "' -> '" << N2.ToolPtr->Name() << N1.ToolPtr->Name() << "' -> '" << N2->ToolPtr->Name()
<< "'!\n" << "'!\n"
<< "Expected one of { "; << "Expected one of { ";
InLangs = N2.ToolPtr->InputLanguages(); InLangs = N2->ToolPtr->InputLanguages();
for (;*InLangs; ++InLangs) { for (;*InLangs; ++InLangs) {
errs() << '\'' << *InLangs << (*(InLangs+1) ? "', " : "'"); errs() << '\'' << *InLangs << (*(InLangs+1) ? "', " : "'");
} }
@ -422,7 +494,12 @@ int CompilationGraph::CheckMultipleDefaultEdges() const {
int CompilationGraph::CheckCycles() { int CompilationGraph::CheckCycles() {
unsigned deleted = 0; unsigned deleted = 0;
std::queue<Node*> Q; std::queue<Node*> Q;
Q.push(&getNode("root"));
Node* Root = getNode("root");
if (Root == 0)
return -1;
Q.push(Root);
// Try to delete all nodes that have no ingoing edges, starting from the // Try to delete all nodes that have no ingoing edges, starting from the
// root. If there are any nodes left after this operation, then we have a // root. If there are any nodes left after this operation, then we have a
@ -434,7 +511,10 @@ int CompilationGraph::CheckCycles() {
for (Node::iterator EB = A->EdgesBegin(), EE = A->EdgesEnd(); for (Node::iterator EB = A->EdgesBegin(), EE = A->EdgesEnd();
EB != EE; ++EB) { EB != EE; ++EB) {
Node* B = &getNode((*EB)->ToolName()); Node* B = getNode((*EB)->ToolName());
if (B == 0)
return -1;
B->DecrInEdges(); B->DecrInEdges();
if (B->HasNoInEdges()) if (B->HasNoInEdges())
Q.push(B); Q.push(B);
@ -453,18 +533,28 @@ int CompilationGraph::CheckCycles() {
int CompilationGraph::Check () { int CompilationGraph::Check () {
// We try to catch as many errors as we can in one go. // We try to catch as many errors as we can in one go.
int errs = 0;
int ret = 0; int ret = 0;
// Check that output/input language names match. // Check that output/input language names match.
ret += this->CheckLanguageNames(); ret = this->CheckLanguageNames();
if (ret < 0)
return -1;
errs += ret;
// Check for multiple default edges. // Check for multiple default edges.
ret += this->CheckMultipleDefaultEdges(); ret = this->CheckMultipleDefaultEdges();
if (ret < 0)
return -1;
errs += ret;
// Check for cycles. // Check for cycles.
ret += this->CheckCycles(); ret = this->CheckCycles();
if (ret < 0)
return -1;
errs += ret;
return ret; return errs;
} }
// Code related to graph visualization. // Code related to graph visualization.
@ -516,7 +606,7 @@ namespace llvm {
} }
void CompilationGraph::writeGraph(const std::string& OutputFilename) { int CompilationGraph::writeGraph(const std::string& OutputFilename) {
std::string ErrorInfo; std::string ErrorInfo;
raw_fd_ostream O(OutputFilename.c_str(), ErrorInfo); raw_fd_ostream O(OutputFilename.c_str(), ErrorInfo);
@ -526,9 +616,11 @@ void CompilationGraph::writeGraph(const std::string& OutputFilename) {
errs() << "done.\n"; errs() << "done.\n";
} }
else { else {
throw std::runtime_error("Error opening file '" + OutputFilename PrintError("Error opening file '" + OutputFilename + "' for writing!");
+ "' for writing!"); return -1;
} }
return 0;
} }
void CompilationGraph::viewGraph() { void CompilationGraph::viewGraph() {

View File

@ -20,7 +20,6 @@
#include "llvm/System/Path.h" #include "llvm/System/Path.h"
#include <sstream> #include <sstream>
#include <stdexcept>
#include <string> #include <string>
namespace cl = llvm::cl; namespace cl = llvm::cl;
@ -31,9 +30,7 @@ namespace {
std::stringstream* GlobalTimeLog; std::stringstream* GlobalTimeLog;
sys::Path getTempDir() { int getTempDir(sys::Path& tempDir) {
sys::Path tempDir;
// The --temp-dir option. // The --temp-dir option.
if (!TempDirname.empty()) { if (!TempDirname.empty()) {
tempDir = TempDirname; tempDir = TempDirname;
@ -41,7 +38,7 @@ namespace {
// GCC 4.5-style -save-temps handling. // GCC 4.5-style -save-temps handling.
else if (SaveTemps == SaveTempsEnum::Unset) { else if (SaveTemps == SaveTempsEnum::Unset) {
tempDir = sys::Path::GetTemporaryDirectory(); tempDir = sys::Path::GetTemporaryDirectory();
return tempDir; return 0;
} }
else if (SaveTemps == SaveTempsEnum::Obj && !OutputFilename.empty()) { else if (SaveTemps == SaveTempsEnum::Obj && !OutputFilename.empty()) {
tempDir = OutputFilename; tempDir = OutputFilename;
@ -49,35 +46,34 @@ namespace {
} }
else { else {
// SaveTemps == Cwd --> use current dir (leave tempDir empty). // SaveTemps == Cwd --> use current dir (leave tempDir empty).
return tempDir; return 0;
} }
if (!tempDir.exists()) { if (!tempDir.exists()) {
std::string ErrMsg; std::string ErrMsg;
if (tempDir.createDirectoryOnDisk(true, &ErrMsg)) if (tempDir.createDirectoryOnDisk(true, &ErrMsg)) {
throw std::runtime_error(ErrMsg); PrintError(ErrMsg);
return -1;
}
} }
return tempDir; return 0;
} }
/// BuildTargets - A small wrapper for CompilationGraph::Build. /// BuildTargets - A small wrapper for CompilationGraph::Build.
int BuildTargets(CompilationGraph& graph, const LanguageMap& langMap) { int BuildTargets(CompilationGraph& graph, const LanguageMap& langMap) {
int ret; int ret;
const sys::Path& tempDir = getTempDir(); sys::Path tempDir;
bool toDelete = (SaveTemps == SaveTempsEnum::Unset); bool toDelete = (SaveTemps == SaveTempsEnum::Unset);
try { if (int ret = getTempDir(tempDir))
return ret;
ret = graph.Build(tempDir, langMap); ret = graph.Build(tempDir, langMap);
}
catch(...) {
if (toDelete)
tempDir.eraseFromDisk(true);
throw;
}
if (toDelete) if (toDelete)
tempDir.eraseFromDisk(true); tempDir.eraseFromDisk(true);
return ret; return ret;
} }
} }
@ -93,7 +89,7 @@ void AppendToGlobalTimeLog(const std::string& cmd, double time) {
const char* ProgramName; const char* ProgramName;
int Main(int argc, char** argv) { int Main(int argc, char** argv) {
try { int ret = 0;
LanguageMap langMap; LanguageMap langMap;
CompilationGraph graph; CompilationGraph graph;
@ -104,10 +100,11 @@ int Main(int argc, char** argv) {
/* ReadResponseFiles = */ false); /* ReadResponseFiles = */ false);
PluginLoader Plugins; PluginLoader Plugins;
Plugins.RunInitialization(langMap, graph); if (int ret = Plugins.RunInitialization(langMap, graph))
return ret;
if (CheckGraph) { if (CheckGraph) {
int ret = graph.Check(); ret = graph.Check();
if (!ret) if (!ret)
llvm::errs() << "check-graph: no errors found.\n"; llvm::errs() << "check-graph: no errors found.\n";
@ -121,10 +118,10 @@ int Main(int argc, char** argv) {
} }
if (WriteGraph) { if (WriteGraph) {
graph.writeGraph(OutputFilename.empty() const std::string& Out = (OutputFilename.empty()
? std::string("compilation-graph.dot") ? std::string("compilation-graph.dot")
: OutputFilename); : OutputFilename);
return 0; return graph.writeGraph(Out);
} }
if (Time) { if (Time) {
@ -132,7 +129,7 @@ int Main(int argc, char** argv) {
GlobalTimeLog->precision(2); GlobalTimeLog->precision(2);
} }
int ret = BuildTargets(graph, langMap); ret = BuildTargets(graph, langMap);
if (Time) { if (Time) {
llvm::errs() << GlobalTimeLog->str(); llvm::errs() << GlobalTimeLog->str();
@ -141,16 +138,5 @@ int Main(int argc, char** argv) {
return ret; return ret;
} }
catch(llvmc::error_code& ec) {
return ec.code();
}
catch(const std::exception& ex) {
llvm::errs() << argv[0] << ": " << ex.what() << '\n';
}
catch(...) {
llvm::errs() << argv[0] << ": unknown error!\n";
}
return 1;
}
} // end namespace llvmc } // end namespace llvmc

View File

@ -21,9 +21,6 @@ else
LINK_COMPONENTS = support system LINK_COMPONENTS = support system
endif endif
REQUIRES_EH := 1
REQUIRES_RTTI := 1
include $(LEVEL)/Makefile.common include $(LEVEL)/Makefile.common
ifeq ($(ENABLE_LLVMC_DYNAMIC_PLUGINS), 1) ifeq ($(ENABLE_LLVMC_DYNAMIC_PLUGINS), 1)

View File

@ -62,17 +62,22 @@ namespace llvmc {
pluginListInitialized = false; pluginListInitialized = false;
} }
void PluginLoader::RunInitialization(LanguageMap& langMap, int PluginLoader::RunInitialization(LanguageMap& langMap,
CompilationGraph& graph) const CompilationGraph& graph) const
{ {
llvm::sys::SmartScopedLock<true> Lock(*PluginMutex); llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
for (PluginList::iterator B = Plugins.begin(), E = Plugins.end(); for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
B != E; ++B) { B != E; ++B) {
const BasePlugin* BP = *B; const BasePlugin* BP = *B;
BP->PreprocessOptions(); if (int ret = BP->PreprocessOptions())
BP->PopulateLanguageMap(langMap); return ret;
BP->PopulateCompilationGraph(graph); if (int ret = BP->PopulateLanguageMap(langMap))
return ret;
if (int ret = BP->PopulateCompilationGraph(graph))
return ret;
} }
return 0;
} }
} }

View File

@ -11,7 +11,6 @@ LEVEL = ../..
export LLVMC_BASED_DRIVER_NAME = llvmc export LLVMC_BASED_DRIVER_NAME = llvmc
export LLVMC_BUILTIN_PLUGINS = Base Clang export LLVMC_BUILTIN_PLUGINS = Base Clang
REQUIRES_RTTI = 1
DIRS = plugins driver DIRS = plugins driver

View File

@ -1957,10 +1957,10 @@ struct ActionHandlingCallbackBase
unsigned IndentLevel, raw_ostream& O) const unsigned IndentLevel, raw_ostream& O) const
{ {
O.indent(IndentLevel) O.indent(IndentLevel)
<< "throw std::runtime_error(\"" << << "PrintError(\""
(d.getNumArgs() >= 1 ? InitPtrToString(d.getArg(0)) << (d.getNumArgs() >= 1 ? InitPtrToString(d.getArg(0)) : "Unknown error!")
: "Unknown error!")
<< "\");\n"; << "\");\n";
O.indent(IndentLevel) << "return -1;\n";
} }
void onWarningDag(const DagInit& d, void onWarningDag(const DagInit& d,
@ -2154,26 +2154,33 @@ class EmitActionHandlersCallback :
}; };
void EmitGenerateActionMethodHeader(const ToolDescription& D, void EmitGenerateActionMethodHeader(const ToolDescription& D,
bool IsJoin, raw_ostream& O) bool IsJoin, bool Naked,
raw_ostream& O)
{ {
if (IsJoin) O.indent(Indent1) << "int GenerateAction(Action& Out,\n";
O.indent(Indent1) << "Action GenerateAction(const PathVector& inFiles,\n";
else
O.indent(Indent1) << "Action GenerateAction(const sys::Path& inFile,\n";
O.indent(Indent2) << "bool HasChildren,\n"; if (IsJoin)
O.indent(Indent2) << "const PathVector& inFiles,\n";
else
O.indent(Indent2) << "const sys::Path& inFile,\n";
O.indent(Indent2) << "const bool HasChildren,\n";
O.indent(Indent2) << "const llvm::sys::Path& TempDir,\n"; O.indent(Indent2) << "const llvm::sys::Path& TempDir,\n";
O.indent(Indent2) << "const InputLanguagesSet& InLangs,\n"; O.indent(Indent2) << "const InputLanguagesSet& InLangs,\n";
O.indent(Indent2) << "const LanguageMap& LangMap) const\n"; O.indent(Indent2) << "const LanguageMap& LangMap) const\n";
O.indent(Indent1) << "{\n"; O.indent(Indent1) << "{\n";
if (!Naked) {
O.indent(Indent2) << "std::string cmd;\n"; O.indent(Indent2) << "std::string cmd;\n";
O.indent(Indent2) << "std::string out_file;\n"; O.indent(Indent2) << "std::string out_file;\n";
O.indent(Indent2) << "std::vector<std::pair<unsigned, std::string> > vec;\n"; O.indent(Indent2)
<< "std::vector<std::pair<unsigned, std::string> > vec;\n";
O.indent(Indent2) << "bool stop_compilation = !HasChildren;\n"; O.indent(Indent2) << "bool stop_compilation = !HasChildren;\n";
O.indent(Indent2) << "bool no_out_file = false;\n"; O.indent(Indent2) << "bool no_out_file = false;\n";
O.indent(Indent2) << "const char* output_suffix = \"" O.indent(Indent2) << "const char* output_suffix = \""
<< D.OutputSuffix << "\";\n"; << D.OutputSuffix << "\";\n";
} }
}
// EmitGenerateActionMethod - Emit either a normal or a "join" version of the // EmitGenerateActionMethod - Emit either a normal or a "join" version of the
// Tool::GenerateAction() method. // Tool::GenerateAction() method.
@ -2181,7 +2188,7 @@ void EmitGenerateActionMethod (const ToolDescription& D,
const OptionDescriptions& OptDescs, const OptionDescriptions& OptDescs,
bool IsJoin, raw_ostream& O) { bool IsJoin, raw_ostream& O) {
EmitGenerateActionMethodHeader(D, IsJoin, O); EmitGenerateActionMethodHeader(D, IsJoin, /* Naked = */ false, O);
if (!D.CmdLine) if (!D.CmdLine)
throw "Tool " + D.Name + " has no cmd_line property!"; throw "Tool " + D.Name + " has no cmd_line property!";
@ -2245,8 +2252,9 @@ void EmitGenerateActionMethod (const ToolDescription& D,
O.indent(Indent2) << "}\n"; O.indent(Indent2) << "}\n";
} }
O.indent(Indent2) << "return Action(cmd, this->SortArgs(vec), " O.indent(Indent2) << "Out.Construct(cmd, this->SortArgs(vec), "
<< "stop_compilation, out_file);\n"; << "stop_compilation, out_file);\n";
O.indent(Indent2) << "return 0;\n";
O.indent(Indent1) << "}\n\n"; O.indent(Indent1) << "}\n\n";
} }
@ -2256,14 +2264,11 @@ void EmitGenerateActionMethods (const ToolDescription& ToolDesc,
const OptionDescriptions& OptDescs, const OptionDescriptions& OptDescs,
raw_ostream& O) { raw_ostream& O) {
if (!ToolDesc.isJoin()) { if (!ToolDesc.isJoin()) {
O.indent(Indent1) << "Action GenerateAction(const PathVector& inFiles,\n"; EmitGenerateActionMethodHeader(ToolDesc, /* IsJoin = */ true,
O.indent(Indent2) << "bool HasChildren,\n"; /* Naked = */ true, O);
O.indent(Indent2) << "const llvm::sys::Path& TempDir,\n"; O.indent(Indent2) << "PrintError(\"" << ToolDesc.Name
O.indent(Indent2) << "const InputLanguagesSet& InLangs,\n";
O.indent(Indent2) << "const LanguageMap& LangMap) const\n";
O.indent(Indent1) << "{\n";
O.indent(Indent2) << "throw std::runtime_error(\"" << ToolDesc.Name
<< " is not a Join tool!\");\n"; << " is not a Join tool!\");\n";
O.indent(Indent2) << "return -1;\n";
O.indent(Indent1) << "}\n\n"; O.indent(Indent1) << "}\n\n";
} }
else { else {
@ -2627,7 +2632,7 @@ public:
void EmitPreprocessOptions (const RecordKeeper& Records, void EmitPreprocessOptions (const RecordKeeper& Records,
const OptionDescriptions& OptDecs, raw_ostream& O) const OptionDescriptions& OptDecs, raw_ostream& O)
{ {
O << "void PreprocessOptionsLocal() {\n"; O << "int PreprocessOptionsLocal() {\n";
const RecordVector& OptionPreprocessors = const RecordVector& OptionPreprocessors =
Records.getAllDerivedDefinitions("OptionPreprocessor"); Records.getAllDerivedDefinitions("OptionPreprocessor");
@ -2640,13 +2645,15 @@ void EmitPreprocessOptions (const RecordKeeper& Records,
false, OptDecs, O); false, OptDecs, O);
} }
O << '\n';
O.indent(Indent1) << "return 0;\n";
O << "}\n\n"; O << "}\n\n";
} }
/// EmitPopulateLanguageMap - Emit the PopulateLanguageMapLocal() function. /// EmitPopulateLanguageMap - Emit the PopulateLanguageMapLocal() function.
void EmitPopulateLanguageMap (const RecordKeeper& Records, raw_ostream& O) void EmitPopulateLanguageMap (const RecordKeeper& Records, raw_ostream& O)
{ {
O << "void PopulateLanguageMapLocal(LanguageMap& langMap) {\n"; O << "int PopulateLanguageMapLocal(LanguageMap& langMap) {\n";
// Get the relevant field out of RecordKeeper // Get the relevant field out of RecordKeeper
const Record* LangMapRecord = Records.getDef("LanguageMap"); const Record* LangMapRecord = Records.getDef("LanguageMap");
@ -2671,6 +2678,8 @@ void EmitPopulateLanguageMap (const RecordKeeper& Records, raw_ostream& O)
} }
} }
O << '\n';
O.indent(Indent1) << "return 0;\n";
O << "}\n\n"; O << "}\n\n";
} }
@ -2688,10 +2697,12 @@ void IncDecWeight (const Init* i, unsigned IndentLevel,
O.indent(IndentLevel) << "ret -= "; O.indent(IndentLevel) << "ret -= ";
} }
else if (OpName == "error") { else if (OpName == "error") {
// TODO: fix this
CheckNumberOfArguments(d, 1); CheckNumberOfArguments(d, 1);
O.indent(IndentLevel) << "throw std::runtime_error(\"" O.indent(IndentLevel) << "PrintError(\""
<< InitPtrToString(d.getArg(0)) << InitPtrToString(d.getArg(0))
<< "\");\n"; << "\");\n";
O.indent(IndentLevel) << "return -1;\n";
return; return;
} }
else { else {
@ -2752,7 +2763,7 @@ void EmitPopulateCompilationGraph (const RecordVector& EdgeVector,
const ToolDescriptions& ToolDescs, const ToolDescriptions& ToolDescs,
raw_ostream& O) raw_ostream& O)
{ {
O << "void PopulateCompilationGraphLocal(CompilationGraph& G) {\n"; O << "int PopulateCompilationGraphLocal(CompilationGraph& G) {\n";
for (ToolDescriptions::const_iterator B = ToolDescs.begin(), for (ToolDescriptions::const_iterator B = ToolDescs.begin(),
E = ToolDescs.end(); B != E; ++B) E = ToolDescs.end(); B != E; ++B)
@ -2770,17 +2781,21 @@ void EmitPopulateCompilationGraph (const RecordVector& EdgeVector,
const std::string& NodeB = Edge->getValueAsString("b"); const std::string& NodeB = Edge->getValueAsString("b");
DagInit& Weight = *Edge->getValueAsDag("weight"); DagInit& Weight = *Edge->getValueAsDag("weight");
O.indent(Indent1) << "G.insertEdge(\"" << NodeA << "\", "; O.indent(Indent1) << "if (int ret = G.insertEdge(\"" << NodeA << "\", ";
if (IsDagEmpty(Weight)) if (IsDagEmpty(Weight))
O << "new SimpleEdge(\"" << NodeB << "\")"; O << "new SimpleEdge(\"" << NodeB << "\")";
else else
O << "new Edge" << i << "()"; O << "new Edge" << i << "()";
O << ");\n"; O << "))\n";
O.indent(Indent2) << "return ret;\n";
++i; ++i;
} }
O << '\n';
O.indent(Indent1) << "return 0;\n";
O << "}\n\n"; O << "}\n\n";
} }
@ -2963,13 +2978,13 @@ void EmitRegisterPlugin(int Priority, raw_ostream& O) {
O << "struct Plugin : public llvmc::BasePlugin {\n\n"; O << "struct Plugin : public llvmc::BasePlugin {\n\n";
O.indent(Indent1) << "int Priority() const { return " O.indent(Indent1) << "int Priority() const { return "
<< Priority << "; }\n\n"; << Priority << "; }\n\n";
O.indent(Indent1) << "void PreprocessOptions() const\n"; O.indent(Indent1) << "int PreprocessOptions() const\n";
O.indent(Indent1) << "{ PreprocessOptionsLocal(); }\n\n"; O.indent(Indent1) << "{ return PreprocessOptionsLocal(); }\n\n";
O.indent(Indent1) << "void PopulateLanguageMap(LanguageMap& langMap) const\n"; O.indent(Indent1) << "int PopulateLanguageMap(LanguageMap& langMap) const\n";
O.indent(Indent1) << "{ PopulateLanguageMapLocal(langMap); }\n\n"; O.indent(Indent1) << "{ return PopulateLanguageMapLocal(langMap); }\n\n";
O.indent(Indent1) O.indent(Indent1)
<< "void PopulateCompilationGraph(CompilationGraph& graph) const\n"; << "int PopulateCompilationGraph(CompilationGraph& graph) const\n";
O.indent(Indent1) << "{ PopulateCompilationGraphLocal(graph); }\n" O.indent(Indent1) << "{ return PopulateCompilationGraphLocal(graph); }\n"
<< "};\n\n" << "};\n\n"
<< "static llvmc::RegisterPlugin<Plugin> RP;\n\n"; << "static llvmc::RegisterPlugin<Plugin> RP;\n\n";
} }
@ -2979,6 +2994,7 @@ void EmitRegisterPlugin(int Priority, raw_ostream& O) {
void EmitIncludes(raw_ostream& O) { void EmitIncludes(raw_ostream& O) {
O << "#include \"llvm/CompilerDriver/BuiltinOptions.h\"\n" O << "#include \"llvm/CompilerDriver/BuiltinOptions.h\"\n"
<< "#include \"llvm/CompilerDriver/CompilationGraph.h\"\n" << "#include \"llvm/CompilerDriver/CompilationGraph.h\"\n"
<< "#include \"llvm/CompilerDriver/Error.h\"\n"
<< "#include \"llvm/CompilerDriver/ForceLinkageMacros.h\"\n" << "#include \"llvm/CompilerDriver/ForceLinkageMacros.h\"\n"
<< "#include \"llvm/CompilerDriver/Plugin.h\"\n" << "#include \"llvm/CompilerDriver/Plugin.h\"\n"
<< "#include \"llvm/CompilerDriver/Tool.h\"\n\n" << "#include \"llvm/CompilerDriver/Tool.h\"\n\n"