From d03317047d4e2933e13f85bebfcd4766aa34e9d9 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 19 Nov 2009 18:22:16 +0000 Subject: [PATCH] TableGen/OptParser: When ordering options, make "sentinel" options appear before everything else. llvm-svn: 89368 --- utils/TableGen/OptParserEmitter.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/utils/TableGen/OptParserEmitter.cpp b/utils/TableGen/OptParserEmitter.cpp index a09ba083f3e..ce1aef5e4da 100644 --- a/utils/TableGen/OptParserEmitter.cpp +++ b/utils/TableGen/OptParserEmitter.cpp @@ -35,9 +35,16 @@ static int CompareOptionRecords(const void *Av, const void *Bv) { const Record *A = *(Record**) Av; const Record *B = *(Record**) Bv; - // Compare options by name first. - if (int Cmp = StrCmpOptionName(A->getValueAsString("Name").c_str(), - B->getValueAsString("Name").c_str())) + // Sentinel options preceed all others and are only ordered by precedence. + bool ASent = A->getValueAsDef("Kind")->getValueAsBit("Sentinel"); + bool BSent = B->getValueAsDef("Kind")->getValueAsBit("Sentinel"); + if (ASent != BSent) + return ASent ? -1 : 1; + + // Compare options by name, unless they are sentinels. + if (!ASent) + if (int Cmp = StrCmpOptionName(A->getValueAsString("Name").c_str(), + B->getValueAsString("Name").c_str())) return Cmp; // Then by the kind precedence;