1 //===- Parser.cpp - Main dispatch module for the Parser library -----------===//
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 library implements the functionality defined in llvm/Assembly/Parser.h
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Assembly/Parser.h"
16 #include "llvm/Module.h"
17 #include "llvm/ADT/OwningPtr.h"
18 #include "llvm/Support/SourceMgr.h"
19 #include "llvm/Support/MemoryBuffer.h"
20 #include "llvm/Support/raw_ostream.h"
24 Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err,
25 LLVMContext &Context) {
27 OwningPtr<MemoryBuffer>
28 F(MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr));
30 Err = SMDiagnostic("", -1, -1,
31 "Could not open input file '" + Filename + "'", "");
35 OwningPtr<Module> M(new Module(Filename, Context));
36 if (LLParser(F.get(), Err, M.get()).Run())
41 Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
42 SMDiagnostic &Err, LLVMContext &Context) {
43 OwningPtr<MemoryBuffer>
44 F(MemoryBuffer::getMemBuffer(AsmString, AsmString+strlen(AsmString),
47 // If we are parsing into an existing module, do it.
49 return LLParser(F.get(), Err, M).Run() ? 0 : M;
51 // Otherwise create a new module.
52 OwningPtr<Module> M2(new Module("<string>", Context));
53 if (LLParser(F.get(), Err, M2.get()).Run())