summaryrefslogtreecommitdiffstats
path: root/lib/AsmParser/Parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/AsmParser/Parser.cpp')
-rw-r--r--lib/AsmParser/Parser.cpp39
1 files changed, 20 insertions, 19 deletions
diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp
index d66c13d..331a233 100644
--- a/lib/AsmParser/Parser.cpp
+++ b/lib/AsmParser/Parser.cpp
@@ -21,6 +21,24 @@
#include <cstring>
using namespace llvm;
+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() ? 0 : M;
+
+ // Otherwise create a new module.
+ OwningPtr<Module> M2(new Module(F->getBufferIdentifier(), 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 +49,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, 0, Err, Context);
}
Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
@@ -45,17 +57,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, M, Err, Context);
}
OpenPOWER on IntegriCloud