diff options
author | Rui Ueyama <ruiu@google.com> | 2013-08-27 23:47:01 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2013-08-27 23:47:01 +0000 |
commit | 055f4e99ffb32462db6fc62f9a306f2865acacb0 (patch) | |
tree | a3981efdb6d873eebe2916e5eeb789fb0c344f54 /utils/TableGen | |
parent | 587e1939fa1bd2bcce764c6dc53263f9faa44ab9 (diff) | |
download | llvm-055f4e99ffb32462db6fc62f9a306f2865acacb0.tar.gz llvm-055f4e99ffb32462db6fc62f9a306f2865acacb0.tar.bz2 llvm-055f4e99ffb32462db6fc62f9a306f2865acacb0.tar.xz |
Option parsing: support case-insensitive option matching.
Link.exe's command line options are case-insensitive. This patch
adds a new attribute to OptTable to let the option parser to compare
options, ignoring case.
Command lines are generally case-insensitive on Windows. CL.exe is an
exception. So this new attribute should be useful for other commands
running on Windows.
Differential Revision: http://llvm-reviews.chandlerc.com/D1485
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189416 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen')
-rw-r--r-- | utils/TableGen/OptParserEmitter.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/utils/TableGen/OptParserEmitter.cpp b/utils/TableGen/OptParserEmitter.cpp index 86328bf18f..f2694361db 100644 --- a/utils/TableGen/OptParserEmitter.cpp +++ b/utils/TableGen/OptParserEmitter.cpp @@ -13,27 +13,25 @@ #include "llvm/ADT/Twine.h" #include "llvm/TableGen/Record.h" #include "llvm/TableGen/TableGenBackend.h" +#include <cstring> #include <map> +#include <strings.h> using namespace llvm; +// Ordering on Info. The logic should match with the consumer-side function in +// llvm/Option/OptTable.h. static int StrCmpOptionName(const char *A, const char *B) { - char a = *A, b = *B; - while (a == b) { - if (a == '\0') - return 0; - - a = *++A; - b = *++B; + size_t I = strlen(A); + size_t J = strlen(B); + if (I == J) { + if (int N = strcasecmp(A, B)) + return N; + return strcmp(A, B); } - - if (a == '\0') // A is a prefix of B. - return 1; - if (b == '\0') // B is a prefix of A. - return -1; - - // Otherwise lexicographic. - return (a < b) ? -1 : 1; + if (I < J) + return strncasecmp(A, B, I) < 0 ? -1 : 1; + return strncasecmp(A, B, J) <= 0 ? -1 : 1; } static int CompareOptionRecords(const void *Av, const void *Bv) { @@ -50,7 +48,7 @@ static int CompareOptionRecords(const void *Av, const void *Bv) { if (!ASent) if (int Cmp = StrCmpOptionName(A->getValueAsString("Name").c_str(), B->getValueAsString("Name").c_str())) - return Cmp; + return Cmp; if (!ASent) { std::vector<std::string> APrefixes = A->getValueAsListOfStrings("Prefixes"); |