1 //===- CommandLine.cpp ----------------------------------------------------===//
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 #include "mcld/Support/CommandLine.h"
10 #include <llvm/ADT/StringRef.h>
11
12 using namespace llvm;
13 using namespace llvm::cl;
14
15 //--------------------------------------------------
16 // parser<mcld::sys::fs::Path>
17 //
parse(llvm::cl::Option & O,llvm::StringRef ArgName,llvm::StringRef Arg,mcld::sys::fs::Path & Val)18 bool parser<mcld::sys::fs::Path>::parse(llvm::cl::Option &O,
19 llvm::StringRef ArgName,
20 llvm::StringRef Arg,
21 mcld::sys::fs::Path &Val)
22 {
23 Val.assign<llvm::StringRef::const_iterator>(Arg.begin(), Arg.end());
24 return false;
25 }
26
27 static const size_t MaxOptWidth = 8; // arbitrary spacing for printOptionDiff
28
printOptionDiff(const llvm::cl::Option & O,const mcld::sys::fs::Path & V,parser<mcld::sys::fs::Path>::OptVal Default,size_t GlobalWidth) const29 void parser<mcld::sys::fs::Path>::printOptionDiff(const llvm::cl::Option &O,
30 const mcld::sys::fs::Path &V,
31 parser<mcld::sys::fs::Path>::OptVal Default,
32 size_t GlobalWidth) const
33 {
34 printOptionName(O, GlobalWidth);
35 outs() << "= " << V;
36 size_t VSize = V.native().size();
37 size_t NumSpaces = MaxOptWidth > VSize ? MaxOptWidth - VSize : 0;
38 outs().indent(NumSpaces) << " (default: ";
39 if (Default.hasValue())
40 outs() << Default.getValue().c_str();
41 else
42 outs() << "*no default*";
43 outs() << ")\n";
44 }
45
anchor()46 void parser<mcld::sys::fs::Path>::anchor()
47 {
48 // do nothing
49 }
50
51 //--------------------------------------------------
52 // parser<mcld::MCLDDirectory>
53 //
parse(llvm::cl::Option & O,llvm::StringRef ArgName,llvm::StringRef Arg,mcld::MCLDDirectory & Val)54 bool parser<mcld::MCLDDirectory>::parse(llvm::cl::Option &O,
55 llvm::StringRef ArgName,
56 llvm::StringRef Arg,
57 mcld::MCLDDirectory &Val)
58 {
59 Val.assign(Arg);
60 return false;
61 }
62
printOptionDiff(const llvm::cl::Option & O,const mcld::MCLDDirectory & V,parser<mcld::MCLDDirectory>::OptVal Default,size_t GlobalWidth) const63 void parser<mcld::MCLDDirectory>::printOptionDiff(const llvm::cl::Option &O,
64 const mcld::MCLDDirectory &V,
65 parser<mcld::MCLDDirectory>::OptVal Default,
66 size_t GlobalWidth) const
67 {
68 printOptionName(O, GlobalWidth);
69 outs() << "= " << V.name();
70 size_t VSize = V.name().size();
71 size_t NumSpaces = MaxOptWidth > VSize ? MaxOptWidth - VSize : 0;
72 outs().indent(NumSpaces) << " (default: ";
73 if (Default.hasValue())
74 outs() << Default.getValue().name();
75 else
76 outs() << "*no default*";
77 outs() << ")\n";
78 }
79
anchor()80 void parser<mcld::MCLDDirectory>::anchor()
81 {
82 // do nothing
83 }
84
85