Imported Upstream version 5.18.0.167

Former-commit-id: 289509151e0fee68a1b591a20c9f109c3c789d3a
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-10-20 08:25:10 +00:00
parent e19d552987
commit b084638f15
28489 changed files with 184 additions and 3866856 deletions

View File

@ -1,122 +0,0 @@
//===- Arg.cpp - Argument Implementations ---------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/SmallString.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
using namespace llvm::opt;
Arg::Arg(const Option Opt, StringRef S, unsigned Index, const Arg *BaseArg)
: Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
OwnsValues(false) {}
Arg::Arg(const Option Opt, StringRef S, unsigned Index, const char *Value0,
const Arg *BaseArg)
: Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
OwnsValues(false) {
Values.push_back(Value0);
}
Arg::Arg(const Option Opt, StringRef S, unsigned Index, const char *Value0,
const char *Value1, const Arg *BaseArg)
: Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
OwnsValues(false) {
Values.push_back(Value0);
Values.push_back(Value1);
}
Arg::~Arg() {
if (OwnsValues) {
for (unsigned i = 0, e = Values.size(); i != e; ++i)
delete[] Values[i];
}
}
void Arg::print(raw_ostream& O) const {
O << "<";
O << " Opt:";
Opt.print(O);
O << " Index:" << Index;
O << " Values: [";
for (unsigned i = 0, e = Values.size(); i != e; ++i) {
if (i) O << ", ";
O << "'" << Values[i] << "'";
}
O << "]>\n";
}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void Arg::dump() const { print(dbgs()); }
#endif
std::string Arg::getAsString(const ArgList &Args) const {
SmallString<256> Res;
raw_svector_ostream OS(Res);
ArgStringList ASL;
render(Args, ASL);
for (ArgStringList::iterator
it = ASL.begin(), ie = ASL.end(); it != ie; ++it) {
if (it != ASL.begin())
OS << ' ';
OS << *it;
}
return OS.str();
}
void Arg::renderAsInput(const ArgList &Args, ArgStringList &Output) const {
if (!getOption().hasNoOptAsInput()) {
render(Args, Output);
return;
}
Output.append(Values.begin(), Values.end());
}
void Arg::render(const ArgList &Args, ArgStringList &Output) const {
switch (getOption().getRenderStyle()) {
case Option::RenderValuesStyle:
Output.append(Values.begin(), Values.end());
break;
case Option::RenderCommaJoinedStyle: {
SmallString<256> Res;
raw_svector_ostream OS(Res);
OS << getSpelling();
for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
if (i) OS << ',';
OS << getValue(i);
}
Output.push_back(Args.MakeArgString(OS.str()));
break;
}
case Option::RenderJoinedStyle:
Output.push_back(Args.GetOrMakeJoinedArgString(
getIndex(), getSpelling(), getValue(0)));
Output.append(Values.begin() + 1, Values.end());
break;
case Option::RenderSeparateStyle:
Output.push_back(Args.MakeArgString(getSpelling()));
Output.append(Values.begin(), Values.end());
break;
}
}

View File

