[llvm-commits] [llvm] r143616 - in /llvm/trunk/tools: CMakeLists.txt Makefile llvm-config-2/ llvm-config-2/CMakeLists.txt llvm-config-2/Makefile llvm-config-2/llvm-config.cpp

Chandler Carruth chandlerc at google.com
Thu Nov 3 12:43:43 PDT 2011


On Thu, Nov 3, 2011 at 11:51 AM, Wesley Peck <peckw at wesleypeck.com> wrote:

>
> On Nov 3, 2011, at 12:30 PM, Daniel Dunbar wrote:
> > +  for (int i = 1; i != argc; ++i) {
> > +    StringRef Arg = argv[i];
> > +
> > +    if (Arg.startswith("-")) {
> > +      HasAnyOption = true;
> > +      if (Arg == "--version") {
> > +        OS << PACKAGE_VERSION << '\n';
> > +      } else if (Arg == "--prefix") {
> > +        OS << ActivePrefix << '\n';
> > +      } else if (Arg == "--bindir") {
> > +        OS << ActiveBinDir << '\n';
> > +      } else if (Arg == "--includedir") {
> > +        OS << ActiveIncludeDir << '\n';
> > +      } else if (Arg == "--libdir") {
> > +        OS << ActiveLibDir << '\n';
> > +      } else if (Arg == "--cppflags") {
> > +        OS << ActiveIncludeOption << ' ' << LLVM_CPPFLAGS << '\n';
> > +      } else if (Arg == "--cflags") {
> > +        OS << ActiveIncludeOption << ' ' << LLVM_CFLAGS << '\n';
> > +      } else if (Arg == "--cxxflags") {
> > +        OS << ActiveIncludeOption << ' ' << LLVM_CXXFLAGS << '\n';
> > +      } else if (Arg == "--ldflags") {
> > +        OS << "-L" << ActiveLibDir << ' ' << LLVM_LDFLAGS
> > +           << ' ' << LLVM_SYSTEM_LIBS << '\n';
> > +      } else if (Arg == "--libs") {
> > +        PrintLibs = true;
> > +      } else if (Arg == "--libnames") {
> > +        PrintLibNames = true;
> > +      } else if (Arg == "--libfiles") {
> > +        PrintLibFiles = true;
> > +      } else if (Arg == "--components") {
> > +        for (unsigned j = 0; j != NumAvailableComponents; ++j) {
> > +          if (j)
> > +            OS << ' ';
> > +          OS << AvailableComponents[j].Name;
> > +        }
> > +        OS << '\n';
> > +      } else if (Arg == "--targets-built") {
> > +        bool First = true;
> > +        for (TargetRegistry::iterator I = TargetRegistry::begin(),
> > +               E = TargetRegistry::end(); I != E; First = false, ++I) {
> > +          if (!First)
> > +            OS << ' ';
> > +          OS << I->getName();
> > +        }
> > +        OS << '\n';
> > +      } else if (Arg == "--host-target") {
> > +        OS << LLVM_DEFAULT_TARGET_TRIPLE << '\n';
> > +      } else if (Arg == "--build-mode") {
> > +        OS << LLVM_BUILDMODE << '\n';
> > +      } else if (Arg == "--obj-root") {
> > +        OS << LLVM_OBJ_ROOT << '\n';
> > +      } else if (Arg == "--src-root") {
> > +        OS << LLVM_SRC_ROOT << '\n';
> > +      } else {
> > +        usage();
> > +      }
> > +    } else {
> > +      Components.push_back(Arg);
> > +    }
> > +  }
> > +
> > +  if (!HasAnyOption)
> > +    usage();
>
> Just out of curiosity, why not use LLVM's command line parsing library for
> this? Is is not capable of parsing the required syntax or are you trying to
> avoid some sort of dependency? It seems like it would be a lot cleaner and
> easier to maintain than this code.


Agreed, this would be much cleaner using the commandline library.

Also, there is a lot of string manipulation and path manipulation that I
think would be cleaner using StringRef / Twine / raw_ostream-derivatives /
PathV2... if those libraries don't quite fit or aren't so clean to use, we
should improve them so that we can use them for exactly this type of ced.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20111103/dcd6281a/attachment.html>


More information about the llvm-commits mailing list