diff options
author | Mikhail Glushenkov <foldr@codedgers.com> | 2008-09-22 20:49:34 +0000 |
---|---|---|
committer | Mikhail Glushenkov <foldr@codedgers.com> | 2008-09-22 20:49:34 +0000 |
commit | 945522f6b1f2d21bbe7bcd69c174a8e455c84f8c (patch) | |
tree | 62621694b4b03bd8603ea50f346d0db32d46dd92 /utils/TableGen | |
parent | f74495a0dbd6cd0a1c0575189b13910f9b2f600b (diff) | |
download | external_llvm-945522f6b1f2d21bbe7bcd69c174a8e455c84f8c.zip external_llvm-945522f6b1f2d21bbe7bcd69c174a8e455c84f8c.tar.gz external_llvm-945522f6b1f2d21bbe7bcd69c174a8e455c84f8c.tar.bz2 |
Plugin support for llvmc2 (a-la opt).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56465 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen')
-rw-r--r-- | utils/TableGen/LLVMCConfigurationEmitter.cpp | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/utils/TableGen/LLVMCConfigurationEmitter.cpp b/utils/TableGen/LLVMCConfigurationEmitter.cpp index 9bfb5da..9bb3be3 100644 --- a/utils/TableGen/LLVMCConfigurationEmitter.cpp +++ b/utils/TableGen/LLVMCConfigurationEmitter.cpp @@ -1456,7 +1456,8 @@ void EmitPopulateLanguageMap (const RecordKeeper& Records, std::ostream& O) throw std::string("Error in the language map definition!"); // Generate code - O << "void llvmc::PopulateLanguageMap(LanguageMap& langMap) {\n"; + O << "namespace {\n\n"; + O << "void PopulateLanguageMapLocal(LanguageMap& langMap) {\n"; for (unsigned i = 0; i < LangsToSuffixesList->size(); ++i) { Record* LangToSuffixes = LangsToSuffixesList->getElementAsRecord(i); @@ -1470,7 +1471,7 @@ void EmitPopulateLanguageMap (const RecordKeeper& Records, std::ostream& O) << "\"] = \"" << Lang << "\";\n"; } - O << "}\n\n"; + O << "}\n\n}\n\n"; } /// FillInToolToLang - Fills in two tables that map tool names to @@ -1593,7 +1594,8 @@ void EmitPopulateCompilationGraph (Record* CompilationGraph, ListInit* edges = CompilationGraph->getValueAsListInit("edges"); // Generate code - O << "void llvmc::PopulateCompilationGraph(CompilationGraph& G) {\n"; + O << "namespace {\n\n"; + O << "void PopulateCompilationGraphLocal(CompilationGraph& G) {\n"; // Insert vertices @@ -1627,7 +1629,7 @@ void EmitPopulateCompilationGraph (Record* CompilationGraph, O << ");\n"; } - O << "}\n\n"; + O << "}\n\n}\n\n"; } /// ExtractHookNames - Extract the hook names from all instances of @@ -1704,6 +1706,38 @@ void EmitHookDeclarations(const ToolPropertiesList& ToolProps, O << "}\n\n"; } +/// EmitRegisterPlugin - Emit code to register this plugin. +void EmitRegisterPlugin(std::ostream& O) { + O << "namespace {\n\n" + << "struct Plugin : public llvmc::BasePlugin {\n" + << Indent1 << "void PopulateLanguageMap(LanguageMap& langMap) const\n" + << Indent1 << "{ PopulateLanguageMapLocal(langMap); }\n\n" + << Indent1 + << "void PopulateCompilationGraph(CompilationGraph& graph) const\n" + << Indent1 << "{ PopulateCompilationGraphLocal(graph); }\n" + << "};\n\n" + + << "static llvmc::RegisterPlugin<Plugin> RP;\n\n}\n\n"; +} + +/// EmitInclude - Emit necessary #include directives. +void EmitIncludes(std::ostream& O) { + O << "#include \"CompilationGraph.h\"\n" + << "#include \"Plugin.h\"\n" + << "#include \"Tool.h\"\n\n" + + << "#include \"llvm/ADT/StringExtras.h\"\n" + << "#include \"llvm/Support/CommandLine.h\"\n\n" + + << "#include <cstdlib>\n" + << "#include <stdexcept>\n\n" + + << "using namespace llvm;\n" + << "using namespace llvmc;\n\n" + + << "extern cl::opt<std::string> OutputFilename;\n\n"; +} + // End of anonymous namespace } @@ -1713,6 +1747,7 @@ void LLVMCConfigurationEmitter::run (std::ostream &O) { // Emit file header. EmitSourceFileHeader("LLVMC Configuration Library", O); + EmitIncludes(O); // Get a list of all defined Tools. RecordVector Tools = Records.getAllDerivedDefinitions("Tool"); @@ -1760,6 +1795,9 @@ void LLVMCConfigurationEmitter::run (std::ostream &O) { // Emit PopulateCompilationGraph() function. EmitPopulateCompilationGraph(CompilationGraphRecord, O); + // Emit code for plugin registration. + EmitRegisterPlugin(O); + // EOF } catch (std::exception& Error) { throw Error.what() + std::string(" - usually this means a syntax error."); |