Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===---- llvm/IRReader/IRReader.h - Reader for LLVM IR files ---*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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 |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 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 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 17 | #include "llvm/ADT/STLExtras.h" |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 18 | #include "llvm/ADT/StringRef.h" |
| 19 | #include <memory> |
| 20 | |
| 21 | namespace llvm { |
| 22 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 23 | class MemoryBuffer; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 24 | class MemoryBufferRef; |
| 25 | class Module; |
| 26 | class SMDiagnostic; |
| 27 | class LLVMContext; |
| 28 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 29 | typedef llvm::function_ref<Optional<std::string>(StringRef)> |
| 30 | DataLayoutCallbackTy; |
| 31 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 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. |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 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; }); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 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. |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 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; }); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | #endif |