Support dependencies between plugins by priority-sorting.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@59449 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/TableGen/LLVMCConfigurationEmitter.cpp b/utils/TableGen/LLVMCConfigurationEmitter.cpp
index 42d4d9e..d43e62b 100644
--- a/utils/TableGen/LLVMCConfigurationEmitter.cpp
+++ b/utils/TableGen/LLVMCConfigurationEmitter.cpp
@@ -771,7 +771,7 @@
GlobalOptionDescriptions& OptDescs)
{
// Iterate over a properties list of every Tool definition
- for (;B!=E;++B) {
+ for (; B!=E; ++B) {
RecordVector::value_type T = *B;
// Throws an exception if the value does not exist.
ListInit* PropList = T->getValueAsListInit("options");
@@ -1701,9 +1701,10 @@
}
/// EmitRegisterPlugin - Emit code to register this plugin.
-void EmitRegisterPlugin(std::ostream& O) {
+void EmitRegisterPlugin(int Priority, std::ostream& O) {
O << "namespace {\n\n"
- << "struct Plugin : public llvmc::BasePlugin {\n"
+ << "struct Plugin : public llvmc::BasePlugin {\n\n"
+ << Indent1 << "int Priority() const { return " << Priority << "; }\n\n"
<< Indent1 << "void PopulateLanguageMap(LanguageMap& langMap) const\n"
<< Indent1 << "{ PopulateLanguageMapLocal(langMap); }\n\n"
<< Indent1
@@ -1777,6 +1778,15 @@
ToolProps.erase(new_end, ToolProps.end());
}
+int CalculatePriority(RecordVector::const_iterator B,
+ RecordVector::const_iterator E) {
+ int total = 0;
+ for (; B!=E; ++B) {
+ total += static_cast<int>((*B)->getValueAsInt("priority"));
+ }
+ return total;
+}
+
// End of anonymous namespace
}
@@ -1799,7 +1809,8 @@
GlobalOptionDescriptions OptDescs;
CollectToolProperties(Tools.begin(), Tools.end(), ToolProps, OptDescs);
- RecordVector OptionLists = Records.getAllDerivedDefinitions("OptionList");
+ const RecordVector& OptionLists =
+ Records.getAllDerivedDefinitions("OptionList");
CollectPropertiesFromOptionLists(OptionLists.begin(), OptionLists.end(),
OptDescs);
@@ -1841,7 +1852,10 @@
EmitPopulateCompilationGraph(CompilationGraphRecord, ToolProps, O);
// Emit code for plugin registration.
- EmitRegisterPlugin(O);
+ const RecordVector& Priorities =
+ Records.getAllDerivedDefinitions("PluginPriority");
+ EmitRegisterPlugin(CalculatePriority(Priorities.begin(), Priorities.end()),
+ O);
// EOF
} catch (std::exception& Error) {