21 #include <system_error>
34 static std::unique_ptr<Module>
37 if (
isBitcode((
const unsigned char *)Buffer->getBufferStart(),
38 (
const unsigned char *)Buffer->getBufferEnd())) {
40 std::move(Buffer), Context, ShouldLazyLoadMetadata);
48 return std::move(ModuleOrErr.
get());
57 bool ShouldLazyLoadMetadata) {
60 if (std::error_code EC = FileOrErr.
getError()) {
62 "Could not open input file: " + EC.message());
67 ShouldLazyLoadMetadata);
86 return std::move(ModuleOrErr.
get());
96 if (std::error_code EC = FileOrErr.
getError()) {
98 "Could not open input file: " + EC.message());
114 std::unique_ptr<MemoryBuffer> MB(
unwrap(MemBuf));
123 Diag.
print(
nullptr, os,
false);
126 *OutMessage = strdup(buf.c_str());
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
static const char *const TimeIRParsingGroupDescription
std::error_code getError() const
Represents either an error or a value T.
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef
LLVM uses a polymorphic type hierarchy which C cannot represent, therefore parameters must be passed ...
const char * getBufferStart() const
Error takeError()
Take ownership of the stored error.
Base class for error info classes.
Attribute unwrap(LLVMAttributeRef Attr)
This class is basically a combination of TimeRegion and Timer.
std::unique_ptr< Module > parseIRFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context)
If the given file holds a bitcode image, return a Module for it.
Tagged union holding either a T or a Error.
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
std::unique_ptr< Module > parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr)
parseAssemblyFile and parseAssemblyString are wrappers around this function.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
static const char *const TimeIRParsingName
This is an important class for using LLVM in a threaded context.
const char * getBufferEnd() const
void handleAllErrors(Error E, HandlerTs &&...Handlers)
Behaves the same as handleErrors, except that it requires that all errors be handled by the given han...
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...
Module.h This file contains the declarations for the Module class.
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, either with or without a wrapper.
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. ...
reference get()
Returns a reference to the stored T value.
Expected< std::unique_ptr< Module > > parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context)
Read the specified bitcode file, returning the module.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
LLVMAttributeRef wrap(Attribute Attr)
static const char *const TimeIRParsingGroupName
Expected< std::unique_ptr< Module > > getOwningLazyBitcodeModule(std::unique_ptr< MemoryBuffer > &&Buffer, LLVMContext &Context, bool ShouldLazyLoadMetadata=false, bool IsImporting=false)
Like getLazyBitcodeModule, except that the module takes ownership of the memory buffer if successful...
StringRef getBufferIdentifier() const
A raw_ostream that writes to an std::string.
Lightweight error class with error context and mandatory checking.
virtual std::string message() const
Return the error message as a string.
StringRef - Represent a constant reference to a string, i.e.
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)
If the given MemoryBuffer holds a bitcode image, return a Module for it.
static const char *const TimeIRParsingDescription
static std::unique_ptr< Module > getLazyIRModule(std::unique_ptr< MemoryBuffer > Buffer, SMDiagnostic &Err, LLVMContext &Context, bool ShouldLazyLoadMetadata)
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...