@ -1,289 +0,0 @@
//===- ArgList.cpp - Argument List Management -----------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
#include "llvm/Option/OptSpecifier.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <memory>
#include <string>
#include <utility>
#include <vector>
using namespace llvm;
using namespace llvm::opt;
void ArgList::append(Arg *A) {
Args.push_back(A);
// Update ranges for the option and all of its groups.
for (Option O = A->getOption().getUnaliasedOption(); O.isValid();
O = O.getGroup()) {
auto &R =
OptRanges.insert(std::make_pair(O.getID(), emptyRange())).first->second;
R.first = std::min<unsigned>(R.first, Args.size() - 1);
R.second = Args.size();
}
}
void ArgList::eraseArg(OptSpecifier Id) {
// Zero out the removed entries but keep them around so that we don't
// need to invalidate OptRanges.
for (Arg *const &A : filtered(Id)) {
// Avoid the need for a non-const filtered iterator variant.
Arg **ArgsBegin = Args.data();
ArgsBegin[&A - ArgsBegin] = nullptr;
}
OptRanges.erase(Id.getID());
}
ArgList::OptRange
ArgList::getRange(std::initializer_list<OptSpecifier> Ids) const {
OptRange R = emptyRange();
for (auto Id : Ids) {
auto I = OptRanges.find(Id.getID());
if (I != OptRanges.end()) {
R.first = std::min(R.first, I->second.first);
R.second = std::max(R.second, I->second.second);
}
}
// Map an empty {-1, 0} range to {0, 0} so it can be used to form iterators.
if (R.first == -1u)
R.first = 0;
return R;
}
bool ArgList::hasFlag(OptSpecifier Pos, OptSpecifier Neg, bool Default) const {
if (Arg *A = getLastArg(Pos, Neg))
return A->getOption().matches(Pos);
return Default;
}
bool ArgList::hasFlag(OptSpecifier Pos, OptSpecifier PosAlias, OptSpecifier Neg,
bool Default) const {
if (Arg *A = getLastArg(Pos, PosAlias, Neg))
return A->getOption().matches(Pos) || A->getOption().matches(PosAlias);
return Default;
}
StringRef ArgList::getLastArgValue(OptSpecifier Id, StringRef Default) const {
if (Arg *A = getLastArg(Id))
return A->getValue();
return Default;
}
std::vector<std::string> ArgList::getAllArgValues(OptSpecifier Id) const {
SmallVector<const char *, 16> Values;
AddAllArgValues(Values, Id);
return std::vector<std::string>(Values.begin(), Values.end());
}
void ArgList::AddLastArg(ArgStringList &Output, OptSpecifier Id) const {
if (Arg *A = getLastArg(Id)) {
A->claim();
A->render(*this, Output);
}
}
void ArgList::AddLastArg(ArgStringList &Output, OptSpecifier Id0,
OptSpecifier Id1) const {
if (Arg *A = getLastArg(Id0, Id1)) {
A->claim();
A->render(*this, Output);
}
}
void ArgList::AddAllArgsExcept(ArgStringList &Output,
ArrayRef<OptSpecifier> Ids,
ArrayRef<OptSpecifier> ExcludeIds) const {
for (const Arg *Arg : *this) {
bool Excluded = false;
for (OptSpecifier Id : ExcludeIds) {
if (Arg->getOption().matches(Id)) {
Excluded = true;
break;
}
}
if (!Excluded) {
for (OptSpecifier Id : Ids) {
if (Arg->getOption().matches(Id)) {
Arg->claim();
Arg->render(*this, Output);
break;
}
}
}
}
}
/// This is a nicer interface when you don't have a list of Ids to exclude.
void ArgList::AddAllArgs(ArgStringList &Output,
ArrayRef<OptSpecifier> Ids) const {
ArrayRef<OptSpecifier> Exclude = None;
AddAllArgsExcept(Output, Ids, Exclude);
}
/// This 3-opt variant of AddAllArgs could be eliminated in favor of one
/// that accepts a single specifier, given the above which accepts any number.
void ArgList::AddAllArgs(ArgStringList &Output, OptSpecifier Id0,
OptSpecifier Id1, OptSpecifier Id2) const {
for (auto Arg: filtered(Id0, Id1, Id2)) {
Arg->claim();
Arg->render(*this, Output);
}
}
void ArgList::AddAllArgValues(ArgStringList &Output, OptSpecifier Id0,
OptSpecifier Id1, OptSpecifier Id2) const {
for (auto Arg : filtered(Id0, Id1, Id2)) {
Arg->claim();
const auto &Values = Arg->getValues();
Output.append(Values.begin(), Values.end());
}
}
void ArgList::AddAllArgsTranslated(ArgStringList &Output, OptSpecifier Id0,
const char *Translation,
bool Joined) const {
for (auto Arg: filtered(Id0)) {
Arg->claim();
if (Joined) {
Output.push_back(MakeArgString(StringRef(Translation) +
Arg->getValue(0)));
} else {
Output.push_back(Translation);
Output.push_back(Arg->getValue(0));
}
}
}
void ArgList::ClaimAllArgs(OptSpecifier Id0) const {
for (auto *Arg : filtered(Id0))
Arg->claim();
}
void ArgList::ClaimAllArgs() const {
for (auto *Arg : *this)
if (!Arg->isClaimed())
Arg->claim();
}
const char *ArgList::GetOrMakeJoinedArgString(unsigned Index,
StringRef LHS,
StringRef RHS) const {
StringRef Cur = getArgString(Index);
if (Cur.size() == LHS.size() + RHS.size() &&
Cur.startswith(LHS) && Cur.endswith(RHS))
return Cur.data();
return MakeArgString(LHS + RHS);
}
void ArgList::print(raw_ostream &O) const {
for (Arg *A : *this) {
O << "* ";
A->print(O);
}
}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void ArgList::dump() const { print(dbgs()); }
#endif
void InputArgList::releaseMemory() {
// An InputArgList always owns its arguments.
for (Arg *A : *this)
delete A;
}
InputArgList::InputArgList(const char* const *ArgBegin,
const char* const *ArgEnd)
: NumInputArgStrings(ArgEnd - ArgBegin) {
ArgStrings.append(ArgBegin, ArgEnd);
}
unsigned InputArgList::MakeIndex(StringRef String0) const {
unsigned Index = ArgStrings.size();
// Tuck away so we have a reliable const char *.
SynthesizedStrings.push_back(String0);
ArgStrings.push_back(SynthesizedStrings.back().c_str());
return Index;
}
unsigned InputArgList::MakeIndex(StringRef String0,
StringRef String1) const {
unsigned Index0 = MakeIndex(String0);
unsigned Index1 = MakeIndex(String1);
assert(Index0 + 1 == Index1 && "Unexpected non-consecutive indices!");
(void) Index1;
return Index0;
}
const char *InputArgList::MakeArgStringRef(StringRef Str) const {
return getArgString(MakeIndex(Str));
}
DerivedArgList::DerivedArgList(const InputArgList &BaseArgs)
: BaseArgs(BaseArgs) {}
const char *DerivedArgList::MakeArgStringRef(StringRef Str) const {
return BaseArgs.MakeArgString(Str);
}
void DerivedArgList::AddSynthesizedArg(Arg *A) {
SynthesizedArgs.push_back(std::unique_ptr<Arg>(A));
}
Arg *DerivedArgList::MakeFlagArg(const Arg *BaseArg, const Option Opt) const {
SynthesizedArgs.push_back(
make_unique<Arg>(Opt, MakeArgString(Opt.getPrefix() + Opt.getName()),
BaseArgs.MakeIndex(Opt.getName()), BaseArg));
return SynthesizedArgs.back().get();
}
Arg *DerivedArgList::MakePositionalArg(const Arg *BaseArg, const Option Opt,
StringRef Value) const {
unsigned Index = BaseArgs.MakeIndex(Value);
SynthesizedArgs.push_back(
make_unique<Arg>(Opt, MakeArgString(Opt.getPrefix() + Opt.getName()),
Index, BaseArgs.getArgString(Index), BaseArg));
return SynthesizedArgs.back().get();
}
Arg *DerivedArgList::MakeSeparateArg(const Arg *BaseArg, const Option Opt,
StringRef Value) const {
unsigned Index = BaseArgs.MakeIndex(Opt.getName(), Value);
SynthesizedArgs.push_back(
make_unique<Arg>(Opt, MakeArgString(Opt.getPrefix() + Opt.getName()),
Index, BaseArgs.getArgString(Index + 1), BaseArg));
return SynthesizedArgs.back().get();
}
Arg *DerivedArgList::MakeJoinedArg(const Arg *BaseArg, const Option Opt,
StringRef Value) const {
unsigned Index = BaseArgs.MakeIndex((Opt.getName() + Value).str());
SynthesizedArgs.push_back(make_unique<Arg>(
Opt, MakeArgString(Opt.getPrefix() + Opt.getName()), Index,
BaseArgs.getArgString(Index) + Opt.getName().size(), BaseArg));
return SynthesizedArgs.back().get();
}

