IRReader.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/STLExtras.h"
  21. #include "llvm/ADT/StringRef.h"
  22. #include <memory>
  23. namespace llvm {
  24. class MemoryBuffer;
  25. class MemoryBufferRef;
  26. class Module;
  27. class SMDiagnostic;
  28. class LLVMContext;
  29. typedef llvm::function_ref<Optional<std::string>(StringRef)>
  30. DataLayoutCallbackTy;
  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(
  53. MemoryBufferRef Buffer, SMDiagnostic &Err, LLVMContext &Context,
  54. DataLayoutCallbackTy DataLayoutCallback = [](StringRef) { return None; });
  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(
  60. StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
  61. DataLayoutCallbackTy DataLayoutCallback = [](StringRef) { return None; });
  62. }
  63. #endif
  64. #ifdef __GNUC__
  65. #pragma GCC diagnostic pop
  66. #endif