21 #include <system_error>
32 static std::unique_ptr<Module>
35 if (
isBitcode((
const unsigned char *)Buffer->getBufferStart(),
36 (
const unsigned char *)Buffer->getBufferEnd())) {
39 if (std::error_code EC = ModuleOrErr.
getError()) {
44 return std::move(ModuleOrErr.
get());
47 return parseAssembly(Buffer->getMemBufferRef(), Err, Context);
55 if (std::error_code EC = FileOrErr.
getError()) {
57 "Could not open input file: " + EC.message());
72 if (std::error_code EC = ModuleOrErr.
getError()) {
77 return std::move(ModuleOrErr.
get());
87 if (std::error_code EC = FileOrErr.
getError()) {
89 "Could not open input file: " + EC.message());
93 return parseIR(FileOrErr.
get()->getMemBufferRef(), Err, Context);
105 std::unique_ptr<MemoryBuffer> MB(
unwrap(MemBuf));
114 Diag.
print(
nullptr, os,
false);
117 *OutMessage = strdup(buf.c_str());
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
std::error_code getError() const
Represents either an error or a value T.
struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef
Used to pass regions of memory through LLVM interfaces.
std::unique_ptr< Module > getLazyIRFileModule(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context)
If the given file holds a bitcode image, return a Module for it which does lazy deserialization of fu...
const char * getBufferStart() const
NamedRegionTimer - 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.
LLVMTargetDataRef wrap(const DataLayout *P)
std::unique_ptr< Module > parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr)
parseAssemblyFile and parseAssemblyString are wrappers around this function.
static std::unique_ptr< Module > getLazyIRModule(std::unique_ptr< MemoryBuffer > Buffer, SMDiagnostic &Err, LLVMContext &Context)
DataLayout * unwrap(LLVMTargetDataRef P)
static const char *const TimeIRParsingName
This is an important class for using LLVM in a threaded context.
const char * getBufferEnd() const
ErrorOr< std::unique_ptr< Module > > parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context, DiagnosticHandlerFunction DiagnosticHandler=nullptr)
Read the specified bitcode file, returning the module.
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, int64_t FileSize=-1)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
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. ...
static const char *const TimeIRParsingGroupName
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
StringRef getBufferIdentifier() const
A raw_ostream that writes to an std::string.
ErrorOr< std::unique_ptr< Module > > getLazyBitcodeModule(std::unique_ptr< MemoryBuffer > &&Buffer, LLVMContext &Context, DiagnosticHandlerFunction DiagnosticHandler=nullptr, bool ShouldLazyLoadMetadata=false)
Read the header of the specified bitcode buffer and prepare for lazy deserialization of function bodi...
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.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...