summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/lib/CompilerDriver
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/lib/CompilerDriver')
-rw-r--r--contrib/llvm/lib/CompilerDriver/Action.cpp13
-rw-r--r--contrib/llvm/lib/CompilerDriver/BuiltinOptions.cpp4
-rw-r--r--contrib/llvm/lib/CompilerDriver/CompilationGraph.cpp289
-rw-r--r--contrib/llvm/lib/CompilerDriver/Main.cpp123
-rw-r--r--contrib/llvm/lib/CompilerDriver/Makefile36
-rw-r--r--contrib/llvm/lib/CompilerDriver/Plugin.cpp78
6 files changed, 269 insertions, 274 deletions
diff --git a/contrib/llvm/lib/CompilerDriver/Action.cpp b/contrib/llvm/lib/CompilerDriver/Action.cpp
index 5f30dce..0be8049 100644
--- a/contrib/llvm/lib/CompilerDriver/Action.cpp
+++ b/contrib/llvm/lib/CompilerDriver/Action.cpp
@@ -13,6 +13,7 @@
#include "llvm/CompilerDriver/Action.h"
#include "llvm/CompilerDriver/BuiltinOptions.h"
+#include "llvm/CompilerDriver/Error.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/SystemUtils.h"
@@ -58,11 +59,15 @@ namespace {
if (prog.isEmpty()) {
prog = FindExecutable(name, ProgramName, (void *)(intptr_t)&Main);
- if (prog.isEmpty())
- throw std::runtime_error("Can't find program '" + name + "'");
+ if (prog.isEmpty()) {
+ 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.
const sys::Path* redirects[3] = {0,0,0};
diff --git a/contrib/llvm/lib/CompilerDriver/BuiltinOptions.cpp b/contrib/llvm/lib/CompilerDriver/BuiltinOptions.cpp
index d1ac8c9..3844203 100644
--- a/contrib/llvm/lib/CompilerDriver/BuiltinOptions.cpp
+++ b/contrib/llvm/lib/CompilerDriver/BuiltinOptions.cpp
@@ -19,7 +19,7 @@
namespace cl = llvm::cl;
-// External linkage here is intentional.
+namespace llvmc {
cl::list<std::string> InputFilenames(cl::Positional, cl::desc("<input file>"),
cl::ZeroOrMore);
@@ -57,3 +57,5 @@ cl::opt<SaveTempsEnum::Values> SaveTemps
clEnumValN(SaveTempsEnum::Obj, "", "Same as 'cwd'"),
clEnumValEnd),
cl::ValueOptional);
+
+} // End namespace llvmc.
diff --git a/contrib/llvm/lib/CompilerDriver/CompilationGraph.cpp b/contrib/llvm/lib/CompilerDriver/CompilationGraph.cpp
index 7d1c7fe..d0c0e15 100644
--- a/contrib/llvm/lib/CompilerDriver/CompilationGraph.cpp
+++ b/contrib/llvm/lib/CompilerDriver/CompilationGraph.cpp
@@ -25,39 +25,46 @@
#include <iterator>
#include <limits>
#include <queue>
-#include <stdexcept>
using namespace llvm;
using 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();
LanguageMap::const_iterator Lang =
this->find(suf.empty() ? "*empty*" : suf);
- if (Lang == this->end())
- throw std::runtime_error("File '" + File.str() +
- "' has unknown suffix '" + suf.str() + '\'');
- return Lang->second;
+ if (Lang == this->end()) {
+ PrintError("File '" + File.str() + "' has unknown suffix '"
+ + suf.str() + '\'');
+ return 0;
+ }
+ return &Lang->second;
}
}
namespace {
- /// ChooseEdge - Return the edge with the maximum weight.
+ /// ChooseEdge - Return the edge with the maximum weight. Returns 0 on error.
template <class C>
const Edge* ChooseEdge(const C& EdgesContainer,
const InputLanguagesSet& InLangs,
const std::string& NodeName = "root") {
const Edge* MaxEdge = 0;
- unsigned MaxWeight = 0;
+ int MaxWeight = 0;
bool SingleMax = true;
+ // TODO: fix calculation of SingleMax.
for (typename C::const_iterator B = EdgesContainer.begin(),
E = EdgesContainer.end(); B != E; ++B) {
const Edge* e = B->getPtr();
- unsigned EW = e->Weight(InLangs);
+ int EW = e->Weight(InLangs);
+ if (EW < 0) {
+ // (error) invocation in TableGen -> we don't need to print an error
+ // message.
+ return 0;
+ }
if (EW > MaxWeight) {
MaxEdge = e;
MaxWeight = EW;
@@ -67,14 +74,16 @@ namespace {
}
}
- if (!SingleMax)
- throw std::runtime_error("Node " + NodeName +
- ": multiple maximal outward edges found!"
- " Most probably a specification error.");
- if (!MaxEdge)
- throw std::runtime_error("Node " + NodeName +
- ": no maximal outward edge found!"
- " Most probably a specification error.");
+ if (!SingleMax) {
+ PrintError("Node " + NodeName + ": multiple maximal outward edges found!"
+ " Most probably a specification error.");
+ return 0;
+ }
+ if (!MaxEdge) {
+ PrintError("Node " + NodeName + ": no maximal outward edge found!"
+ " Most probably a specification error.");
+ return 0;
+ }
return MaxEdge;
}
@@ -98,29 +107,34 @@ CompilationGraph::CompilationGraph() {
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);
- if (I == NodesMap.end())
- throw std::runtime_error("Node " + ToolName + " is not in the graph");
- return I->second;
+ if (I == NodesMap.end()) {
+ PrintError("Node " + ToolName + " is not in the graph");
+ 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);
- if (I == NodesMap.end())
- throw std::runtime_error("Node " + ToolName + " is not in the graph!");
- return I->second;
+ if (I == NodesMap.end()) {
+ PrintError("Node " + ToolName + " is not in the graph!");
+ return 0;
+ }
+ return &I->second;
}
// 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
{
tools_map_type::const_iterator I = ToolsMap.find(LangName);
- if (I == ToolsMap.end())
- throw std::runtime_error("No tool corresponding to the language "
- + LangName + " found");
- return I->second;
+ if (I == ToolsMap.end()) {
+ PrintError("No tool corresponding to the language " + LangName + " found");
+ return 0;
+ }
+ return &I->second;
}
void CompilationGraph::insertNode(Tool* V) {
@@ -128,29 +142,37 @@ void CompilationGraph::insertNode(Tool* V) {
NodesMap[V->Name()] = Node(this, V);
}
-void CompilationGraph::insertEdge(const std::string& A, Edge* Edg) {
- Node& B = getNode(Edg->ToolName());
+int CompilationGraph::insertEdge(const std::string& A, Edge* Edg) {
+ Node* B = getNode(Edg->ToolName());
+ if (B == 0)
+ return 1;
+
if (A == "root") {
- const char** InLangs = B.ToolPtr->InputLanguages();
+ const char** InLangs = B->ToolPtr->InputLanguages();
for (;*InLangs; ++InLangs)
ToolsMap[*InLangs].push_back(IntrusiveRefCntPtr<Edge>(Edg));
NodesMap["root"].AddEdge(Edg);
}
else {
- Node& N = getNode(A);
- N.AddEdge(Edg);
+ Node* N = getNode(A);
+ if (N == 0)
+ return 1;
+
+ N->AddEdge(Edg);
}
// 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
// a node that says that it is the last.
-void CompilationGraph::PassThroughGraph (const sys::Path& InFile,
- const Node* StartNode,
- const InputLanguagesSet& InLangs,
- const sys::Path& TempDir,
- const LanguageMap& LangMap) const {
+int CompilationGraph::PassThroughGraph (const sys::Path& InFile,
+ const Node* StartNode,
+ const InputLanguagesSet& InLangs,
+ const sys::Path& TempDir,
+ const LanguageMap& LangMap) const {
sys::Path In = InFile;
const Node* CurNode = StartNode;
@@ -158,25 +180,35 @@ void CompilationGraph::PassThroughGraph (const sys::Path& InFile,
Tool* CurTool = CurNode->ToolPtr.getPtr();
if (CurTool->IsJoin()) {
- JoinTool& JT = dynamic_cast<JoinTool&>(*CurTool);
+ JoinTool& JT = static_cast<JoinTool&>(*CurTool);
JT.AddToJoinList(In);
break;
}
- Action CurAction = CurTool->GenerateAction(In, CurNode->HasChildren(),
- TempDir, InLangs, LangMap);
+ Action CurAction;
+ if (int ret = CurTool->GenerateAction(CurAction, In, CurNode->HasChildren(),
+ TempDir, InLangs, LangMap)) {
+ return ret;
+ }
if (int ret = CurAction.Execute())
- throw error_code(ret);
+ return ret;
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();
}
+
+ return 0;
}
// Find the head of the toolchain corresponding to the given file.
@@ -186,26 +218,39 @@ FindToolChain(const sys::Path& In, const std::string* ForceLanguage,
InputLanguagesSet& InLangs, const LanguageMap& LangMap) const {
// Determine the input language.
- const std::string& InLanguage =
- ForceLanguage ? *ForceLanguage : LangMap.GetLanguage(In);
+ const std::string* InLang = 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.
InLangs.insert(InLanguage);
// Find the toolchain for the input language.
- const tools_vector_type& TV = getToolsVector(InLanguage);
- if (TV.empty())
- throw std::runtime_error("No toolchain corresponding to language "
- + InLanguage + " found");
- return &getNode(ChooseEdge(TV, InLangs)->ToolName());
+ const tools_vector_type* pTV = getToolsVector(InLanguage);
+ if (pTV == 0)
+ return 0;
+
+ const tools_vector_type& TV = *pTV;
+ if (TV.empty()) {
+ PrintError("No toolchain corresponding to language "
+ + InLanguage + " found");
+ return 0;
+ }
+
+ const Edge* Edg = ChooseEdge(TV, InLangs);
+ if (Edg == 0)
+ return 0;
+
+ return getNode(Edg->ToolName());
}
// Helper function used by Build().
// Traverses initial portions of the toolchains (up to the first Join node).
// This function is also responsible for handling the -x option.
-void CompilationGraph::BuildInitial (InputLanguagesSet& InLangs,
- const sys::Path& TempDir,
- const LanguageMap& LangMap) {
+int CompilationGraph::BuildInitial (InputLanguagesSet& InLangs,
+ const sys::Path& TempDir,
+ const LanguageMap& LangMap) {
// This is related to -x option handling.
cl::list<std::string>::const_iterator xIter = Languages.begin(),
xBegin = xIter, xEnd = Languages.end();
@@ -255,15 +300,25 @@ void CompilationGraph::BuildInitial (InputLanguagesSet& InLangs,
// Find the toolchain corresponding to this file.
const Node* N = FindToolChain(In, xLanguage, InLangs, LangMap);
+ if (N == 0)
+ return 1;
// 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.
-void CompilationGraph::TopologicalSort(std::vector<const Node*>& Out) {
+int CompilationGraph::TopologicalSort(std::vector<const Node*>& Out) {
std::queue<const Node*> Q;
- Q.push(&getNode("root"));
+
+ Node* Root = getNode("root");
+ if (Root == 0)
+ return 1;
+
+ Q.push(Root);
while (!Q.empty()) {
const Node* A = Q.front();
@@ -271,12 +326,17 @@ void CompilationGraph::TopologicalSort(std::vector<const Node*>& Out) {
Out.push_back(A);
for (Node::const_iterator EB = A->EdgesBegin(), EE = A->EdgesEnd();
EB != EE; ++EB) {
- Node* B = &getNode((*EB)->ToolName());
+ Node* B = getNode((*EB)->ToolName());
+ if (B == 0)
+ return 1;
+
B->DecrInEdges();
if (B->HasNoInEdges())
Q.push(B);
}
}
+
+ return 0;
}
namespace {
@@ -287,49 +347,71 @@ namespace {
// Call TopologicalSort and filter the resulting list to include
// only Join nodes.
-void CompilationGraph::
+int CompilationGraph::
TopologicalSortFilterJoinNodes(std::vector<const Node*>& Out) {
std::vector<const Node*> TopSorted;
- TopologicalSort(TopSorted);
+ if (int ret = TopologicalSort(TopSorted))
+ return ret;
std::remove_copy_if(TopSorted.begin(), TopSorted.end(),
std::back_inserter(Out), NotJoinNode);
+
+ return 0;
}
int CompilationGraph::Build (const sys::Path& TempDir,
const LanguageMap& LangMap) {
-
InputLanguagesSet InLangs;
+ bool WasSomeActionGenerated = !InputFilenames.empty();
// 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;
- TopologicalSortFilterJoinNodes(JTV);
+ if (int ret = TopologicalSortFilterJoinNodes(JTV))
+ return ret;
// For all join nodes in topological order:
for (std::vector<const Node*>::iterator B = JTV.begin(), E = JTV.end();
B != E; ++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?
if (JT->JoinListEmpty() && !(JT->WorksOnEmpty() && InputFilenames.empty()))
continue;
- Action CurAction = JT->GenerateAction(CurNode->HasChildren(),
- TempDir, InLangs, LangMap);
+ WasSomeActionGenerated = true;
+ Action CurAction;
+ if (int ret = JT->GenerateAction(CurAction, CurNode->HasChildren(),
+ TempDir, InLangs, LangMap)) {
+ return ret;
+ }
if (int ret = CurAction.Execute())
- throw error_code(ret);
+ return ret;
if (CurAction.StopCompilation())
return 0;
- const Node* NextNode = &getNode(ChooseEdge(CurNode->OutEdges, InLangs,
- CurNode->Name())->ToolName());
- PassThroughGraph(sys::Path(CurAction.OutFile()), NextNode,
- InLangs, TempDir, LangMap);
+ const Edge* Edg = ChooseEdge(CurNode->OutEdges, InLangs, CurNode->Name());
+ if (Edg == 0)
+ return 1;
+
+ 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;
+ }
+ }
+
+ if (!WasSomeActionGenerated) {
+ PrintError("no input files");
+ return 1;
}
return 0;
@@ -337,6 +419,7 @@ int CompilationGraph::Build (const sys::Path& TempDir,
int CompilationGraph::CheckLanguageNames() const {
int ret = 0;
+
// Check that names for output and input languages on all edges do match.
for (const_nodes_iterator B = this->NodesMap.begin(),
E = this->NodesMap.end(); B != E; ++B) {
@@ -345,9 +428,11 @@ int CompilationGraph::CheckLanguageNames() const {
if (N1.ToolPtr) {
for (Node::const_iterator EB = N1.EdgesBegin(), EE = N1.EdgesEnd();
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;
errs() << "Error: there is an edge from '" << N1.ToolPtr->Name()
<< "' back to the root!\n\n";
@@ -355,7 +440,7 @@ int CompilationGraph::CheckLanguageNames() const {
}
const char* OutLang = N1.ToolPtr->OutputLanguage();
- const char** InLangs = N2.ToolPtr->InputLanguages();
+ const char** InLangs = N2->ToolPtr->InputLanguages();
bool eq = false;
for (;*InLangs; ++InLangs) {
if (std::strcmp(OutLang, *InLangs) == 0) {
@@ -367,11 +452,11 @@ int CompilationGraph::CheckLanguageNames() const {
if (!eq) {
++ret;
errs() << "Error: Output->input language mismatch in the edge '"
- << N1.ToolPtr->Name() << "' -> '" << N2.ToolPtr->Name()
+ << N1.ToolPtr->Name() << "' -> '" << N2->ToolPtr->Name()
<< "'!\n"
<< "Expected one of { ";
- InLangs = N2.ToolPtr->InputLanguages();
+ InLangs = N2->ToolPtr->InputLanguages();
for (;*InLangs; ++InLangs) {
errs() << '\'' << *InLangs << (*(InLangs+1) ? "', " : "'");
}
@@ -395,7 +480,7 @@ int CompilationGraph::CheckMultipleDefaultEdges() const {
for (const_nodes_iterator B = this->NodesMap.begin(),
E = this->NodesMap.end(); B != E; ++B) {
const Node& N = B->second;
- unsigned MaxWeight = 0;
+ int MaxWeight = 0;
// Ignore the root node.
if (!N.ToolPtr)
@@ -403,7 +488,7 @@ int CompilationGraph::CheckMultipleDefaultEdges() const {
for (Node::const_iterator EB = N.EdgesBegin(), EE = N.EdgesEnd();
EB != EE; ++EB) {
- unsigned EdgeWeight = (*EB)->Weight(Dummy);
+ int EdgeWeight = (*EB)->Weight(Dummy);
if (EdgeWeight > MaxWeight) {
MaxWeight = EdgeWeight;
}
@@ -422,7 +507,12 @@ int CompilationGraph::CheckMultipleDefaultEdges() const {
int CompilationGraph::CheckCycles() {
unsigned deleted = 0;
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
// root. If there are any nodes left after this operation, then we have a
@@ -434,7 +524,10 @@ int CompilationGraph::CheckCycles() {
for (Node::iterator EB = A->EdgesBegin(), EE = A->EdgesEnd();
EB != EE; ++EB) {
- Node* B = &getNode((*EB)->ToolName());
+ Node* B = getNode((*EB)->ToolName());
+ if (B == 0)
+ return 1;
+
B->DecrInEdges();
if (B->HasNoInEdges())
Q.push(B);
@@ -453,18 +546,28 @@ int CompilationGraph::CheckCycles() {
int CompilationGraph::Check () {
// We try to catch as many errors as we can in one go.
+ int errs = 0;
int ret = 0;
// 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.
- ret += this->CheckMultipleDefaultEdges();
+ ret = this->CheckMultipleDefaultEdges();
+ if (ret < 0)
+ return 1;
+ errs += ret;
// 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.
@@ -516,7 +619,7 @@ namespace llvm {
}
-void CompilationGraph::writeGraph(const std::string& OutputFilename) {
+int CompilationGraph::writeGraph(const std::string& OutputFilename) {
std::string ErrorInfo;
raw_fd_ostream O(OutputFilename.c_str(), ErrorInfo);
@@ -526,9 +629,11 @@ void CompilationGraph::writeGraph(const std::string& OutputFilename) {
errs() << "done.\n";
}
else {
- throw std::runtime_error("Error opening file '" + OutputFilename
- + "' for writing!");
+ PrintError("Error opening file '" + OutputFilename + "' for writing!");
+ return 1;
}
+
+ return 0;
}
void CompilationGraph::viewGraph() {
diff --git a/contrib/llvm/lib/CompilerDriver/Main.cpp b/contrib/llvm/lib/CompilerDriver/Main.cpp
index b5e507d..0a6613a 100644
--- a/contrib/llvm/lib/CompilerDriver/Main.cpp
+++ b/contrib/llvm/lib/CompilerDriver/Main.cpp
@@ -11,16 +11,15 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/CompilerDriver/AutoGenerated.h"
#include "llvm/CompilerDriver/BuiltinOptions.h"
#include "llvm/CompilerDriver/CompilationGraph.h"
#include "llvm/CompilerDriver/Error.h"
-#include "llvm/CompilerDriver/Plugin.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Path.h"
#include <sstream>
-#include <stdexcept>
#include <string>
namespace cl = llvm::cl;
@@ -31,9 +30,9 @@ namespace {
std::stringstream* GlobalTimeLog;
- sys::Path getTempDir() {
- sys::Path tempDir;
-
+ /// GetTempDir - Get the temporary directory location. Returns non-zero value
+ /// on error.
+ int GetTempDir(sys::Path& tempDir) {
// The --temp-dir option.
if (!TempDirname.empty()) {
tempDir = TempDirname;
@@ -41,7 +40,7 @@ namespace {
// GCC 4.5-style -save-temps handling.
else if (SaveTemps == SaveTempsEnum::Unset) {
tempDir = sys::Path::GetTemporaryDirectory();
- return tempDir;
+ return 0;
}
else if (SaveTemps == SaveTempsEnum::Obj && !OutputFilename.empty()) {
tempDir = OutputFilename;
@@ -49,35 +48,35 @@ namespace {
}
else {
// SaveTemps == Cwd --> use current dir (leave tempDir empty).
- return tempDir;
+ return 0;
}
if (!tempDir.exists()) {
std::string ErrMsg;
- if (tempDir.createDirectoryOnDisk(true, &ErrMsg))
- throw std::runtime_error(ErrMsg);
+ if (tempDir.createDirectoryOnDisk(true, &ErrMsg)) {
+ PrintError(ErrMsg);
+ return 1;
+ }
}
- return tempDir;
+ return 0;
}
- /// BuildTargets - A small wrapper for CompilationGraph::Build.
+ /// BuildTargets - A small wrapper for CompilationGraph::Build. Returns
+ /// non-zero value in case of error.
int BuildTargets(CompilationGraph& graph, const LanguageMap& langMap) {
int ret;
- const sys::Path& tempDir = getTempDir();
+ sys::Path tempDir;
bool toDelete = (SaveTemps == SaveTempsEnum::Unset);
- try {
- ret = graph.Build(tempDir, langMap);
- }
- catch(...) {
- if (toDelete)
- tempDir.eraseFromDisk(true);
- throw;
- }
+ if (int ret = GetTempDir(tempDir))
+ return ret;
+
+ ret = graph.Build(tempDir, langMap);
if (toDelete)
tempDir.eraseFromDisk(true);
+
return ret;
}
}
@@ -89,68 +88,58 @@ void AppendToGlobalTimeLog(const std::string& cmd, double time) {
*GlobalTimeLog << "# " << cmd << ' ' << time << '\n';
}
-// Sometimes plugins want to condition on the value in argv[0].
+// Sometimes user code wants to access the argv[0] value.
const char* ProgramName;
int Main(int argc, char** argv) {
- try {
- LanguageMap langMap;
- CompilationGraph graph;
-
- ProgramName = argv[0];
+ int ret = 0;
+ LanguageMap langMap;
+ CompilationGraph graph;
- cl::ParseCommandLineOptions
- (argc, argv, "LLVM Compiler Driver (Work In Progress)",
- /* ReadResponseFiles = */ false);
+ ProgramName = argv[0];
- PluginLoader Plugins;
- Plugins.RunInitialization(langMap, graph);
+ cl::ParseCommandLineOptions
+ (argc, argv,
+ /* Overview = */ "LLVM Compiler Driver (Work In Progress)",
+ /* ReadResponseFiles = */ false);
- if (CheckGraph) {
- int ret = graph.Check();
- if (!ret)
- llvm::errs() << "check-graph: no errors found.\n";
+ if (int ret = autogenerated::RunInitialization(langMap, graph))
+ return ret;
- return ret;
- }
+ if (CheckGraph) {
+ ret = graph.Check();
+ if (!ret)
+ llvm::errs() << "check-graph: no errors found.\n";
- if (ViewGraph) {
- graph.viewGraph();
- if (!WriteGraph)
- return 0;
- }
+ return ret;
+ }
- if (WriteGraph) {
- graph.writeGraph(OutputFilename.empty()
- ? std::string("compilation-graph.dot")
- : OutputFilename);
+ if (ViewGraph) {
+ graph.viewGraph();
+ if (!WriteGraph)
return 0;
- }
+ }
- if (Time) {
- GlobalTimeLog = new std::stringstream;
- GlobalTimeLog->precision(2);
- }
+ if (WriteGraph) {
+ const std::string& Out = (OutputFilename.empty()
+ ? std::string("compilation-graph.dot")
+ : OutputFilename);
+ return graph.writeGraph(Out);
+ }
- int ret = BuildTargets(graph, langMap);
+ if (Time) {
+ GlobalTimeLog = new std::stringstream;
+ GlobalTimeLog->precision(2);
+ }
- if (Time) {
- llvm::errs() << GlobalTimeLog->str();
- delete GlobalTimeLog;
- }
+ ret = BuildTargets(graph, langMap);
- return ret;
- }
- catch(llvmc::error_code& ec) {
- return ec.code();
+ if (Time) {
+ llvm::errs() << GlobalTimeLog->str();
+ delete GlobalTimeLog;
}
- catch(const std::exception& ex) {
- llvm::errs() << argv[0] << ": " << ex.what() << '\n';
- }
- catch(...) {
- llvm::errs() << argv[0] << ": unknown error!\n";
- }
- return 1;
+
+ return ret;
}
} // end namespace llvmc
diff --git a/contrib/llvm/lib/CompilerDriver/Makefile b/contrib/llvm/lib/CompilerDriver/Makefile
index 66c6d11..8e8b73c 100644
--- a/contrib/llvm/lib/CompilerDriver/Makefile
+++ b/contrib/llvm/lib/CompilerDriver/Makefile
@@ -10,39 +10,11 @@
LEVEL = ../..
# We don't want this library to appear in `llvm-config --libs` output, so its
-# name doesn't start with "LLVM".
+# name doesn't start with "LLVM" and NO_LLVM_CONFIG is set.
-ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
- LIBRARYNAME = libCompilerDriver
- LLVMLIBS = LLVMSupport.a LLVMSystem.a
- LOADABLE_MODULE := 1
-else
- LIBRARYNAME = CompilerDriver
- LINK_COMPONENTS = support system
-endif
+LIBRARYNAME = CompilerDriver
+LINK_COMPONENTS = support system
+NO_LLVM_CONFIG = 1
-REQUIRES_EH := 1
-REQUIRES_RTTI := 1
include $(LEVEL)/Makefile.common
-
-ifeq ($(ENABLE_LLVMC_DYNAMIC_PLUGINS), 1)
- CPP.Flags += -DENABLE_LLVMC_DYNAMIC_PLUGINS
-endif
-
-# Copy libCompilerDriver to the bin dir so that llvmc can find it.
-ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
-
-FullLibName = $(LIBRARYNAME)$(SHLIBEXT)
-
-all-local:: $(ToolDir)/$(FullLibName)
-
-$(ToolDir)/$(FullLibName): $(LibDir)/$(FullLibName) $(ToolDir)/.dir
- $(Echo) Copying $(BuildMode) Shared Library $(FullLibName) to $@
- -$(Verb) $(CP) $< $@
-
-clean-local::
- $(Echo) Removing $(BuildMode) Shared Library $(FullLibName) \
- from $(ToolDir)
- -$(Verb) $(RM) -f $(ToolDir)/$(FullLibName)
-endif
diff --git a/contrib/llvm/lib/CompilerDriver/Plugin.cpp b/contrib/llvm/lib/CompilerDriver/Plugin.cpp
deleted file mode 100644
index 0fdfef4..0000000
--- a/contrib/llvm/lib/CompilerDriver/Plugin.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-//===--- Plugin.cpp - 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.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/CompilerDriver/Plugin.h"
-#include "llvm/Support/ManagedStatic.h"
-#include "llvm/System/Mutex.h"
-#include <algorithm>
-#include <vector>
-
-namespace {
-
- // Registry::Add<> does not do lifetime management (probably issues
- // with static constructor/destructor ordering), so we have to
- // implement it here.
- //
- // All this static registration/life-before-main model seems
- // unnecessary convoluted to me.
-
- static bool pluginListInitialized = false;
- typedef std::vector<const llvmc::BasePlugin*> PluginList;
- static PluginList Plugins;
- static llvm::ManagedStatic<llvm::sys::SmartMutex<true> > PluginMutex;
-
- struct ByPriority {
- bool operator()(const llvmc::BasePlugin* lhs,
- const llvmc::BasePlugin* rhs) {
- return lhs->Priority() < rhs->Priority();
- }
- };
-}
-
-namespace llvmc {
-
- PluginLoader::PluginLoader() {
- llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
- if (!pluginListInitialized) {
- for (PluginRegistry::iterator B = PluginRegistry::begin(),
- E = PluginRegistry::end(); B != E; ++B)
- Plugins.push_back(B->instantiate());
- std::sort(Plugins.begin(), Plugins.end(), ByPriority());
- }
- pluginListInitialized = true;
- }
-
- PluginLoader::~PluginLoader() {
- llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
- if (pluginListInitialized) {
- for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
- B != E; ++B)
- delete (*B);
- }
- pluginListInitialized = false;
- }
-
- void PluginLoader::RunInitialization(LanguageMap& langMap,
- CompilationGraph& graph) const
- {
- llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
- for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
- B != E; ++B) {
- const BasePlugin* BP = *B;
- BP->PreprocessOptions();
- BP->PopulateLanguageMap(langMap);
- BP->PopulateCompilationGraph(graph);
- }
- }
-
-}
OpenPOWER on IntegriCloud