[llvm-commits] [llvm] r56462 - in /llvm/trunk: tools/llvmc2/AutoGenerated.cpp tools/llvmc2/AutoGenerated.h tools/llvmc2/CompilationGraph.cpp tools/llvmc2/CompilationGraph.h tools/llvmc2/Tool.h tools/llvmc2/llvmc.cpp utils/TableGen/LLVMCConfigurationEmitter.cpp
Mikhail Glushenkov
foldr at codedgers.com
Mon Sep 22 13:47:49 PDT 2008
Author: foldr
Date: Mon Sep 22 15:47:46 2008
New Revision: 56462
URL: http://llvm.org/viewvc/llvm-project?rev=56462&view=rev
Log:
Get rid of GlobalLanguageMap. Global state is evil.
Modified:
llvm/trunk/tools/llvmc2/AutoGenerated.cpp
llvm/trunk/tools/llvmc2/AutoGenerated.h
llvm/trunk/tools/llvmc2/CompilationGraph.cpp
llvm/trunk/tools/llvmc2/CompilationGraph.h
llvm/trunk/tools/llvmc2/Tool.h
llvm/trunk/tools/llvmc2/llvmc.cpp
llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp
Modified: llvm/trunk/tools/llvmc2/AutoGenerated.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/AutoGenerated.cpp?rev=56462&r1=56461&r2=56462&view=diff
==============================================================================
--- llvm/trunk/tools/llvmc2/AutoGenerated.cpp (original)
+++ llvm/trunk/tools/llvmc2/AutoGenerated.cpp Mon Sep 22 15:47:46 2008
@@ -24,11 +24,6 @@
using namespace llvm;
using namespace llvmc;
-namespace llvmc {
- extern LanguageMap GlobalLanguageMap;
- extern const std::string& GetLanguage(const sys::Path& File);
-}
-
extern cl::opt<std::string> OutputFilename;
// The auto-generated file
Modified: llvm/trunk/tools/llvmc2/AutoGenerated.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/AutoGenerated.h?rev=56462&r1=56461&r2=56462&view=diff
==============================================================================
--- llvm/trunk/tools/llvmc2/AutoGenerated.h (original)
+++ llvm/trunk/tools/llvmc2/AutoGenerated.h Mon Sep 22 15:47:46 2008
@@ -20,12 +20,12 @@
namespace llvmc {
- typedef llvm::StringMap<std::string> LanguageMap;
+ class LanguageMap;
class CompilationGraph;
/// PopulateLanguageMap - The auto-generated function that fills in
/// the language map (map from file extensions to language names).
- void PopulateLanguageMap();
+ void PopulateLanguageMap(LanguageMap& langMap);
/// PopulateCompilationGraph - The auto-generated function that
/// populates the compilation graph with nodes and edges.
void PopulateCompilationGraph(CompilationGraph& tools);
Modified: llvm/trunk/tools/llvmc2/CompilationGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/CompilationGraph.cpp?rev=56462&r1=56461&r2=56462&view=diff
==============================================================================
--- llvm/trunk/tools/llvmc2/CompilationGraph.cpp (original)
+++ llvm/trunk/tools/llvmc2/CompilationGraph.cpp Mon Sep 22 15:47:46 2008
@@ -33,13 +33,10 @@
extern cl::list<std::string> Languages;
namespace llvmc {
- /// ExtsToLangs - Map from file extensions to language names.
- LanguageMap GlobalLanguageMap;
- /// GetLanguage - Find the language name corresponding to the given file.
- const std::string& GetLanguage(const sys::Path& File) {
- LanguageMap::const_iterator Lang = GlobalLanguageMap.find(File.getSuffix());
- if (Lang == GlobalLanguageMap.end())
+ const std::string& LanguageMap::GetLanguage(const sys::Path& File) const {
+ LanguageMap::const_iterator Lang = this->find(File.getSuffix());
+ if (Lang == this->end())
throw std::runtime_error("Unknown suffix: " + File.getSuffix());
return Lang->second;
}
@@ -165,7 +162,8 @@
void CompilationGraph::PassThroughGraph (const sys::Path& InFile,
const Node* StartNode,
const InputLanguagesSet& InLangs,
- const sys::Path& TempDir) const {
+ const sys::Path& TempDir,
+ const LanguageMap& LangMap) const {
bool Last = false;
sys::Path In = InFile;
const Node* CurNode = StartNode;
@@ -196,7 +194,7 @@
Out = MakeTempFile(TempDir, In.getBasename(), CurTool->OutputSuffix());
}
- if (int ret = CurTool->GenerateAction(In, Out, InLangs).Execute())
+ if (int ret = CurTool->GenerateAction(In, Out, InLangs, LangMap).Execute())
throw error_code(ret);
if (Last)
@@ -212,12 +210,12 @@
// Find the head of the toolchain corresponding to the given file.
// Also, insert an input language into InLangs.
const Node* CompilationGraph::
-FindToolChain(const sys::Path& In, const std::string* forceLanguage,
- InputLanguagesSet& InLangs) const {
+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 : GetLanguage(In);
+ ForceLanguage ? *ForceLanguage : LangMap.GetLanguage(In);
// Add the current input language to the input language set.
InLangs.insert(InLanguage);
@@ -234,7 +232,8 @@
// 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 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();
@@ -283,9 +282,9 @@
}
// Find the toolchain corresponding to this file.
- const Node* N = FindToolChain(In, xLanguage, InLangs);
+ const Node* N = FindToolChain(In, xLanguage, InLangs, LangMap);
// Pass file through the chain starting at head.
- PassThroughGraph(In, N, InLangs, TempDir);
+ PassThroughGraph(In, N, InLangs, TempDir, LangMap);
}
}
@@ -324,12 +323,13 @@
std::back_inserter(Out), NotJoinNode);
}
-int CompilationGraph::Build (const sys::Path& TempDir) {
+int CompilationGraph::Build (const sys::Path& TempDir,
+ const LanguageMap& LangMap) {
InputLanguagesSet InLangs;
// Traverse initial parts of the toolchains and fill in InLangs.
- BuildInitial(InLangs, TempDir);
+ BuildInitial(InLangs, TempDir, LangMap);
std::vector<const Node*> JTV;
TopologicalSortFilterJoinNodes(JTV);
@@ -362,14 +362,14 @@
Out = MakeTempFile(TempDir, "tmp", JT->OutputSuffix());
}
- if (int ret = JT->GenerateAction(Out, InLangs).Execute())
+ if (int ret = JT->GenerateAction(Out, InLangs, LangMap).Execute())
throw error_code(ret);
if (!IsLast) {
const Node* NextNode =
&getNode(ChooseEdge(CurNode->OutEdges, InLangs,
CurNode->Name())->ToolName());
- PassThroughGraph(Out, NextNode, InLangs, TempDir);
+ PassThroughGraph(Out, NextNode, InLangs, TempDir, LangMap);
}
}
Modified: llvm/trunk/tools/llvmc2/CompilationGraph.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/CompilationGraph.h?rev=56462&r1=56461&r2=56462&view=diff
==============================================================================
--- llvm/trunk/tools/llvmc2/CompilationGraph.h (original)
+++ llvm/trunk/tools/llvmc2/CompilationGraph.h Mon Sep 22 15:47:46 2008
@@ -32,6 +32,14 @@
typedef llvm::StringSet<> InputLanguagesSet;
+ /// LanguageMap - Maps from extensions to language names.
+ class LanguageMap : public llvm::StringMap<std::string> {
+ 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<Edge> {
public:
@@ -128,7 +136,7 @@
/// 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);
+ 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.
@@ -161,16 +169,19 @@
/// starting at StartNode.
void PassThroughGraph (const llvm::sys::Path& In, const Node* StartNode,
const InputLanguagesSet& InLangs,
- const llvm::sys::Path& TempDir) const;
+ 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;
+ 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 llvm::sys::Path& TempDir,
+ const LanguageMap& LangMap);
/// TopologicalSort - Sort the nodes in topological order.
void TopologicalSort(std::vector<const Node*>& Out);
Modified: llvm/trunk/tools/llvmc2/Tool.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/Tool.h?rev=56462&r1=56461&r2=56462&view=diff
==============================================================================
--- llvm/trunk/tools/llvmc2/Tool.h (original)
+++ llvm/trunk/tools/llvmc2/Tool.h Mon Sep 22 15:47:46 2008
@@ -36,11 +36,13 @@
virtual Action GenerateAction (const PathVector& inFiles,
const llvm::sys::Path& outFile,
- const InputLanguagesSet& InLangs) const = 0;
+ 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 = 0;
+ const InputLanguagesSet& InLangs,
+ const LanguageMap& LangMap) const = 0;
virtual const char* Name() const = 0;
virtual const char** InputLanguages() const = 0;
@@ -59,8 +61,9 @@
bool JoinListEmpty() const { return JoinList_.empty(); }
Action GenerateAction(const llvm::sys::Path& outFile,
- const InputLanguagesSet& InLangs) const {
- return GenerateAction(JoinList_, outFile, InLangs);
+ 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;
Modified: llvm/trunk/tools/llvmc2/llvmc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/llvmc.cpp?rev=56462&r1=56461&r2=56462&view=diff
==============================================================================
--- llvm/trunk/tools/llvmc2/llvmc.cpp (original)
+++ llvm/trunk/tools/llvmc2/llvmc.cpp Mon Sep 22 15:47:46 2008
@@ -55,14 +55,14 @@
namespace {
/// BuildTargets - A small wrapper for CompilationGraph::Build.
- int BuildTargets(CompilationGraph& graph) {
+ int BuildTargets(CompilationGraph& graph, const LanguageMap& langMap) {
int ret;
const sys::Path& tempDir = SaveTemps
? sys::Path("")
: sys::Path(sys::Path::GetTemporaryDirectory());
try {
- ret = graph.Build(tempDir);
+ ret = graph.Build(tempDir, langMap);
}
catch(...) {
tempDir.eraseFromDisk(true);
@@ -77,10 +77,13 @@
int main(int argc, char** argv) {
try {
+ LanguageMap langMap;
CompilationGraph graph;
cl::ParseCommandLineOptions
(argc, argv, "LLVM Compiler Driver (Work In Progress)", true);
+
+ PopulateLanguageMap(langMap);
PopulateCompilationGraph(graph);
if (WriteGraph) {
@@ -98,7 +101,7 @@
throw std::runtime_error("no input files");
}
- return BuildTargets(graph);
+ return BuildTargets(graph, langMap);
}
catch(llvmc::error_code& ec) {
return ec.code();
Modified: llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp?rev=56462&r1=56461&r2=56462&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Mon Sep 22 15:47:46 2008
@@ -826,8 +826,9 @@
O << "InLangs.count(\"" << OptName << "\") != 0";
return true;
} else if (TestName == "in_language") {
+ // TODO: remove this restriction
// Works only for cmd_line!
- O << "GetLanguage(inFile) == \"" << OptName << '\"';
+ O << "LangMap.GetLanguage(inFile) == \"" << OptName << '\"';
return true;
} else if (TestName == "not_empty") {
if (OptName == "o") {
@@ -1205,7 +1206,8 @@
O << Indent1 << "Action GenerateAction(const sys::Path& inFile,\n";
O << Indent2 << "const sys::Path& outFile,\n"
- << Indent2 << "const InputLanguagesSet& InLangs) const\n"
+ << Indent2 << "const InputLanguagesSet& InLangs,\n"
+ << Indent2 << "const LanguageMap& LangMap) const\n"
<< Indent1 << "{\n"
<< Indent2 << "const char* cmd;\n"
<< Indent2 << "std::vector<std::string> vec;\n";
@@ -1245,7 +1247,8 @@
if (!P.isJoin())
O << Indent1 << "Action GenerateAction(const PathVector& inFiles,\n"
<< Indent2 << "const llvm::sys::Path& outFile,\n"
- << Indent2 << "const InputLanguagesSet& InLangs) const\n"
+ << Indent2 << "const InputLanguagesSet& InLangs,\n"
+ << Indent2 << "const LanguageMap& LangMap) const\n"
<< Indent1 << "{\n"
<< Indent2 << "throw std::runtime_error(\"" << P.Name
<< " is not a Join tool!\");\n"
@@ -1451,7 +1454,7 @@
throw std::string("Error in the language map definition!");
// Generate code
- O << "void llvmc::PopulateLanguageMap() {\n";
+ O << "void llvmc::PopulateLanguageMap(LanguageMap& langMap) {\n";
for (unsigned i = 0; i < LangsToSuffixesList->size(); ++i) {
Record* LangToSuffixes = LangsToSuffixesList->getElementAsRecord(i);
@@ -1460,7 +1463,7 @@
const ListInit* Suffixes = LangToSuffixes->getValueAsListInit("suffixes");
for (unsigned i = 0; i < Suffixes->size(); ++i)
- O << Indent1 << "GlobalLanguageMap[\""
+ O << Indent1 << "langMap[\""
<< InitPtrToString(Suffixes->getElement(i))
<< "\"] = \"" << Lang << "\";\n";
}
@@ -1588,8 +1591,7 @@
ListInit* edges = CompilationGraph->getValueAsListInit("edges");
// Generate code
- O << "void llvmc::PopulateCompilationGraph(CompilationGraph& G) {\n"
- << Indent1 << "PopulateLanguageMap();\n\n";
+ O << "void llvmc::PopulateCompilationGraph(CompilationGraph& G) {\n";
// Insert vertices
More information about the llvm-commits
mailing list