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