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 21namespace llvm { 22 23class MemoryBuffer; 24class MemoryBufferRef; 25class Module; 26class SMDiagnostic; 27class LLVMContext; 28 29typedef llvm::function_ref<Optional<std::string>(StringRef)> 30 DataLayoutCallbackTy; 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. 38std::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. 47std::unique_ptr<Module> 48getLazyIRFileModule(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. 55std::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. 63std::unique_ptr<Module> parseIRFile( 64 StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, 65 DataLayoutCallbackTy DataLayoutCallback = [](StringRef) { return None; }); 66} 67 68#endif 69