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/STLFunctionalExtras.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/Bitcode/BitcodeReader.h"
20 #include <memory>
21 #include <optional>
22 
23 namespace llvm {
24 
25 class MemoryBuffer;
26 class MemoryBufferRef;
27 class Module;
28 class SMDiagnostic;
29 class LLVMContext;
30 
31 /// If the given MemoryBuffer holds a bitcode image, return a Module
32 /// for it which does lazy deserialization of function bodies.  Otherwise,
33 /// attempt to parse it as LLVM Assembly and return a fully populated
34 /// Module. The ShouldLazyLoadMetadata flag is passed down to the bitcode
35 /// reader to optionally enable lazy metadata loading. This takes ownership
36 /// of \p Buffer.
37 std::unique_ptr<Module> getLazyIRModule(std::unique_ptr<MemoryBuffer> Buffer,
38                                         SMDiagnostic &Err, LLVMContext &Context,
39                                         bool ShouldLazyLoadMetadata = false);
40 
41 /// If the given file holds a bitcode image, return a Module
42 /// for it which does lazy deserialization of function bodies.  Otherwise,
43 /// attempt to parse it as LLVM Assembly and return a fully populated
44 /// Module. The ShouldLazyLoadMetadata flag is passed down to the bitcode
45 /// reader to optionally enable lazy metadata loading.
46 std::unique_ptr<Module>
47 getLazyIRFileModule(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
48                     bool ShouldLazyLoadMetadata = false);
49 
50 /// If the given MemoryBuffer holds a bitcode image, return a Module
51 /// for it.  Otherwise, attempt to parse it as LLVM Assembly and return
52 /// a Module for it.
53 /// \param DataLayoutCallback Override datalayout in the llvm assembly.
54 std::unique_ptr<Module> parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err,
55                                 LLVMContext &Context,
56                                 ParserCallbacks Callbacks = {});
57 
58 /// If the given file holds a bitcode image, return a Module for it.
59 /// Otherwise, attempt to parse it as LLVM Assembly and return a Module
60 /// for it.
61 /// \param DataLayoutCallback Override datalayout in the llvm assembly.
62 std::unique_ptr<Module> parseIRFile(StringRef Filename, SMDiagnostic &Err,
63                                     LLVMContext &Context,
64                                     ParserCallbacks Callbacks = {});
65 }
66 
67 #endif
68