本文整理汇总了C++中StringRef::compare方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRef::compare方法的具体用法?C++ StringRef::compare怎么用?C++ StringRef::compare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringRef
的用法示例。
在下文中一共展示了StringRef::compare方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mergeInstrProfile
static void mergeInstrProfile(const cl::list<std::string> &Inputs,
StringRef OutputFilename) {
if (OutputFilename.compare("-") == 0)
exitWithError("Cannot write indexed profdata format to stdout.");
std::error_code EC;
raw_fd_ostream Output(OutputFilename.data(), EC, sys::fs::F_None);
if (EC)
exitWithError(EC.message(), OutputFilename);
InstrProfWriter Writer;
for (const auto &Filename : Inputs) {
auto ReaderOrErr = InstrProfReader::create(Filename);
if (std::error_code ec = ReaderOrErr.getError())
exitWithError(ec.message(), Filename);
auto Reader = std::move(ReaderOrErr.get());
for (auto &I : *Reader)
if (std::error_code EC = Writer.addRecord(std::move(I)))
errs() << Filename << ": " << I.Name << ": " << EC.message() << "\n";
if (Reader->hasError())
exitWithError(Reader->getError().message(), Filename);
}
Writer.write(Output);
}
示例2: cmpMem
int FunctionComparator::cmpMem(StringRef L, StringRef R) const {
// Prevent heavy comparison, compare sizes first.
if (int Res = cmpNumbers(L.size(), R.size()))
return Res;
// Compare strings lexicographically only when it is necessary: only when
// strings are equal in size.
return L.compare(R);
}
示例3: getOrderedName
bool clang::operator<(const CodeCompletionResult &X,
const CodeCompletionResult &Y) {
std::string XSaved, YSaved;
StringRef XStr = getOrderedName(X, XSaved);
StringRef YStr = getOrderedName(Y, YSaved);
int cmp = XStr.compare_lower(YStr);
if (cmp)
return cmp < 0;
// If case-insensitive comparison fails, try case-sensitive comparison.
cmp = XStr.compare(YStr);
if (cmp)
return cmp < 0;
return false;
}
示例4: mergeInstrProfile
static void mergeInstrProfile(const WeightedFileVector &Inputs,
StringRef OutputFilename,
ProfileFormat OutputFormat, bool OutputSparse) {
if (OutputFilename.compare("-") == 0)
exitWithError("Cannot write indexed profdata format to stdout.");
if (OutputFormat != PF_Binary && OutputFormat != PF_Text)
exitWithError("Unknown format is specified.");
std::error_code EC;
raw_fd_ostream Output(OutputFilename.data(), EC, sys::fs::F_None);
if (EC)
exitWithErrorCode(EC, OutputFilename);
InstrProfWriter Writer(OutputSparse);
SmallSet<instrprof_error, 4> WriterErrorCodes;
for (const auto &Input : Inputs) {
auto ReaderOrErr = InstrProfReader::create(Input.Filename);
if (Error E = ReaderOrErr.takeError())
exitWithError(std::move(E), Input.Filename);
auto Reader = std::move(ReaderOrErr.get());
bool IsIRProfile = Reader->isIRLevelProfile();
if (Writer.setIsIRLevelProfile(IsIRProfile))
exitWithError("Merge IR generated profile with Clang generated profile.");
for (auto &I : *Reader) {
if (Error E = Writer.addRecord(std::move(I), Input.Weight)) {
// Only show hint the first time an error occurs.
instrprof_error IPE = InstrProfError::take(std::move(E));
bool firstTime = WriterErrorCodes.insert(IPE).second;
handleMergeWriterError(make_error<InstrProfError>(IPE), Input.Filename,
I.Name, firstTime);
}
}
if (Reader->hasError())
exitWithError(Reader->getError(), Input.Filename);
}
if (OutputFormat == PF_Text)
Writer.writeText(Output);
else
Writer.write(Output);
}
示例5: recordRelocations
void ObjectLoadListener::recordRelocations(
const ObjectFile &Obj, const RuntimeDyld::LoadedObjectInfo &L) {
for (section_iterator SI = Obj.section_begin(), SE = Obj.section_end();
SI != SE; ++SI) {
section_iterator Section = SI->getRelocatedSection();
if (Section == SE) {
continue;
}
StringRef SectionName;
std::error_code ErrorCode = Section->getName(SectionName);
if (ErrorCode) {
assert(false && ErrorCode.message().c_str());
}
if (SectionName.startswith(".debug") ||
SectionName.startswith(".rela.debug") ||
!SectionName.compare(".pdata") || SectionName.startswith(".eh_frame") ||
SectionName.startswith(".rela.eh_frame")) {
// Skip sections whose contents are not directly reported to the EE
continue;
}
relocation_iterator I = SI->relocation_begin();
relocation_iterator E = SI->relocation_end();
for (; I != E; ++I) {
symbol_iterator Symbol = I->getSymbol();
assert(Symbol != Obj.symbol_end());
ErrorOr<section_iterator> SymbolSectionOrErr = Symbol->getSection();
assert(!SymbolSectionOrErr.getError());
object::section_iterator SymbolSection = *SymbolSectionOrErr;
const bool IsExtern = SymbolSection == Obj.section_end();
uint64_t RelType = I->getType();
uint64_t Offset = I->getOffset();
uint8_t *RelocationTarget;
if (IsExtern) {
// This is an external symbol. Verify that it's one we created for
// a global variable and report the relocation via Jit interface.
ErrorOr<StringRef> NameOrError = Symbol->getName();
assert(NameOrError);
StringRef TargetName = NameOrError.get();
auto MapIter = Context->NameToHandleMap.find(TargetName);
if (MapIter == Context->NameToHandleMap.end()) {
// The xdata gets a pointer to our personality routine, which we
// dummied up. We can safely skip it since the EE isn't actually
// going to use the value (it inserts the correct one before handing
// the xdata off to the OS).
assert(!TargetName.compare("ProcessCLRException"));
assert(SectionName.startswith(".xdata"));
continue;
} else {
assert(MapIter->second == Context->NameToHandleMap[TargetName]);
RelocationTarget = (uint8_t *)MapIter->second;
}
} else {
RelocationTarget = (uint8_t *)(L.getSectionLoadAddress(*SymbolSection) +
Symbol->getValue());
}
uint64_t Addend = 0;
uint64_t EERelType = getRelocationType(RelType);
uint64_t SectionAddress = L.getSectionLoadAddress(*Section);
assert(SectionAddress != 0);
uint8_t *FixupAddress = (uint8_t *)(SectionAddress + Offset);
if (Obj.isELF()) {
// Addend is part of the relocation
ELFRelocationRef ElfReloc(*I);
ErrorOr<uint64_t> ElfAddend = ElfReloc.getAddend();
assert(!ElfAddend.getError());
Addend = ElfAddend.get();
} else {
// Addend is read from the location to be fixed up
Addend = getRelocationAddend(RelType, FixupAddress);
}
Context->JitInfo->recordRelocation(FixupAddress,
RelocationTarget + Addend, EERelType);
}
}
}
示例6: DisassembleInputMachO
//.........这里部分代码省略.........
// Find the named debug info sections.
for (unsigned SectIdx = 0; SectIdx != DebugSections.size(); SectIdx++) {
StringRef SectName;
if (!DebugSections[SectIdx].getName(SectName)) {
if (SectName.equals("__DWARF,__debug_abbrev"))
DebugSections[SectIdx].getContents(DebugAbbrevSection);
else if (SectName.equals("__DWARF,__debug_info"))
DebugSections[SectIdx].getContents(DebugInfoSection);
else if (SectName.equals("__DWARF,__debug_aranges"))
DebugSections[SectIdx].getContents(DebugArangesSection);
else if (SectName.equals("__DWARF,__debug_line"))
DebugSections[SectIdx].getContents(DebugLineSection);
else if (SectName.equals("__DWARF,__debug_str"))
DebugSections[SectIdx].getContents(DebugStrSection);
}
}
// Setup the DIContext.
diContext.reset(DIContext::getDWARFContext(DbgInfoObj->isLittleEndian(),
DebugInfoSection,
DebugAbbrevSection,
DebugArangesSection,
DebugLineSection,
DebugStrSection));
}
FunctionMapTy FunctionMap;
FunctionListTy Functions;
for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) {
StringRef SectName;
if (Sections[SectIdx].getName(SectName) ||
SectName.compare("__TEXT,__text"))
continue; // Skip non-text sections
// Insert the functions from the function starts segment into our map.
uint64_t VMAddr;
Sections[SectIdx].getAddress(VMAddr);
for (unsigned i = 0, e = FoundFns.size(); i != e; ++i) {
StringRef SectBegin;
Sections[SectIdx].getContents(SectBegin);
uint64_t Offset = (uint64_t)SectBegin.data();
FunctionMap.insert(std::make_pair(VMAddr + FoundFns[i]-Offset,
(MCFunction*)0));
}
StringRef Bytes;
Sections[SectIdx].getContents(Bytes);
StringRefMemoryObject memoryObject(Bytes);
bool symbolTableWorked = false;
// Parse relocations.
std::vector<std::pair<uint64_t, SymbolRef> > Relocs;
error_code ec;
for (relocation_iterator RI = Sections[SectIdx].begin_relocations(),
RE = Sections[SectIdx].end_relocations(); RI != RE; RI.increment(ec)) {
uint64_t RelocOffset, SectionAddress;
RI->getAddress(RelocOffset);
Sections[SectIdx].getAddress(SectionAddress);
RelocOffset -= SectionAddress;
SymbolRef RelocSym;
RI->getSymbol(RelocSym);
Relocs.push_back(std::make_pair(RelocOffset, RelocSym));
示例7: main
int main(int argc, char **argv){
// Load the bitcode
cl::ParseCommandLineOptions(argc, argv, "helper_call_modifier\n");
SMDiagnostic Err;
LLVMContext &Context = getGlobalContext();
Module *Mod = ParseIRFile(InputFile, Err, Context);
if (!Mod) {
Err.print(argv[0], errs());
exit(1);
}
/*
* This iterates through the list of functions, copies/renames, and deletes
* the original function. This is how we have to do it with the while loop
* because of how the LLVM function list is implemented.
*/
Module::iterator i = Mod->begin();
while (i != Mod->end()){
Function *f = i;
i++;
Module *m = f->getParent();
assert(m);
if (!f->isDeclaration()){ // internal functions only
StringRef fname = f->getName();
if (!fname.compare("__ldb_mmu")
|| !fname.compare("__ldw_mmu")
|| !fname.compare("__ldl_mmu")
|| !fname.compare("__ldq_mmu")
|| !fname.compare("__stb_mmu")
|| !fname.compare("__stw_mmu")
|| !fname.compare("__stl_mmu")
|| !fname.compare("__stq_mmu")){
/* Replace LLVM memory functions with ASM panda (logging) memory
* functions and delete original. For example, we want to call
* out of the LLVM module to __ldb_mmu_panda().
*/
Function *pandaFunc =
m->getFunction(StringRef(f->getName().str() + "_panda"));
assert(pandaFunc);
if (!pandaFunc->isDeclaration()){
pandaFunc->deleteBody();
}
f->replaceAllUsesWith(pandaFunc);
f->eraseFromParent();
}
else if (!fname.compare("slow_ldb_mmu")
|| !fname.compare("slow_ldw_mmu")
|| !fname.compare("slow_ldl_mmu")
|| !fname.compare("slow_ldq_mmu")
|| !fname.compare("slow_stb_mmu")
|| !fname.compare("slow_stw_mmu")
|| !fname.compare("slow_stl_mmu")
|| !fname.compare("slow_stq_mmu")
|| !fname.compare("slow_ldb_mmu_panda")
|| !fname.compare("slow_ldw_mmu_panda")
|| !fname.compare("slow_ldl_mmu_panda")
|| !fname.compare("slow_ldq_mmu_panda")
|| !fname.compare("slow_stb_mmu_panda")
|| !fname.compare("slow_stw_mmu_panda")
|| !fname.compare("slow_stl_mmu_panda")
|| !fname.compare("slow_stq_mmu_panda")){
/* These functions are just artifacts, and are only contained
* within the previous functions. We want these deleted from
* the LLVM module too, this is just kind of a hacky way to make
* sure the functions are deleted in the right order without
* making LLVM angry.
*/
if (f->hasNUsesOrMore(3)){
m->getFunctionList().remove(f);
m->getFunctionList().push_back(f);
continue;
}
else {
f->eraseFromParent();
}
}
else {
ValueToValueMapTy VMap;
Function *newFunc = CloneFunction(f, VMap, false);
std::string origName = f->getName();
std::string newName = origName.append("_llvm");
newFunc->setName(newName);
/*
* XXX: We need to remove stack smash protection from helper
* functions that are to be compiled with the JIT. There is a bug
* in LLVM 3.0 that causes the JIT to generate stack protection code
* that causes the program to segfault. More information available
* here: http://llvm.org/bugs/show_bug.cgi?id=11089
*/
const AttributeSet AS = newFunc->getAttributes();
newFunc->setAttributes(AS.removeAttribute(newFunc->getContext(),
AttributeSet::FunctionIndex, Attribute::StackProtectReq));
// push to the front so the iterator doesn't see them again
m->getFunctionList().push_front(newFunc);
f->replaceAllUsesWith(newFunc);
f->eraseFromParent();
}
//.........这里部分代码省略.........
示例8:
bool operator>=(const StringRef strRef, const char* cstr) {
return strRef.compare(StringRef(cstr)) >= 0;
}
示例9: getNextToken
int SSPParser::getNextToken(void *Val) {
YYSTYPE *Value = static_cast<YYSTYPE*>(Val);
StringRef BufferData = Buf->getBuffer();
const char *Data = BufferData.data();
const char* CurCh = Data+CurPos;
while (CurPos < BufferData.size() &&
(*CurCh == '\t' || *CurCh == ' ' || *CurCh == '\r' ||
*CurCh == '\n')) {
CurPos++;
CurCh = Data+CurPos;
}
if (CurPos >= BufferData.size())
return 0; // EOF
if (*CurCh == '+') {
CurPos++;
return PLUS;
} else if (*CurCh == '-') {
CurPos++;
return MINUS;
} else if (*CurCh == '*') {
CurPos++;
return ASTERISK;
} else if (*CurCh == '/') {
CurPos++;
return SLASH;
} else if (*CurCh == '$') {
CurPos++;
return DOLLAR;
} else if (*CurCh == '@') {
CurPos++;
return AT;
} else if (IsAlpha(*CurCh)) {
const char *Start = CurCh;
size_t Length = 0;
do {
Length++;
CurPos++;
CurCh = Data+CurPos;
} while (CurPos < BufferData.size() && (IsAlphaOrDigit(*CurCh) || *CurCh == '_'));
StringRef *Str = new StringRef(Start, Length);
// Check for keywords
if (Str->compare("double") == 0) {
return DOUBLE;
} else if (Str->compare("field") == 0) {
return FIELD;
} else if (Str->compare("float") == 0) {
return FLOAT;
} else if (Str->compare("grid") == 0) {
return GRID;
} else if (Str->compare("in") == 0) {
return IN;
} else if (Str->compare("inout") == 0) {
return INOUT;
} else if (Str->compare("is") == 0) {
return IS;
} else if (Str->compare("let") == 0) {
return LET;
} else if (Str->compare("out") == 0) {
return OUT;
} else if (Str->compare("param") == 0) {
return PARAM;
} else if (Str->compare("program") == 0) {
return PROGRAM;
}
// Not a keyword
InternedStrings.push_back(Str);
Value->Ident = Str;
return IDENT;
} else if (IsDigit(*CurCh)) {
const char *Start = CurCh;
size_t Length = 0;
bool IsFloat = false;
do {
if (*CurCh == '.') IsFloat = true;
Length++;
CurPos++;
CurCh = Data+CurPos;
} while (CurPos < BufferData.size() && (IsDigit(*CurCh) || *CurCh == '.'));
if (CurPos < BufferData.size() && (*CurCh == 'e' || *CurCh == 'E')) {
// Start of an exponent
IsFloat = true;
CurPos++;
CurCh = Data+CurPos;
Length++;
//.........这里部分代码省略.........
示例10: mergeInstrProfile
static void mergeInstrProfile(const WeightedFileVector &Inputs,
StringRef OutputFilename,
ProfileFormat OutputFormat, bool OutputSparse,
unsigned NumThreads) {
if (OutputFilename.compare("-") == 0)
exitWithError("Cannot write indexed profdata format to stdout.");
if (OutputFormat != PF_Binary && OutputFormat != PF_Text)
exitWithError("Unknown format is specified.");
std::error_code EC;
raw_fd_ostream Output(OutputFilename.data(), EC, sys::fs::F_None);
if (EC)
exitWithErrorCode(EC, OutputFilename);
std::mutex ErrorLock;
SmallSet<instrprof_error, 4> WriterErrorCodes;
// If NumThreads is not specified, auto-detect a good default.
if (NumThreads == 0)
NumThreads = std::max(1U, std::min(std::thread::hardware_concurrency(),
unsigned(Inputs.size() / 2)));
// Initialize the writer contexts.
SmallVector<std::unique_ptr<WriterContext>, 4> Contexts;
for (unsigned I = 0; I < NumThreads; ++I)
Contexts.emplace_back(llvm::make_unique<WriterContext>(
OutputSparse, ErrorLock, WriterErrorCodes));
if (NumThreads == 1) {
for (const auto &Input : Inputs)
loadInput(Input, Contexts[0].get());
} else {
ThreadPool Pool(NumThreads);
// Load the inputs in parallel (N/NumThreads serial steps).
unsigned Ctx = 0;
for (const auto &Input : Inputs) {
Pool.async(loadInput, Input, Contexts[Ctx].get());
Ctx = (Ctx + 1) % NumThreads;
}
Pool.wait();
// Merge the writer contexts together (~ lg(NumThreads) serial steps).
unsigned Mid = Contexts.size() / 2;
unsigned End = Contexts.size();
assert(Mid > 0 && "Expected more than one context");
do {
for (unsigned I = 0; I < Mid; ++I)
Pool.async(mergeWriterContexts, Contexts[I].get(),
Contexts[I + Mid].get());
Pool.wait();
if (End & 1) {
Pool.async(mergeWriterContexts, Contexts[0].get(),
Contexts[End - 1].get());
Pool.wait();
}
End = Mid;
Mid /= 2;
} while (Mid > 0);
}
// Handle deferred hard errors encountered during merging.
for (std::unique_ptr<WriterContext> &WC : Contexts)
if (WC->Err)
exitWithError(std::move(WC->Err), WC->ErrWhence);
InstrProfWriter &Writer = Contexts[0]->Writer;
if (OutputFormat == PF_Text)
Writer.writeText(Output);
else
Writer.write(Output);
}
示例11: RegularCommentPrinter
//.........这里部分代码省略.........
// If group name is given and the decl does not belong to the group, skip it.
if (GroupName && (!D->getGroupName() ||
D->getGroupName().getValue() != GroupName.getValue()))
continue;
// Add Swift decls if we are printing the top-level module.
SwiftDecls.push_back(D);
}
}
// Create the missing import decls and add to the collector.
for (auto *SM : NoImportSubModules) {
ImportDecls.push_back(createImportDecl(M->getASTContext(), M, SM, {}));
}
auto &ClangSourceManager = Importer.getClangASTContext().getSourceManager();
// Sort imported declarations in source order *within a submodule*.
for (auto &P : ClangDecls) {
std::sort(P.second.begin(), P.second.end(),
[&](std::pair<Decl *, clang::SourceLocation> LHS,
std::pair<Decl *, clang::SourceLocation> RHS) -> bool {
return ClangSourceManager.isBeforeInTranslationUnit(LHS.second,
RHS.second);
});
}
// Sort Swift declarations so that we print them in a consistent order.
std::sort(ImportDecls.begin(), ImportDecls.end(),
[](ImportDecl *LHS, ImportDecl *RHS) -> bool {
auto LHSPath = LHS->getFullAccessPath();
auto RHSPath = RHS->getFullAccessPath();
for (unsigned i = 0, e = std::min(LHSPath.size(), RHSPath.size()); i != e;
i++) {
if (int Ret = LHSPath[i].first.str().compare(RHSPath[i].first.str()))
return Ret < 0;
}
return false;
});
// If the group name is specified, we sort them according to their source order,
// which is the order preserved by getTopLeveDecls.
if (!GroupName) {
std::sort(SwiftDecls.begin(), SwiftDecls.end(),
[&](Decl *LHS, Decl *RHS) -> bool {
auto *LHSValue = dyn_cast<ValueDecl>(LHS);
auto *RHSValue = dyn_cast<ValueDecl>(RHS);
if (LHSValue && RHSValue) {
StringRef LHSName = LHSValue->getName().str();
StringRef RHSName = RHSValue->getName().str();
if (int Ret = LHSName.compare(RHSName))
return Ret < 0;
// FIXME: this is not sufficient to establish a total order for overloaded
// decls.
return LHS->getKind() < RHS->getKind();
}
return LHS->getKind() < RHS->getKind();
});
}
ASTPrinter *PrinterToUse = &Printer;
ClangCommentPrinter RegularCommentPrinter(Printer, Importer);
if (Options.PrintRegularClangComments)
PrinterToUse = &RegularCommentPrinter;
示例12: recordRelocations
void ObjectLoadListener::recordRelocations(
const ObjectFile &Obj, const RuntimeDyld::LoadedObjectInfo &L) {
for (section_iterator SI = Obj.section_begin(), SE = Obj.section_end();
SI != SE; ++SI) {
section_iterator Section = SI->getRelocatedSection();
if (Section == SE) {
continue;
}
StringRef SectionName;
std::error_code ErrorCode = Section->getName(SectionName);
if (ErrorCode) {
assert(false && ErrorCode.message().c_str());
}
if (SectionName.startswith(".debug") ||
SectionName.startswith(".rela.debug") ||
!SectionName.compare(".pdata") || SectionName.startswith(".eh_frame") ||
SectionName.startswith(".rela.eh_frame")) {
// Skip sections whose contents are not directly reported to the EE
continue;
}
relocation_iterator I = SI->relocation_begin();
relocation_iterator E = SI->relocation_end();
for (; I != E; ++I) {
symbol_iterator Symbol = I->getSymbol();
assert(Symbol != Obj.symbol_end());
ErrorOr<section_iterator> SymbolSectionOrErr = Symbol->getSection();
assert(!SymbolSectionOrErr.getError());
object::section_iterator SymbolSection = *SymbolSectionOrErr;
const bool IsExtern = SymbolSection == Obj.section_end();
uint64_t RelType = I->getType();
uint64_t Offset = I->getOffset();
uint8_t *RelocationTarget = nullptr;
if (IsExtern) {
// This is an external symbol. Verify that it's one we created for
// a global variable and report the relocation via Jit interface.
ErrorOr<StringRef> NameOrError = Symbol->getName();
assert(NameOrError);
StringRef TargetName = NameOrError.get();
assert(Context->NameToHandleMap.count(TargetName) == 1);
RelocationTarget = (uint8_t *)Context->NameToHandleMap[TargetName];
} else {
RelocationTarget = (uint8_t *)(L.getSectionLoadAddress(*SymbolSection) +
Symbol->getValue());
}
uint64_t Addend = 0;
uint64_t EERelType = getRelocationType(RelType);
uint64_t SectionAddress = L.getSectionLoadAddress(*Section);
assert(SectionAddress != 0);
uint8_t *FixupAddress = (uint8_t *)(SectionAddress + Offset);
if (Obj.isELF()) {
// Addend is part of the relocation
ELFRelocationRef ElfReloc(*I);
ErrorOr<uint64_t> ElfAddend = ElfReloc.getAddend();
assert(!ElfAddend.getError());
Addend = ElfAddend.get();
} else {
// Addend is read from the location to be fixed up
Addend = getRelocationAddend(RelType, FixupAddress);
}
Context->JitInfo->recordRelocation(FixupAddress,
RelocationTarget + Addend, EERelType);
}
}
}
示例13: ends_with
inline bool ends_with(const StringRef& input, const StringRef& target) {
return input.length() >= target.length() &&
input.compare(input.length() - target.length(), target.length(), target) == 0;
}