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::ParseAssembly(MemoryBuffer *F,
25 const std::string &Name,
28 LLVMContext &Context) {
30 SM.AddNewSourceBuffer(F, SMLoc());
32 // If we are parsing into an existing module, do it.
34 return LLParser(F, SM, Err, M).Run() ? 0 : M;
36 // Otherwise create a new module.
37 OwningPtr<Module> M2(new Module(Name, Context));
38 if (LLParser(F, SM, Err, M2.get()).Run())
43 Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err,
44 LLVMContext &Context) {
46 MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr);
48 Err = SMDiagnostic("", -1, -1,
49 "Could not open input file '" + Filename + "'", "");
53 return ParseAssembly(F, Filename, 0, Err, Context);
56 Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
57 SMDiagnostic &Err, LLVMContext &Context) {
59 MemoryBuffer::getMemBuffer(AsmString, AsmString+strlen(AsmString),
62 return ParseAssembly(F, "<string>", M, Err, Context);