本文整理汇总了C++中llvm::StringRef方法的典型用法代码示例。如果您正苦于以下问题:C++ llvm::StringRef方法的具体用法?C++ llvm::StringRef怎么用?C++ llvm::StringRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类llvm
的用法示例。
在下文中一共展示了llvm::StringRef方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: input
static StringRef input(StringRef scalar, void*, VMProtect &value) {
value = 0;
if (scalar.size() != 3)
return "segment access protection must be three chars (e.g. \"r-x\")";
switch (scalar[0]) {
case 'r':
value = llvm::MachO::VM_PROT_READ;
break;
case '-':
break;
default:
return "segment access protection first char must be 'r' or '-'";
}
switch (scalar[1]) {
case 'w':
value = value | llvm::MachO::VM_PROT_WRITE;
break;
case '-':
break;
default:
return "segment access protection second char must be 'w' or '-'";
}
switch (scalar[2]) {
case 'x':
value = value | llvm::MachO::VM_PROT_EXECUTE;
break;
case '-':
break;
default:
return "segment access protection third char must be 'x' or '-'";
}
// Return the empty string on success,
return StringRef();
}
示例2: addExportInfo
void Util::addExportInfo(const lld::File &atomFile, NormalizedFile &nFile) {
if (_ctx.outputMachOType() == llvm::MachO::MH_OBJECT)
return;
for (SectionInfo *sect : _sectionInfos) {
for (const AtomInfo &info : sect->atomsAndOffsets) {
const DefinedAtom *atom = info.atom;
if (atom->scope() != Atom::scopeGlobal)
continue;
if (_ctx.exportRestrictMode()) {
if (!_ctx.exportSymbolNamed(atom->name()))
continue;
}
Export exprt;
exprt.name = atom->name();
exprt.offset = _atomToAddress[atom] - _ctx.baseAddress();
exprt.kind = EXPORT_SYMBOL_FLAGS_KIND_REGULAR;
if (atom->merge() == DefinedAtom::mergeAsWeak)
exprt.flags = EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION;
else
exprt.flags = 0;
exprt.otherOffset = 0;
exprt.otherName = StringRef();
nFile.exportInfo.push_back(exprt);
}
}
}
示例3: Print
void Command::Print(raw_ostream &OS, const char *Terminator, bool Quote,
CrashReportInfo *CrashInfo) const {
// Always quote the exe.
OS << ' ';
printArg(OS, Executable, /*Quote=*/true);
llvm::ArrayRef<const char *> Args = Arguments;
llvm::SmallVector<const char *, 128> ArgsRespFile;
if (ResponseFile != nullptr) {
buildArgvForResponseFile(ArgsRespFile);
Args = ArrayRef<const char *>(ArgsRespFile).slice(1); // no executable name
}
bool HaveCrashVFS = CrashInfo && !CrashInfo->VFSPath.empty();
for (size_t i = 0, e = Args.size(); i < e; ++i) {
const char *const Arg = Args[i];
if (CrashInfo) {
if (int Skip = skipArgs(Arg, HaveCrashVFS)) {
i += Skip - 1;
continue;
}
auto Found = std::find_if(InputFilenames.begin(), InputFilenames.end(),
[&Arg](StringRef IF) { return IF == Arg; });
if (Found != InputFilenames.end() &&
(i == 0 || StringRef(Args[i - 1]) != "-main-file-name")) {
// Replace the input file name with the crashinfo's file name.
OS << ' ';
StringRef ShortName = llvm::sys::path::filename(CrashInfo->Filename);
printArg(OS, ShortName.str().c_str(), Quote);
continue;
}
}
OS << ' ';
printArg(OS, Arg, Quote);
}
if (CrashInfo && HaveCrashVFS) {
OS << ' ';
printArg(OS, "-ivfsoverlay", Quote);
OS << ' ';
printArg(OS, CrashInfo->VFSPath.str().c_str(), Quote);
}
if (ResponseFile != nullptr) {
OS << "\n Arguments passed via response file:\n";
writeResponseFile(OS);
// Avoiding duplicated newline terminator, since FileLists are
// newline-separated.
if (Creator.getResponseFilesSupport() != Tool::RF_FileList)
OS << "\n";
OS << " (end of response file)";
}
OS << Terminator;
}
示例4: readString
bool readString(RemoteAddress address, std::string &dest) override {
if (!isAddressValid(address, 1))
return false;
// TODO: Account for running off the edge of an object, offset in ELF
// binaries
auto cString = StringRef((const char*)address.getAddressData());
dest.append(cString.begin(), cString.end());
return true;
}
示例5: mapping
static void mapping(IO &io, Export &exp) {
io.mapRequired("name", exp.name);
io.mapOptional("offset", exp.offset);
io.mapOptional("kind", exp.kind,
llvm::MachO::EXPORT_SYMBOL_FLAGS_KIND_REGULAR);
if (!io.outputting() || exp.flags)
io.mapOptional("flags", exp.flags);
io.mapOptional("other", exp.otherOffset, Hex32(0));
io.mapOptional("other-name", exp.otherName, StringRef());
}
示例6: main
int main(int argc, char *argv[]) {
PROGRAM_START(argc, argv);
llvm::cl::ParseCommandLineOptions(argc, argv, "Swift Syntax Test\n");
int ExitCode = EXIT_SUCCESS;
if (options::InputSourceFilename.empty() &&
options::InputSourceDirectory.empty()) {
llvm::errs() << "input source file is required\n";
ExitCode = EXIT_FAILURE;
}
if (!options::InputSourceFilename.empty() &&
!options::InputSourceDirectory.empty()) {
llvm::errs() << "input-source-filename and input-source-directory cannot "
"be used together\n\n";
ExitCode = EXIT_FAILURE;
}
if (options::Action == ActionType::None) {
llvm::errs() << "an action is required\n";
ExitCode = EXIT_FAILURE;
}
if (ExitCode == EXIT_FAILURE) {
llvm::cl::PrintHelpMessage();
return ExitCode;
}
if (!options::InputSourceFilename.empty()) {
ExitCode = invokeCommand(argv[0], options::InputSourceFilename);
} else {
assert(!options::InputSourceDirectory.empty());
std::error_code errorCode;
llvm::sys::fs::recursive_directory_iterator DI(options::InputSourceDirectory, errorCode);
llvm::sys::fs::recursive_directory_iterator endIterator;
for (; DI != endIterator; DI.increment(errorCode)) {
auto entry = *DI;
auto path = entry.path();
if (!llvm::sys::fs::is_directory(path) &&
StringRef(path).endswith(".swift")) {
ExitCode = invokeCommand(argv[0], path);
}
}
}
return ExitCode;
}
示例7: parseArgs
bool TestOptions::parseArgs(llvm::ArrayRef<const char *> Args) {
if (Args.empty())
return false;
// Parse command line options using Options.td
TestOptTable Table;
unsigned MissingIndex;
unsigned MissingCount;
llvm::opt::InputArgList ParsedArgs =
Table.ParseArgs(Args, MissingIndex, MissingCount);
if (MissingCount) {
llvm::errs() << "error: missing argument value for '"
<< ParsedArgs.getArgString(MissingIndex) << "', expected "
<< MissingCount << " argument(s)\n";
return true;
}
for (auto InputArg : ParsedArgs) {
switch (InputArg->getOption().getID()) {
case OPT_req:
Request = llvm::StringSwitch<SourceKitRequest>(InputArg->getValue())
.Case("version", SourceKitRequest::ProtocolVersion)
.Case("demangle", SourceKitRequest::DemangleNames)
.Case("mangle", SourceKitRequest::MangleSimpleClasses)
.Case("index", SourceKitRequest::Index)
.Case("complete", SourceKitRequest::CodeComplete)
.Case("complete.open", SourceKitRequest::CodeCompleteOpen)
.Case("complete.close", SourceKitRequest::CodeCompleteClose)
.Case("complete.update", SourceKitRequest::CodeCompleteUpdate)
.Case("complete.cache.ondisk", SourceKitRequest::CodeCompleteCacheOnDisk)
.Case("complete.setpopularapi", SourceKitRequest::CodeCompleteSetPopularAPI)
.Case("cursor", SourceKitRequest::CursorInfo)
.Case("related-idents", SourceKitRequest::RelatedIdents)
.Case("syntax-map", SourceKitRequest::SyntaxMap)
.Case("structure", SourceKitRequest::Structure)
.Case("format", SourceKitRequest::Format)
.Case("expand-placeholder", SourceKitRequest::ExpandPlaceholder)
.Case("doc-info", SourceKitRequest::DocInfo)
.Case("sema", SourceKitRequest::SemanticInfo)
.Case("interface-gen", SourceKitRequest::InterfaceGen)
.Case("interface-gen-open", SourceKitRequest::InterfaceGenOpen)
.Case("find-usr", SourceKitRequest::FindUSR)
.Case("find-interface", SourceKitRequest::FindInterfaceDoc)
.Case("open", SourceKitRequest::Open)
.Case("edit", SourceKitRequest::Edit)
.Case("print-annotations", SourceKitRequest::PrintAnnotations)
.Case("print-diags", SourceKitRequest::PrintDiags)
.Case("extract-comment", SourceKitRequest::ExtractComment)
.Case("module-groups", SourceKitRequest::ModuleGroups)
.Default(SourceKitRequest::None);
if (Request == SourceKitRequest::None) {
llvm::errs() << "error: invalid request, expected one of "
<< "version/demangle/mangle/index/complete/cursor/related-idents/syntax-map/structure/"
"format/expand-placeholder/doc-info/sema/interface-gen/interface-gen-open/"
"find-usr/find-interface/open/edit/print-annotations/extract-comment/"
"module-groups\n";
return true;
}
break;
case OPT_offset:
if (StringRef(InputArg->getValue()).getAsInteger(10, Offset)) {
llvm::errs() << "error: expected integer for 'offset'\n";
return true;
}
break;
case OPT_length:
if (StringRef(InputArg->getValue()).getAsInteger(10, Length)) {
llvm::errs() << "error: expected integer for 'length'\n";
return true;
}
break;
case OPT_pos: {
auto linecol = parseLineCol(InputArg->getValue());
Line = linecol.first;
Col = linecol.second;
break;
}
case OPT_line:
if (StringRef(InputArg->getValue()).getAsInteger(10, Line)) {
llvm::errs() << "error: expected integer for 'line'\n";
return true;
}
Col = 1;
break;
case OPT_replace:
ReplaceText = InputArg->getValue();
break;
case OPT_module:
ModuleName = InputArg->getValue();
break;
case OPT_group_name:
ModuleGroupName = InputArg->getValue();
break;
//.........这里部分代码省略.........
示例8: doDumpReflectionSections
static int doDumpReflectionSections(ArrayRef<std::string> binaryFilenames,
StringRef arch,
ActionType action,
std::ostream &OS) {
// Note: binaryOrError and objectOrError own the memory for our ObjectFile;
// once they go out of scope, we can no longer do anything.
std::vector<OwningBinary<Binary>> binaryOwners;
std::vector<std::unique_ptr<ObjectFile>> objectOwners;
// Construct the TypeRefBuilder
TypeRefBuilder builder;
for (auto binaryFilename : binaryFilenames) {
auto binaryOwner = unwrap(createBinary(binaryFilename));
Binary *binaryFile = binaryOwner.getBinary();
// The object file we are doing lookups in -- either the binary itself, or
// a particular slice of a universal binary.
std::unique_ptr<ObjectFile> objectOwner;
const ObjectFile *objectFile;
if (auto o = dyn_cast<ObjectFile>(binaryFile)) {
objectFile = o;
} else {
auto universal = cast<MachOUniversalBinary>(binaryFile);
objectOwner = unwrap(universal->getObjectForArch(arch));
objectFile = objectOwner.get();
}
builder.addReflectionInfo(findReflectionInfo(objectFile));
// Retain the objects that own section memory
binaryOwners.push_back(std::move(binaryOwner));
objectOwners.push_back(std::move(objectOwner));
}
switch (action) {
case ActionType::DumpReflectionSections:
// Dump everything
builder.dumpAllSections(OS);
break;
case ActionType::DumpTypeLowering: {
for (std::string line; std::getline(std::cin, line); ) {
if (line.empty())
continue;
if (StringRef(line).startswith("//"))
continue;
Demangle::Demangler Dem;
auto demangled = Dem.demangleType(line);
auto *typeRef = swift::remote::decodeMangledType(builder, demangled);
if (typeRef == nullptr) {
OS << "Invalid typeref: " << line << "\n";
continue;
}
typeRef->dump(OS);
auto *typeInfo = builder.getTypeConverter().getTypeInfo(typeRef);
if (typeInfo == nullptr) {
OS << "Invalid lowering\n";
continue;
}
typeInfo->dump(OS);
}
break;
}
}
return EXIT_SUCCESS;
}
示例9: parseArgs
bool TestOptions::parseArgs(llvm::ArrayRef<const char *> Args) {
if (Args.empty())
return false;
// Parse command line options using Options.td
TestOptTable Table;
unsigned MissingIndex;
unsigned MissingCount;
llvm::opt::InputArgList ParsedArgs =
Table.ParseArgs(Args, MissingIndex, MissingCount);
if (MissingCount) {
llvm::errs() << "error: missing argument value for '"
<< ParsedArgs.getArgString(MissingIndex) << "', expected "
<< MissingCount << " argument(s)\n";
return true;
}
for (auto InputArg : ParsedArgs) {
switch (InputArg->getOption().getID()) {
case OPT_req:
Request = llvm::StringSwitch<SourceKitRequest>(InputArg->getValue())
.Case("version", SourceKitRequest::ProtocolVersion)
.Case("demangle", SourceKitRequest::DemangleNames)
.Case("mangle", SourceKitRequest::MangleSimpleClasses)
.Case("index", SourceKitRequest::Index)
.Case("complete", SourceKitRequest::CodeComplete)
.Case("complete.open", SourceKitRequest::CodeCompleteOpen)
.Case("complete.close", SourceKitRequest::CodeCompleteClose)
.Case("complete.update", SourceKitRequest::CodeCompleteUpdate)
.Case("complete.cache.ondisk", SourceKitRequest::CodeCompleteCacheOnDisk)
.Case("complete.setpopularapi", SourceKitRequest::CodeCompleteSetPopularAPI)
.Case("cursor", SourceKitRequest::CursorInfo)
.Case("related-idents", SourceKitRequest::RelatedIdents)
.Case("syntax-map", SourceKitRequest::SyntaxMap)
.Case("syntax-tree", SourceKitRequest::SyntaxTree)
.Case("structure", SourceKitRequest::Structure)
.Case("format", SourceKitRequest::Format)
.Case("expand-placeholder", SourceKitRequest::ExpandPlaceholder)
.Case("doc-info", SourceKitRequest::DocInfo)
.Case("sema", SourceKitRequest::SemanticInfo)
.Case("interface-gen", SourceKitRequest::InterfaceGen)
.Case("interface-gen-open", SourceKitRequest::InterfaceGenOpen)
.Case("find-usr", SourceKitRequest::FindUSR)
.Case("find-interface", SourceKitRequest::FindInterfaceDoc)
.Case("open", SourceKitRequest::Open)
.Case("close", SourceKitRequest::Close)
.Case("edit", SourceKitRequest::Edit)
.Case("print-annotations", SourceKitRequest::PrintAnnotations)
.Case("print-diags", SourceKitRequest::PrintDiags)
.Case("extract-comment", SourceKitRequest::ExtractComment)
.Case("module-groups", SourceKitRequest::ModuleGroups)
.Case("range", SourceKitRequest::RangeInfo)
.Case("syntactic-rename", SourceKitRequest::SyntacticRename)
.Case("find-rename-ranges", SourceKitRequest::FindRenameRanges)
.Case("find-local-rename-ranges", SourceKitRequest::FindLocalRenameRanges)
.Case("translate", SourceKitRequest::NameTranslation)
.Case("local-rename", SourceKitRequest::LocalRename)
.Case("extract-expr", SourceKitRequest::ExtractExpr)
.Case("extract-repeated", SourceKitRequest::ExtractRepeatedExpr)
.Case("extract-func", SourceKitRequest::ExtractFunction)
.Case("fill-stub", SourceKitRequest::FillProtocolStub)
.Case("expand-default", SourceKitRequest::ExpandDefault)
.Case("localize-string", SourceKitRequest::LocalizeString)
.Case("markup-xml", SourceKitRequest::MarkupToXML)
.Case("stats", SourceKitRequest::Statistics)
.Case("track-compiles", SourceKitRequest::EnableCompileNotifications)
.Default(SourceKitRequest::None);
if (Request == SourceKitRequest::None) {
llvm::errs() << "error: invalid request '" << InputArg->getValue()
<< "'\nexpected one of "
<< "version/demangle/mangle/index/complete/complete.open/complete.cursor/"
"complete.update/complete.cache.ondisk/complete.cache.setpopularapi/"
"cursor/related-idents/syntax-map/structure/format/expand-placeholder/"
"doc-info/sema/interface-gen/interface-gen-openfind-usr/find-interface/"
"open/close/edit/print-annotations/print-diags/extract-comment/module-groups/"
"range/syntactic-rename/find-rename-ranges/translate/markup-xml/stats/"
"track-compiles\n";
return true;
}
break;
case OPT_help: {
printHelp(false);
return true;
}
case OPT_offset:
if (StringRef(InputArg->getValue()).getAsInteger(10, Offset)) {
llvm::errs() << "error: expected integer for 'offset'\n";
return true;
}
break;
case OPT_length:
if (StringRef(InputArg->getValue()).getAsInteger(10, Length)) {
llvm::errs() << "error: expected integer for 'length'\n";
return true;
}
break;
//.........这里部分代码省略.........