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