mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-08 21:32:39 +00:00
Support multiple compilation graph definitions. Not terribly useful, but makes the code more generic.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60199 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
739c720e66
commit
ad746beb64
@ -1539,20 +1539,18 @@ void FillInToolToLang (const ToolPropertiesList& TPList,
|
|||||||
/// on all edges do match. This doesn't do much when the information
|
/// on all edges do match. This doesn't do much when the information
|
||||||
/// about the whole graph is not available (i.e. when compiling most
|
/// about the whole graph is not available (i.e. when compiling most
|
||||||
/// plugins).
|
/// plugins).
|
||||||
// TODO: add a --check-graph switch to llvmc2. It would also make it
|
void TypecheckGraph (const RecordVector& EdgeVector,
|
||||||
// possible to detect cycles and multiple default edges.
|
|
||||||
void TypecheckGraph (const Record* CompilationGraph,
|
|
||||||
const ToolPropertiesList& TPList) {
|
const ToolPropertiesList& TPList) {
|
||||||
StringMap<StringSet<> > ToolToInLang;
|
StringMap<StringSet<> > ToolToInLang;
|
||||||
StringMap<std::string> ToolToOutLang;
|
StringMap<std::string> ToolToOutLang;
|
||||||
|
|
||||||
FillInToolToLang(TPList, ToolToInLang, ToolToOutLang);
|
FillInToolToLang(TPList, ToolToInLang, ToolToOutLang);
|
||||||
ListInit* edges = CompilationGraph->getValueAsListInit("edges");
|
|
||||||
StringMap<std::string>::iterator IAE = ToolToOutLang.end();
|
StringMap<std::string>::iterator IAE = ToolToOutLang.end();
|
||||||
StringMap<StringSet<> >::iterator IBE = ToolToInLang.end();
|
StringMap<StringSet<> >::iterator IBE = ToolToInLang.end();
|
||||||
|
|
||||||
for (unsigned i = 0; i < edges->size(); ++i) {
|
for (RecordVector::const_iterator B = EdgeVector.begin(),
|
||||||
const Record* Edge = edges->getElementAsRecord(i);
|
E = EdgeVector.end(); B != E; ++B) {
|
||||||
|
const Record* Edge = *B;
|
||||||
const std::string& A = Edge->getValueAsString("a");
|
const std::string& A = Edge->getValueAsString("a");
|
||||||
const std::string& B = Edge->getValueAsString("b");
|
const std::string& B = Edge->getValueAsString("b");
|
||||||
StringMap<std::string>::iterator IA = ToolToOutLang.find(A);
|
StringMap<std::string>::iterator IA = ToolToOutLang.find(A);
|
||||||
@ -1613,31 +1611,28 @@ void EmitEdgeClass (unsigned N, const std::string& Target,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// EmitEdgeClasses - Emit Edge* classes that represent graph edges.
|
/// EmitEdgeClasses - Emit Edge* classes that represent graph edges.
|
||||||
void EmitEdgeClasses (const Record* CompilationGraph,
|
void EmitEdgeClasses (const RecordVector& EdgeVector,
|
||||||
const GlobalOptionDescriptions& OptDescs,
|
const GlobalOptionDescriptions& OptDescs,
|
||||||
std::ostream& O) {
|
std::ostream& O) {
|
||||||
ListInit* edges = CompilationGraph->getValueAsListInit("edges");
|
int i = 0;
|
||||||
|
for (RecordVector::const_iterator B = EdgeVector.begin(),
|
||||||
for (unsigned i = 0; i < edges->size(); ++i) {
|
E = EdgeVector.end(); B != E; ++B) {
|
||||||
const Record* Edge = edges->getElementAsRecord(i);
|
const Record* Edge = *B;
|
||||||
const std::string& B = Edge->getValueAsString("b");
|
const std::string& B = Edge->getValueAsString("b");
|
||||||
DagInit* Weight = Edge->getValueAsDag("weight");
|
DagInit* Weight = Edge->getValueAsDag("weight");
|
||||||
|
|
||||||
if (isDagEmpty(Weight))
|
if (!isDagEmpty(Weight))
|
||||||
continue;
|
EmitEdgeClass(i, B, Weight, OptDescs, O);
|
||||||
|
++i;
|
||||||
EmitEdgeClass(i, B, Weight, OptDescs, O);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EmitPopulateCompilationGraph - Emit the PopulateCompilationGraph()
|
/// EmitPopulateCompilationGraph - Emit the PopulateCompilationGraph()
|
||||||
/// function.
|
/// function.
|
||||||
void EmitPopulateCompilationGraph (const Record* CompilationGraph,
|
void EmitPopulateCompilationGraph (const RecordVector& EdgeVector,
|
||||||
const ToolPropertiesList& ToolProps,
|
const ToolPropertiesList& ToolProps,
|
||||||
std::ostream& O)
|
std::ostream& O)
|
||||||
{
|
{
|
||||||
ListInit* edges = CompilationGraph->getValueAsListInit("edges");
|
|
||||||
|
|
||||||
O << "namespace {\n\n";
|
O << "namespace {\n\n";
|
||||||
O << "void PopulateCompilationGraphLocal(CompilationGraph& G) {\n";
|
O << "void PopulateCompilationGraphLocal(CompilationGraph& G) {\n";
|
||||||
|
|
||||||
@ -1649,8 +1644,10 @@ void EmitPopulateCompilationGraph (const Record* CompilationGraph,
|
|||||||
|
|
||||||
// Insert edges.
|
// Insert edges.
|
||||||
|
|
||||||
for (unsigned i = 0; i < edges->size(); ++i) {
|
int i = 0;
|
||||||
const Record* Edge = edges->getElementAsRecord(i);
|
for (RecordVector::const_iterator B = EdgeVector.begin(),
|
||||||
|
E = EdgeVector.end(); B != E; ++B) {
|
||||||
|
const Record* Edge = *B;
|
||||||
const std::string& A = Edge->getValueAsString("a");
|
const std::string& A = Edge->getValueAsString("a");
|
||||||
const std::string& B = Edge->getValueAsString("b");
|
const std::string& B = Edge->getValueAsString("b");
|
||||||
DagInit* Weight = Edge->getValueAsDag("weight");
|
DagInit* Weight = Edge->getValueAsDag("weight");
|
||||||
@ -1663,6 +1660,7 @@ void EmitPopulateCompilationGraph (const Record* CompilationGraph,
|
|||||||
O << "new Edge" << i << "()";
|
O << "new Edge" << i << "()";
|
||||||
|
|
||||||
O << ");\n";
|
O << ");\n";
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
O << "}\n\n}\n\n";
|
O << "}\n\n}\n\n";
|
||||||
@ -1796,15 +1794,16 @@ public:
|
|||||||
|
|
||||||
/// FilterNotInGraph - Filter out from ToolProps all Tools not
|
/// FilterNotInGraph - Filter out from ToolProps all Tools not
|
||||||
/// mentioned in the compilation graph definition.
|
/// mentioned in the compilation graph definition.
|
||||||
void FilterNotInGraph (const Record* CompilationGraph,
|
void FilterNotInGraph (const RecordVector& EdgeVector,
|
||||||
ToolPropertiesList& ToolProps) {
|
ToolPropertiesList& ToolProps) {
|
||||||
|
|
||||||
// List all tools mentioned in the graph.
|
// List all tools mentioned in the graph.
|
||||||
llvm::StringSet<> ToolsInGraph;
|
llvm::StringSet<> ToolsInGraph;
|
||||||
ListInit* edges = CompilationGraph->getValueAsListInit("edges");
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < edges->size(); ++i) {
|
for (RecordVector::const_iterator B = EdgeVector.begin(),
|
||||||
const Record* Edge = edges->getElementAsRecord(i);
|
E = EdgeVector.end(); B != E; ++B) {
|
||||||
|
|
||||||
|
const Record* Edge = *B;
|
||||||
const std::string& A = Edge->getValueAsString("a");
|
const std::string& A = Edge->getValueAsString("a");
|
||||||
const std::string& B = Edge->getValueAsString("b");
|
const std::string& B = Edge->getValueAsString("b");
|
||||||
|
|
||||||
@ -1820,6 +1819,7 @@ void FilterNotInGraph (const Record* CompilationGraph,
|
|||||||
ToolProps.erase(new_end, ToolProps.end());
|
ToolProps.erase(new_end, ToolProps.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// CalculatePriority - Calculate the priority of this plugin.
|
||||||
int CalculatePriority(RecordVector::const_iterator B,
|
int CalculatePriority(RecordVector::const_iterator B,
|
||||||
RecordVector::const_iterator E) {
|
RecordVector::const_iterator E) {
|
||||||
int total = 0;
|
int total = 0;
|
||||||
@ -1829,6 +1829,18 @@ int CalculatePriority(RecordVector::const_iterator B,
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// FillInEdgeVector - Merge all compilation graph definitions into
|
||||||
|
/// one single edge list.
|
||||||
|
void FillInEdgeVector(RecordVector::const_iterator B,
|
||||||
|
RecordVector::const_iterator E, RecordVector& Out) {
|
||||||
|
for (; B != E; ++B) {
|
||||||
|
const ListInit* edges = (*B)->getValueAsListInit("edges");
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < edges->size(); ++i)
|
||||||
|
Out.push_back(edges->getElementAsRecord(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// End of anonymous namespace
|
// End of anonymous namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1840,33 +1852,30 @@ void LLVMCConfigurationEmitter::run (std::ostream &O) {
|
|||||||
EmitSourceFileHeader("LLVMC Configuration Library", O);
|
EmitSourceFileHeader("LLVMC Configuration Library", O);
|
||||||
EmitIncludes(O);
|
EmitIncludes(O);
|
||||||
|
|
||||||
// Get a list of all defined Tools.
|
// Collect tool properties.
|
||||||
|
|
||||||
RecordVector Tools = Records.getAllDerivedDefinitions("Tool");
|
RecordVector Tools = Records.getAllDerivedDefinitions("Tool");
|
||||||
if (Tools.empty())
|
|
||||||
throw std::string("No tool definitions found!");
|
|
||||||
|
|
||||||
// Gather information from the Tool description dags.
|
|
||||||
ToolPropertiesList ToolProps;
|
ToolPropertiesList ToolProps;
|
||||||
GlobalOptionDescriptions OptDescs;
|
GlobalOptionDescriptions OptDescs;
|
||||||
CollectToolProperties(Tools.begin(), Tools.end(), ToolProps, OptDescs);
|
CollectToolProperties(Tools.begin(), Tools.end(), ToolProps, OptDescs);
|
||||||
|
|
||||||
|
// Collect option properties.
|
||||||
const RecordVector& OptionLists =
|
const RecordVector& OptionLists =
|
||||||
Records.getAllDerivedDefinitions("OptionList");
|
Records.getAllDerivedDefinitions("OptionList");
|
||||||
CollectPropertiesFromOptionLists(OptionLists.begin(), OptionLists.end(),
|
CollectPropertiesFromOptionLists(OptionLists.begin(), OptionLists.end(),
|
||||||
OptDescs);
|
OptDescs);
|
||||||
|
|
||||||
// TOTHINK: Nothing actually prevents us from having multiple
|
// Collect compilation graph edges.
|
||||||
// compilation graphs in a single plugin; OTOH, I do not see how
|
const RecordVector& CompilationGraphs =
|
||||||
// that could be useful.
|
Records.getAllDerivedDefinitions("CompilationGraph");
|
||||||
const Record* CompilationGraphRecord = Records.getDef("CompilationGraph");
|
RecordVector EdgeVector;
|
||||||
if (!CompilationGraphRecord)
|
FillInEdgeVector(CompilationGraphs.begin(), CompilationGraphs.end(),
|
||||||
throw std::string("Compilation graph description not found!");
|
EdgeVector);
|
||||||
|
|
||||||
FilterNotInGraph(CompilationGraphRecord, ToolProps);
|
// Filter out all tools not mentioned in the compilation graph.
|
||||||
|
FilterNotInGraph(EdgeVector, ToolProps);
|
||||||
|
|
||||||
// Typecheck the compilation graph.
|
// Typecheck the compilation graph.
|
||||||
TypecheckGraph(CompilationGraphRecord, ToolProps);
|
TypecheckGraph(EdgeVector, ToolProps);
|
||||||
|
|
||||||
// Check that there are no options without side effects (specified
|
// Check that there are no options without side effects (specified
|
||||||
// only in the OptionList).
|
// only in the OptionList).
|
||||||
@ -1888,16 +1897,16 @@ void LLVMCConfigurationEmitter::run (std::ostream &O) {
|
|||||||
EmitToolClassDefinition(*(*B), OptDescs, O);
|
EmitToolClassDefinition(*(*B), OptDescs, O);
|
||||||
|
|
||||||
// Emit Edge# classes.
|
// Emit Edge# classes.
|
||||||
EmitEdgeClasses(CompilationGraphRecord, OptDescs, O);
|
EmitEdgeClasses(EdgeVector, OptDescs, O);
|
||||||
|
|
||||||
// Emit PopulateCompilationGraph() function.
|
// Emit PopulateCompilationGraph() function.
|
||||||
EmitPopulateCompilationGraph(CompilationGraphRecord, ToolProps, O);
|
EmitPopulateCompilationGraph(EdgeVector, ToolProps, O);
|
||||||
|
|
||||||
// Emit code for plugin registration.
|
// Emit code for plugin registration.
|
||||||
const RecordVector& Priorities =
|
const RecordVector& Priorities =
|
||||||
Records.getAllDerivedDefinitions("PluginPriority");
|
Records.getAllDerivedDefinitions("PluginPriority");
|
||||||
EmitRegisterPlugin(CalculatePriority(Priorities.begin(), Priorities.end()),
|
EmitRegisterPlugin(CalculatePriority(Priorities.begin(),
|
||||||
O);
|
Priorities.end()), O);
|
||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
} catch (std::exception& Error) {
|
} catch (std::exception& Error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user