blob: fc1f9753309a42fa4bb388e94e2db1a0f41c8db7 [file] [log] [blame]
Alex Lorenz2bdb4e12015-05-27 18:02:19 +00001//===- MIRParser.cpp - MIR serialization format parser implementation -----===//
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 file implements the class that parses the optional LLVM IR and machine
11// functions that are stored in MIR files.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/CodeGen/MIRParser/MIRParser.h"
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000016#include "MIParser.h"
Alex Lorenz33f0aef2015-06-26 16:46:11 +000017#include "llvm/ADT/DenseMap.h"
Alex Lorenz2bdb4e12015-05-27 18:02:19 +000018#include "llvm/ADT/StringRef.h"
Alex Lorenz735c47e2015-06-15 20:30:22 +000019#include "llvm/ADT/StringMap.h"
Alex Lorenz2bdb4e12015-05-27 18:02:19 +000020#include "llvm/ADT/STLExtras.h"
21#include "llvm/AsmParser/Parser.h"
Alex Lorenz5d6108e2015-06-26 22:56:48 +000022#include "llvm/AsmParser/SlotMapping.h"
Alex Lorenz735c47e2015-06-15 20:30:22 +000023#include "llvm/CodeGen/MachineFunction.h"
Alex Lorenz54565cf2015-06-24 19:56:10 +000024#include "llvm/CodeGen/MachineRegisterInfo.h"
Alex Lorenz78d78312015-05-28 22:41:12 +000025#include "llvm/CodeGen/MIRYamlMapping.h"
Alex Lorenz4f093bf2015-06-19 17:43:07 +000026#include "llvm/IR/BasicBlock.h"
Alex Lorenz735c47e2015-06-15 20:30:22 +000027#include "llvm/IR/DiagnosticInfo.h"
Alex Lorenz8e7a58d72015-06-15 23:07:38 +000028#include "llvm/IR/Instructions.h"
Alex Lorenz735c47e2015-06-15 20:30:22 +000029#include "llvm/IR/LLVMContext.h"
Alex Lorenz2bdb4e12015-05-27 18:02:19 +000030#include "llvm/IR/Module.h"
Alex Lorenz4f093bf2015-06-19 17:43:07 +000031#include "llvm/IR/ValueSymbolTable.h"
Alex Lorenz09b832c2015-05-29 17:05:41 +000032#include "llvm/Support/LineIterator.h"
Alex Lorenz2bdb4e12015-05-27 18:02:19 +000033#include "llvm/Support/SMLoc.h"
34#include "llvm/Support/SourceMgr.h"
35#include "llvm/Support/MemoryBuffer.h"
36#include "llvm/Support/YAMLTraits.h"
37#include <memory>
38
39using namespace llvm;
40
Alex Lorenz735c47e2015-06-15 20:30:22 +000041namespace llvm {
Alex Lorenz2bdb4e12015-05-27 18:02:19 +000042
43/// This class implements the parsing of LLVM IR that's embedded inside a MIR
44/// file.
45class MIRParserImpl {
46 SourceMgr SM;
47 StringRef Filename;
48 LLVMContext &Context;
Alex Lorenz735c47e2015-06-15 20:30:22 +000049 StringMap<std::unique_ptr<yaml::MachineFunction>> Functions;
Alex Lorenz5d6108e2015-06-26 22:56:48 +000050 SlotMapping IRSlots;
Alex Lorenz2bdb4e12015-05-27 18:02:19 +000051
52public:
53 MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents, StringRef Filename,
54 LLVMContext &Context);
55
Alex Lorenz735c47e2015-06-15 20:30:22 +000056 void reportDiagnostic(const SMDiagnostic &Diag);
57
58 /// Report an error with the given message at unknown location.
59 ///
60 /// Always returns true.
61 bool error(const Twine &Message);
62
Alex Lorenzb1f9ce82015-07-08 20:22:20 +000063 /// Report an error with the given message at the given location.
64 ///
65 /// Always returns true.
66 bool error(SMLoc Loc, const Twine &Message);
67
Alex Lorenz0fd7c622015-06-30 17:55:00 +000068 /// Report a given error with the location translated from the location in an
69 /// embedded string literal to a location in the MIR file.
70 ///
71 /// Always returns true.
72 bool error(const SMDiagnostic &Error, SMRange SourceRange);
73
Alex Lorenz78d78312015-05-28 22:41:12 +000074 /// Try to parse the optional LLVM module and the machine functions in the MIR
75 /// file.
Alex Lorenz2bdb4e12015-05-27 18:02:19 +000076 ///
Alex Lorenz78d78312015-05-28 22:41:12 +000077 /// Return null if an error occurred.
Alex Lorenz735c47e2015-06-15 20:30:22 +000078 std::unique_ptr<Module> parse();
Alex Lorenz78d78312015-05-28 22:41:12 +000079
80 /// Parse the machine function in the current YAML document.
81 ///
Alex Lorenz8e7a58d72015-06-15 23:07:38 +000082 /// \param NoLLVMIR - set to true when the MIR file doesn't have LLVM IR.
83 /// A dummy IR function is created and inserted into the given module when
84 /// this parameter is true.
85 ///
Alex Lorenz78d78312015-05-28 22:41:12 +000086 /// Return true if an error occurred.
Alex Lorenz8e7a58d72015-06-15 23:07:38 +000087 bool parseMachineFunction(yaml::Input &In, Module &M, bool NoLLVMIR);
Alex Lorenz09b832c2015-05-29 17:05:41 +000088
Alex Lorenz735c47e2015-06-15 20:30:22 +000089 /// Initialize the machine function to the state that's described in the MIR
90 /// file.
91 ///
92 /// Return true if error occurred.
93 bool initializeMachineFunction(MachineFunction &MF);
94
Alex Lorenz4f093bf2015-06-19 17:43:07 +000095 /// Initialize the machine basic block using it's YAML representation.
96 ///
97 /// Return true if an error occurred.
Alex Lorenz7a503fa2015-07-07 17:46:43 +000098 bool initializeMachineBasicBlock(MachineFunction &MF, MachineBasicBlock &MBB,
99 const yaml::MachineBasicBlock &YamlMBB,
100 const PerFunctionMIParsingState &PFS);
Alex Lorenz4f093bf2015-06-19 17:43:07 +0000101
Alex Lorenz54565cf2015-06-24 19:56:10 +0000102 bool initializeRegisterInfo(MachineRegisterInfo &RegInfo,
103 const yaml::MachineFunction &YamlMF);
104
Alex Lorenz09b832c2015-05-29 17:05:41 +0000105private:
Alex Lorenz51af1602015-06-23 22:39:23 +0000106 /// Return a MIR diagnostic converted from an MI string diagnostic.
107 SMDiagnostic diagFromMIStringDiag(const SMDiagnostic &Error,
108 SMRange SourceRange);
109
Alex Lorenz09b832c2015-05-29 17:05:41 +0000110 /// Return a MIR diagnostic converted from an LLVM assembly diagnostic.
111 SMDiagnostic diagFromLLVMAssemblyDiag(const SMDiagnostic &Error,
112 SMRange SourceRange);
Alex Lorenz8e7a58d72015-06-15 23:07:38 +0000113
114 /// Create an empty function with the given name.
115 void createDummyFunction(StringRef Name, Module &M);
Alex Lorenz2bdb4e12015-05-27 18:02:19 +0000116};
117
Alex Lorenz735c47e2015-06-15 20:30:22 +0000118} // end namespace llvm
Alex Lorenz2bdb4e12015-05-27 18:02:19 +0000119
120MIRParserImpl::MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents,
121 StringRef Filename, LLVMContext &Context)
122 : SM(), Filename(Filename), Context(Context) {
123 SM.AddNewSourceBuffer(std::move(Contents), SMLoc());
124}
125
Alex Lorenz735c47e2015-06-15 20:30:22 +0000126bool MIRParserImpl::error(const Twine &Message) {
127 Context.diagnose(DiagnosticInfoMIRParser(
128 DS_Error, SMDiagnostic(Filename, SourceMgr::DK_Error, Message.str())));
129 return true;
Alex Lorenz78d78312015-05-28 22:41:12 +0000130}
Alex Lorenz2bdb4e12015-05-27 18:02:19 +0000131
Alex Lorenzb1f9ce82015-07-08 20:22:20 +0000132bool MIRParserImpl::error(SMLoc Loc, const Twine &Message) {
133 Context.diagnose(DiagnosticInfoMIRParser(
134 DS_Error, SM.GetMessage(Loc, SourceMgr::DK_Error, Message)));
135 return true;
136}
137
Alex Lorenz0fd7c622015-06-30 17:55:00 +0000138bool MIRParserImpl::error(const SMDiagnostic &Error, SMRange SourceRange) {
139 assert(Error.getKind() == SourceMgr::DK_Error && "Expected an error");
140 reportDiagnostic(diagFromMIStringDiag(Error, SourceRange));
141 return true;
142}
143
Alex Lorenz735c47e2015-06-15 20:30:22 +0000144void MIRParserImpl::reportDiagnostic(const SMDiagnostic &Diag) {
145 DiagnosticSeverity Kind;
146 switch (Diag.getKind()) {
147 case SourceMgr::DK_Error:
148 Kind = DS_Error;
149 break;
150 case SourceMgr::DK_Warning:
151 Kind = DS_Warning;
152 break;
153 case SourceMgr::DK_Note:
154 Kind = DS_Note;
155 break;
156 }
157 Context.diagnose(DiagnosticInfoMIRParser(Kind, Diag));
158}
159
160static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context) {
161 reinterpret_cast<MIRParserImpl *>(Context)->reportDiagnostic(Diag);
162}
163
164std::unique_ptr<Module> MIRParserImpl::parse() {
Alex Lorenz78d78312015-05-28 22:41:12 +0000165 yaml::Input In(SM.getMemoryBuffer(SM.getMainFileID())->getBuffer(),
Alex Lorenz735c47e2015-06-15 20:30:22 +0000166 /*Ctxt=*/nullptr, handleYAMLDiag, this);
Alex Lorenz51af1602015-06-23 22:39:23 +0000167 In.setContext(&In);
Alex Lorenz78d78312015-05-28 22:41:12 +0000168
169 if (!In.setCurrentDocument()) {
Alex Lorenz735c47e2015-06-15 20:30:22 +0000170 if (In.error())
Alex Lorenz78d78312015-05-28 22:41:12 +0000171 return nullptr;
172 // Create an empty module when the MIR file is empty.
173 return llvm::make_unique<Module>(Filename, Context);
Alex Lorenz2bdb4e12015-05-27 18:02:19 +0000174 }
175
Alex Lorenz78d78312015-05-28 22:41:12 +0000176 std::unique_ptr<Module> M;
Alex Lorenz8e7a58d72015-06-15 23:07:38 +0000177 bool NoLLVMIR = false;
Alex Lorenz78d78312015-05-28 22:41:12 +0000178 // Parse the block scalar manually so that we can return unique pointer
179 // without having to go trough YAML traits.
180 if (const auto *BSN =
181 dyn_cast_or_null<yaml::BlockScalarNode>(In.getCurrentNode())) {
Alex Lorenz735c47e2015-06-15 20:30:22 +0000182 SMDiagnostic Error;
Alex Lorenz78d78312015-05-28 22:41:12 +0000183 M = parseAssembly(MemoryBufferRef(BSN->getValue(), Filename), Error,
Alex Lorenz5d6108e2015-06-26 22:56:48 +0000184 Context, &IRSlots);
Alex Lorenz09b832c2015-05-29 17:05:41 +0000185 if (!M) {
Alex Lorenz735c47e2015-06-15 20:30:22 +0000186 reportDiagnostic(diagFromLLVMAssemblyDiag(Error, BSN->getSourceRange()));
Alex Lorenz78d78312015-05-28 22:41:12 +0000187 return M;
Alex Lorenz09b832c2015-05-29 17:05:41 +0000188 }
Alex Lorenz78d78312015-05-28 22:41:12 +0000189 In.nextDocument();
190 if (!In.setCurrentDocument())
191 return M;
192 } else {
193 // Create an new, empty module.
194 M = llvm::make_unique<Module>(Filename, Context);
Alex Lorenz8e7a58d72015-06-15 23:07:38 +0000195 NoLLVMIR = true;
Alex Lorenz78d78312015-05-28 22:41:12 +0000196 }
197
198 // Parse the machine functions.
199 do {
Alex Lorenz8e7a58d72015-06-15 23:07:38 +0000200 if (parseMachineFunction(In, *M, NoLLVMIR))
Alex Lorenz78d78312015-05-28 22:41:12 +0000201 return nullptr;
202 In.nextDocument();
203 } while (In.setCurrentDocument());
204
205 return M;
206}
207
Alex Lorenz8e7a58d72015-06-15 23:07:38 +0000208bool MIRParserImpl::parseMachineFunction(yaml::Input &In, Module &M,
209 bool NoLLVMIR) {
Alex Lorenz735c47e2015-06-15 20:30:22 +0000210 auto MF = llvm::make_unique<yaml::MachineFunction>();
211 yaml::yamlize(In, *MF, false);
Alex Lorenz78d78312015-05-28 22:41:12 +0000212 if (In.error())
213 return true;
Alex Lorenz735c47e2015-06-15 20:30:22 +0000214 auto FunctionName = MF->Name;
Alex Lorenzfe2aa972015-06-15 22:23:23 +0000215 if (Functions.find(FunctionName) != Functions.end())
216 return error(Twine("redefinition of machine function '") + FunctionName +
217 "'");
Alex Lorenz735c47e2015-06-15 20:30:22 +0000218 Functions.insert(std::make_pair(FunctionName, std::move(MF)));
Alex Lorenz8e7a58d72015-06-15 23:07:38 +0000219 if (NoLLVMIR)
220 createDummyFunction(FunctionName, M);
Alex Lorenz5ef16b82015-06-16 17:06:29 +0000221 else if (!M.getFunction(FunctionName))
222 return error(Twine("function '") + FunctionName +
223 "' isn't defined in the provided LLVM IR");
Alex Lorenz735c47e2015-06-15 20:30:22 +0000224 return false;
225}
226
Alex Lorenz8e7a58d72015-06-15 23:07:38 +0000227void MIRParserImpl::createDummyFunction(StringRef Name, Module &M) {
228 auto &Context = M.getContext();
229 Function *F = cast<Function>(M.getOrInsertFunction(
230 Name, FunctionType::get(Type::getVoidTy(Context), false)));
231 BasicBlock *BB = BasicBlock::Create(Context, "entry", F);
232 new UnreachableInst(Context, BB);
233}
234
Alex Lorenz735c47e2015-06-15 20:30:22 +0000235bool MIRParserImpl::initializeMachineFunction(MachineFunction &MF) {
236 auto It = Functions.find(MF.getName());
237 if (It == Functions.end())
238 return error(Twine("no machine function information for function '") +
239 MF.getName() + "' in the MIR file");
240 // TODO: Recreate the machine function.
Alex Lorenz5b5f9752015-06-16 00:10:47 +0000241 const yaml::MachineFunction &YamlMF = *It->getValue();
242 if (YamlMF.Alignment)
243 MF.setAlignment(YamlMF.Alignment);
244 MF.setExposesReturnsTwice(YamlMF.ExposesReturnsTwice);
245 MF.setHasInlineAsm(YamlMF.HasInlineAsm);
Alex Lorenz54565cf2015-06-24 19:56:10 +0000246 if (initializeRegisterInfo(MF.getRegInfo(), YamlMF))
247 return true;
248
Alex Lorenz7a503fa2015-07-07 17:46:43 +0000249 PerFunctionMIParsingState PFS;
Alex Lorenz4f093bf2015-06-19 17:43:07 +0000250 const auto &F = *MF.getFunction();
251 for (const auto &YamlMBB : YamlMF.BasicBlocks) {
252 const BasicBlock *BB = nullptr;
Alex Lorenzb1f9ce82015-07-08 20:22:20 +0000253 const yaml::StringValue &Name = YamlMBB.Name;
254 if (!Name.Value.empty()) {
Alex Lorenz4f093bf2015-06-19 17:43:07 +0000255 BB = dyn_cast_or_null<BasicBlock>(
Alex Lorenzb1f9ce82015-07-08 20:22:20 +0000256 F.getValueSymbolTable().lookup(Name.Value));
Alex Lorenz00302df2015-06-19 20:12:03 +0000257 if (!BB)
Alex Lorenzb1f9ce82015-07-08 20:22:20 +0000258 return error(Name.SourceRange.Start,
259 Twine("basic block '") + Name.Value +
260 "' is not defined in the function '" + MF.getName() +
261 "'");
Alex Lorenz4f093bf2015-06-19 17:43:07 +0000262 }
263 auto *MBB = MF.CreateMachineBasicBlock(BB);
264 MF.insert(MF.end(), MBB);
Alex Lorenz7a503fa2015-07-07 17:46:43 +0000265 bool WasInserted =
266 PFS.MBBSlots.insert(std::make_pair(YamlMBB.ID, MBB)).second;
Alex Lorenz33f0aef2015-06-26 16:46:11 +0000267 if (!WasInserted)
268 return error(Twine("redefinition of machine basic block with id #") +
269 Twine(YamlMBB.ID));
270 }
271
272 // Initialize the machine basic blocks after creating them all so that the
273 // machine instructions parser can resolve the MBB references.
274 unsigned I = 0;
275 for (const auto &YamlMBB : YamlMF.BasicBlocks) {
276 if (initializeMachineBasicBlock(MF, *MF.getBlockNumbered(I++), YamlMBB,
Alex Lorenz7a503fa2015-07-07 17:46:43 +0000277 PFS))
Alex Lorenz4f093bf2015-06-19 17:43:07 +0000278 return true;
279 }
280 return false;
281}
282
283bool MIRParserImpl::initializeMachineBasicBlock(
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000284 MachineFunction &MF, MachineBasicBlock &MBB,
Alex Lorenz33f0aef2015-06-26 16:46:11 +0000285 const yaml::MachineBasicBlock &YamlMBB,
Alex Lorenz7a503fa2015-07-07 17:46:43 +0000286 const PerFunctionMIParsingState &PFS) {
Alex Lorenz4f093bf2015-06-19 17:43:07 +0000287 MBB.setAlignment(YamlMBB.Alignment);
288 if (YamlMBB.AddressTaken)
289 MBB.setHasAddressTaken();
290 MBB.setIsLandingPad(YamlMBB.IsLandingPad);
Alex Lorenzf09df002015-06-30 18:16:42 +0000291 SMDiagnostic Error;
292 // Parse the successors.
293 for (const auto &MBBSource : YamlMBB.Successors) {
294 MachineBasicBlock *SuccMBB = nullptr;
Alex Lorenz7a503fa2015-07-07 17:46:43 +0000295 if (parseMBBReference(SuccMBB, SM, MF, MBBSource.Value, PFS, IRSlots,
Alex Lorenzf09df002015-06-30 18:16:42 +0000296 Error))
297 return error(Error, MBBSource.SourceRange);
298 // TODO: Report an error when adding the same successor more than once.
299 MBB.addSuccessor(SuccMBB);
300 }
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000301 // Parse the instructions.
302 for (const auto &MISource : YamlMBB.Instructions) {
Alex Lorenz3708a642015-06-30 17:47:50 +0000303 MachineInstr *MI = nullptr;
Alex Lorenz7a503fa2015-07-07 17:46:43 +0000304 if (parseMachineInstr(MI, SM, MF, MISource.Value, PFS, IRSlots, Error))
Alex Lorenz0fd7c622015-06-30 17:55:00 +0000305 return error(Error, MISource.SourceRange);
Alex Lorenz3708a642015-06-30 17:47:50 +0000306 MBB.insert(MBB.end(), MI);
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000307 }
Alex Lorenz78d78312015-05-28 22:41:12 +0000308 return false;
Alex Lorenz2bdb4e12015-05-27 18:02:19 +0000309}
310
Alex Lorenz54565cf2015-06-24 19:56:10 +0000311bool MIRParserImpl::initializeRegisterInfo(
312 MachineRegisterInfo &RegInfo, const yaml::MachineFunction &YamlMF) {
313 assert(RegInfo.isSSA());
314 if (!YamlMF.IsSSA)
315 RegInfo.leaveSSA();
316 assert(RegInfo.tracksLiveness());
317 if (!YamlMF.TracksRegLiveness)
318 RegInfo.invalidateLiveness();
319 RegInfo.enableSubRegLiveness(YamlMF.TracksSubRegLiveness);
320 return false;
321}
322
Alex Lorenz51af1602015-06-23 22:39:23 +0000323SMDiagnostic MIRParserImpl::diagFromMIStringDiag(const SMDiagnostic &Error,
324 SMRange SourceRange) {
325 assert(SourceRange.isValid() && "Invalid source range");
326 SMLoc Loc = SourceRange.Start;
327 bool HasQuote = Loc.getPointer() < SourceRange.End.getPointer() &&
328 *Loc.getPointer() == '\'';
329 // Translate the location of the error from the location in the MI string to
330 // the corresponding location in the MIR file.
331 Loc = Loc.getFromPointer(Loc.getPointer() + Error.getColumnNo() +
332 (HasQuote ? 1 : 0));
333
334 // TODO: Translate any source ranges as well.
335 return SM.GetMessage(Loc, Error.getKind(), Error.getMessage(), None,
336 Error.getFixIts());
337}
338
Alex Lorenz09b832c2015-05-29 17:05:41 +0000339SMDiagnostic MIRParserImpl::diagFromLLVMAssemblyDiag(const SMDiagnostic &Error,
340 SMRange SourceRange) {
341 assert(SourceRange.isValid());
342
343 // Translate the location of the error from the location in the llvm IR string
344 // to the corresponding location in the MIR file.
345 auto LineAndColumn = SM.getLineAndColumn(SourceRange.Start);
346 unsigned Line = LineAndColumn.first + Error.getLineNo() - 1;
347 unsigned Column = Error.getColumnNo();
348 StringRef LineStr = Error.getLineContents();
349 SMLoc Loc = Error.getLoc();
350
351 // Get the full line and adjust the column number by taking the indentation of
352 // LLVM IR into account.
353 for (line_iterator L(*SM.getMemoryBuffer(SM.getMainFileID()), false), E;
354 L != E; ++L) {
355 if (L.line_number() == Line) {
356 LineStr = *L;
357 Loc = SMLoc::getFromPointer(LineStr.data());
358 auto Indent = LineStr.find(Error.getLineContents());
359 if (Indent != StringRef::npos)
360 Column += Indent;
361 break;
362 }
363 }
364
365 return SMDiagnostic(SM, Loc, Filename, Line, Column, Error.getKind(),
366 Error.getMessage(), LineStr, Error.getRanges(),
367 Error.getFixIts());
368}
369
Alex Lorenz735c47e2015-06-15 20:30:22 +0000370MIRParser::MIRParser(std::unique_ptr<MIRParserImpl> Impl)
371 : Impl(std::move(Impl)) {}
372
373MIRParser::~MIRParser() {}
374
375std::unique_ptr<Module> MIRParser::parseLLVMModule() { return Impl->parse(); }
376
377bool MIRParser::initializeMachineFunction(MachineFunction &MF) {
378 return Impl->initializeMachineFunction(MF);
379}
380
381std::unique_ptr<MIRParser> llvm::createMIRParserFromFile(StringRef Filename,
382 SMDiagnostic &Error,
383 LLVMContext &Context) {
Alex Lorenz2bdb4e12015-05-27 18:02:19 +0000384 auto FileOrErr = MemoryBuffer::getFile(Filename);
385 if (std::error_code EC = FileOrErr.getError()) {
386 Error = SMDiagnostic(Filename, SourceMgr::DK_Error,
387 "Could not open input file: " + EC.message());
Alex Lorenz735c47e2015-06-15 20:30:22 +0000388 return nullptr;
Alex Lorenz2bdb4e12015-05-27 18:02:19 +0000389 }
Alex Lorenz735c47e2015-06-15 20:30:22 +0000390 return createMIRParser(std::move(FileOrErr.get()), Context);
Alex Lorenz2bdb4e12015-05-27 18:02:19 +0000391}
392
Alex Lorenz735c47e2015-06-15 20:30:22 +0000393std::unique_ptr<MIRParser>
394llvm::createMIRParser(std::unique_ptr<MemoryBuffer> Contents,
395 LLVMContext &Context) {
Alex Lorenz2bdb4e12015-05-27 18:02:19 +0000396 auto Filename = Contents->getBufferIdentifier();
Alex Lorenz735c47e2015-06-15 20:30:22 +0000397 return llvm::make_unique<MIRParser>(
398 llvm::make_unique<MIRParserImpl>(std::move(Contents), Filename, Context));
Alex Lorenz2bdb4e12015-05-27 18:02:19 +0000399}