本文整理汇总了C++中MemoryBufferRef::getBufferIdentifier方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryBufferRef::getBufferIdentifier方法的具体用法?C++ MemoryBufferRef::getBufferIdentifier怎么用?C++ MemoryBufferRef::getBufferIdentifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryBufferRef
的用法示例。
在下文中一共展示了MemoryBufferRef::getBufferIdentifier方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: T
static uint8_t getBitcodeMachineKind(MemoryBufferRef MB) {
Triple T(getBitcodeTargetTriple(MB, Driver->Context));
switch (T.getArch()) {
case Triple::aarch64:
return EM_AARCH64;
case Triple::arm:
return EM_ARM;
case Triple::mips:
case Triple::mipsel:
case Triple::mips64:
case Triple::mips64el:
return EM_MIPS;
case Triple::ppc:
return EM_PPC;
case Triple::ppc64:
return EM_PPC64;
case Triple::x86:
return T.isOSIAMCU() ? EM_IAMCU : EM_386;
case Triple::x86_64:
return EM_X86_64;
default:
fatal(MB.getBufferIdentifier() +
": could not infer e_machine from bitcode target triple " + T.str());
}
}
示例2: createELFObj
template <class ELFT> static ELFFile<ELFT> createELFObj(MemoryBufferRef MB) {
std::error_code EC;
ELFFile<ELFT> F(MB.getBuffer(), EC);
if (EC)
fatal(EC, "failed to read " + MB.getBufferIdentifier());
return F;
}
示例3: createELFFile
static std::unique_ptr<InputFile> createELFFile(MemoryBufferRef MB) {
unsigned char Size;
unsigned char Endian;
std::tie(Size, Endian) = getElfArchType(MB.getBuffer());
if (Endian != ELFDATA2LSB && Endian != ELFDATA2MSB)
fatal("invalid data encoding: " + MB.getBufferIdentifier());
if (Size == ELFCLASS32) {
if (Endian == ELFDATA2LSB)
return createELFFileAux<T<ELF32LE>>(MB);
return createELFFileAux<T<ELF32BE>>(MB);
}
if (Size == ELFCLASS64) {
if (Endian == ELFDATA2LSB)
return createELFFileAux<T<ELF64LE>>(MB);
return createELFFileAux<T<ELF64BE>>(MB);
}
fatal("invalid file class: " + MB.getBufferIdentifier());
}
示例4: getELFKind
static ELFKind getELFKind(MemoryBufferRef MB) {
unsigned char Size;
unsigned char Endian;
std::tie(Size, Endian) = getElfArchType(MB.getBuffer());
if (Endian != ELFDATA2LSB && Endian != ELFDATA2MSB)
fatal(MB.getBufferIdentifier() + ": invalid data encoding");
if (Size != ELFCLASS32 && Size != ELFCLASS64)
fatal(MB.getBufferIdentifier() + ": invalid file class");
size_t BufSize = MB.getBuffer().size();
if ((Size == ELFCLASS32 && BufSize < sizeof(Elf32_Ehdr)) ||
(Size == ELFCLASS64 && BufSize < sizeof(Elf64_Ehdr)))
fatal(MB.getBufferIdentifier() + ": file is too short");
if (Size == ELFCLASS32)
return (Endian == ELFDATA2LSB) ? ELF32LEKind : ELF32BEKind;
return (Endian == ELFDATA2LSB) ? ELF64LEKind : ELF64BEKind;
}
示例5:
std::unique_ptr<Module> llvm::parseAssembly(MemoryBufferRef F,
SMDiagnostic &Err,
LLVMContext &Context) {
std::unique_ptr<Module> M =
make_unique<Module>(F.getBufferIdentifier(), Context);
if (parseAssemblyInto(F, *M, Err))
return nullptr;
return M;
}
示例6: create
ErrorOr<std::unique_ptr<SymbolicFile>> SymbolicFile::createSymbolicFile(
MemoryBufferRef Object, sys::fs::file_magic Type, LLVMContext *Context) {
StringRef Data = Object.getBuffer();
if (Type == sys::fs::file_magic::unknown)
Type = sys::fs::identify_magic(Data);
switch (Type) {
case sys::fs::file_magic::bitcode:
if (Context)
return IRObjectFile::create(Object, *Context);
// Fallthrough
case sys::fs::file_magic::unknown:
case sys::fs::file_magic::archive:
case sys::fs::file_magic::macho_universal_binary:
case sys::fs::file_magic::windows_resource:
return object_error::invalid_file_type;
case sys::fs::file_magic::elf:
case sys::fs::file_magic::elf_executable:
case sys::fs::file_magic::elf_shared_object:
case sys::fs::file_magic::elf_core:
case sys::fs::file_magic::macho_executable:
case sys::fs::file_magic::macho_fixed_virtual_memory_shared_lib:
case sys::fs::file_magic::macho_core:
case sys::fs::file_magic::macho_preload_executable:
case sys::fs::file_magic::macho_dynamically_linked_shared_lib:
case sys::fs::file_magic::macho_dynamic_linker:
case sys::fs::file_magic::macho_bundle:
case sys::fs::file_magic::macho_dynamically_linked_shared_lib_stub:
case sys::fs::file_magic::macho_dsym_companion:
case sys::fs::file_magic::macho_kext_bundle:
case sys::fs::file_magic::pecoff_executable:
return ObjectFile::createObjectFile(Object, Type);
case sys::fs::file_magic::coff_import_library:
return std::unique_ptr<SymbolicFile>(new COFFImportFile(Object));
case sys::fs::file_magic::elf_relocatable:
case sys::fs::file_magic::macho_object:
case sys::fs::file_magic::coff_object: {
ErrorOr<std::unique_ptr<ObjectFile>> Obj =
ObjectFile::createObjectFile(Object, Type);
if (!Obj || !Context)
return std::move(Obj);
ErrorOr<MemoryBufferRef> BCData =
IRObjectFile::findBitcodeInObject(*Obj->get());
if (!BCData)
return std::move(Obj);
return IRObjectFile::create(
MemoryBufferRef(BCData->getBuffer(), Object.getBufferIdentifier()),
*Context);
}
}
llvm_unreachable("Unexpected Binary File Type");
}
示例7: createFile
static std::unique_ptr<InputFile> createFile(MemoryBufferRef MB) {
// File type is detected by contents, not by file extension.
file_magic Magic = identify_magic(MB.getBuffer());
if (Magic == file_magic::archive)
return std::unique_ptr<InputFile>(new ArchiveFile(MB));
if (Magic == file_magic::bitcode)
return std::unique_ptr<InputFile>(new BitcodeFile(MB));
if (Config->OutputFile == "")
Config->OutputFile = getOutputPath(MB.getBufferIdentifier());
return std::unique_ptr<InputFile>(new ObjectFile<llvm::object::ELF64LE>(MB));
}
示例8:
std::unique_ptr<Module>
llvm::parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context,
SlotMapping *Slots, bool UpgradeDebugInfo) {
std::unique_ptr<Module> M =
make_unique<Module>(F.getBufferIdentifier(), Context);
if (parseAssemblyInto(F, *M, Err, Slots, UpgradeDebugInfo))
return nullptr;
return M;
}
示例9: MBRef
BitcodeFile::BitcodeFile(MemoryBufferRef MB, StringRef ArchiveName,
uint64_t OffsetInArchive)
: InputFile(BitcodeKind, MB) {
this->ArchiveName = ArchiveName;
// Here we pass a new MemoryBufferRef which is identified by ArchiveName
// (the fully resolved path of the archive) + member name + offset of the
// member in the archive.
// ThinLTO uses the MemoryBufferRef identifier to access its internal
// data structures and if two archives define two members with the same name,
// this causes a collision which result in only one of the objects being
// taken into consideration at LTO time (which very likely causes undefined
// symbols later in the link stage).
MemoryBufferRef MBRef(MB.getBuffer(),
Saver.save(ArchiveName + MB.getBufferIdentifier() +
utostr(OffsetInArchive)));
Obj = check(lto::InputFile::create(MBRef), toString(this));
Triple T(Obj->getTargetTriple());
EKind = getBitcodeELFKind(T);
EMachine = getBitcodeMachineKind(MB.getBufferIdentifier(), T);
}
示例10: tokenize
// Split S into linker script tokens.
void ScriptParserBase::tokenize(MemoryBufferRef MB) {
std::vector<StringRef> Vec;
MBs.push_back(MB);
StringRef S = MB.getBuffer();
StringRef Begin = S;
for (;;) {
S = skipSpace(S);
if (S.empty())
break;
// Quoted token. Note that double-quote characters are parts of a token
// because, in a glob match context, only unquoted tokens are interpreted
// as glob patterns. Double-quoted tokens are literal patterns in that
// context.
if (S.startswith("\"")) {
size_t E = S.find("\"", 1);
if (E == StringRef::npos) {
StringRef Filename = MB.getBufferIdentifier();
size_t Lineno = Begin.substr(0, S.data() - Begin.data()).count('\n');
error(Filename + ":" + Twine(Lineno + 1) + ": unclosed quote");
return;
}
Vec.push_back(S.take_front(E + 1));
S = S.substr(E + 1);
continue;
}
// Unquoted token. This is more relaxed than tokens in C-like language,
// so that you can write "file-name.cpp" as one bare token, for example.
size_t Pos = S.find_first_not_of(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
"0123456789_.$/\\~=+[]*?-:!<>^");
// A character that cannot start a word (which is usually a
// punctuation) forms a single character token.
if (Pos == 0)
Pos = 1;
Vec.push_back(S.substr(0, Pos));
S = S.substr(Pos);
}
Tokens.insert(Tokens.begin() + Pos, Vec.begin(), Vec.end());
}
示例11: T
std::unique_ptr<Module> llvm::parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err,
LLVMContext &Context) {
NamedRegionTimer T(TimeIRParsingName, TimeIRParsingGroupName,
TimePassesIsEnabled);
if (isBitcode((const unsigned char *)Buffer.getBufferStart(),
(const unsigned char *)Buffer.getBufferEnd())) {
ErrorOr<std::unique_ptr<Module>> ModuleOrErr =
parseBitcodeFile(Buffer, Context);
if (std::error_code EC = ModuleOrErr.getError()) {
Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error,
EC.message());
return nullptr;
}
return std::move(ModuleOrErr.get());
}
return parseAssembly(Buffer, Err, Context);
}
示例12: move
// Simple helper to load a module from bitcode
std::unique_ptr<Module> loadModuleFromBuffer(const MemoryBufferRef &Buffer,
LLVMContext &Context, bool Lazy) {
SMDiagnostic Err;
ErrorOr<std::unique_ptr<Module>> ModuleOrErr(nullptr);
if (Lazy) {
ModuleOrErr =
getLazyBitcodeModule(MemoryBuffer::getMemBuffer(Buffer, false), Context,
/* ShouldLazyLoadMetadata */ Lazy);
} else {
ModuleOrErr = parseBitcodeFile(Buffer, Context);
}
if (std::error_code EC = ModuleOrErr.getError()) {
Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error,
EC.message());
Err.print("ThinLTO", errs());
report_fatal_error("Can't load module, abort.");
}
return std::move(ModuleOrErr.get());
}
示例13: SolveInst
int SolveInst(const MemoryBufferRef &MB, Solver *S) {
InstContext IC;
std::string ErrStr;
std::vector<ParsedReplacement> Reps;
std::vector<ReplacementContext> Contexts;
if (InferRHS || ParseLHSOnly) {
Reps = ParseReplacementLHSs(IC, MB.getBufferIdentifier(), MB.getBuffer(),
Contexts, ErrStr);
} else {
Reps = ParseReplacements(IC, MB.getBufferIdentifier(), MB.getBuffer(), ErrStr);
}
if (!ErrStr.empty()) {
llvm::errs() << ErrStr << '\n';
return 1;
}
if (EmitLHSDot) {
llvm::outs() << "; emitting DOT for parsed LHS souper IR ...\n";
for (auto &Rep : Reps) {
llvm::WriteGraph(llvm::outs(), Rep.Mapping.LHS);
}
}
if (ParseOnly || ParseLHSOnly) {
llvm::outs() << "; parsing successful\n";
return 0;
}
unsigned Index = 0;
int Ret = 0;
int Success = 0, Fail = 0, Error = 0;
for (auto Rep : Reps) {
if (InferRHS || ReInferRHS) {
int OldCost;
if (ReInferRHS) {
OldCost = cost(Rep.Mapping.RHS);
Rep.Mapping.RHS = 0;
}
if (std::error_code EC = S->infer(Rep.BPCs, Rep.PCs, Rep.Mapping.LHS,
Rep.Mapping.RHS, IC)) {
llvm::errs() << EC.message() << '\n';
Ret = 1;
++Error;
}
if (Rep.Mapping.RHS) {
++Success;
if (ReInferRHS) {
int NewCost = cost(Rep.Mapping.RHS);
int LHSCost = cost(Rep.Mapping.LHS);
if (NewCost <= OldCost)
llvm::outs() << "; RHS inferred successfully, no cost regression";
else
llvm::outs() << "; RHS inferred successfully, but cost regressed";
llvm::outs() << " (Old= " << OldCost << ", New= " << NewCost <<
", LHS= " << LHSCost << ")\n";
} else {
llvm::outs() << "; RHS inferred successfully\n";
}
if (PrintRepl) {
PrintReplacement(llvm::outs(), Rep.BPCs, Rep.PCs, Rep.Mapping);
} else if (PrintReplSplit) {
ReplacementContext Context;
PrintReplacementLHS(llvm::outs(), Rep.BPCs, Rep.PCs,
Rep.Mapping.LHS, Context);
PrintReplacementRHS(llvm::outs(), Rep.Mapping.RHS, Context);
} else {
ReplacementContext Context;
PrintReplacementRHS(llvm::outs(), Rep.Mapping.RHS,
ReInferRHS ? Context : Contexts[Index]);
}
} else {
++Fail;
llvm::outs() << "; Failed to infer RHS\n";
if (PrintRepl || PrintReplSplit) {
ReplacementContext Context;
PrintReplacementLHS(llvm::outs(), Rep.BPCs, Rep.PCs,
Rep.Mapping.LHS, Context);
}
}
} else {
bool Valid;
std::vector<std::pair<Inst *, APInt>> Models;
if (std::error_code EC = S->isValid(IC, Rep.BPCs, Rep.PCs,
Rep.Mapping, Valid, &Models)) {
llvm::errs() << EC.message() << '\n';
Ret = 1;
++Error;
}
if (Valid) {
++Success;
llvm::outs() << "; LGTM\n";
if (PrintRepl)
PrintReplacement(llvm::outs(), Rep.BPCs, Rep.PCs, Rep.Mapping);
if (PrintReplSplit) {
ReplacementContext Context;
PrintReplacementLHS(llvm::outs(), Rep.BPCs, Rep.PCs,
Rep.Mapping.LHS, Context);
PrintReplacementRHS(llvm::outs(), Rep.Mapping.RHS, Context);
//.........这里部分代码省略.........
示例14: Buf
NewArchiveMember::NewArchiveMember(MemoryBufferRef BufRef)
: Buf(MemoryBuffer::getMemBuffer(BufRef, false)),
MemberName(BufRef.getBufferIdentifier()) {}
示例15:
std::unique_ptr<MemoryBuffer>
MemoryBuffer::getMemBuffer(MemoryBufferRef Ref, bool RequiresNullTerminator) {
return std::unique_ptr<MemoryBuffer>(getMemBuffer(
Ref.getBuffer(), Ref.getBufferIdentifier(), RequiresNullTerminator));
}