20#include <system_error>
33std::unique_ptr<Module>
35 LLVMContext &Context,
bool ShouldLazyLoadMetadata) {
36 if (
isBitcode((
const unsigned char *)Buffer->getBufferStart(),
37 (
const unsigned char *)Buffer->getBufferEnd())) {
39 std::move(Buffer), Context, ShouldLazyLoadMetadata);
47 return std::move(ModuleOrErr.
get());
50 return parseAssembly(Buffer->getMemBufferRef(), Err, Context);
56 bool ShouldLazyLoadMetadata) {
59 if (std::error_code EC = FileOrErr.
getError()) {
61 "Could not open input file: " + EC.message());
66 ShouldLazyLoadMetadata);
86 return std::move(ModuleOrErr.
get());
99 if (std::error_code EC = FileOrErr.
getError()) {
101 "Could not open input file: " + EC.message());
105 return parseIR(FileOrErr.
get()->getMemBufferRef(), Err, Context, Callbacks);
117 std::unique_ptr<MemoryBuffer> MB(
unwrap(MemBuf));
126 Diag.
print(
nullptr, os,
false);
128 *OutMessage = strdup(buf.c_str());
const char TimeIRParsingDescription[]
const char TimeIRParsingGroupDescription[]
const char TimeIRParsingName[]
const char TimeIRParsingGroupName[]
Module.h This file contains the declarations for the Module class.
Base class for error info classes.
virtual std::string message() const
Return the error message as a string.
Represents either an error or a value T.
std::error_code getError() const
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
This is an important class for using LLVM in a threaded context.
StringRef getBufferIdentifier() const
const char * getBufferStart() const
const char * getBufferEnd() const
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true, bool ShowLocation=true) const
StringRef - Represent a constant reference to a string, i.e.
A raw_ostream that writes to an std::string.
LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef, LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM, char **OutMessage)
Read LLVM IR from a memory buffer and convert it into an in-memory Module object.
struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef
LLVM uses a polymorphic type hierarchy which C cannot represent, therefore parameters must be passed ...
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
This is an optimization pass for GlobalISel generic memory operations.
std::unique_ptr< Module > parseIRFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, ParserCallbacks Callbacks={})
If the given file holds a bitcode image, return a Module for it.
Expected< std::unique_ptr< Module > > parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context, ParserCallbacks Callbacks={})
Read the specified bitcode file, returning the module.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
bool TimePassesIsEnabled
If the user specifies the -time-passes argument on an LLVM tool command line then the value of this b...
std::unique_ptr< Module > parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err, LLVMContext &Context, ParserCallbacks Callbacks={})
If the given MemoryBuffer holds a bitcode image, return a Module for it.
Attribute unwrap(LLVMAttributeRef Attr)
std::unique_ptr< Module > getLazyIRFileModule(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, bool ShouldLazyLoadMetadata=false)
If the given file holds a bitcode image, return a Module for it which does lazy deserialization of fu...
std::unique_ptr< Module > parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr, DataLayoutCallbackTy DataLayoutCallback=[](StringRef, StringRef) { return std::nullopt;})
parseAssemblyFile and parseAssemblyString are wrappers around this function.
LLVMAttributeRef wrap(Attribute Attr)
bool isBitcode(const unsigned char *BufPtr, const unsigned char *BufEnd)
isBitcode - Return true if the given bytes are the magic bytes for LLVM IR bitcode,...
Expected< std::unique_ptr< Module > > getOwningLazyBitcodeModule(std::unique_ptr< MemoryBuffer > &&Buffer, LLVMContext &Context, bool ShouldLazyLoadMetadata=false, bool IsImporting=false, ParserCallbacks Callbacks={})
Like getLazyBitcodeModule, except that the module takes ownership of the memory buffer if successful.
std::unique_ptr< Module > getLazyIRModule(std::unique_ptr< MemoryBuffer > Buffer, SMDiagnostic &Err, LLVMContext &Context, bool ShouldLazyLoadMetadata=false)
If the given MemoryBuffer holds a bitcode image, return a Module for it which does lazy deserializati...
This class is basically a combination of TimeRegion and Timer.
std::optional< DataLayoutCallbackFuncTy > DataLayout