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 | |
| 17 | #include "llvm/ADT/StringRef.h" |
| 18 | #include <memory> |
| 19 | |
| 20 | namespace llvm { |
| 21 | |
| 22 | class StringRef; |
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 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 29 | /// If the given MemoryBuffer holds a bitcode image, return a Module |
| 30 | /// for it which does lazy deserialization of function bodies. Otherwise, |
| 31 | /// attempt to parse it as LLVM Assembly and return a fully populated |
| 32 | /// Module. The ShouldLazyLoadMetadata flag is passed down to the bitcode |
| 33 | /// reader to optionally enable lazy metadata loading. This takes ownership |
| 34 | /// of \p Buffer. |
| 35 | std::unique_ptr<Module> getLazyIRModule(std::unique_ptr<MemoryBuffer> Buffer, |
| 36 | SMDiagnostic &Err, LLVMContext &Context, |
| 37 | bool ShouldLazyLoadMetadata = false); |
| 38 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 39 | /// If the given file holds a bitcode image, return a Module |
| 40 | /// for it which does lazy deserialization of function bodies. Otherwise, |
| 41 | /// attempt to parse it as LLVM Assembly and return a fully populated |
| 42 | /// Module. The ShouldLazyLoadMetadata flag is passed down to the bitcode |
| 43 | /// reader to optionally enable lazy metadata loading. |
| 44 | std::unique_ptr<Module> |
| 45 | getLazyIRFileModule(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, |
| 46 | bool ShouldLazyLoadMetadata = false); |
| 47 | |
| 48 | /// If the given MemoryBuffer holds a bitcode image, return a Module |
| 49 | /// for it. Otherwise, attempt to parse it as LLVM Assembly and return |
| 50 | /// a Module for it. |
| 51 | /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier. |
| 52 | /// This option should only be set to false by llvm-as |
| 53 | /// for use inside the LLVM testuite! |
| 54 | /// \param DataLayoutString Override datalayout in the llvm assembly. |
| 55 | std::unique_ptr<Module> parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err, |
| 56 | LLVMContext &Context, |
| 57 | bool UpgradeDebugInfo = true, |
| 58 | StringRef DataLayoutString = ""); |
| 59 | |
| 60 | /// If the given file holds a bitcode image, return a Module for it. |
| 61 | /// Otherwise, attempt to parse it as LLVM Assembly and return a Module |
| 62 | /// for it. |
| 63 | /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier. |
| 64 | /// This option should only be set to false by llvm-as |
| 65 | /// for use inside the LLVM testuite! |
| 66 | /// \param DataLayoutString Override datalayout in the llvm assembly. |
| 67 | std::unique_ptr<Module> parseIRFile(StringRef Filename, SMDiagnostic &Err, |
| 68 | LLVMContext &Context, |
| 69 | bool UpgradeDebugInfo = true, |
| 70 | StringRef DataLayoutString = ""); |
| 71 | } |
| 72 | |
| 73 | #endif |