Improve help output.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23893 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2005-10-23 05:33:39 +00:00
parent 2e1f823aed
commit ba76c21858

View File

@ -125,25 +125,29 @@ static const SubtargetFeatureKV *Find(const std::string &S,
/// Display help for feature choices. /// Display help for feature choices.
/// ///
static void Help(const char *Heading, const SubtargetFeatureKV *Table, static void Help(bool isFeature, const SubtargetFeatureKV *Table,
size_t TableSize) { size_t TableSize) {
// Determine the length of the longest key // Determine the length of the longest key.
size_t MaxLen = 0; size_t MaxLen = 0;
for (size_t i = 0; i < TableSize; i++) for (size_t i = 0; i < TableSize; i++)
MaxLen = std::max(MaxLen, std::strlen(Table[i].Key)); MaxLen = std::max(MaxLen, std::strlen(Table[i].Key));
// Print heading
std::cerr << "Help for " << Heading << " choices:\n\n"; std::cerr << "Available " << (isFeature ? "features" : "CPUs")
// For each feature << " for this target:\n\n";
for (size_t i = 0; i < TableSize; i++) { for (size_t i = 0; i < TableSize; i++) {
// Compute required padding // Compute required padding
size_t Pad = MaxLen - std::strlen(Table[i].Key); size_t Pad = MaxLen - std::strlen(Table[i].Key);
// Print details
std::cerr << Table[i].Key << std::string(Pad, ' ') << " - " std::cerr << Table[i].Key << std::string(Pad, ' ') << " - "
<< Table[i].Desc << "\n"; << Table[i].Desc << ".\n";
}
std::cerr << "\n";
if (isFeature) {
std::cerr
<< "Use +feature to enable a feature, or -feature to disable it.\n"
<< "For example, llc -mcpu=mycpu -mattr=+feature1,-feature2\n";
} }
// Wrap it up
std::cerr << "\n\n";
// Leave tool
exit(1); exit(1);
} }
@ -202,7 +206,7 @@ uint32_t SubtargetFeatures::Parse(const std::string &String,
// Check if default is needed // Check if default is needed
if (Features[0].empty()) Features[0] = DefaultCPU; if (Features[0].empty()) Features[0] = DefaultCPU;
// Check for help // Check for help
if (Features[0] == "help") Help("CPU", CPUTable, CPUTableSize); if (Features[0] == "help") Help(false, CPUTable, CPUTableSize);
// Find CPU entry // Find CPU entry
const SubtargetFeatureKV *CPUEntry = const SubtargetFeatureKV *CPUEntry =
Find(Features[0], CPUTable, CPUTableSize); Find(Features[0], CPUTable, CPUTableSize);
@ -221,7 +225,7 @@ uint32_t SubtargetFeatures::Parse(const std::string &String,
// Get next feature // Get next feature
const std::string &Feature = Features[i]; const std::string &Feature = Features[i];
// Check for help // Check for help
if (Feature == "+help") Help("feature", FeatureTable, FeatureTableSize); if (Feature == "+help") Help(true, FeatureTable, FeatureTableSize);
// Find feature in table. // Find feature in table.
const SubtargetFeatureKV *FeatureEntry = const SubtargetFeatureKV *FeatureEntry =
Find(StripFlag(Feature), FeatureTable, FeatureTableSize); Find(StripFlag(Feature), FeatureTable, FeatureTableSize);