20 #include <system_error> 33 static std::unique_ptr<Module>
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());
56 bool ShouldLazyLoadMetadata) {
59 if (std::error_code EC = FileOrErr.
getError()) {
61 "Could not open input file: " + EC.message());
66 ShouldLazyLoadMetadata);
74 TimeIRParsingGroupName, TimeIRParsingGroupDescription,
87 if (!DataLayoutString.
empty())
88 ModuleOrErr.
get()->setDataLayout(DataLayoutString);
89 return std::move(ModuleOrErr.
get());
92 return parseAssembly(Buffer, Err, Context,
nullptr, UpgradeDebugInfo,
102 if (std::error_code EC = FileOrErr.
getError()) {
104 "Could not open input file: " + EC.message());
121 std::unique_ptr<MemoryBuffer> MB(
unwrap(MemBuf));
130 Diag.
print(
nullptr, os,
false);
133 *OutMessage = strdup(buf.c_str());
std::unique_ptr< Module > parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err, LLVMContext &Context, bool UpgradeDebugInfo=true, StringRef DataLayoutString="")
If the given MemoryBuffer holds a bitcode image, return a Module for it.
static const char *const TimeIRParsingGroupDescription
Represents either an error or a value T.
This class represents lattice values for constants.
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
const char * getBufferEnd() const
struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef
LLVM uses a polymorphic type hierarchy which C cannot represent, therefore parameters must be passed ...
virtual std::string message() const
Return the error message as a string.
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.
Tagged union holding either a T or a Error.
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
std::unique_ptr< Module > parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr, bool UpgradeDebugInfo=true, StringRef DataLayoutString="")
parseAssemblyFile and parseAssemblyString are wrappers around this function.
static const char *const TimeIRParsingName
This is an important class for using LLVM in a threaded context.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
std::error_code getError() const
bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
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...
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
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.
StringRef getBufferIdentifier() const
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)
std::unique_ptr< Module > parseIRFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, bool UpgradeDebugInfo=true, StringRef DataLayoutString="")
If the given file holds a bitcode image, return a Module for it.
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...
const char * getBufferStart() const
A raw_ostream that writes to an std::string.
Lightweight error class with error context and mandatory checking.
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...
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...