mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
Refactor common code from ParseAssemblyString and ParseAssemblyFile,
to expose a low-level interface for parsing from an existing MemoryBuffer. llvm-svn: 80803
This commit is contained in:
parent
58b376193d
commit
3f7a370991
@ -19,6 +19,7 @@
|
|||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
class Module;
|
class Module;
|
||||||
|
class MemoryBuffer;
|
||||||
class SMDiagnostic;
|
class SMDiagnostic;
|
||||||
class raw_ostream;
|
class raw_ostream;
|
||||||
class LLVMContext;
|
class LLVMContext;
|
||||||
@ -48,6 +49,17 @@ Module *ParseAssemblyString(
|
|||||||
LLVMContext &Context
|
LLVMContext &Context
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// This function is the low-level interface to the LLVM Assembly Parser.
|
||||||
|
/// ParseAssemblyFile and ParseAssemblyString are wrappers around this function.
|
||||||
|
/// @brief Parse LLVM Assembly from a MemoryBuffer.
|
||||||
|
Module *ParseAssembly(
|
||||||
|
MemoryBuffer *F, ///< The MemoryBuffer containing assembly
|
||||||
|
const std::string &Name, ///< The name of the original source file
|
||||||
|
Module *M, ///< A module to add the assembly too.
|
||||||
|
SMDiagnostic &Err, ///< Error result info.
|
||||||
|
LLVMContext &Context
|
||||||
|
);
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -21,6 +21,25 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
using namespace llvm;
|
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,
|
Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err,
|
||||||
LLVMContext &Context) {
|
LLVMContext &Context) {
|
||||||
std::string ErrorStr;
|
std::string ErrorStr;
|
||||||
@ -31,13 +50,7 @@ Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceMgr SM;
|
return ParseAssembly(F, Filename, 0, Err, Context);
|
||||||
SM.AddNewSourceBuffer(F, SMLoc());
|
|
||||||
|
|
||||||
OwningPtr<Module> M(new Module(Filename, Context));
|
|
||||||
if (LLParser(F, SM, Err, M.get()).Run())
|
|
||||||
return 0;
|
|
||||||
return M.take();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
|
Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
|
||||||
@ -45,17 +58,6 @@ Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
|
|||||||
MemoryBuffer *F =
|
MemoryBuffer *F =
|
||||||
MemoryBuffer::getMemBuffer(AsmString, AsmString+strlen(AsmString),
|
MemoryBuffer::getMemBuffer(AsmString, AsmString+strlen(AsmString),
|
||||||
"<string>");
|
"<string>");
|
||||||
|
|
||||||
SourceMgr SM;
|
|
||||||
SM.AddNewSourceBuffer(F, SMLoc());
|
|
||||||
|
|
||||||
// If we are parsing into an existing module, do it.
|
return ParseAssembly(F, "<string>", M, Err, Context);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user