1 //===- MIRParser.h - MIR serialization format parser ------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This MIR serialization library is currently a work in progress. It can't
10 // serialize machine functions at this time.
12 // This file declares the functions that parse the MIR serialization format
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_CODEGEN_MIRPARSER_MIRPARSER_H
18 #define LLVM_CODEGEN_MIRPARSER_MIRPARSER_H
20 #include "llvm/IR/Module.h"
21 #include "llvm/Support/MemoryBuffer.h"
28 class MachineModuleInfo
;
31 /// This class initializes machine functions by applying the state loaded from
34 std::unique_ptr
<MIRParserImpl
> Impl
;
37 MIRParser(std::unique_ptr
<MIRParserImpl
> Impl
);
38 MIRParser(const MIRParser
&) = delete;
41 /// Parses the optional LLVM IR module in the MIR file.
43 /// A new, empty module is created if the LLVM IR isn't present.
44 /// \returns nullptr if a parsing error occurred.
45 std::unique_ptr
<Module
> parseIRModule();
47 /// Parses MachineFunctions in the MIR file and add them to the given
48 /// MachineModuleInfo \p MMI.
50 /// \returns true if an error occurred.
51 bool parseMachineFunctions(Module
&M
, MachineModuleInfo
&MMI
);
54 /// This function is the main interface to the MIR serialization format parser.
56 /// It reads in a MIR file and returns a MIR parser that can parse the embedded
57 /// LLVM IR module and initialize the machine functions by parsing the machine
60 /// \param Filename - The name of the file to parse.
61 /// \param Error - Error result info.
62 /// \param Context - Context which will be used for the parsed LLVM IR module.
63 std::unique_ptr
<MIRParser
> createMIRParserFromFile(StringRef Filename
,
65 LLVMContext
&Context
);
67 /// This function is another interface to the MIR serialization format parser.
69 /// It returns a MIR parser that works with the given memory buffer and that can
70 /// parse the embedded LLVM IR module and initialize the machine functions by
71 /// parsing the machine function's state.
73 /// \param Contents - The MemoryBuffer containing the machine level IR.
74 /// \param Context - Context which will be used for the parsed LLVM IR module.
75 std::unique_ptr
<MIRParser
>
76 createMIRParser(std::unique_ptr
<MemoryBuffer
> Contents
, LLVMContext
&Context
);
78 } // end namespace llvm
80 #endif // LLVM_CODEGEN_MIRPARSER_MIRPARSER_H