IRReader.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===---- llvm/IRReader/IRReader.h - Reader for LLVM IR files ---*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines functions for reading LLVM IR. They support both
  15. // Bitcode and Assembly, automatically detecting the input format.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_IRREADER_IRREADER_H
  19. #define LLVM_IRREADER_IRREADER_H
  20. #include "llvm/ADT/STLFunctionalExtras.h"
  21. #include "llvm/ADT/StringRef.h"
  22. #include "llvm/Bitcode/BitcodeReader.h"
  23. #include <memory>
  24. #include <optional>
  25. namespace llvm {
  26. class MemoryBuffer;
  27. class MemoryBufferRef;
  28. class Module;
  29. class SMDiagnostic;
  30. class LLVMContext;
  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. /// If the given file holds a bitcode image, return a Module
  41. /// for it which does lazy deserialization of function bodies. Otherwise,
  42. /// attempt to parse it as LLVM Assembly and return a fully populated
  43. /// Module. The ShouldLazyLoadMetadata flag is passed down to the bitcode
  44. /// reader to optionally enable lazy metadata loading.
  45. std::unique_ptr<Module>
  46. getLazyIRFileModule(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
  47. bool ShouldLazyLoadMetadata = false);
  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 DataLayoutCallback Override datalayout in the llvm assembly.
  52. std::unique_ptr<Module> parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err,
  53. LLVMContext &Context,
  54. ParserCallbacks Callbacks = {});
  55. /// If the given file holds a bitcode image, return a Module for it.
  56. /// Otherwise, attempt to parse it as LLVM Assembly and return a Module
  57. /// for it.
  58. /// \param DataLayoutCallback Override datalayout in the llvm assembly.
  59. std::unique_ptr<Module> parseIRFile(StringRef Filename, SMDiagnostic &Err,
  60. LLVMContext &Context,
  61. ParserCallbacks Callbacks = {});
  62. }
  63. #endif
  64. #ifdef __GNUC__
  65. #pragma GCC diagnostic pop
  66. #endif