-// The useful interface defined by this file... Parse an ASCII file, and return
-// the internal representation in a nice slice'n'dice'able representation.
-//
-Module *llvm::ParseAssemblyFile(const std::string &Filename) {
- FILE *F = stdin;
-
- if (Filename != "-") {
- F = fopen(Filename.c_str(), "r");
-
- if (F == 0)
- throw ParseException(Filename, "Could not open file '" + Filename + "'");
- }
-
- Module *Result;
- try {
- Result = RunVMAsmParser(Filename, F);
- } catch (...) {
- if (F != stdin) fclose(F); // Make sure to close file descriptor if an
- throw; // exception is thrown
- }
-
- if (F != stdin)
- fclose(F);
-
- return Result;
+Module *llvm::ParseAssembly(MemoryBuffer *F,
+ Module *M,
+ SMDiagnostic &Err,
+ LLVMContext &Context) {
+ SourceMgr SM;
+ SM.AddNewSourceBuffer(F, SMLoc());
+
+ // If we are parsing into an existing module, do it.
+ if (M)
+ return LLParser(F, SM, Err, M).Run() ? nullptr : M;
+
+ // Otherwise create a new module.
+ std::unique_ptr<Module> M2(new Module(F->getBufferIdentifier(), Context));
+ if (LLParser(F, SM, Err, M2.get()).Run())
+ return nullptr;
+ return M2.release();