From 7dc02047fbb4b014e914458f54ea539c8ae58316 Mon Sep 17 00:00:00 2001 From: Jim Laskey Date: Sat, 22 Oct 2005 07:59:56 +0000 Subject: [PATCH] Sort the features and processor lists for the sake of search (and maintainers.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23879 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/SubtargetEmitter.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/utils/TableGen/SubtargetEmitter.cpp b/utils/TableGen/SubtargetEmitter.cpp index 8af7166a3d3..5318173b0d3 100644 --- a/utils/TableGen/SubtargetEmitter.cpp +++ b/utils/TableGen/SubtargetEmitter.cpp @@ -20,17 +20,42 @@ #include using namespace llvm; -// Convenience types +// +// Convenience types. +// typedef std::vector RecordList; typedef std::vector::iterator RecordListIter; +// +// Record sort by name function. +// +struct LessRecord { + bool operator()(const Record *Rec1, const Record *Rec2) const { + return Rec1->getName() < Rec2->getName(); + } +}; +// +// Record sort by field "Name" function. +// +struct LessRecordFieldName { + bool operator()(const Record *Rec1, const Record *Rec2) const { + return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name"); + } +}; + + +// // SubtargetEmitter::run - Main subtarget enumeration emitter. // void SubtargetEmitter::run(std::ostream &OS) { EmitSourceFileHeader("Subtarget Enumeration Source Fragment", OS); + RecordList Features = Records.getAllDerivedDefinitions("SubtargetFeature"); + sort(Features.begin(), Features.end(), LessRecord()); + RecordList Processors = Records.getAllDerivedDefinitions("Processor"); + sort(Processors.begin(), Processors.end(), LessRecordFieldName()); OS << "namespace llvm {\n\n"; @@ -70,7 +95,7 @@ void SubtargetEmitter::run(std::ostream &OS) { OS << "};\n"; } - { // Feature key values + { // CPU key values OS << "\n\n" << "/// Sorted (by key) array of values for CPU subtype.\n" << "static const SubtargetFeatureKV SubTypeKV[] = {\n";