View File

@ -1,9 +0,0 @@
add_llvm_library(LLVMOption
Arg.cpp
ArgList.cpp
Option.cpp
OptTable.cpp
ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/Option
)

View File

@ -1,22 +0,0 @@
;===- ./lib/Option/LLVMBuild.txt -------------------------------*- Conf -*--===;
;
; The LLVM Compiler Infrastructure
;
; This file is distributed under the University of Illinois Open Source
; License. See LICENSE.TXT for details.
;
;===------------------------------------------------------------------------===;
;
; This is an LLVMBuild description file for the components in this subdirectory.
;
; For more information on the LLVMBuild system, please see:
;
; http://llvm.org/docs/LLVMBuild.html
;
;===------------------------------------------------------------------------===;
[component_0]
type = Library
name = Option
parent = Libraries
required_libraries = Support

File diff suppressed because it is too large Load Diff

View File

@ -1,259 +0,0 @@
//===- Option.cpp - Abstract Driver Options -------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
#include "llvm/Option/OptTable.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <cstring>
using namespace llvm;
using namespace llvm::opt;
Option::Option(const OptTable::Info *info, const OptTable *owner)
: Info(info), Owner(owner) {
// Multi-level aliases are not supported. This just simplifies option
// tracking, it is not an inherent limitation.
assert((!Info || !getAlias().isValid() || !getAlias().getAlias().isValid()) &&
"Multi-level aliases are not supported.");
if (Info && getAliasArgs()) {
assert(getAlias().isValid() && "Only alias options can have alias args.");
assert(getKind() == FlagClass && "Only Flag aliases can have alias args.");
assert(getAlias().getKind() != FlagClass &&
"Cannot provide alias args to a flag option.");
}
}
void Option::print(raw_ostream &O) const {
O << "<";
switch (getKind()) {
#define P(N) case N: O << #N; break
P(GroupClass);
P(InputClass);
P(UnknownClass);
P(FlagClass);
P(JoinedClass);
P(ValuesClass);
P(SeparateClass);
P(CommaJoinedClass);
P(MultiArgClass);
P(JoinedOrSeparateClass);
P(JoinedAndSeparateClass);
P(RemainingArgsClass);
P(RemainingArgsJoinedClass);
#undef P
}
if (Info->Prefixes) {
O << " Prefixes:[";
for (const char *const *Pre = Info->Prefixes; *Pre != nullptr; ++Pre) {
O << '"' << *Pre << (*(Pre + 1) == nullptr ? "\"" : "\", ");
}
O << ']';
}
O << " Name:\"" << getName() << '"';
const Option Group = getGroup();
if (Group.isValid()) {
O << " Group:";
Group.print(O);
}
const Option Alias = getAlias();
if (Alias.isValid()) {
O << " Alias:";
Alias.print(O);
}
if (getKind() == MultiArgClass)
O << " NumArgs:" << getNumArgs();
O << ">\n";
}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void Option::dump() const { print(dbgs()); }
#endif
bool Option::matches(OptSpecifier Opt) const {
// Aliases are never considered in matching, look through them.
const Option Alias = getAlias();
if (Alias.isValid())
return Alias.matches(Opt);
// Check exact match.
if (getID() == Opt.getID())
return true;
const Option Group = getGroup();
if (Group.isValid())
return Group.matches(Opt);
return false;
}
Arg *Option::accept(const ArgList &Args,
unsigned &Index,
unsigned ArgSize) const {
const Option &UnaliasedOption = getUnaliasedOption();
StringRef Spelling;
// If the option was an alias, get the spelling from the unaliased one.
if (getID() == UnaliasedOption.getID()) {
Spelling = StringRef(Args.getArgString(Index), ArgSize);
} else {
Spelling = Args.MakeArgString(Twine(UnaliasedOption.getPrefix()) +
Twine(UnaliasedOption.getName()));
}
switch (getKind()) {
case FlagClass: {
if (ArgSize != strlen(Args.getArgString(Index)))
return nullptr;
Arg *A = new Arg(UnaliasedOption, Spelling, Index++);
if (getAliasArgs()) {
const char *Val = getAliasArgs();
while (*Val != '\0') {
A->getValues().push_back(Val);
// Move past the '\0' to the next argument.
Val += strlen(Val) + 1;
}
}
if (UnaliasedOption.getKind() == JoinedClass && !getAliasArgs())
// A Flag alias for a Joined option must provide an argument.
A->getValues().push_back("");
return A;
}
case JoinedClass: {
const char *Value = Args.getArgString(Index) + ArgSize;
return new Arg(UnaliasedOption, Spelling, Index++, Value);
}
case CommaJoinedClass: {
// Always matches.
const char *Str = Args.getArgString(Index) + ArgSize;
Arg *A = new Arg(UnaliasedOption, Spelling, Index++);
// Parse out the comma separated values.
const char *Prev = Str;
for (;; ++Str) {
char c = *Str;
if (!c || c == ',') {
if (Prev != Str) {
char *Value = new char[Str - Prev + 1];
memcpy(Value, Prev, Str - Prev);
Value[Str - Prev] = '\0';
A->getValues().push_back(Value);
}
if (!c)
break;
Prev = Str + 1;
}
}
A->setOwnsValues(true);
return A;
}
case SeparateClass:
// Matches iff this is an exact match.
// FIXME: Avoid strlen.
if (ArgSize != strlen(Args.getArgString(Index)))
return nullptr;
Index += 2;
if (Index > Args.getNumInputArgStrings() ||
Args.getArgString(Index - 1) == nullptr)
return nullptr;
return new Arg(UnaliasedOption, Spelling,
Index - 2, Args.getArgString(Index - 1));
case MultiArgClass: {
// Matches iff this is an exact match.
// FIXME: Avoid strlen.
if (ArgSize != strlen(Args.getArgString(Index)))
return nullptr;
Index += 1 + getNumArgs();
if (Index > Args.getNumInputArgStrings())
return nullptr;
Arg *A = new Arg(UnaliasedOption, Spelling, Index - 1 - getNumArgs(),
Args.getArgString(Index - getNumArgs()));
for (unsigned i = 1; i != getNumArgs(); ++i)
A->getValues().push_back(Args.getArgString(Index - getNumArgs() + i));
return A;
}
case JoinedOrSeparateClass: {
// If this is not an exact match, it is a joined arg.
// FIXME: Avoid strlen.
if (ArgSize != strlen(Args.getArgString(Index))) {
const char *Value = Args.getArgString(Index) + ArgSize;
return new Arg(*this, Spelling, Index++, Value);
}
// Otherwise it must be separate.
Index += 2;
if (Index > Args.getNumInputArgStrings() ||
Args.getArgString(Index - 1) == nullptr)
return nullptr;
return new Arg(UnaliasedOption, Spelling,
Index - 2, Args.getArgString(Index - 1));
}
case JoinedAndSeparateClass:
// Always matches.
Index += 2;
if (Index > Args.getNumInputArgStrings() ||
Args.getArgString(Index - 1) == nullptr)
return nullptr;
return new Arg(UnaliasedOption, Spelling, Index - 2,
Args.getArgString(Index - 2) + ArgSize,
Args.getArgString(Index - 1));
case RemainingArgsClass: {
// Matches iff this is an exact match.
// FIXME: Avoid strlen.
if (ArgSize != strlen(Args.getArgString(Index)))
return nullptr;
Arg *A = new Arg(UnaliasedOption, Spelling, Index++);
while (Index < Args.getNumInputArgStrings() &&
Args.getArgString(Index) != nullptr)
A->getValues().push_back(Args.getArgString(Index++));
return A;
}
case RemainingArgsJoinedClass: {
Arg *A = new Arg(UnaliasedOption, Spelling, Index);
if (ArgSize != strlen(Args.getArgString(Index))) {
// An inexact match means there is a joined arg.
A->getValues().push_back(Args.getArgString(Index) + ArgSize);
}
Index++;
while (Index < Args.getNumInputArgStrings() &&
Args.getArgString(Index) != nullptr)
A->getValues().push_back(Args.getArgString(Index++));
return A;
}
default:
llvm_unreachable("Invalid option kind!");
}
}