Home | History | Annotate | Download | only in Support
      1 //===- CommandLine.h ------------------------------------------------------===//
      2 //
      3 //                     The MCLinker Project
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 #ifndef MCLD_COMMANDLINE_H
     10 #define MCLD_COMMANDLINE_H
     11 #ifdef ENABLE_UNITTEST
     12 #include <gtest.h>
     13 #endif
     14 #include <mcld/Support/FileSystem.h>
     15 #include <mcld/MC/ZOption.h>
     16 
     17 #include <llvm/ADT/StringRef.h>
     18 #include <llvm/ADT/Triple.h>
     19 #include <llvm/Support/CommandLine.h>
     20 
     21 #include <string>
     22 
     23 namespace llvm {
     24 namespace cl {
     25 
     26 //===----------------------------------------------------------------------===//
     27 // SearchDirParser
     28 //===----------------------------------------------------------------------===//
     29 class SearchDirParser : public llvm::cl::basic_parser<std::string>
     30 {
     31 public:
     32   // parse - Return true on error.
     33   bool parse(Option &pOption,
     34              StringRef pArgName,
     35              StringRef pArg,
     36              std::string &pValue);
     37 
     38   const char *getValueName() const { return "searchdir"; }
     39 
     40   void printOptionDiff(const Option &pOption,
     41                        StringRef pValue,
     42                        OptVal pDefault,
     43                        size_t pGlobalWidth) const;
     44 
     45   void anchor();
     46 };
     47 
     48 //===----------------------------------------------------------------------===//
     49 // FalseParser
     50 //===----------------------------------------------------------------------===//
     51 class FalseParser : public cl::parser<bool>
     52 {
     53 public:
     54   // parse - Return true on error.
     55   bool parse(cl::Option &O, StringRef ArgName, StringRef Arg, bool &Val) {
     56     if (cl::parser<bool>::parse(O, ArgName, Arg, Val))
     57       return false;
     58     Val = false;
     59     return false;
     60   }
     61 };
     62 
     63 //===----------------------------------------------------------------------===//
     64 // parser<mcld::sys::fs::Path>
     65 //===----------------------------------------------------------------------===//
     66 template<>
     67 class parser<mcld::sys::fs::Path> : public basic_parser<mcld::sys::fs::Path>
     68 {
     69 public:
     70   bool parse(Option &O,
     71              StringRef ArgName,
     72              StringRef Arg,
     73              mcld::sys::fs::Path &Val);
     74 
     75   virtual const char *getValueName() const { return "path"; }
     76   void printOptionDiff(const Option &O,
     77                        const mcld::sys::fs::Path &V,
     78                        OptVal Default,
     79                        size_t GlobalWidth) const;
     80   virtual void anchor();
     81 };
     82 
     83 //===----------------------------------------------------------------------===//
     84 // parser<mcld::ZOption>
     85 //===----------------------------------------------------------------------===//
     86 template<>
     87 class parser<mcld::ZOption> : public llvm::cl::basic_parser<mcld::ZOption>
     88 {
     89 public:
     90   bool parse(Option &O, StringRef ArgName, StringRef Arg, mcld::ZOption &Val);
     91 
     92   virtual const char *getValueName() const { return "z-option"; }
     93   void printOptionDiff(const Option &O,
     94                        const mcld::ZOption &V,
     95                        OptVal Default,
     96                        size_t GlobalWidth) const;
     97   virtual void anchor();
     98 };
     99 
    100 } // namespace of cl
    101 } // namespace of llvm
    102 
    103 #endif
    104 
    105