MIRParser.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //===- MIRParser.h - MIR serialization format parser ----------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This MIR serialization library is currently a work in progress. It can't
  11. // serialize machine functions at this time.
  12. //
  13. // This file declares the functions that parse the MIR serialization format
  14. // files.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CODEGEN_MIRPARSER_MIRPARSER_H
  18. #define LLVM_CODEGEN_MIRPARSER_MIRPARSER_H
  19. #include "llvm/ADT/StringRef.h"
  20. #include "llvm/CodeGen/MachineFunctionInitializer.h"
  21. #include "llvm/IR/Module.h"
  22. #include "llvm/Support/MemoryBuffer.h"
  23. #include <memory>
  24. namespace llvm {
  25. class MIRParserImpl;
  26. class SMDiagnostic;
  27. /// This class initializes machine functions by applying the state loaded from
  28. /// a MIR file.
  29. class MIRParser : public MachineFunctionInitializer {
  30. std::unique_ptr<MIRParserImpl> Impl;
  31. public:
  32. MIRParser(std::unique_ptr<MIRParserImpl> Impl);
  33. MIRParser(const MIRParser &) = delete;
  34. ~MIRParser();
  35. /// Parse the optional LLVM IR module that's embedded in the MIR file.
  36. ///
  37. /// A new, empty module is created if the LLVM IR isn't present.
  38. /// Returns null if a parsing error occurred.
  39. std::unique_ptr<Module> parseLLVMModule();
  40. /// Initialize the machine function to the state that's described in the MIR
  41. /// file.
  42. ///
  43. /// Return true if error occurred.
  44. bool initializeMachineFunction(MachineFunction &MF) override;
  45. };
  46. /// This function is the main interface to the MIR serialization format parser.
  47. ///
  48. /// It reads in a MIR file and returns a MIR parser that can parse the embedded
  49. /// LLVM IR module and initialize the machine functions by parsing the machine
  50. /// function's state.
  51. ///
  52. /// \param Filename - The name of the file to parse.
  53. /// \param Error - Error result info.
  54. /// \param Context - Context which will be used for the parsed LLVM IR module.
  55. std::unique_ptr<MIRParser> createMIRParserFromFile(StringRef Filename,
  56. SMDiagnostic &Error,
  57. LLVMContext &Context);
  58. /// This function is another interface to the MIR serialization format parser.
  59. ///
  60. /// It returns a MIR parser that works with the given memory buffer and that can
  61. /// parse the embedded LLVM IR module and initialize the machine functions by
  62. /// parsing the machine function's state.
  63. ///
  64. /// \param Contents - The MemoryBuffer containing the machine level IR.
  65. /// \param Context - Context which will be used for the parsed LLVM IR module.
  66. std::unique_ptr<MIRParser>
  67. createMIRParser(std::unique_ptr<MemoryBuffer> Contents, LLVMContext &Context);
  68. } // end namespace llvm
  69. #endif