aboutsummaryrefslogtreecommitdiff
path: root/lib/Driver/Option.cpp
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2012-10-22 22:13:48 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2012-10-22 22:13:48 +0000
commitc635710bcbb9598acd5a14647ba7ca28bee89a68 (patch)
tree978feeef3e87ac75ea630c0c301bc5c96a79b1af /lib/Driver/Option.cpp
parent6b8194e4d7ca980087a3a5e1addb74090be990ff (diff)
[Options] Add prefixes to options.
Each option has a set of prefixes. When matching an argument such as -funroll-loops. First the leading - is removed as it is a prefix. Then a lower_bound search for "funroll-loops" is done against the option table by option name. From there each option prefix + option name combination is tested against the argument. This allows us to support Microsoft style options where both / and - are valid prefixes. It also simplifies the cases we already have where options come in both - and -- forms. Almost every option for gnu-ld happens to have this form. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166444 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/Option.cpp')
-rw-r--r--lib/Driver/Option.cpp45
1 files changed, 27 insertions, 18 deletions
diff --git a/lib/Driver/Option.cpp b/lib/Driver/Option.cpp
index e9440c5242..a22cb15e2e 100644
--- a/lib/Driver/Option.cpp
+++ b/lib/Driver/Option.cpp
@@ -48,6 +48,12 @@ void Option::dump() const {
#undef P
}
+ llvm::errs() << " Prefixes:[";
+ for (const char * const *Pre = Info->Prefixes; *Pre != 0; ++Pre) {
+ llvm::errs() << '"' << *Pre << (*(Pre + 1) == 0 ? "\"" : "\", ");
+ }
+ llvm::errs() << ']';
+
llvm::errs() << " Name:\"" << getName() << '"';
const Option Group = getGroup();
@@ -84,21 +90,24 @@ bool Option::matches(OptSpecifier Opt) const {
return false;
}
-Arg *Option::accept(const ArgList &Args, unsigned &Index) const {
+Arg *Option::accept(const ArgList &Args,
+ unsigned &Index,
+ unsigned ArgSize) const {
+ StringRef Spelling(Args.getArgString(Index), ArgSize);
switch (getKind()) {
case FlagClass:
- if (getName().size() != strlen(Args.getArgString(Index)))
+ if (ArgSize != strlen(Args.getArgString(Index)))
return 0;
- return new Arg(getUnaliasedOption(), Index++);
+ return new Arg(getUnaliasedOption(), Spelling, Index++);
case JoinedClass: {
- const char *Value = Args.getArgString(Index) + getName().size();
- return new Arg(getUnaliasedOption(), Index++, Value);
+ const char *Value = Args.getArgString(Index) + ArgSize;
+ return new Arg(getUnaliasedOption(), Spelling, Index++, Value);
}
case CommaJoinedClass: {
// Always matches.
- const char *Str = Args.getArgString(Index) + getName().size();
- Arg *A = new Arg(getUnaliasedOption(), Index++);
+ const char *Str = Args.getArgString(Index) + ArgSize;
+ Arg *A = new Arg(getUnaliasedOption(), Spelling, Index++);
// Parse out the comma separated values.
const char *Prev = Str;
@@ -126,26 +135,26 @@ Arg *Option::accept(const ArgList &Args, unsigned &Index) const {
case SeparateClass:
// Matches iff this is an exact match.
// FIXME: Avoid strlen.
- if (getName().size() != strlen(Args.getArgString(Index)))
+ if (ArgSize != strlen(Args.getArgString(Index)))
return 0;
Index += 2;
if (Index > Args.getNumInputArgStrings())
return 0;
- return new Arg(getUnaliasedOption(),
+ return new Arg(getUnaliasedOption(), Spelling,
Index - 2, Args.getArgString(Index - 1));
case MultiArgClass: {
// Matches iff this is an exact match.
// FIXME: Avoid strlen.
- if (getName().size() != strlen(Args.getArgString(Index)))
+ if (ArgSize != strlen(Args.getArgString(Index)))
return 0;
Index += 1 + getNumArgs();
if (Index > Args.getNumInputArgStrings())
return 0;
- Arg *A = new Arg(getUnaliasedOption(), Index - 1 - getNumArgs(),
+ Arg *A = new Arg(getUnaliasedOption(), Spelling, Index - 1 - getNumArgs(),
Args.getArgString(Index - getNumArgs()));
for (unsigned i = 1; i != getNumArgs(); ++i)
A->getValues().push_back(Args.getArgString(Index - getNumArgs() + i));
@@ -154,9 +163,9 @@ Arg *Option::accept(const ArgList &Args, unsigned &Index) const {
case JoinedOrSeparateClass: {
// If this is not an exact match, it is a joined arg.
// FIXME: Avoid strlen.
- if (getName().size() != strlen(Args.getArgString(Index))) {
- const char *Value = Args.getArgString(Index) + getName().size();
- return new Arg(*this, Index++, Value);
+ if (ArgSize != strlen(Args.getArgString(Index))) {
+ const char *Value = Args.getArgString(Index) + ArgSize;
+ return new Arg(*this, Spelling, Index++, Value);
}
// Otherwise it must be separate.
@@ -164,7 +173,7 @@ Arg *Option::accept(const ArgList &Args, unsigned &Index) const {
if (Index > Args.getNumInputArgStrings())
return 0;
- return new Arg(getUnaliasedOption(),
+ return new Arg(getUnaliasedOption(), Spelling,
Index - 2, Args.getArgString(Index - 1));
}
case JoinedAndSeparateClass:
@@ -173,9 +182,9 @@ Arg *Option::accept(const ArgList &Args, unsigned &Index) const {
if (Index > Args.getNumInputArgStrings())
return 0;
- return new Arg(getUnaliasedOption(), Index - 2,
- Args.getArgString(Index-2)+getName().size(),
- Args.getArgString(Index-1));
+ return new Arg(getUnaliasedOption(), Spelling, Index - 2,
+ Args.getArgString(Index - 2) + ArgSize,
+ Args.getArgString(Index - 1));
default:
llvm_unreachable("Invalid option kind!");
}