LLVM  12.0.0git
IRReader.h
Go to the documentation of this file.
1 //===---- llvm/IRReader/IRReader.h - Reader for LLVM IR files ---*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines functions for reading LLVM IR. They support both
10 // Bitcode and Assembly, automatically detecting the input format.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_IRREADER_IRREADER_H
15 #define LLVM_IRREADER_IRREADER_H
16 
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/StringRef.h"
19 #include <memory>
20 
21 namespace llvm {
22 
23 class MemoryBuffer;
24 class MemoryBufferRef;
25 class Module;
26 class SMDiagnostic;
27 class LLVMContext;
28 
31 
32 /// If the given MemoryBuffer holds a bitcode image, return a Module
33 /// for it which does lazy deserialization of function bodies. Otherwise,
34 /// attempt to parse it as LLVM Assembly and return a fully populated
35 /// Module. The ShouldLazyLoadMetadata flag is passed down to the bitcode
36 /// reader to optionally enable lazy metadata loading. This takes ownership
37 /// of \p Buffer.
38 std::unique_ptr<Module> getLazyIRModule(std::unique_ptr<MemoryBuffer> Buffer,
39  SMDiagnostic &Err, LLVMContext &Context,
40  bool ShouldLazyLoadMetadata = false);
41 
42 /// If the given file holds a bitcode image, return a Module
43 /// for it which does lazy deserialization of function bodies. Otherwise,
44 /// attempt to parse it as LLVM Assembly and return a fully populated
45 /// Module. The ShouldLazyLoadMetadata flag is passed down to the bitcode
46 /// reader to optionally enable lazy metadata loading.
47 std::unique_ptr<Module>
48 getLazyIRFileModule(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
49  bool ShouldLazyLoadMetadata = false);
50 
51 /// If the given MemoryBuffer holds a bitcode image, return a Module
52 /// for it. Otherwise, attempt to parse it as LLVM Assembly and return
53 /// a Module for it.
54 /// \param DataLayoutCallback Override datalayout in the llvm assembly.
55 std::unique_ptr<Module> parseIR(
56  MemoryBufferRef Buffer, SMDiagnostic &Err, LLVMContext &Context,
57  DataLayoutCallbackTy DataLayoutCallback = [](StringRef) { return None; });
58 
59 /// If the given file holds a bitcode image, return a Module for it.
60 /// Otherwise, attempt to parse it as LLVM Assembly and return a Module
61 /// for it.
62 /// \param DataLayoutCallback Override datalayout in the llvm assembly.
63 std::unique_ptr<Module> parseIRFile(
64  StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
65  DataLayoutCallbackTy DataLayoutCallback = [](StringRef) { return None; });
66 }
67 
68 #endif
const NoneType None
Definition: None.h:23
LLVMContext & Context
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Machine Debugify Module
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:176
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...
Definition: IRReader.cpp:33
std::unique_ptr< Module > parseIRFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, DataLayoutCallbackTy DataLayoutCallback=[](StringRef) { return None;})
If the given file holds a bitcode image, return a Module for it.
Definition: IRReader.cpp:92
llvm::function_ref< Optional< std::string >StringRef)> DataLayoutCallbackTy
Definition: Parser.h:29
std::unique_ptr< Module > parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err, LLVMContext &Context, DataLayoutCallbackTy DataLayoutCallback=[](StringRef) { return None;})
If the given MemoryBuffer holds a bitcode image, return a Module for it.
Definition: IRReader.cpp:68
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...
Definition: IRReader.cpp:52