LLVM  14.0.0git
Arg.cpp
Go to the documentation of this file.
1 //===- Arg.cpp - Argument Implementations ---------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/ADT/SmallString.h"
10 #include "llvm/Config/llvm-config.h"
11 #include "llvm/Option/Arg.h"
12 #include "llvm/Option/ArgList.h"
13 #include "llvm/Option/Option.h"
14 #include "llvm/Support/Compiler.h"
15 #include "llvm/Support/Debug.h"
17 
18 using namespace llvm;
19 using namespace llvm::opt;
20 
21 Arg::Arg(const Option Opt, StringRef S, unsigned Index, const Arg *BaseArg)
22  : Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
23  OwnsValues(false) {}
24 
25 Arg::Arg(const Option Opt, StringRef S, unsigned Index, const char *Value0,
26  const Arg *BaseArg)
27  : Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
28  OwnsValues(false) {
29  Values.push_back(Value0);
30 }
31 
32 Arg::Arg(const Option Opt, StringRef S, unsigned Index, const char *Value0,
33  const char *Value1, const Arg *BaseArg)
34  : Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
35  OwnsValues(false) {
36  Values.push_back(Value0);
37  Values.push_back(Value1);
38 }
39 
41  if (OwnsValues) {
42  for (unsigned i = 0, e = Values.size(); i != e; ++i)
43  delete[] Values[i];
44  }
45 }
46 
47 void Arg::print(raw_ostream& O) const {
48  O << "<";
49 
50  O << " Opt:";
51  Opt.print(O);
52 
53  O << " Index:" << Index;
54 
55  O << " Values: [";
56  for (unsigned i = 0, e = Values.size(); i != e; ++i) {
57  if (i) O << ", ";
58  O << "'" << Values[i] << "'";
59  }
60 
61  O << "]>\n";
62 }
63 
64 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
65 LLVM_DUMP_METHOD void Arg::dump() const { print(dbgs()); }
66 #endif
67 
68 std::string Arg::getAsString(const ArgList &Args) const {
69  if (Alias)
70  return Alias->getAsString(Args);
71 
72  SmallString<256> Res;
73  raw_svector_ostream OS(Res);
74 
75  ArgStringList ASL;
76  render(Args, ASL);
78  it = ASL.begin(), ie = ASL.end(); it != ie; ++it) {
79  if (it != ASL.begin())
80  OS << ' ';
81  OS << *it;
82  }
83 
84  return std::string(OS.str());
85 }
86 
87 void Arg::renderAsInput(const ArgList &Args, ArgStringList &Output) const {
88  if (!getOption().hasNoOptAsInput()) {
89  render(Args, Output);
90  return;
91  }
92 
93  Output.append(Values.begin(), Values.end());
94 }
95 
96 void Arg::render(const ArgList &Args, ArgStringList &Output) const {
97  switch (getOption().getRenderStyle()) {
99  Output.append(Values.begin(), Values.end());
100  break;
101 
103  SmallString<256> Res;
104  raw_svector_ostream OS(Res);
105  OS << getSpelling();
106  for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
107  if (i) OS << ',';
108  OS << getValue(i);
109  }
110  Output.push_back(Args.MakeArgString(OS.str()));
111  break;
112  }
113 
115  Output.push_back(Args.GetOrMakeJoinedArgString(
116  getIndex(), getSpelling(), getValue(0)));
117  Output.append(Values.begin() + 1, Values.end());
118  break;
119 
121  Output.push_back(Args.MakeArgString(getSpelling()));
122  Output.append(Values.begin(), Values.end());
123  break;
124  }
125 }
i
i
Definition: README.txt:29
llvm::opt::Arg::getAsString
std::string getAsString(const ArgList &Args) const
Return a formatted version of the argument and its values, for diagnostics.
Definition: Arg.cpp:68
Option.h
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:491
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
it
into xmm2 addss xmm2 xmm1 xmm3 addss xmm3 movaps xmm0 unpcklps xmm0 ret seems silly when it could just be one addps Expand libm rounding functions main should enable SSE DAZ mode and other fast SSE modes Think about doing i64 math in SSE regs on x86 This testcase should have no SSE instructions in it
Definition: README-SSE.txt:81
llvm::opt::Arg
A concrete instance of a particular driver option.
Definition: Arg.h:34
llvm::opt::ArgList
ArgList - Ordered collection of driver arguments.
Definition: ArgList.h:116
llvm::SmallVector< const char *, 16 >
llvm::opt::Option::RenderCommaJoinedStyle
@ RenderCommaJoinedStyle
Definition: Option.h:70
llvm::opt::Arg::~Arg
~Arg()
Definition: Arg.cpp:40
llvm::opt::Arg::print
void print(raw_ostream &O) const
Definition: Arg.cpp:47
llvm::opt::Arg::getIndex
unsigned getIndex() const
Definition: Arg.h:87
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::opt::Arg::getOption
const Option & getOption() const
Definition: Arg.h:77
SmallString.h
llvm::SmallVectorImpl::append
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:648
false
Definition: StackSlotColoring.cpp:142
llvm::opt::Arg::getNumValues
unsigned getNumValues() const
Definition: Arg.h:111
llvm::opt
Definition: Arg.h:26
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::opt::Option::RenderValuesStyle
@ RenderValuesStyle
Definition: Option.h:73
llvm::opt::Arg::dump
void dump() const
Definition: Arg.cpp:65
llvm::opt::Arg::getValue
const char * getValue(unsigned N=0) const
Definition: Arg.h:113
llvm::opt::Option::print
void print(raw_ostream &O) const
Definition: Option.cpp:41
llvm::SmallString< 256 >
llvm::opt::Option::RenderJoinedStyle
@ RenderJoinedStyle
Definition: Option.h:71
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:192
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::opt::Arg::getSpelling
StringRef getSpelling() const
Returns the used prefix and name of the option: For --foo=bar, returns --foo=.
Definition: Arg.h:85
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::opt::Arg::render
void render(const ArgList &Args, ArgStringList &Output) const
Append the argument onto the given array as strings.
Definition: Arg.cpp:96
llvm::opt::Option::RenderSeparateStyle
@ RenderSeparateStyle
Definition: Option.h:72
Arg.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::raw_svector_ostream::str
StringRef str() const
Return a StringRef for the vector contents.
Definition: raw_ostream.h:683
Compiler.h
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::opt::Arg::renderAsInput
void renderAsInput(const ArgList &Args, ArgStringList &Output) const
Append the argument, render as an input, onto the given array as strings.
Definition: Arg.cpp:87
ArgList.h
llvm::opt::Option
Option - Abstract representation for a single form of driver argument.
Definition: Option.h:51
llvm::opt::Arg::Arg
Arg(const Option Opt, StringRef Spelling, unsigned Index, const Arg *BaseArg=nullptr)
Definition: Arg.cpp:21
llvm::SmallVectorImpl< const char * >::iterator
typename SuperClass::iterator iterator
Definition: SmallVector.h:562
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:658
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:389
raw_ostream.h
Debug.h