本文整理汇总了C++中StringRef类的典型用法代码示例。如果您正苦于以下问题:C++ StringRef类的具体用法?C++ StringRef怎么用?C++ StringRef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringRef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runOnFunction
bool WinEHStatePass::runOnFunction(Function &F) {
// If this is an outlined handler, don't do anything. We'll do state insertion
// for it in the parent.
StringRef WinEHParentName =
F.getFnAttribute("wineh-parent").getValueAsString();
if (WinEHParentName != F.getName() && !WinEHParentName.empty())
return false;
// Check the personality. Do nothing if this is not an MSVC personality.
if (!F.hasPersonalityFn())
return false;
PersonalityFn =
dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts());
if (!PersonalityFn)
return false;
Personality = classifyEHPersonality(PersonalityFn);
if (!isMSVCEHPersonality(Personality))
return false;
// Skip this function if there are no EH pads and we aren't using IR-level
// outlining.
if (WinEHParentName.empty()) {
bool HasPads = false;
for (BasicBlock &BB : F) {
if (BB.isEHPad()) {
HasPads = true;
break;
}
}
if (!HasPads)
return false;
}
// Disable frame pointer elimination in this function.
// FIXME: Do the nested handlers need to keep the parent ebp in ebp, or can we
// use an arbitrary register?
F.addFnAttr("no-frame-pointer-elim", "true");
emitExceptionRegistrationRecord(&F);
auto *MMI = getAnalysisIfAvailable<MachineModuleInfo>();
// If MMI is null, create our own WinEHFuncInfo. This only happens in opt
// tests.
std::unique_ptr<WinEHFuncInfo> FuncInfoPtr;
if (!MMI)
FuncInfoPtr.reset(new WinEHFuncInfo());
WinEHFuncInfo &FuncInfo =
*(MMI ? &MMI->getWinEHFuncInfo(&F) : FuncInfoPtr.get());
FuncInfo.EHRegNode = RegNode;
switch (Personality) {
default: llvm_unreachable("unexpected personality function");
case EHPersonality::MSVC_CXX:
addCXXStateStores(F, FuncInfo);
break;
case EHPersonality::MSVC_X86SEH:
addSEHStateStores(F, FuncInfo);
break;
}
// Reset per-function state.
PersonalityFn = nullptr;
Personality = EHPersonality::Unknown;
return true;
}
示例2: performLLVM
/// Run the LLVM passes. In multi-threaded compilation this will be done for
/// multiple LLVM modules in parallel.
static bool performLLVM(IRGenOptions &Opts, DiagnosticEngine &Diags,
llvm::sys::Mutex *DiagMutex,
llvm::Module *Module,
llvm::TargetMachine *TargetMachine,
StringRef OutputFilename) {
llvm::SmallString<0> Buffer;
std::unique_ptr<raw_pwrite_stream> RawOS;
if (!OutputFilename.empty()) {
// Try to open the output file. Clobbering an existing file is fine.
// Open in binary mode if we're doing binary output.
llvm::sys::fs::OpenFlags OSFlags = llvm::sys::fs::F_None;
std::error_code EC;
auto *FDOS = new raw_fd_ostream(OutputFilename, EC, OSFlags);
RawOS.reset(FDOS);
if (FDOS->has_error() || EC) {
if (DiagMutex)
DiagMutex->lock();
Diags.diagnose(SourceLoc(), diag::error_opening_output,
OutputFilename, EC.message());
if (DiagMutex)
DiagMutex->unlock();
FDOS->clear_error();
return true;
}
// Most output kinds want a formatted output stream. It's not clear
// why writing an object file does.
//if (Opts.OutputKind != IRGenOutputKind::LLVMBitcode)
// FormattedOS.setStream(*RawOS, formatted_raw_ostream::PRESERVE_STREAM);
} else {
RawOS.reset(new raw_svector_ostream(Buffer));
}
performLLVMOptimizations(Opts, Module, TargetMachine);
legacy::PassManager EmitPasses;
// Set up the final emission passes.
switch (Opts.OutputKind) {
case IRGenOutputKind::Module:
break;
case IRGenOutputKind::LLVMAssembly:
EmitPasses.add(createPrintModulePass(*RawOS));
break;
case IRGenOutputKind::LLVMBitcode:
EmitPasses.add(createBitcodeWriterPass(*RawOS));
break;
case IRGenOutputKind::NativeAssembly:
case IRGenOutputKind::ObjectFile: {
llvm::TargetMachine::CodeGenFileType FileType;
FileType = (Opts.OutputKind == IRGenOutputKind::NativeAssembly
? llvm::TargetMachine::CGFT_AssemblyFile
: llvm::TargetMachine::CGFT_ObjectFile);
EmitPasses.add(createTargetTransformInfoWrapperPass(
TargetMachine->getTargetIRAnalysis()));
// Make sure we do ARC contraction under optimization. We don't
// rely on any other LLVM ARC transformations, but we do need ARC
// contraction to add the objc_retainAutoreleasedReturnValue
// assembly markers.
if (Opts.Optimize)
EmitPasses.add(createObjCARCContractPass());
bool fail = TargetMachine->addPassesToEmitFile(EmitPasses, *RawOS,
FileType, !Opts.Verify);
if (fail) {
if (DiagMutex)
DiagMutex->lock();
Diags.diagnose(SourceLoc(), diag::error_codegen_init_fail);
if (DiagMutex)
DiagMutex->unlock();
return true;
}
break;
}
}
{
SharedTimer timer("LLVM output");
EmitPasses.run(*Module);
}
return false;
}
示例3: hash_value
// Implementation of StringRef hashing.
hash_code llvm::hash_value(StringRef S) {
return hash_combine_range(S.begin(), S.end());
}
示例4: Binary
Archive::Archive(MemoryBufferRef Source, Error &Err)
: Binary(Binary::ID_Archive, Source) {
ErrorAsOutParameter ErrAsOutParam(&Err);
StringRef Buffer = Data.getBuffer();
// Check for sufficient magic.
if (Buffer.startswith(ThinMagic)) {
IsThin = true;
} else if (Buffer.startswith(Magic)) {
IsThin = false;
} else {
Err = make_error<GenericBinaryError>("File too small to be an archive",
object_error::invalid_file_type);
return;
}
// Get the special members.
child_iterator I = child_begin(Err, false);
if (Err)
return;
child_iterator E = child_end();
// This is at least a valid empty archive. Since an empty archive is the
// same in all formats, just claim it to be gnu to make sure Format is
// initialized.
Format = K_GNU;
if (I == E) {
Err = Error::success();
return;
}
const Child *C = &*I;
auto Increment = [&]() {
++I;
if (Err)
return true;
C = &*I;
return false;
};
StringRef Name = C->getRawName();
// Below is the pattern that is used to figure out the archive format
// GNU archive format
// First member : / (may exist, if it exists, points to the symbol table )
// Second member : // (may exist, if it exists, points to the string table)
// Note : The string table is used if the filename exceeds 15 characters
// BSD archive format
// First member : __.SYMDEF or "__.SYMDEF SORTED" (the symbol table)
// There is no string table, if the filename exceeds 15 characters or has a
// embedded space, the filename has #1/<size>, The size represents the size
// of the filename that needs to be read after the archive header
// COFF archive format
// First member : /
// Second member : / (provides a directory of symbols)
// Third member : // (may exist, if it exists, contains the string table)
// Note: Microsoft PE/COFF Spec 8.3 says that the third member is present
// even if the string table is empty. However, lib.exe does not in fact
// seem to create the third member if there's no member whose filename
// exceeds 15 characters. So the third member is optional.
if (Name == "__.SYMDEF" || Name == "__.SYMDEF_64") {
if (Name == "__.SYMDEF")
Format = K_BSD;
else // Name == "__.SYMDEF_64"
Format = K_DARWIN64;
// We know that the symbol table is not an external file, so we just assert
// there is no error.
SymbolTable = *C->getBuffer();
if (Increment())
return;
setFirstRegular(*C);
Err = Error::success();
return;
}
if (Name.startswith("#1/")) {
Format = K_BSD;
// We know this is BSD, so getName will work since there is no string table.
ErrorOr<StringRef> NameOrErr = C->getName();
if (auto ec = NameOrErr.getError()) {
Err = errorCodeToError(ec);
return;
}
Name = NameOrErr.get();
if (Name == "__.SYMDEF SORTED" || Name == "__.SYMDEF") {
// We know that the symbol table is not an external file, so we just
// assert there is no error.
SymbolTable = *C->getBuffer();
if (Increment())
return;
}
else if (Name == "__.SYMDEF_64 SORTED" || Name == "__.SYMDEF_64") {
Format = K_DARWIN64;
// We know that the symbol table is not an external file, so we just
// assert there is no error.
SymbolTable = *C->getBuffer();
if (Increment())
return;
//.........这里部分代码省略.........
示例5: assert
void Value::setName(const Twine &NewName) {
assert(SubclassID != MDStringVal &&
"Cannot set the name of MDString with this method!");
// Fast path for common IRBuilder case of setName("") when there is no name.
if (NewName.isTriviallyEmpty() && !hasName())
return;
SmallString<256> NameData;
StringRef NameRef = NewName.toStringRef(NameData);
assert(NameRef.find_first_of(0) == StringRef::npos &&
"Null bytes are not allowed in names");
// Name isn't changing?
if (getName() == NameRef)
return;
assert(!getType()->isVoidTy() && "Cannot assign a name to void values!");
// Get the symbol table to update for this object.
ValueSymbolTable *ST;
if (getSymTab(this, ST))
return; // Cannot set a name on this value (e.g. constant).
if (Function *F = dyn_cast<Function>(this))
getContext().pImpl->IntrinsicIDCache.erase(F);
if (!ST) { // No symbol table to update? Just do the change.
if (NameRef.empty()) {
// Free the name for this value.
Name->Destroy();
Name = nullptr;
return;
}
if (Name)
Name->Destroy();
// NOTE: Could optimize for the case the name is shrinking to not deallocate
// then reallocated.
// Create the new name.
Name = ValueName::Create(NameRef);
Name->setValue(this);
return;
}
// NOTE: Could optimize for the case the name is shrinking to not deallocate
// then reallocated.
if (hasName()) {
// Remove old name.
ST->removeValueName(Name);
Name->Destroy();
Name = nullptr;
if (NameRef.empty())
return;
}
// Name is changing to something new.
Name = ST->createValueName(NameRef, this);
}
示例6: switch
/// Determine the prefix to be stripped from the names of the enum constants
/// within the given enum.
void EnumInfo::determineConstantNamePrefix(ASTContext &ctx,
const clang::EnumDecl *decl) {
switch (getKind()) {
case EnumKind::Enum:
case EnumKind::Options:
// Enums are mapped to Swift enums, Options to Swift option sets, both
// of which attempt prefix-stripping.
break;
case EnumKind::Constants:
case EnumKind::Unknown:
// Nothing to do.
return;
}
// If there are no enumers, there is no prefix to compute.
auto ec = decl->enumerator_begin(), ecEnd = decl->enumerator_end();
if (ec == ecEnd)
return;
// Determine whether the given enumerator is non-deprecated and has no
// specifically-provided name.
auto isNonDeprecatedWithoutCustomName = [](
const clang::EnumConstantDecl *elem) -> bool {
if (elem->hasAttr<clang::SwiftNameAttr>())
return false;
clang::VersionTuple maxVersion{~0U, ~0U, ~0U};
switch (elem->getAvailability(nullptr, maxVersion)) {
case clang::AR_Available:
case clang::AR_NotYetIntroduced:
for (auto attr : elem->attrs()) {
if (auto annotate = dyn_cast<clang::AnnotateAttr>(attr)) {
if (annotate->getAnnotation() == "swift1_unavailable")
return false;
}
if (auto avail = dyn_cast<clang::AvailabilityAttr>(attr)) {
if (avail->getPlatform()->getName() == "swift")
return false;
}
}
return true;
case clang::AR_Deprecated:
case clang::AR_Unavailable:
return false;
}
};
// Move to the first non-deprecated enumerator, or non-swift_name'd
// enumerator, if present.
auto firstNonDeprecated =
std::find_if(ec, ecEnd, isNonDeprecatedWithoutCustomName);
bool hasNonDeprecated = (firstNonDeprecated != ecEnd);
if (hasNonDeprecated) {
ec = firstNonDeprecated;
} else {
// Advance to the first case without a custom name, deprecated or not.
while (ec != ecEnd && (*ec)->hasAttr<clang::SwiftNameAttr>())
++ec;
if (ec == ecEnd) {
return;
}
}
// Compute the common prefix.
StringRef commonPrefix = (*ec)->getName();
bool followedByNonIdentifier = false;
for (++ec; ec != ecEnd; ++ec) {
// Skip deprecated or swift_name'd enumerators.
const clang::EnumConstantDecl *elem = *ec;
if (hasNonDeprecated) {
if (!isNonDeprecatedWithoutCustomName(elem))
continue;
} else {
if (elem->hasAttr<clang::SwiftNameAttr>())
continue;
}
commonPrefix = getCommonWordPrefix(commonPrefix, elem->getName(),
followedByNonIdentifier);
if (commonPrefix.empty())
break;
}
if (!commonPrefix.empty()) {
StringRef checkPrefix = commonPrefix;
// Account for the 'kConstant' naming convention on enumerators.
if (checkPrefix[0] == 'k') {
bool canDropK;
if (checkPrefix.size() >= 2)
canDropK = clang::isUppercase(checkPrefix[1]);
else
canDropK = !followedByNonIdentifier;
if (canDropK)
checkPrefix = checkPrefix.drop_front();
//.........这里部分代码省略.........
示例7: Parent
Archive::Child::Child(const Archive *Parent, StringRef Data,
uint16_t StartOfFile)
: Parent(Parent), Header(Parent, Data.data(), Data.size(), nullptr),
Data(Data), StartOfFile(StartOfFile) {
}
示例8: HeaderDirectory
// Load single header list and dependencies.
std::error_code ModularizeUtilities::loadSingleHeaderListsAndDependencies(
llvm::StringRef InputPath) {
// By default, use the path component of the list file name.
SmallString<256> HeaderDirectory(InputPath);
llvm::sys::path::remove_filename(HeaderDirectory);
SmallString<256> CurrentDirectory;
llvm::sys::fs::current_path(CurrentDirectory);
// Get the prefix if we have one.
if (HeaderPrefix.size() != 0)
HeaderDirectory = HeaderPrefix;
// Read the header list file into a buffer.
ErrorOr<std::unique_ptr<MemoryBuffer>> listBuffer =
MemoryBuffer::getFile(InputPath);
if (std::error_code EC = listBuffer.getError())
return EC;
// Parse the header list into strings.
SmallVector<StringRef, 32> Strings;
listBuffer.get()->getBuffer().split(Strings, "\n", -1, false);
// Collect the header file names from the string list.
for (SmallVectorImpl<StringRef>::iterator I = Strings.begin(),
E = Strings.end();
I != E; ++I) {
StringRef Line = I->trim();
// Ignore comments and empty lines.
if (Line.empty() || (Line[0] == '#'))
continue;
std::pair<StringRef, StringRef> TargetAndDependents = Line.split(':');
SmallString<256> HeaderFileName;
// Prepend header file name prefix if it's not absolute.
if (llvm::sys::path::is_absolute(TargetAndDependents.first))
llvm::sys::path::native(TargetAndDependents.first, HeaderFileName);
else {
if (HeaderDirectory.size() != 0)
HeaderFileName = HeaderDirectory;
else
HeaderFileName = CurrentDirectory;
llvm::sys::path::append(HeaderFileName, TargetAndDependents.first);
llvm::sys::path::native(HeaderFileName);
}
// Handle optional dependencies.
DependentsVector Dependents;
SmallVector<StringRef, 4> DependentsList;
TargetAndDependents.second.split(DependentsList, " ", -1, false);
int Count = DependentsList.size();
for (int Index = 0; Index < Count; ++Index) {
SmallString<256> Dependent;
if (llvm::sys::path::is_absolute(DependentsList[Index]))
Dependent = DependentsList[Index];
else {
if (HeaderDirectory.size() != 0)
Dependent = HeaderDirectory;
else
Dependent = CurrentDirectory;
llvm::sys::path::append(Dependent, DependentsList[Index]);
}
llvm::sys::path::native(Dependent);
Dependents.push_back(getCanonicalPath(Dependent.str()));
}
// Get canonical form.
HeaderFileName = getCanonicalPath(HeaderFileName);
// Save the resulting header file path and dependencies.
HeaderFileNames.push_back(HeaderFileName.str());
Dependencies[HeaderFileName.str()] = Dependents;
}
return std::error_code();
}
示例9: memcpy
/// GetDwarfFile - takes a file name an number to place in the dwarf file and
/// directory tables. If the file number has already been allocated it is an
/// error and zero is returned and the client reports the error, else the
/// allocated file number is returned. The file numbers may be in any order.
unsigned MCContext::GetDwarfFile(StringRef Directory, StringRef FileName,
unsigned FileNumber, unsigned CUID) {
// TODO: a FileNumber of zero says to use the next available file number.
// Note: in GenericAsmParser::ParseDirectiveFile() FileNumber was checked
// to not be less than one. This needs to be change to be not less than zero.
SmallVectorImpl<MCDwarfFile *>& MCDwarfFiles = MCDwarfFilesCUMap[CUID];
SmallVectorImpl<StringRef>& MCDwarfDirs = MCDwarfDirsCUMap[CUID];
// Make space for this FileNumber in the MCDwarfFiles vector if needed.
if (FileNumber >= MCDwarfFiles.size()) {
MCDwarfFiles.resize(FileNumber + 1);
} else {
MCDwarfFile *&ExistingFile = MCDwarfFiles[FileNumber];
if (ExistingFile)
// It is an error to use see the same number more than once.
return 0;
}
// Get the new MCDwarfFile slot for this FileNumber.
MCDwarfFile *&File = MCDwarfFiles[FileNumber];
if (Directory.empty()) {
// Separate the directory part from the basename of the FileName.
StringRef tFileName = sys::path::filename(FileName);
if (!tFileName.empty()) {
Directory = sys::path::parent_path(FileName);
if (!Directory.empty())
FileName = tFileName;
}
}
// Find or make a entry in the MCDwarfDirs vector for this Directory.
// Capture directory name.
unsigned DirIndex;
if (Directory.empty()) {
// For FileNames with no directories a DirIndex of 0 is used.
DirIndex = 0;
} else {
DirIndex = 0;
for (unsigned End = MCDwarfDirs.size(); DirIndex < End; DirIndex++) {
if (Directory == MCDwarfDirs[DirIndex])
break;
}
if (DirIndex >= MCDwarfDirs.size()) {
char *Buf = static_cast<char *>(Allocate(Directory.size()));
memcpy(Buf, Directory.data(), Directory.size());
MCDwarfDirs.push_back(StringRef(Buf, Directory.size()));
}
// The DirIndex is one based, as DirIndex of 0 is used for FileNames with
// no directories. MCDwarfDirs[] is unlike MCDwarfFiles[] in that the
// directory names are stored at MCDwarfDirs[DirIndex-1] where FileNames
// are stored at MCDwarfFiles[FileNumber].Name .
DirIndex++;
}
// Now make the MCDwarfFile entry and place it in the slot in the MCDwarfFiles
// vector.
char *Buf = static_cast<char *>(Allocate(FileName.size()));
memcpy(Buf, FileName.data(), FileName.size());
File = new (*this) MCDwarfFile(StringRef(Buf, FileName.size()), DirIndex);
// return the allocated FileNumber.
return FileNumber;
}
示例10: startsWithWord
/// Interpreting the given string using the normal CamelCase
/// conventions, determine whether the given string starts with the
/// given "word", which is assumed to end in a lowercase letter.
static bool startsWithWord(StringRef name, StringRef word) {
if (name.size() < word.size()) return false;
return ((name.size() == word.size() || !isLowercase(name[word.size()])) &&
name.startswith(word));
}
示例11: if
/// emitModuleFlags - Perform code emission for module flags.
void TargetLoweringObjectFileMachO::emitModuleFlags(
MCStreamer &Streamer, ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
const TargetMachine &TM) const {
unsigned VersionVal = 0;
unsigned ImageInfoFlags = 0;
MDNode *LinkerOptions = nullptr;
StringRef SectionVal;
for (const auto &MFE : ModuleFlags) {
// Ignore flags with 'Require' behavior.
if (MFE.Behavior == Module::Require)
continue;
StringRef Key = MFE.Key->getString();
Metadata *Val = MFE.Val;
if (Key == "Objective-C Image Info Version") {
VersionVal = mdconst::extract<ConstantInt>(Val)->getZExtValue();
} else if (Key == "Objective-C Garbage Collection" ||
Key == "Objective-C GC Only" ||
Key == "Objective-C Is Simulated" ||
Key == "Objective-C Class Properties" ||
Key == "Objective-C Image Swift Version") {
ImageInfoFlags |= mdconst::extract<ConstantInt>(Val)->getZExtValue();
} else if (Key == "Objective-C Image Info Section") {
SectionVal = cast<MDString>(Val)->getString();
} else if (Key == "Linker Options") {
LinkerOptions = cast<MDNode>(Val);
}
}
// Emit the linker options if present.
if (LinkerOptions) {
for (const auto &Option : LinkerOptions->operands()) {
SmallVector<std::string, 4> StrOptions;
for (const auto &Piece : cast<MDNode>(Option)->operands())
StrOptions.push_back(cast<MDString>(Piece)->getString());
Streamer.EmitLinkerOptions(StrOptions);
}
}
// The section is mandatory. If we don't have it, then we don't have GC info.
if (SectionVal.empty()) return;
StringRef Segment, Section;
unsigned TAA = 0, StubSize = 0;
bool TAAParsed;
std::string ErrorCode =
MCSectionMachO::ParseSectionSpecifier(SectionVal, Segment, Section,
TAA, TAAParsed, StubSize);
if (!ErrorCode.empty())
// If invalid, report the error with report_fatal_error.
report_fatal_error("Invalid section specifier '" + Section + "': " +
ErrorCode + ".");
// Get the section.
MCSectionMachO *S = getContext().getMachOSection(
Segment, Section, TAA, StubSize, SectionKind::getData());
Streamer.SwitchSection(S);
Streamer.EmitLabel(getContext().
getOrCreateSymbol(StringRef("L_OBJC_IMAGE_INFO")));
Streamer.EmitIntValue(VersionVal, 4);
Streamer.EmitIntValue(ImageInfoFlags, 4);
Streamer.AddBlankLine();
}
示例12: getELFKindForNamedSection
static SectionKind
getELFKindForNamedSection(StringRef Name, SectionKind K) {
// N.B.: The defaults used in here are no the same ones used in MC.
// We follow gcc, MC follows gas. For example, given ".section .eh_frame",
// both gas and MC will produce a section with no flags. Given
// section(".eh_frame") gcc will produce:
//
// .section .eh_frame,"a",@progbits
if (Name == getInstrProfCoverageSectionName(false))
return SectionKind::getMetadata();
if (Name.empty() || Name[0] != '.') return K;
// Some lame default implementation based on some magic section names.
if (Name == ".bss" ||
Name.startswith(".bss.") ||
Name.startswith(".gnu.linkonce.b.") ||
Name.startswith(".llvm.linkonce.b.") ||
Name == ".sbss" ||
Name.startswith(".sbss.") ||
Name.startswith(".gnu.linkonce.sb.") ||
Name.startswith(".llvm.linkonce.sb."))
return SectionKind::getBSS();
if (Name == ".tdata" ||
Name.startswith(".tdata.") ||
Name.startswith(".gnu.linkonce.td.") ||
Name.startswith(".llvm.linkonce.td."))
return SectionKind::getThreadData();
if (Name == ".tbss" ||
Name.startswith(".tbss.") ||
Name.startswith(".gnu.linkonce.tb.") ||
Name.startswith(".llvm.linkonce.tb."))
return SectionKind::getThreadBSS();
return K;
}
示例13: if
/// Parse - Analyze the specified string (e.g. "==&{eax}") and fill in the
/// fields in this structure. If the constraint string is not understood,
/// return true, otherwise return false.
bool InlineAsm::ConstraintInfo::Parse(StringRef Str,
InlineAsm::ConstraintInfoVector &ConstraintsSoFar) {
StringRef::iterator I = Str.begin(), E = Str.end();
unsigned multipleAlternativeCount = Str.count('|') + 1;
unsigned multipleAlternativeIndex = 0;
ConstraintCodeVector *pCodes = &Codes;
// Initialize
isMultipleAlternative = (multipleAlternativeCount > 1 ? true : false);
if (isMultipleAlternative) {
multipleAlternatives.resize(multipleAlternativeCount);
pCodes = &multipleAlternatives[0].Codes;
}
Type = isInput;
isEarlyClobber = false;
MatchingInput = -1;
isCommutative = false;
isIndirect = false;
currentAlternativeIndex = 0;
// Parse prefixes.
if (*I == '~') {
Type = isClobber;
++I;
} else if (*I == '=') {
++I;
Type = isOutput;
}
if (*I == '*') {
isIndirect = true;
++I;
}
if (I == E) return true; // Just a prefix, like "==" or "~".
// Parse the modifiers.
bool DoneWithModifiers = false;
while (!DoneWithModifiers) {
switch (*I) {
default:
DoneWithModifiers = true;
break;
case '&': // Early clobber.
if (Type != isOutput || // Cannot early clobber anything but output.
isEarlyClobber) // Reject &&&&&&
return true;
isEarlyClobber = true;
break;
case '%': // Commutative.
if (Type == isClobber || // Cannot commute clobbers.
isCommutative) // Reject %%%%%
return true;
isCommutative = true;
break;
case '#': // Comment.
case '*': // Register preferencing.
return true; // Not supported.
}
if (!DoneWithModifiers) {
++I;
if (I == E) return true; // Just prefixes and modifiers!
}
}
// Parse the various constraints.
while (I != E) {
if (*I == '{') { // Physical register reference.
// Find the end of the register name.
StringRef::iterator ConstraintEnd = std::find(I+1, E, '}');
if (ConstraintEnd == E) return true; // "{foo"
pCodes->push_back(std::string(I, ConstraintEnd+1));
I = ConstraintEnd+1;
} else if (isdigit(static_cast<unsigned char>(*I))) { // Matching Constraint
// Maximal munch numbers.
StringRef::iterator NumStart = I;
while (I != E && isdigit(static_cast<unsigned char>(*I)))
++I;
pCodes->push_back(std::string(NumStart, I));
unsigned N = atoi(pCodes->back().c_str());
// Check that this is a valid matching constraint!
if (N >= ConstraintsSoFar.size() || ConstraintsSoFar[N].Type != isOutput||
Type != isInput)
return true; // Invalid constraint number.
// If Operand N already has a matching input, reject this. An output
// can't be constrained to the same value as multiple inputs.
if (isMultipleAlternative) {
InlineAsm::SubConstraintInfo &scInfo =
ConstraintsSoFar[N].multipleAlternatives[multipleAlternativeIndex];
if (scInfo.MatchingInput != -1)
return true;
// Note that operand #n has a matching input.
scInfo.MatchingInput = ConstraintsSoFar.size();
} else {
if (ConstraintsSoFar[N].hasMatchingInput())
//.........这里部分代码省略.........
示例14: ParseLine
/// Parse \p Input as line sample.
///
/// \param Input input line.
/// \param IsCallsite true if the line represents an inlined callsite.
/// \param Depth the depth of the inline stack.
/// \param NumSamples total samples of the line/inlined callsite.
/// \param LineOffset line offset to the start of the function.
/// \param Discriminator discriminator of the line.
/// \param TargetCountMap map from indirect call target to count.
///
/// returns true if parsing is successful.
static bool ParseLine(const StringRef &Input, bool &IsCallsite, uint32_t &Depth,
uint64_t &NumSamples, uint32_t &LineOffset,
uint32_t &Discriminator, StringRef &CalleeName,
DenseMap<StringRef, uint64_t> &TargetCountMap) {
for (Depth = 0; Input[Depth] == ' '; Depth++)
;
if (Depth == 0)
return false;
size_t n1 = Input.find(':');
StringRef Loc = Input.substr(Depth, n1 - Depth);
size_t n2 = Loc.find('.');
if (n2 == StringRef::npos) {
if (Loc.getAsInteger(10, LineOffset) || !isOffsetLegal(LineOffset))
return false;
Discriminator = 0;
} else {
if (Loc.substr(0, n2).getAsInteger(10, LineOffset))
return false;
if (Loc.substr(n2 + 1).getAsInteger(10, Discriminator))
return false;
}
StringRef Rest = Input.substr(n1 + 2);
if (Rest[0] >= '0' && Rest[0] <= '9') {
IsCallsite = false;
size_t n3 = Rest.find(' ');
if (n3 == StringRef::npos) {
if (Rest.getAsInteger(10, NumSamples))
return false;
} else {
if (Rest.substr(0, n3).getAsInteger(10, NumSamples))
return false;
}
// Find call targets and their sample counts.
// Note: In some cases, there are symbols in the profile which are not
// mangled. To accommodate such cases, use colon + integer pairs as the
// anchor points.
// An example:
// _M_construct<char *>:1000 string_view<std::allocator<char> >:437
// ":1000" and ":437" are used as anchor points so the string above will
// be interpreted as
// target: _M_construct<char *>
// count: 1000
// target: string_view<std::allocator<char> >
// count: 437
while (n3 != StringRef::npos) {
n3 += Rest.substr(n3).find_first_not_of(' ');
Rest = Rest.substr(n3);
n3 = Rest.find_first_of(':');
if (n3 == StringRef::npos || n3 == 0)
return false;
StringRef Target;
uint64_t count, n4;
while (true) {
// Get the segment after the current colon.
StringRef AfterColon = Rest.substr(n3 + 1);
// Get the target symbol before the current colon.
Target = Rest.substr(0, n3);
// Check if the word after the current colon is an integer.
n4 = AfterColon.find_first_of(' ');
n4 = (n4 != StringRef::npos) ? n3 + n4 + 1 : Rest.size();
StringRef WordAfterColon = Rest.substr(n3 + 1, n4 - n3 - 1);
if (!WordAfterColon.getAsInteger(10, count))
break;
// Try to find the next colon.
uint64_t n5 = AfterColon.find_first_of(':');
if (n5 == StringRef::npos)
return false;
n3 += n5 + 1;
}
// An anchor point is found. Save the {target, count} pair
TargetCountMap[Target] = count;
if (n4 == Rest.size())
break;
// Change n3 to the next blank space after colon + integer pair.
n3 = n4;
}
} else {
IsCallsite = true;
size_t n3 = Rest.find_last_of(':');
CalleeName = Rest.substr(0, n3);
if (Rest.substr(n3 + 1).getAsInteger(10, NumSamples))
return false;
}
return true;
//.........这里部分代码省略.........
示例15: formatDiagnosticArgument
/// \brief Format a single diagnostic argument and write it to the given
/// stream.
static void formatDiagnosticArgument(StringRef Modifier,
StringRef ModifierArguments,
ArrayRef<DiagnosticArgument> Args,
unsigned ArgIndex,
llvm::raw_ostream &Out) {
const DiagnosticArgument &Arg = Args[ArgIndex];
switch (Arg.getKind()) {
case DiagnosticArgumentKind::Integer:
if (Modifier == "select") {
assert(Arg.getAsInteger() >= 0 && "Negative selection index");
formatSelectionArgument(ModifierArguments, Args, Arg.getAsInteger(),
Out);
} else if (Modifier == "s") {
if (Arg.getAsInteger() != 1)
Out << 's';
} else {
assert(Modifier.empty() && "Improper modifier for integer argument");
Out << Arg.getAsInteger();
}
break;
case DiagnosticArgumentKind::Unsigned:
if (Modifier == "select") {
formatSelectionArgument(ModifierArguments, Args, Arg.getAsUnsigned(),
Out);
} else if (Modifier == "s") {
if (Arg.getAsUnsigned() != 1)
Out << 's';
} else {
assert(Modifier.empty() && "Improper modifier for unsigned argument");
Out << Arg.getAsUnsigned();
}
break;
case DiagnosticArgumentKind::String:
assert(Modifier.empty() && "Improper modifier for string argument");
Out << Arg.getAsString();
break;
case DiagnosticArgumentKind::Identifier:
assert(Modifier.empty() && "Improper modifier for identifier argument");
Out << '\'';
Arg.getAsIdentifier().printPretty(Out);
Out << '\'';
break;
case DiagnosticArgumentKind::ObjCSelector:
assert(Modifier.empty() && "Improper modifier for selector argument");
Out << '\'' << Arg.getAsObjCSelector() << '\'';
break;
case DiagnosticArgumentKind::Type: {
assert(Modifier.empty() && "Improper modifier for Type argument");
// Strip extraneous parentheses; they add no value.
auto type = Arg.getAsType()->getWithoutParens();
std::string typeName = type->getString();
Out << '\'' << typeName << '\'';
// Decide whether to show the desugared type or not. We filter out some
// cases to avoid too much noise.
bool showAKA = !type->isCanonical();
// Substituted types are uninteresting sugar that prevents the heuristics
// below from kicking in.
if (showAKA)
if (auto *ST = dyn_cast<SubstitutedType>(type.getPointer()))
type = ST->getReplacementType();
// If we're complaining about a function type, don't "aka" just because of
// differences in the argument or result types.
if (showAKA && type->is<FunctionType>() &&
isa<FunctionType>(type.getPointer()))
showAKA = false;
// Don't unwrap intentional sugar types like T? or [T].
if (showAKA && (isa<SyntaxSugarType>(type.getPointer()) ||
isa<DictionaryType>(type.getPointer()) ||
type->is<BuiltinType>()))
showAKA = false;
// If they are textually the same, don't show them. This can happen when
// they are actually different types, because they exist in different scopes
// (e.g. everyone names their type parameters 'T').
if (showAKA && typeName == type->getCanonicalType()->getString())
showAKA = false;
// Don't show generic type parameters.
if (showAKA && type->getCanonicalType()->hasTypeParameter())
showAKA = false;
if (showAKA)
Out << " (aka '" << type->getCanonicalType() << "')";
break;
}
case DiagnosticArgumentKind::TypeRepr:
assert(Modifier.empty() && "Improper modifier for TypeRepr argument");
//.........这里部分代码省略.........