diff options
author | Dan Gohman <gohman@apple.com> | 2009-09-02 17:18:19 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-09-02 17:18:19 +0000 |
commit | 2ec5fe524c6ab957524fa02422b026cfe168d948 (patch) | |
tree | cd6d88f5b95a397f6220aca1e69cfca836fdb46b /lib/AsmParser | |
parent | 3445d9a72aec68512df265705e2be7704496f541 (diff) | |
download | external_llvm-2ec5fe524c6ab957524fa02422b026cfe168d948.zip external_llvm-2ec5fe524c6ab957524fa02422b026cfe168d948.tar.gz external_llvm-2ec5fe524c6ab957524fa02422b026cfe168d948.tar.bz2 |
Refactor common code from ParseAssemblyString and ParseAssemblyFile,
to expose a low-level interface for parsing from an existing MemoryBuffer.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80803 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AsmParser')
-rw-r--r-- | lib/AsmParser/Parser.cpp | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp index d66c13d..3fc913b 100644 --- a/lib/AsmParser/Parser.cpp +++ b/lib/AsmParser/Parser.cpp @@ -21,6 +21,25 @@ #include <cstring> using namespace llvm; +Module *llvm::ParseAssembly(MemoryBuffer *F, + const std::string &Name, + 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() ? 0 : M; + + // Otherwise create a new module. + OwningPtr<Module> M2(new Module(Name, Context)); + if (LLParser(F, SM, Err, M2.get()).Run()) + return 0; + return M2.take(); +} + Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err, LLVMContext &Context) { std::string ErrorStr; @@ -31,13 +50,7 @@ Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err, return 0; } - SourceMgr SM; - SM.AddNewSourceBuffer(F, SMLoc()); - - OwningPtr<Module> M(new Module(Filename, Context)); - if (LLParser(F, SM, Err, M.get()).Run()) - return 0; - return M.take(); + return ParseAssembly(F, Filename, 0, Err, Context); } Module *llvm::ParseAssemblyString(const char *AsmString, Module *M, @@ -45,17 +58,6 @@ Module *llvm::ParseAssemblyString(const char *AsmString, Module *M, MemoryBuffer *F = MemoryBuffer::getMemBuffer(AsmString, AsmString+strlen(AsmString), "<string>"); - - 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() ? 0 : M; - - // Otherwise create a new module. - OwningPtr<Module> M2(new Module("<string>", Context)); - if (LLParser(F, SM, Err, M2.get()).Run()) - return 0; - return M2.take(); + return ParseAssembly(F, "<string>", M, Err, Context); } |