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_SUPPORT_COMMANDLINE_H
10#define MCLD_SUPPORT_COMMANDLINE_H
11#include <mcld/Support/FileSystem.h>
12#include <mcld/MC/ZOption.h>
13
14#include <llvm/ADT/StringRef.h>
15#include <llvm/ADT/Triple.h>
16#include <llvm/Support/CommandLine.h>
17
18#include <string>
19
20namespace llvm {
21namespace cl {
22
23//===----------------------------------------------------------------------===//
24// SearchDirParser
25//===----------------------------------------------------------------------===//
26class SearchDirParser : public llvm::cl::basic_parser<std::string>
27{
28public:
29  // parse - Return true on error.
30  bool parse(Option &pOption,
31             StringRef pArgName,
32             StringRef pArg,
33             std::string &pValue);
34
35  const char *getValueName() const { return "searchdir"; }
36
37  void printOptionDiff(const Option &pOption,
38                       StringRef pValue,
39                       OptVal pDefault,
40                       size_t pGlobalWidth) const;
41
42  void anchor();
43};
44
45//===----------------------------------------------------------------------===//
46// FalseParser
47//===----------------------------------------------------------------------===//
48class FalseParser : public cl::parser<bool>
49{
50public:
51  // parse - Return true on error.
52  bool parse(cl::Option &O, StringRef ArgName, StringRef Arg, bool &Val) {
53    if (cl::parser<bool>::parse(O, ArgName, Arg, Val))
54      return false;
55    Val = false;
56    return false;
57  }
58};
59
60//===----------------------------------------------------------------------===//
61// parser<mcld::sys::fs::Path>
62//===----------------------------------------------------------------------===//
63template<>
64class parser<mcld::sys::fs::Path> : public basic_parser<mcld::sys::fs::Path>
65{
66public:
67  bool parse(Option &O,
68             StringRef ArgName,
69             StringRef Arg,
70             mcld::sys::fs::Path &Val);
71
72  virtual const char *getValueName() const { return "path"; }
73  void printOptionDiff(const Option &O,
74                       const mcld::sys::fs::Path &V,
75                       OptVal Default,
76                       size_t GlobalWidth) const;
77  virtual void anchor();
78};
79
80//===----------------------------------------------------------------------===//
81// parser<mcld::ZOption>
82//===----------------------------------------------------------------------===//
83template<>
84class parser<mcld::ZOption> : public llvm::cl::basic_parser<mcld::ZOption>
85{
86public:
87  bool parse(Option &O, StringRef ArgName, StringRef Arg, mcld::ZOption &Val);
88
89  virtual const char *getValueName() const { return "z-option"; }
90  void printOptionDiff(const Option &O,
91                       const mcld::ZOption &V,
92                       OptVal Default,
93                       size_t GlobalWidth) const;
94  virtual void anchor();
95};
96
97} // namespace of cl
98} // namespace of llvm
99
100#endif
101
102